10 #include "../misc/coding/coding.h" 15 #include "../../helper/string.h" 20 #define chk_fwrite(data, size, count, file) \ 21 if (fwrite(data, size, count, file) != count) goto fail; 46 size_t width, height, x;
49 if (width == 0 && height == 0) {
56 return x/8 + (x%8 > 0);
58 return (width*height + 7)/8;
67 return height*width/8;
70 return (height+7)/8*width;
72 return width*((height+7)/8);
81 if (x > width || y > height)
return FALSE;
88 i=(buffer[(y / 8 * width) + x] & (1 << (y % 8)));
98 i=(buffer[pixel / 8] & (1 << (7 - (pixel % 8))));
101 i=(buffer[(9 * y) + (x / 8)] & (1 << (7 - (x % 8))));
118 buffer[(y / 8 * width)+x] |= 1 << (y % 8);
128 buffer[pixel / 8] |= 1 << (7 - (pixel % 8));
131 buffer[(9 * y) + (x / 8)] |= 1 << (7 - (x % 8));
135 if ((height % 8) != 0) pixel++;
136 buffer[(pixel * x) + (y / 8)] |= 1 << (7 - (y % 8));
143 size_t width, height, x,y;
199 size_t width, height, x, y;
203 if (width == 0 && height == 0) {
210 for (x=0;x<width;x++) {
211 for (y=0;y<height;y++) {
290 size_t startx=0,endx=0,setx=0, starty=0,endy=0,sety=0, x, y;
298 endx = startx + width;
307 endy = starty + height;
313 for (x=startx;x<endx;x++) {
314 for (y=starty;y<endy;y++) {
323 size_t x,i,sizeimage,buffpos=0;
325 unsigned char buff[1];
329 unsigned char header[]={
353 if (file!=NULL) isfile=
TRUE;
366 if (x!=0) sizeimage++;
386 dbgprintf(NULL,
"Data size in BMP file: %ld\n", (
long)sizeimage);
387 division=div(sizeimage,256);
388 header[35]=division.quot;
389 header[34]=sizeimage-(division.quot*256);
390 sizeimage=sizeimage+
sizeof(header);
391 dbgprintf(NULL,
"Size of BMP file: %ld\n", (
long)sizeimage);
392 division=div(sizeimage,256);
393 header[3]=division.quot;
394 header[2]=sizeimage-(division.quot*256);
399 memcpy(buffer,header,
sizeof(header));
400 buffpos +=
sizeof(header);
414 memcpy (buffer+buffpos,buff,1);
433 memcpy (buffer+buffpos,buff,1);
443 memcpy (buffer+buffpos,buff,1);
465 unsigned char buffer[1000];
473 if (pos2==7) buffer[pos]=0;
477 if (pos2<0) {pos2=7;pos++;}
480 if (pos2!=7) {pos2=7;pos++;}
485 if (division.rem!=0) division.quot++;
513 header[6] = bitmap->
Number - 1;
518 for (i=0;i<bitmap->
Number;i++) {
537 if (buffer == NULL) {
544 buffer[current++] =
'1';
546 buffer[current++] =
'0';
563 'N',
'G',
'G',0x00,0x01,0x00,
583 int country = 0,net = 0;
585 'N',
'O',
'L',0x00,0x01,0x00,
599 header[6] = country%256;
600 header[7] = country/256;
617 fprintf(file,
"/* XPM */\n");
618 fprintf(file,
"static char * ala_xpm[] = {\n");
619 fprintf(file,
"\"%ld %ld 2 1\",\n",
622 fprintf(file,
"\". s c m #000000 g4 #000000 g #000000 c #000000\",\n");
623 fprintf(file,
"\"# s c m #ffffff g4 #ffffff g #ffffff c #ffffff\",\n");
635 fprintf(file,
"};\n");
647 unsigned char header[]={
648 'F',
'O',
'R',
'M', 0x01,0xFE,
649 'N',
'S',
'L',
'D', 0x01,0xF8};
662 unsigned char buffer[4];
681 file = fopen(FileName,
"wb");
685 if (strcasestr(FileName,
".nlm")) {
687 }
else if (strcasestr(FileName,
".ngg")) {
689 }
else if (strcasestr(FileName,
".nol")) {
691 }
else if (strcasestr(FileName,
".xpm")) {
693 }
else if (strcasestr(FileName,
".nsl")) {
695 }
else if (strcasestr(FileName,
".wbmp")) {
708 unsigned char buff[60];
709 size_t w,h,x,i,buffpos=0;
717 if (file!=NULL) isfile=
TRUE;
721 readbytes = fread(buff, 1, 54, file);
724 memcpy(buff,buffer,54);
728 h=buff[22]+256*buff[21];
729 w=buff[18]+256*buff[17];
730 dbgprintf(NULL,
"Image Size in BMP file: %ldx%ld\n", (
long)w, (
long)h);
735 dbgprintf(NULL,
"Height %ld %ld width %ld %ld\n",
744 dbgprintf(NULL,
"Number of colors in BMP file: ");
746 case 1 :
dbgprintf(NULL,
"2 (supported)\n");
break;
747 case 4 :
dbgprintf(NULL,
"16 (NOT SUPPORTED)\n");
break;
748 case 8 :
dbgprintf(NULL,
"256 (NOT SUPPORTED)\n");
break;
749 case 24 :
dbgprintf(NULL,
"True Color (NOT SUPPORTED)\n");
break;
750 default :
dbgprintf(NULL,
"unknown\n");
break;
754 dbgprintf(NULL,
"Wrong number of colors\n");
759 dbgprintf(NULL,
"Compression in BMP file: ");
761 case 0 :
dbgprintf(NULL,
"no compression (supported)\n");
break;
762 case 1 :
dbgprintf(NULL,
"RLE8 (NOT SUPPORTED)\n");
break;
763 case 2 :
dbgprintf(NULL,
"RLE4 (NOT SUPPORTED)\n");
break;
764 default :
dbgprintf(NULL,
"unknown\n");
break;
768 dbgprintf(NULL,
"Compression type not supported\n");
775 readbytes = fread(buff, 1, pos, file);
780 memcpy (buff,buffer+54,pos);
783 first_white = ((buff[6] * buff[5] * buff[4]) > (buff[2] * buff[1] * buff[0]));
785 dbgprintf(NULL,
"First color in BMP file: #%02x%02x%02x%s\n",
786 buff[2], buff[1], buff[0],
787 first_white ?
" (used as white)" :
" (used as black)" 789 dbgprintf(NULL,
"Second color in BMP file: #%02x%02x%02x%s\n",
790 buff[6], buff[5], buff[4],
791 !first_white ?
" (used as white)" :
" (used as black)" 797 for (y=h-1;y>=0;y--) {
803 readbytes = fread(buff, 1, 1, file);
806 memcpy (buff,buffer+buffpos,1);
817 if (x<=bitmap->BitmapWidth && (
size_t)y<=bitmap->BitmapHeight) {
834 readbytes = fread(buff, 1, 1, file);
837 memcpy (buff,buffer+buffpos,1);
848 dbgprintf(NULL,
"Data size in BMP file: %i\n",sizeimage);
864 unsigned char buffer[1000];
865 size_t pos,x,y,h,w,i,number;
870 readbytes = fread(buffer,1,5,file);
873 readbytes = fread(buffer,1,1,file);
896 readbytes = fread(buffer,1,4,file);
898 number = buffer[0] + 1;
901 for (i=0;i<number;i++) {
909 if (division.rem!=0) division.quot++;
910 if (fread(buffer,1,(division.quot*h),file)!=(
unsigned int)(division.quot*h))
return ERR_UNKNOWN;
917 if ((buffer[pos]&(1<<pos2))>0) {
918 if (y<bitmap->Bitmap[i].BitmapHeight && x<bitmap->Bitmap[i].BitmapWidth)
GSM_SetPointBitmap(&bitmap->
Bitmap[i],x,y);
922 if (pos2<0) {pos2=7;pos++;}
925 if (pos2!=7) {pos2=7;pos++;}
935 unsigned char buffer[2000];
939 readbytes = fread(buffer, 1, 6, file);
944 readbytes = fread(buffer, 1, 4, file);
946 sprintf(bitmap->
Bitmap[0].
NetworkCode,
"%d %02d", buffer[0]+256*buffer[1], buffer[2]);
950 readbytes = fread(buffer, 1, 4, file);
960 readbytes = fread(buffer, 1, 6, file);
966 for (i=0; i<w*h; i++) {
970 if (x==w) {x=0; y++;}
975 if (fread(buffer, 1, 1, file) == 1) {
976 dbgprintf(NULL,
"Fileinfo: %c",buffer[0]);
977 while (fread(buffer, 1, 1, file)==1) {
978 if (buffer[0]!=0x0A)
dbgprintf(NULL,
"%c",buffer[0]);
989 unsigned char block[6],buffer[505];
994 while (fread(block,1,6,file)==6) {
995 block_size = block[4]*256 + block[5];
996 dbgprintf(NULL,
"Block %c%c%c%c, size %ld\n",block[0],block[1],block[2],block[3],(
long)block_size);
997 if (!strncmp(block,
"FORM", 4)) {
1001 if (block_size!=0) {
1002 readbytes = fread(buffer,1,block_size,file);
1005 buffer[block_size]=0;
1007 if (!strncmp(block,
"VERS", 4))
dbgprintf(NULL,
"File saved by: %s\n",buffer);
1008 if (!strncmp(block,
"MODL", 4))
dbgprintf(NULL,
"Logo saved from: %s\n",buffer);
1009 if (!strncmp(block,
"COMM", 4))
dbgprintf(NULL,
"Phone was connected to COM port: %s\n",buffer);
1011 if (!strncmp(block,
"NSLD", 4)) {
1017 dbgprintf(NULL,
"Startup logo (size %ld)\n",(
long)block_size);
1028 unsigned char buffer[10000];
1031 readbytes = fread(buffer,1,4,file);
1037 readbytes = fread(buffer,1,10000,file);
1050 size_t readbytes=0, length=0;
1053 fstat(fileno(file), &st);
1059 readbytes = fread(buffer, 1, length, file);
1061 dbgprintf(NULL,
"Length %ld name \"%s\"\n", (
long)length,
1076 unsigned char buffer[300];
1078 char *file_only_name;
1081 file = fopen(FileName,
"rb");
1084 file_only_name = strrchr(FileName,
'/');
1085 if (file_only_name == NULL) {
1086 file_only_name = strrchr(FileName,
'\\');
1090 if (file_only_name == NULL) {
1091 file_only_name = FileName;
1095 len = strlen(file_only_name);
1104 if (fread(buffer, 1, 9, file) != 9) {
1113 if (memcmp(buffer,
"BM",2)==0) {
1115 }
else if (buffer[0] == 0x00 && buffer[1] == 0x00) {
1117 }
else if (memcmp(buffer,
"NLM",3)==0) {
1119 }
else if (memcmp(buffer,
"NOL",3)==0) {
1121 }
else if (memcmp(buffer,
"NGG",3)==0) {
1123 }
else if (memcmp(buffer,
"FORM",4)==0) {
1125 }
else if (memcmp(buffer,
"GIF",3)==0) {
1134 size_t Width, Height;
1136 Buffer[(*Length)++] = 0x00;
1138 Buffer[(*Length)++] = Width;
1139 Buffer[(*Length)++] = Height;
1140 Buffer[(*Length)++] = 0x01;
static void PHONE_SetPointBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int x, int y, int width, int height)
GSM_Error BMP2Bitmap(unsigned char *buffer, FILE *file, GSM_Bitmap *bitmap)
char * DecodeUnicodeString(const unsigned char *src)
size_t PHONE_GetBitmapSize(GSM_Phone_Bitmap_Types Type, size_t Width, size_t Height)
static GSM_Error PrivSaveNGGNOL(FILE *file, GSM_MultiBitmap *bitmap)
unsigned char Sender[2 *(GSM_MAX_NUMBER_LENGTH+1)]
static GSM_Error PrivSaveNLMWBMP(FILE *file, GSM_Bitmap *Bitmap)
#define GSM_MAX_MULTI_BITMAP
int ClearBit(unsigned char *Buffer, size_t BitNum)
void PHONE_EncodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
gboolean FileSystemPicture
GSM_BinaryPicture_Types Type
static GSM_Error savengg(FILE *file, GSM_MultiBitmap *bitmap)
void PHONE_DecodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
static GSM_Error savenlm(FILE *file, GSM_MultiBitmap *bitmap)
unsigned char BitmapPoints[GSM_BITMAP_SIZE]
#define chk_fwrite(data, size, count, file)
static GSM_Error savenol(FILE *file, GSM_MultiBitmap *bitmap)
void NOKIA_CopyBitmap(GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, size_t *Length)
void GSM_ResizeBitmap(GSM_Bitmap *dest, GSM_Bitmap *src, size_t width, size_t height)
static GSM_Error savexpm(FILE *file, GSM_MultiBitmap *bitmap)
void GSM_PrintBitmap(FILE *file, GSM_Bitmap *bitmap)
void EncodeUnicode(unsigned char *dest, const char *src, size_t len)
#define GSM_BITMAP_TEXT_LENGTH
static GSM_Error loadbmp(FILE *file, GSM_MultiBitmap *bitmap)
gboolean GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y)
static GSM_Error savebmp(FILE *file, GSM_MultiBitmap *bitmap)
static GSM_Error loadnsl(FILE *file, GSM_MultiBitmap *bitmap)
static GSM_Error savewbmp(FILE *file, GSM_MultiBitmap *bitmap)
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
GSM_Error GSM_SaveBitmapFile(char *FileName, GSM_MultiBitmap *bitmap)
unsigned char Name[2 *(GSM_BITMAP_TEXT_LENGTH+1)]
int SetBit(unsigned char *Buffer, size_t BitNum)
GSM_BinaryPicture BinaryPic
void GSM_ClearBitmap(GSM_Bitmap *bmp)
static GSM_Error loadgif(FILE *file, GSM_MultiBitmap *bitmap)
void GSM_ReverseBitmap(GSM_Bitmap *Bitmap)
void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, size_t *width, size_t *height)
size_t GSM_GetBitmapSize(GSM_Bitmap *bmp)
static gboolean PHONE_IsPointBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int x, int y, int width, int height)
void GSM_ClearPointBitmap(GSM_Bitmap *bmp, int x, int y)
unsigned char Text[2 *(GSM_BITMAP_TEXT_LENGTH+1)]
static GSM_Error savensl(FILE *file, GSM_MultiBitmap *bitmap)
void GSM_SetPointBitmap(GSM_Bitmap *bmp, int x, int y)
void PHONE_ClearBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, size_t width, size_t height)
static GSM_Error loadnolngg(FILE *file, GSM_MultiBitmap *bitmap, gboolean nolformat)
static GSM_Error loadwbmp(FILE *file, GSM_MultiBitmap *bitmap)
GSM_Error GSM_ReadBitmapFile(char *FileName, GSM_MultiBitmap *bitmap)
int GetBit(unsigned char *Buffer, size_t BitNum)
void GSM_GetMaxBitmapWidthHeight(GSM_Bitmap_Types Type, size_t *width, size_t *height)
static GSM_Error loadnlm(FILE *file, GSM_MultiBitmap *bitmap)
GSM_Error Bitmap2BMP(unsigned char *buffer, FILE *file, GSM_Bitmap *bitmap)