Gammu internals  1.38.0
gsmlogo.c File Reference
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <gammu-debug.h>
#include "../misc/coding/coding.h"
#include "../debug.h"
#include "gsmlogo.h"
#include "gsmnet.h"
#include "../../helper/string.h"
Include dependency graph for gsmlogo.c:

Go to the source code of this file.

Macros

#define _GNU_SOURCE
 
#define chk_fwrite(data, size, count, file)   if (fwrite(data, size, count, file) != count) goto fail;
 

Functions

void PHONE_GetBitmapWidthHeight (GSM_Phone_Bitmap_Types Type, size_t *width, size_t *height)
 
size_t PHONE_GetBitmapSize (GSM_Phone_Bitmap_Types Type, size_t Width, size_t Height)
 
static gboolean PHONE_IsPointBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, int x, int y, int width, int height)
 
static void PHONE_SetPointBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, int x, int y, int width, int height)
 
void PHONE_DecodeBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
 
void PHONE_ClearBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, size_t width, size_t height)
 
void PHONE_EncodeBitmap (GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
 
void GSM_GetMaxBitmapWidthHeight (GSM_Bitmap_Types Type, size_t *width, size_t *height)
 
void GSM_SetPointBitmap (GSM_Bitmap *bmp, int x, int y)
 
void GSM_ClearPointBitmap (GSM_Bitmap *bmp, int x, int y)
 
gboolean GSM_IsPointBitmap (GSM_Bitmap *bmp, int x, int y)
 
void GSM_ClearBitmap (GSM_Bitmap *bmp)
 
size_t GSM_GetBitmapSize (GSM_Bitmap *bmp)
 
void GSM_PrintBitmap (FILE *file, GSM_Bitmap *bitmap)
 
void GSM_ReverseBitmap (GSM_Bitmap *Bitmap)
 
void GSM_ResizeBitmap (GSM_Bitmap *dest, GSM_Bitmap *src, size_t width, size_t height)
 
GSM_Error Bitmap2BMP (unsigned char *buffer, FILE *file, GSM_Bitmap *bitmap)
 
static GSM_Error savebmp (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error PrivSaveNLMWBMP (FILE *file, GSM_Bitmap *Bitmap)
 
static GSM_Error savenlm (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error PrivSaveNGGNOL (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error savengg (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error savenol (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error savexpm (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error savensl (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error savewbmp (FILE *file, GSM_MultiBitmap *bitmap)
 
GSM_Error GSM_SaveBitmapFile (char *FileName, GSM_MultiBitmap *bitmap)
 
GSM_Error BMP2Bitmap (unsigned char *buffer, FILE *file, GSM_Bitmap *bitmap)
 
static GSM_Error loadbmp (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error loadnlm (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error loadnolngg (FILE *file, GSM_MultiBitmap *bitmap, gboolean nolformat)
 
static GSM_Error loadnsl (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error loadwbmp (FILE *file, GSM_MultiBitmap *bitmap)
 
static GSM_Error loadgif (FILE *file, GSM_MultiBitmap *bitmap)
 
GSM_Error GSM_ReadBitmapFile (char *FileName, GSM_MultiBitmap *bitmap)
 
void NOKIA_CopyBitmap (GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, size_t *Length)
 

Macro Definition Documentation

§ _GNU_SOURCE

#define _GNU_SOURCE

Definition at line 3 of file gsmlogo.c.

§ chk_fwrite

#define chk_fwrite (   data,
  size,
  count,
  file 
)    if (fwrite(data, size, count, file) != count) goto fail;

Helper define to check error code from fwrite.

Definition at line 20 of file gsmlogo.c.

Referenced by Bitmap2BMP(), PrivSaveNGGNOL(), PrivSaveNLMWBMP(), savengg(), savenlm(), savenol(), savensl(), and savewbmp().

Function Documentation

§ Bitmap2BMP()

GSM_Error Bitmap2BMP ( unsigned char *  buffer,
FILE *  file,
GSM_Bitmap bitmap 
)

Definition at line 321 of file gsmlogo.c.

References GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, chk_fwrite, dbgprintf, ERR_NONE, ERR_WRITING_FILE, FALSE, GSM_IsPointBitmap(), and TRUE.

Referenced by savebmp().

322 {
323  size_t x,i,sizeimage,buffpos=0;
324  ssize_t y, pos;
325  unsigned char buff[1];
326  div_t division;
327  gboolean isfile=FALSE;
328 
329  unsigned char header[]={
330 /*1'st header*/ 'B','M', /* BMP file ID */
331  0x00,0x00,0x00,0x00, /* Size of file */
332  0x00,0x00, /* Reserved for future use */
333  0x00,0x00, /* Reserved for future use */
334  62,0x00,0x00,0x00, /* Offset for image data */
335 
336 /*2'nd header*/ 40,0x00,0x00,0x00, /* Length of this part of header */
337  0x00,0x00,0x00,0x00, /* Width of image */
338  0x00,0x00,0x00,0x00, /* Height of image */
339  1,0x00, /* How many planes in target device */
340  1,0x00, /* How many colors in image. 1 means 2^1=2 colors */
341  0x00,0x00,0x00,0x00, /* Type of compression. 0 means no compression */
342 /*Sometimes */ 0x00,0x00,0x00,0x00, /* Size of part with image data */
343 /*ttttttt...*/ 0xE8,0x03,0x00,0x00, /* XPelsPerMeter */
344 /*hhiiiiissss*/ 0xE8,0x03,0x00,0x00, /* YPelsPerMeter */
345 /*part of header*/0x02,0x00,0x00,0x00, /* How many colors from palette is used */
346 /*doesn't exist*/ 0x00,0x00,0x00,0x00, /* How many colors from palette is required to display image. 0 means all */
347 
348 /*Color palette*/ 0x00,0x00,0x00, /* First color in palette in Blue, Green, Red. Here white */
349  0x00, /* Each color in palette is end by 4'th byte */
350  102, 204, 102, /* Second color in palette in Blue, Green, Red. Here green */
351  0x00}; /* Each color in palette is end by 4'th byte */
352 
353  if (file!=NULL) isfile=TRUE;
354 
355  header[22]=bitmap->BitmapHeight;
356  header[18]=bitmap->BitmapWidth;
357 
358  pos = 7;
359  sizeimage = 0;
360  /*lines are written from the last to the first*/
361  for (y = bitmap->BitmapHeight - 1; y >= 0; y--) {
362  i=1;
363  for (x=0;x<bitmap->BitmapWidth;x++) {
364  /*new byte !*/
365  if (pos==7) {
366  if (x!=0) sizeimage++;
367  i++;
368  /*each line is written in multiply of 4 bytes*/
369  if(i==5) i=1;
370  }
371  pos--;
372  /*going to new byte*/
373  if (pos<0) pos=7;
374  }
375  /*going to new byte*/
376  pos=7;
377  sizeimage++;
378  if (i!=1) {
379  /*each line is written in multiply of 4 bytes*/
380  while (i!=5) {
381  sizeimage++;
382  i++;
383  }
384  }
385  }
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);
395 
396  if (isfile) {
397  chk_fwrite(header,1,sizeof(header),file);
398  } else {
399  memcpy(buffer,header,sizeof(header));
400  buffpos += sizeof(header);
401  }
402 
403  pos=7;
404  /*lines are written from the last to the first*/
405  for (y=bitmap->BitmapHeight-1;y>=0;y--) {
406  i=1;
407  for (x=0;x<bitmap->BitmapWidth;x++) {
408  /*new byte !*/
409  if (pos==7) {
410  if (x!=0) {
411  if (isfile) {
412  chk_fwrite(buff, 1, sizeof(buff), file);
413  } else {
414  memcpy (buffer+buffpos,buff,1);
415  buffpos++;
416  }
417  }
418  i++;
419  /*each line is written in multiply of 4 bytes*/
420  if(i==5) i=1;
421  buff[0]=0;
422  }
423  if (!GSM_IsPointBitmap(bitmap,x,y)) buff[0]|=(1<<pos);
424  pos--;
425  /*going to new byte*/
426  if (pos<0) pos=7;
427  }
428  /*going to new byte*/
429  pos=7;
430  if (isfile) {
431  chk_fwrite(buff, 1, sizeof(buff), file);
432  } else {
433  memcpy (buffer+buffpos,buff,1);
434  buffpos++;
435  }
436  if (i!=1) {
437  /*each line is written in multiply of 4 bytes*/
438  while (i!=5) {
439  buff[0]=0;
440  if (isfile) {
441  chk_fwrite(buff, 1, sizeof(buff), file);
442  } else {
443  memcpy (buffer+buffpos,buff,1);
444  buffpos++;
445  }
446  i++;
447  }
448  }
449  }
450  return ERR_NONE;
451 fail:
452  return ERR_WRITING_FILE;
453 }
#define chk_fwrite(data, size, count, file)
Definition: gsmlogo.c:20
int gboolean
Definition: gammu-types.h:23
#define FALSE
Definition: gammu-types.h:25
gboolean GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:238
#define dbgprintf
Definition: debug.h:72
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156
#define TRUE
Definition: gammu-types.h:28

§ BMP2Bitmap()

GSM_Error BMP2Bitmap ( unsigned char *  buffer,
FILE *  file,
GSM_Bitmap bitmap 
)

Definition at line 705 of file gsmlogo.c.

References GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, dbgprintf, ERR_FILENOTSUPPORTED, ERR_NONE, FALSE, GSM_ClearBitmap(), GSM_GetMaxBitmapWidthHeight(), GSM_None, GSM_SetPointBitmap(), GSM_StartupLogo, TRUE, and GSM_Bitmap::Type.

Referenced by loadbmp().

706 {
707  gboolean first_white,isfile=FALSE;
708  unsigned char buff[60];
709  size_t w,h,x,i,buffpos=0;
710  ssize_t y, pos;
711  size_t readbytes;
712 #ifdef DEBUG
713  int sizeimage=0;
714 #endif
715 
716  if (bitmap->Type == GSM_None) bitmap->Type = GSM_StartupLogo;
717  if (file!=NULL) isfile=TRUE;
718 
719  /* Read the header */
720  if (isfile) {
721  readbytes = fread(buff, 1, 54, file);
722  if (readbytes != 54) return ERR_FILENOTSUPPORTED;
723  } else {
724  memcpy(buff,buffer,54);
725  }
726 
727  /* height and width of image in the file */
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);
731 
732  GSM_GetMaxBitmapWidthHeight(bitmap->Type, &bitmap->BitmapWidth, &bitmap->BitmapHeight);
733  if (h<bitmap->BitmapHeight) bitmap->BitmapHeight=h;
734  if (w<bitmap->BitmapWidth) bitmap->BitmapWidth=w;
735  dbgprintf(NULL, "Height %ld %ld width %ld %ld\n",
736  (long)h,
737  (long)bitmap->BitmapHeight,
738  (long)w,
739  (long)bitmap->BitmapWidth);
740 
741  GSM_ClearBitmap(bitmap);
742 
743 #ifdef DEBUG
744  dbgprintf(NULL, "Number of colors in BMP file: ");
745  switch (buff[28]) {
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;
751  }
752 #endif
753  if (buff[28]!=1) {
754  dbgprintf(NULL, "Wrong number of colors\n");
755  return ERR_FILENOTSUPPORTED;
756  }
757 
758 #ifdef DEBUG
759  dbgprintf(NULL, "Compression in BMP file: ");
760  switch (buff[30]) {
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;
765  }
766 #endif
767  if (buff[30]!=0) {
768  dbgprintf(NULL, "Compression type not supported\n");
769  return ERR_FILENOTSUPPORTED;
770  }
771 
772  /* Read palette */
773  if (isfile) {
774  pos=buff[10]-54;
775  readbytes = fread(buff, 1, pos, file);
776  if (readbytes != (size_t)pos) return ERR_FILENOTSUPPORTED;
777  } else {
778  pos=buff[10]-54;
779  buffpos=buff[10];
780  memcpy (buff,buffer+54,pos);
781  }
782 
783  first_white = ((buff[6] * buff[5] * buff[4]) > (buff[2] * buff[1] * buff[0]));
784 #ifdef DEBUG
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)"
788  );
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)"
792  );
793 #endif
794 
795  pos=7;
796  /* lines are written from the last to the first */
797  for (y=h-1;y>=0;y--) {
798  i=1;
799  for (x=0;x<w;x++) {
800  /* new byte ! */
801  if (pos==7) {
802  if (isfile) {
803  readbytes = fread(buff, 1, 1, file);
804  if (readbytes != 1) return ERR_FILENOTSUPPORTED;
805  } else {
806  memcpy (buff,buffer+buffpos,1);
807  buffpos++;
808  }
809 #ifdef DEBUG
810  sizeimage++;
811 #endif
812  i++;
813  /* each line is written in multiply of 4 bytes */
814  if(i==5) i=1;
815  }
816  /* we have top left corner ! */
817  if (x<=bitmap->BitmapWidth && (size_t)y<=bitmap->BitmapHeight) {
818  if (first_white) {
819  if ((buff[0]&(1<<pos))<=0) GSM_SetPointBitmap(bitmap,x,y);
820  } else {
821  if ((buff[0]&(1<<pos))>0) GSM_SetPointBitmap(bitmap,x,y);
822  }
823  }
824  pos--;
825  /* going to new byte */
826  if (pos<0) pos=7;
827  }
828  /* going to new byte */
829  pos=7;
830  if (i!=1) {
831  /* each line is written in multiply of 4 bytes */
832  while (i!=5) {
833  if (isfile) {
834  readbytes = fread(buff, 1, 1, file);
835  if (readbytes != 1) return ERR_FILENOTSUPPORTED;
836  } else {
837  memcpy (buff,buffer+buffpos,1);
838  buffpos++;
839  }
840 #ifdef DEBUG
841  sizeimage++;
842 #endif
843  i++;
844  }
845  }
846  }
847 #ifdef DEBUG
848  dbgprintf(NULL, "Data size in BMP file: %i\n",sizeimage);
849 #endif
850  return(ERR_NONE);
851 }
GSM_Bitmap_Types Type
Definition: gammu-bitmap.h:107
int gboolean
Definition: gammu-types.h:23
#define FALSE
Definition: gammu-types.h:25
#define dbgprintf
Definition: debug.h:72
void GSM_ClearBitmap(GSM_Bitmap *bmp)
Definition: gsmlogo.c:247
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156
void GSM_SetPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:228
#define TRUE
Definition: gammu-types.h:28
void GSM_GetMaxBitmapWidthHeight(GSM_Bitmap_Types Type, size_t *width, size_t *height)
Definition: gsmlogo.c:217

§ GSM_GetBitmapSize()

size_t GSM_GetBitmapSize ( GSM_Bitmap bmp)

Definition at line 252 of file gsmlogo.c.

References GSM_Bitmap::BitmapHeight, and GSM_Bitmap::BitmapWidth.

Referenced by GSM_ClearBitmap().

253 {
254  return ((bmp->BitmapWidth * bmp->BitmapHeight) / 8) + 1;
255 }
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156

§ GSM_GetMaxBitmapWidthHeight()

void GSM_GetMaxBitmapWidthHeight ( GSM_Bitmap_Types  Type,
size_t *  width,
size_t *  height 
)

Definition at line 217 of file gsmlogo.c.

References GSM_CallerGroupLogo, GSM_OperatorLogo, GSM_PictureImage, and GSM_StartupLogo.

Referenced by BMP2Bitmap(), loadnlm(), and loadnolngg().

218 {
219  switch (Type) {
220  case GSM_CallerGroupLogo: *width=72; *height=14; break;
221  case GSM_OperatorLogo : *width=101;*height=21; break;
222  case GSM_StartupLogo : *width=96; *height=65; break;
223  case GSM_PictureImage : *width=72; *height=28; break;
224  default : break;
225  }
226 }

§ GSM_ResizeBitmap()

void GSM_ResizeBitmap ( GSM_Bitmap dest,
GSM_Bitmap src,
size_t  width,
size_t  height 
)

Definition at line 288 of file gsmlogo.c.

References GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, GSM_ClearBitmap(), GSM_IsPointBitmap(), and GSM_SetPointBitmap().

Referenced by GSM_EncodeEMSMultiPartSMS(), and PHONE_EncodeBitmap().

289 {
290  size_t startx=0,endx=0,setx=0, starty=0,endy=0,sety=0, x, y;
291 
292  if (src->BitmapWidth<=width) {
293  startx = 0;
294  endx = src->BitmapWidth;
295  setx = (width-src->BitmapWidth)/2;
296  } else {
297  startx = (src->BitmapWidth-width)/2;
298  endx = startx + width;
299  setx = 0;
300  }
301  if (src->BitmapHeight<=height) {
302  starty = 0;
303  endy = src->BitmapHeight;
304  sety = (height-src->BitmapHeight)/2;
305  } else {
306  starty = (src->BitmapHeight-height)/2;
307  endy = starty + height;
308  sety = 0;
309  }
310  dest->BitmapHeight = height;
311  dest->BitmapWidth = width;
312  GSM_ClearBitmap(dest);
313  for (x=startx;x<endx;x++) {
314  for (y=starty;y<endy;y++) {
315  if (GSM_IsPointBitmap(src,x,y))
316  GSM_SetPointBitmap(dest,setx+x-startx,sety+y-starty);
317  }
318  }
319 }
gboolean GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:238
void GSM_ClearBitmap(GSM_Bitmap *bmp)
Definition: gsmlogo.c:247
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156
void GSM_SetPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:228

§ GSM_ReverseBitmap()

void GSM_ReverseBitmap ( GSM_Bitmap Bitmap)

Definition at line 273 of file gsmlogo.c.

References GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, GSM_ClearPointBitmap(), GSM_IsPointBitmap(), and GSM_SetPointBitmap().

Referenced by loadwbmp().

274 {
275  size_t x, y;
276 
277  for (x=0;x<Bitmap->BitmapWidth;x++) {
278  for (y=0;y<Bitmap->BitmapHeight;y++) {
279  if (GSM_IsPointBitmap(Bitmap,x,y)) {
280  GSM_ClearPointBitmap(Bitmap, x, y);
281  } else {
282  GSM_SetPointBitmap(Bitmap, x, y);
283  }
284  }
285  }
286 }
gboolean GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:238
size_t BitmapHeight
Definition: gammu-bitmap.h:152
void GSM_ClearPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:233
size_t BitmapWidth
Definition: gammu-bitmap.h:156
void GSM_SetPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:228

§ loadbmp()

static GSM_Error loadbmp ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 853 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, BMP2Bitmap(), and GSM_MultiBitmap::Number.

Referenced by GSM_ReadBitmapFile().

854 {
855  GSM_Error error;
856 
857  error=BMP2Bitmap(NULL,file,&bitmap->Bitmap[0]);
858  bitmap->Number = 1;
859  return error;
860 }
GSM_Error BMP2Bitmap(unsigned char *buffer, FILE *file, GSM_Bitmap *bitmap)
Definition: gsmlogo.c:705
GSM_Error
Definition: gammu-error.h:23
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
unsigned char Number
Definition: gammu-bitmap.h:188

§ loadgif()

static GSM_Error loadgif ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 1045 of file gsmlogo.c.

References GSM_Bitmap::BinaryPic, GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, GSM_BinaryPicture::Buffer, dbgprintf, DecodeUnicodeString(), ERR_FILENOTSUPPORTED, ERR_MOREMEMORY, ERR_NONE, GSM_PictureBinary, GSM_BinaryPicture::Length, GSM_Bitmap::Name, GSM_MultiBitmap::Number, PICTURE_GIF, GSM_BinaryPicture::Type, and GSM_Bitmap::Type.

Referenced by GSM_ReadBitmapFile().

1046 {
1047  GSM_Bitmap *bmap = &bitmap->Bitmap[0];
1048  char *buffer=NULL;
1049  struct stat st;
1050  size_t readbytes=0, length=0;
1051 
1052  dbgprintf(NULL, "loading gif file\n");
1053  fstat(fileno(file), &st);
1054  bmap->BinaryPic.Length = length = st.st_size;
1055  bmap->BinaryPic.Buffer = buffer = (char *)malloc(length);
1056  if (bmap->BinaryPic.Buffer == NULL)
1057  return ERR_MOREMEMORY;
1058 
1059  readbytes = fread(buffer, 1, length, file);
1060  if (readbytes != length) return ERR_FILENOTSUPPORTED;
1061  dbgprintf(NULL, "Length %ld name \"%s\"\n", (long)length,
1062  DecodeUnicodeString(bmap->Name));
1063 
1064  bmap->Type = GSM_PictureBinary;
1065  bmap->BinaryPic.Type = PICTURE_GIF;
1066  bmap->BitmapWidth = 256 * buffer[7] + buffer[6];
1067  bmap->BitmapHeight = 256 * buffer[9] + buffer[8];
1068  bitmap->Number = 1;
1069 
1070  return ERR_NONE;
1071 }
char * DecodeUnicodeString(const unsigned char *src)
Definition: coding.c:245
GSM_Bitmap_Types Type
Definition: gammu-bitmap.h:107
GSM_BinaryPicture_Types Type
Definition: gammu-bitmap.h:44
unsigned char * Buffer
Definition: gammu-bitmap.h:45
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
unsigned char Name[2 *(GSM_BITMAP_TEXT_LENGTH+1)]
Definition: gammu-bitmap.h:176
GSM_BinaryPicture BinaryPic
Definition: gammu-bitmap.h:172
#define dbgprintf
Definition: debug.h:72
unsigned char Number
Definition: gammu-bitmap.h:188
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156

§ loadnlm()

static GSM_Error loadnlm ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 862 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, dbgprintf, ERR_FILENOTSUPPORTED, ERR_NONE, ERR_UNKNOWN, GSM_CallerGroupLogo, GSM_ClearBitmap(), GSM_GetMaxBitmapWidthHeight(), GSM_MAX_MULTI_BITMAP, GSM_None, GSM_OperatorLogo, GSM_PictureImage, GSM_SetPointBitmap(), GSM_StartupLogo, GSM_MultiBitmap::Number, and GSM_Bitmap::Type.

Referenced by GSM_ReadBitmapFile().

863 {
864  unsigned char buffer[1000];
865  size_t pos,x,y,h,w,i,number;
866  ssize_t pos2;
867  div_t division;
868  size_t readbytes;
869 
870  readbytes = fread(buffer,1,5,file);
871  if (readbytes != 5) return ERR_FILENOTSUPPORTED;
872 
873  readbytes = fread(buffer,1,1,file);
874  if (readbytes != 1) return ERR_FILENOTSUPPORTED;
875 
876  switch (buffer[0]) {
877  case 0x00:
878  dbgprintf(NULL, "Operator logo\n");
879  if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_OperatorLogo;
880  break;
881  case 0x01:
882  dbgprintf(NULL, "Caller logo\n");
883  if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_CallerGroupLogo;
884  break;
885  case 0x02:
886  dbgprintf(NULL, "Startup logo\n");
887  if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_StartupLogo;
888  break;
889  case 0x03:
890  dbgprintf(NULL, "Picture Image logo\n");
891  if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_PictureImage;
892  break;
893  }
894 
895  bitmap->Number = 0;
896  readbytes = fread(buffer,1,4,file);
897  if (readbytes != 4) return ERR_FILENOTSUPPORTED;
898  number = buffer[0] + 1;
899  w = buffer[1];
900  h = buffer[2];
901  for (i=0;i<number;i++) {
902  bitmap->Bitmap[i].Type = bitmap->Bitmap[0].Type;
903  GSM_GetMaxBitmapWidthHeight(bitmap->Bitmap[i].Type, &bitmap->Bitmap[i].BitmapWidth, &bitmap->Bitmap[i].BitmapHeight);
904  if (h < bitmap->Bitmap[i].BitmapHeight) bitmap->Bitmap[i].BitmapHeight = h;
905  if (w < bitmap->Bitmap[i].BitmapWidth) bitmap->Bitmap[i].BitmapWidth = w;
906 
907  division=div(w,8);
908  /* For startup logos */
909  if (division.rem!=0) division.quot++;
910  if (fread(buffer,1,(division.quot*h),file)!=(unsigned int)(division.quot*h)) return ERR_UNKNOWN;
911 
912  GSM_ClearBitmap(&bitmap->Bitmap[i]);
913 
914  pos=0;pos2=7;
915  for (y=0;y<h;y++) {
916  for (x=0;x<w;x++) {
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);
919  }
920  pos2--;
921  /* going to new byte */
922  if (pos2<0) {pos2=7;pos++;}
923  }
924  /* for startup logos-new line means new byte */
925  if (pos2!=7) {pos2=7;pos++;}
926  }
927  bitmap->Number++;
928  if (bitmap->Number == GSM_MAX_MULTI_BITMAP) break;
929  }
930  return (ERR_NONE);
931 }
GSM_Bitmap_Types Type
Definition: gammu-bitmap.h:107
#define GSM_MAX_MULTI_BITMAP
Definition: gammu-limits.h:281
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
#define dbgprintf
Definition: debug.h:72
unsigned char Number
Definition: gammu-bitmap.h:188
void GSM_ClearBitmap(GSM_Bitmap *bmp)
Definition: gsmlogo.c:247
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156
void GSM_SetPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:228
void GSM_GetMaxBitmapWidthHeight(GSM_Bitmap_Types Type, size_t *width, size_t *height)
Definition: gsmlogo.c:217

§ loadnolngg()

static GSM_Error loadnolngg ( FILE *  file,
GSM_MultiBitmap bitmap,
gboolean  nolformat 
)
static

Definition at line 933 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, dbgprintf, ERR_FILENOTSUPPORTED, ERR_NONE, GSM_CallerGroupLogo, GSM_ClearBitmap(), GSM_GetMaxBitmapWidthHeight(), GSM_None, GSM_OperatorLogo, GSM_SetPointBitmap(), GSM_Bitmap::NetworkCode, GSM_MultiBitmap::Number, and GSM_Bitmap::Type.

Referenced by GSM_ReadBitmapFile().

934 {
935  unsigned char buffer[2000];
936  size_t i,h,w,x,y;
937  size_t readbytes;
938 
939  readbytes = fread(buffer, 1, 6, file);
940  if (readbytes != 6) return ERR_FILENOTSUPPORTED;
941 
942  if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_CallerGroupLogo;
943  if (nolformat) {
944  readbytes = fread(buffer, 1, 4, file);
945  if (readbytes != 4) return ERR_FILENOTSUPPORTED;
946  sprintf(bitmap->Bitmap[0].NetworkCode, "%d %02d", buffer[0]+256*buffer[1], buffer[2]);
947  if (bitmap->Bitmap[0].Type == GSM_None) bitmap->Bitmap[0].Type = GSM_OperatorLogo;
948  }
949 
950  readbytes = fread(buffer, 1, 4, file);
951  if (readbytes != 4) return ERR_FILENOTSUPPORTED;
952 
953  w = buffer[0];
954  h = buffer[2];
955  GSM_GetMaxBitmapWidthHeight(bitmap->Bitmap[0].Type, &bitmap->Bitmap[0].BitmapWidth, &bitmap->Bitmap[0].BitmapHeight);
956  if (h < bitmap->Bitmap[0].BitmapHeight) bitmap->Bitmap[0].BitmapHeight = h;
957  if (w < bitmap->Bitmap[0].BitmapWidth) bitmap->Bitmap[0].BitmapWidth = w;
958 
959  /* Unknown bytes. */
960  readbytes = fread(buffer, 1, 6, file);
961  if (readbytes != 6) return ERR_FILENOTSUPPORTED;
962 
963  GSM_ClearBitmap(&bitmap->Bitmap[0]);
964 
965  x=0; y=0;
966  for (i=0; i<w*h; i++) {
967  if (fread(buffer, 1, 1, file)!=1) return ERR_FILENOTSUPPORTED;
968  if (buffer[0]=='1') GSM_SetPointBitmap(&bitmap->Bitmap[0],x,y);
969  x++;
970  if (x==w) {x=0; y++;}
971  }
972 
973 #ifdef DEBUG
974  /* Some programs writes here fileinfo */
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]);
979  }
980  dbgprintf(NULL, "\n");
981  }
982 #endif
983  bitmap->Number = 1;
984  return(ERR_NONE);
985 }
GSM_Bitmap_Types Type
Definition: gammu-bitmap.h:107
char NetworkCode[10]
Definition: gammu-bitmap.h:160
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
#define dbgprintf
Definition: debug.h:72
unsigned char Number
Definition: gammu-bitmap.h:188
void GSM_ClearBitmap(GSM_Bitmap *bmp)
Definition: gsmlogo.c:247
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156
void GSM_SetPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:228
void GSM_GetMaxBitmapWidthHeight(GSM_Bitmap_Types Type, size_t *width, size_t *height)
Definition: gsmlogo.c:217

§ loadnsl()

static GSM_Error loadnsl ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 987 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, dbgprintf, ERR_FILENOTSUPPORTED, ERR_NONE, GSM_NokiaStartupLogo, GSM_None, GSM_MultiBitmap::Number, PHONE_DecodeBitmap(), and GSM_Bitmap::Type.

Referenced by GSM_ReadBitmapFile().

988 {
989  unsigned char block[6],buffer[505];
990  size_t block_size;
991  size_t readbytes;
992  GSM_Bitmap_Types OldType;
993 
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)) {
998  dbgprintf(NULL, "File ID\n");
999  } else {
1000  if (block_size>504) return ERR_FILENOTSUPPORTED;
1001  if (block_size!=0) {
1002  readbytes = fread(buffer,1,block_size,file);
1003  if (readbytes != block_size) return ERR_FILENOTSUPPORTED;
1004  /* if it's string, we end it with 0 */
1005  buffer[block_size]=0;
1006 #ifdef DEBUG
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);
1010 #endif
1011  if (!strncmp(block, "NSLD", 4)) {
1012  bitmap->Bitmap[0].BitmapHeight = 48;
1013  bitmap->Bitmap[0].BitmapWidth = 84;
1014  OldType = bitmap->Bitmap[0].Type;
1015  PHONE_DecodeBitmap(GSM_NokiaStartupLogo, buffer, &bitmap->Bitmap[0]);
1016  if (OldType != GSM_None) bitmap->Bitmap[0].Type = OldType;
1017  dbgprintf(NULL, "Startup logo (size %ld)\n",(long)block_size);
1018  }
1019  }
1020  }
1021  }
1022  bitmap->Number = 1;
1023  return(ERR_NONE);
1024 }
GSM_Bitmap_Types Type
Definition: gammu-bitmap.h:107
GSM_Bitmap_Types
Definition: gammu-bitmap.h:54
void PHONE_DecodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
Definition: gsmlogo.c:141
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
#define dbgprintf
Definition: debug.h:72
unsigned char Number
Definition: gammu-bitmap.h:188
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156

§ loadwbmp()

static GSM_Error loadwbmp ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 1026 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, ERR_FILENOTSUPPORTED, ERR_NONE, GSM_Nokia7110OperatorLogo, GSM_ReverseBitmap(), GSM_MultiBitmap::Number, and PHONE_DecodeBitmap().

Referenced by GSM_ReadBitmapFile().

1027 {
1028  unsigned char buffer[10000];
1029  size_t readbytes;
1030 
1031  readbytes = fread(buffer,1,4,file);
1032  if (readbytes != 4) return ERR_FILENOTSUPPORTED;
1033  bitmap->Bitmap[0].BitmapWidth = buffer[2];
1034  bitmap->Bitmap[0].BitmapHeight = buffer[3];
1035  bitmap->Number = 1;
1036 
1037  readbytes = fread(buffer,1,10000,file);
1038  /* FIXME: Decode function should receive how long is the buffer! */
1039  PHONE_DecodeBitmap(GSM_Nokia7110OperatorLogo, buffer, &bitmap->Bitmap[0]);
1040  GSM_ReverseBitmap(&bitmap->Bitmap[0]);
1041 
1042  return ERR_NONE;
1043 }
void PHONE_DecodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
Definition: gsmlogo.c:141
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
unsigned char Number
Definition: gammu-bitmap.h:188
void GSM_ReverseBitmap(GSM_Bitmap *Bitmap)
Definition: gsmlogo.c:273
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156

§ NOKIA_CopyBitmap()

void NOKIA_CopyBitmap ( GSM_Phone_Bitmap_Types  Type,
GSM_Bitmap Bitmap,
char *  Buffer,
size_t *  Length 
)

Definition at line 1132 of file gsmlogo.c.

References PHONE_EncodeBitmap(), PHONE_GetBitmapSize(), and PHONE_GetBitmapWidthHeight().

Referenced by GSM_EncodeMultiPartSMS(), and GSM_EncodeSMS30MultiPartSMS().

1133 {
1134  size_t Width, Height;
1135 
1136  Buffer[(*Length)++] = 0x00;
1137  PHONE_GetBitmapWidthHeight(Type, &Width, &Height);
1138  Buffer[(*Length)++] = Width;
1139  Buffer[(*Length)++] = Height;
1140  Buffer[(*Length)++] = 0x01;
1141  PHONE_EncodeBitmap(Type, Buffer + (*Length), Bitmap);
1142  (*Length) = (*Length) + PHONE_GetBitmapSize(Type,0,0);
1143 }
size_t PHONE_GetBitmapSize(GSM_Phone_Bitmap_Types Type, size_t Width, size_t Height)
Definition: gsmlogo.c:44
void PHONE_EncodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
Definition: gsmlogo.c:197
void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, size_t *width, size_t *height)
Definition: gsmlogo.c:23

§ PHONE_ClearBitmap()

void PHONE_ClearBitmap ( GSM_Phone_Bitmap_Types  Type,
char *  buffer,
size_t  width,
size_t  height 
)

Definition at line 192 of file gsmlogo.c.

References PHONE_GetBitmapSize().

Referenced by PHONE_EncodeBitmap().

193 {
194  memset(buffer,0,PHONE_GetBitmapSize(Type,width,height));
195 }
size_t PHONE_GetBitmapSize(GSM_Phone_Bitmap_Types Type, size_t Width, size_t Height)
Definition: gsmlogo.c:44

§ PHONE_DecodeBitmap()

void PHONE_DecodeBitmap ( GSM_Phone_Bitmap_Types  Type,
char *  buffer,
GSM_Bitmap Bitmap 
)

Definition at line 141 of file gsmlogo.c.

References GSM_Bitmap::BitmapEnabled, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, GSM_Bitmap::DefaultBitmap, GSM_Bitmap::DefaultName, GSM_Bitmap::DefaultRingtone, FALSE, GSM_Bitmap::FileSystemPicture, GSM_AlcatelBMMIPicture, GSM_CallerGroupLogo, GSM_ClearBitmap(), GSM_EMSBigPicture, GSM_EMSMediumPicture, GSM_EMSSmallPicture, GSM_EMSVariablePicture, GSM_Nokia6210StartupLogo, GSM_Nokia6510OperatorLogo, GSM_Nokia7110OperatorLogo, GSM_Nokia7110StartupLogo, GSM_NokiaCallerLogo, GSM_NokiaOperatorLogo, GSM_NokiaPictureImage, GSM_NokiaStartupLogo, GSM_OperatorLogo, GSM_PictureImage, GSM_SetPointBitmap(), GSM_StartupLogo, GSM_Bitmap::ID, GSM_Bitmap::Location, GSM_Bitmap::Name, GSM_Bitmap::NetworkCode, PHONE_GetBitmapWidthHeight(), PHONE_IsPointBitmap(), GSM_Bitmap::RingtoneID, GSM_Bitmap::Sender, GSM_Bitmap::Text, and GSM_Bitmap::Type.

Referenced by GSM_DecodeEMSMultiPartSMS(), GSM_DecodeMultiPartSMS(), GSM_DecodeNokiaProfile(), loadnsl(), loadwbmp(), and N71_65_DecodePhonebook().

142 {
143  size_t width, height, x,y;
144 
145  PHONE_GetBitmapWidthHeight(Type, &width, &height);
147  Bitmap->BitmapHeight = height;
148  Bitmap->BitmapWidth = width;
149  }
150  switch (Type) {
151  case GSM_NokiaOperatorLogo :
153  case GSM_Nokia6510OperatorLogo : Bitmap->Type=GSM_OperatorLogo; break;
154  case GSM_NokiaCallerLogo : Bitmap->Type=GSM_CallerGroupLogo; break;
156  case GSM_NokiaStartupLogo :
158  case GSM_Nokia6210StartupLogo : Bitmap->Type=GSM_StartupLogo; break;
159  case GSM_NokiaPictureImage :
161  case GSM_EMSSmallPicture :
162  case GSM_EMSMediumPicture :
163  case GSM_EMSBigPicture : Bitmap->Type=GSM_PictureImage; break;
164  }
165 
166  Bitmap->Location = 0;
167  Bitmap->Text[0] = 0;
168  Bitmap->Text[1] = 0;
169  Bitmap->BitmapEnabled = FALSE;
170  Bitmap->DefaultName = FALSE;
171  Bitmap->DefaultBitmap = FALSE;
172  Bitmap->DefaultRingtone = FALSE;
173  Bitmap->RingtoneID = 0;
174  Bitmap->FileSystemPicture = 0;
175  Bitmap->NetworkCode[0] = 0;
176  Bitmap->Sender[0] = 0;
177  Bitmap->Sender[1] = 0;
178  Bitmap->ID = 0;
179  Bitmap->Name[0] = 0;
180  Bitmap->Name[1] = 0;
181 
182  GSM_ClearBitmap(Bitmap);
183  for (x=0;x<Bitmap->BitmapWidth;x++) {
184  for (y=0;y<Bitmap->BitmapHeight;y++) {
185  if (PHONE_IsPointBitmap(Type, buffer, x, y, Bitmap->BitmapWidth, Bitmap->BitmapHeight)) {
186  GSM_SetPointBitmap(Bitmap,x,y);
187  }
188  }
189  }
190 }
gboolean DefaultRingtone
Definition: gammu-bitmap.h:134
unsigned char ID
Definition: gammu-bitmap.h:168
GSM_Bitmap_Types Type
Definition: gammu-bitmap.h:107
unsigned char Sender[2 *(GSM_MAX_NUMBER_LENGTH+1)]
Definition: gammu-bitmap.h:164
gboolean FileSystemPicture
Definition: gammu-bitmap.h:144
unsigned char Location
Definition: gammu-bitmap.h:112
char NetworkCode[10]
Definition: gammu-bitmap.h:160
unsigned char RingtoneID
Definition: gammu-bitmap.h:138
#define FALSE
Definition: gammu-types.h:25
gboolean BitmapEnabled
Definition: gammu-bitmap.h:122
gboolean DefaultBitmap
Definition: gammu-bitmap.h:130
unsigned char Name[2 *(GSM_BITMAP_TEXT_LENGTH+1)]
Definition: gammu-bitmap.h:176
void GSM_ClearBitmap(GSM_Bitmap *bmp)
Definition: gsmlogo.c:247
gboolean DefaultName
Definition: gammu-bitmap.h:126
void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, size_t *width, size_t *height)
Definition: gsmlogo.c:23
size_t BitmapHeight
Definition: gammu-bitmap.h:152
static gboolean PHONE_IsPointBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int x, int y, int width, int height)
Definition: gsmlogo.c:77
size_t BitmapWidth
Definition: gammu-bitmap.h:156
unsigned char Text[2 *(GSM_BITMAP_TEXT_LENGTH+1)]
Definition: gammu-bitmap.h:118
void GSM_SetPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:228

§ PHONE_EncodeBitmap()

void PHONE_EncodeBitmap ( GSM_Phone_Bitmap_Types  Type,
char *  buffer,
GSM_Bitmap Bitmap 
)

Definition at line 197 of file gsmlogo.c.

References GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, GSM_IsPointBitmap(), GSM_ResizeBitmap(), PHONE_ClearBitmap(), PHONE_GetBitmapWidthHeight(), and PHONE_SetPointBitmap().

Referenced by GSM_EncodeEMSMultiPartSMS(), GSM_EncodeMultiPartSMS(), NOKIA_CopyBitmap(), and savensl().

198 {
199  size_t width, height, x, y;
200  GSM_Bitmap dest;
201 
202  PHONE_GetBitmapWidthHeight(Type, &width, &height);
203  if (width == 0 && height == 0) {
204  width = Bitmap->BitmapWidth;
205  height = Bitmap->BitmapHeight;
206  }
207  GSM_ResizeBitmap(&dest, Bitmap, width, height);
208  PHONE_ClearBitmap(Type, buffer, width, height);
209 
210  for (x=0;x<width;x++) {
211  for (y=0;y<height;y++) {
212  if (GSM_IsPointBitmap(&dest,x,y)) PHONE_SetPointBitmap(Type, buffer, x, y, width, height);
213  }
214  }
215 }
static void PHONE_SetPointBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int x, int y, int width, int height)
Definition: gsmlogo.c:109
void GSM_ResizeBitmap(GSM_Bitmap *dest, GSM_Bitmap *src, size_t width, size_t height)
Definition: gsmlogo.c:288
gboolean GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:238
void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, size_t *width, size_t *height)
Definition: gsmlogo.c:23
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156
void PHONE_ClearBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, size_t width, size_t height)
Definition: gsmlogo.c:192

§ PHONE_GetBitmapSize()

size_t PHONE_GetBitmapSize ( GSM_Phone_Bitmap_Types  Type,
size_t  Width,
size_t  Height 
)

Definition at line 44 of file gsmlogo.c.

References GSM_AlcatelBMMIPicture, GSM_EMSBigPicture, GSM_EMSMediumPicture, GSM_EMSSmallPicture, GSM_EMSVariablePicture, GSM_Nokia6210StartupLogo, GSM_Nokia6510OperatorLogo, GSM_Nokia7110OperatorLogo, GSM_Nokia7110StartupLogo, GSM_NokiaCallerLogo, GSM_NokiaOperatorLogo, GSM_NokiaPictureImage, GSM_NokiaStartupLogo, and PHONE_GetBitmapWidthHeight().

Referenced by GSM_DecodeEMSMultiPartSMS(), GSM_EncodeEMSMultiPartSMS(), GSM_EncodeMultiPartSMS(), NOKIA_CopyBitmap(), PHONE_ClearBitmap(), and savensl().

45 {
46  size_t width, height, x;
47 
48  PHONE_GetBitmapWidthHeight(Type, &width, &height);
49  if (width == 0 && height == 0) {
50  width = Width;
51  height = Height;
52  }
53  switch (Type) {
55  x = width * height;
56  return x/8 + (x%8 > 0);
58  return (width*height + 7)/8;
65  case GSM_EMSBigPicture:
67  return height*width/8;
70  return (height+7)/8*width;
72  return width*((height+7)/8);
73  }
74  return 0;
75 }
void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, size_t *width, size_t *height)
Definition: gsmlogo.c:23

§ PHONE_GetBitmapWidthHeight()

void PHONE_GetBitmapWidthHeight ( GSM_Phone_Bitmap_Types  Type,
size_t *  width,
size_t *  height 
)

Definition at line 23 of file gsmlogo.c.

References GSM_AlcatelBMMIPicture, GSM_EMSBigPicture, GSM_EMSMediumPicture, GSM_EMSSmallPicture, GSM_EMSVariablePicture, GSM_Nokia6210StartupLogo, GSM_Nokia6510OperatorLogo, GSM_Nokia7110OperatorLogo, GSM_Nokia7110StartupLogo, GSM_NokiaCallerLogo, GSM_NokiaOperatorLogo, GSM_NokiaPictureImage, and GSM_NokiaStartupLogo.

Referenced by GSM_EncodeEMSMultiPartSMS(), NOKIA_CopyBitmap(), PHONE_DecodeBitmap(), PHONE_EncodeBitmap(), and PHONE_GetBitmapSize().

24 {
25  *width = 0;
26  *height = 0;
27  switch (Type) {
28  case GSM_EMSSmallPicture : *width=8; *height=8; break;
29  case GSM_EMSMediumPicture : *width=16; *height=16; break;
30  case GSM_EMSBigPicture : *width=32; *height=32; break;
32  case GSM_NokiaCallerLogo : *width=72; *height=14; break;
33  case GSM_NokiaPictureImage : *width=72; *height=28; break;
35  case GSM_Nokia6510OperatorLogo : *width=78; *height=21; break;
36  case GSM_NokiaStartupLogo : *width=84; *height=48; break;
37  case GSM_Nokia6210StartupLogo : *width=96; *height=60; break;
38  case GSM_Nokia7110StartupLogo : *width=96; *height=65; break;
39  case GSM_EMSVariablePicture : break;
40  case GSM_AlcatelBMMIPicture : break;
41  }
42 }

§ PHONE_IsPointBitmap()

static gboolean PHONE_IsPointBitmap ( GSM_Phone_Bitmap_Types  Type,
char *  buffer,
int  x,
int  y,
int  width,
int  height 
)
static

Definition at line 77 of file gsmlogo.c.

References FALSE, GSM_AlcatelBMMIPicture, GSM_EMSBigPicture, GSM_EMSMediumPicture, GSM_EMSSmallPicture, GSM_EMSVariablePicture, GSM_Nokia6210StartupLogo, GSM_Nokia6510OperatorLogo, GSM_Nokia7110OperatorLogo, GSM_Nokia7110StartupLogo, GSM_NokiaCallerLogo, GSM_NokiaOperatorLogo, GSM_NokiaPictureImage, GSM_NokiaStartupLogo, and TRUE.

Referenced by PHONE_DecodeBitmap().

78 {
79  int i=0, pixel;
80 
81  if (x > width || y > height) return FALSE;
82 
83  switch (Type) {
88  i=(buffer[(y / 8 * width) + x] & (1 << (y % 8)));
89  break;
96  case GSM_EMSBigPicture:
97  pixel=width*y + x;
98  i=(buffer[pixel / 8] & (1 << (7 - (pixel % 8))));
99  break;
101  i=(buffer[(9 * y) + (x / 8)] & (1 << (7 - (x % 8))));
102  break;
104  break;
105  }
106  if (i) return TRUE; else return FALSE;
107 }
#define FALSE
Definition: gammu-types.h:25
#define TRUE
Definition: gammu-types.h:28

§ PHONE_SetPointBitmap()

static void PHONE_SetPointBitmap ( GSM_Phone_Bitmap_Types  Type,
char *  buffer,
int  x,
int  y,
int  width,
int  height 
)
static

Definition at line 109 of file gsmlogo.c.

References GSM_AlcatelBMMIPicture, GSM_EMSBigPicture, GSM_EMSMediumPicture, GSM_EMSSmallPicture, GSM_EMSVariablePicture, GSM_Nokia6210StartupLogo, GSM_Nokia6510OperatorLogo, GSM_Nokia7110OperatorLogo, GSM_Nokia7110StartupLogo, GSM_NokiaCallerLogo, GSM_NokiaOperatorLogo, GSM_NokiaPictureImage, and GSM_NokiaStartupLogo.

Referenced by PHONE_EncodeBitmap().

110 {
111  int pixel;
112 
113  switch (Type) {
118  buffer[(y / 8 * width)+x] |= 1 << (y % 8);
119  break;
122  case GSM_NokiaCallerLogo:
123  case GSM_EMSSmallPicture:
125  case GSM_EMSBigPicture:
127  pixel = width*y + x;
128  buffer[pixel / 8] |= 1 << (7 - (pixel % 8));
129  break;
131  buffer[(9 * y) + (x / 8)] |= 1 << (7 - (x % 8));
132  break;
134  pixel = height / 8;
135  if ((height % 8) != 0) pixel++;
136  buffer[(pixel * x) + (y / 8)] |= 1 << (7 - (y % 8));
137  break;
138  }
139 }

§ PrivSaveNGGNOL()

static GSM_Error PrivSaveNGGNOL ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 530 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, chk_fwrite, ERR_MOREMEMORY, ERR_NONE, ERR_WRITING_FILE, and GSM_IsPointBitmap().

Referenced by savengg(), and savenol().

531 {
532  char *buffer=NULL;
533  size_t x=0,y=0;
534  size_t current=0;
535 
536  buffer = (char *)malloc(bitmap->Bitmap[0].BitmapHeight * bitmap->Bitmap[0].BitmapWidth);
537  if (buffer == NULL) {
538  return ERR_MOREMEMORY;
539  }
540 
541  for (y=0;y<bitmap->Bitmap[0].BitmapHeight;y++) {
542  for (x=0;x<bitmap->Bitmap[0].BitmapWidth;x++) {
543  if (GSM_IsPointBitmap(&bitmap->Bitmap[0],x,y)) {
544  buffer[current++] = '1';
545  } else {
546  buffer[current++] = '0';
547  }
548  }
549  }
550  chk_fwrite(buffer,1,current,file);
551  free(buffer);
552  buffer=NULL;
553  return ERR_NONE;
554 fail:
555  free(buffer);
556  buffer=NULL;
557  return ERR_WRITING_FILE;
558 }
#define chk_fwrite(data, size, count, file)
Definition: gsmlogo.c:20
gboolean GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:238
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156

§ PrivSaveNLMWBMP()

static GSM_Error PrivSaveNLMWBMP ( FILE *  file,
GSM_Bitmap Bitmap 
)
static

Definition at line 463 of file gsmlogo.c.

References GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, chk_fwrite, ERR_NONE, ERR_WRITING_FILE, and GSM_IsPointBitmap().

Referenced by savenlm(), and savewbmp().

464 {
465  unsigned char buffer[1000];
466  size_t x,y,pos;
467  ssize_t pos2;
468  div_t division;
469 
470  pos=0;pos2=7;
471  for (y=0;y<Bitmap->BitmapHeight;y++) {
472  for (x=0;x<Bitmap->BitmapWidth;x++) {
473  if (pos2==7) buffer[pos]=0;
474  if (GSM_IsPointBitmap(Bitmap,x,y)) buffer[pos]|=(1<<pos2);
475  pos2--;
476  /* going to new line */
477  if (pos2<0) {pos2=7;pos++;}
478  }
479  /* for startup logos - new line with new byte */
480  if (pos2!=7) {pos2=7;pos++;}
481  }
482 
483  division=div(Bitmap->BitmapWidth,8);
484  /* For startup logos */
485  if (division.rem!=0) division.quot++;
486 
487  chk_fwrite(buffer,1,(size_t)(division.quot*Bitmap->BitmapHeight),file);
488  return ERR_NONE;
489 fail:
490  return ERR_WRITING_FILE;
491 }
#define chk_fwrite(data, size, count, file)
Definition: gsmlogo.c:20
gboolean GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:238
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156

§ savebmp()

static GSM_Error savebmp ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 455 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, and Bitmap2BMP().

Referenced by GSM_SaveBitmapFile().

456 {
457  GSM_Error error;
458 
459  error=Bitmap2BMP(NULL,file,&bitmap->Bitmap[0]);
460  return error;
461 }
GSM_Error
Definition: gammu-error.h:23
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
GSM_Error Bitmap2BMP(unsigned char *buffer, FILE *file, GSM_Bitmap *bitmap)
Definition: gsmlogo.c:321

§ savengg()

static GSM_Error savengg ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 560 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, chk_fwrite, ERR_WRITING_FILE, and PrivSaveNGGNOL().

Referenced by GSM_SaveBitmapFile().

561 {
562  char header[]={
563  'N','G','G',0x00,0x01,0x00,
564  0x00,0x00, /* Width */
565  0x00,0x00, /* Height */
566  0x01,0x00,0x01,0x00,
567  0x00, /* Unknown.Can't be checksum - for */
568  /* the same logo files can be different */
569  0x00};
570 
571  header[6] = bitmap->Bitmap[0].BitmapWidth;
572  header[8] = bitmap->Bitmap[0].BitmapHeight;
573  chk_fwrite(header,1,sizeof(header),file);
574 
575  return PrivSaveNGGNOL(file,bitmap);
576 
577 fail:
578  return ERR_WRITING_FILE;
579 }
static GSM_Error PrivSaveNGGNOL(FILE *file, GSM_MultiBitmap *bitmap)
Definition: gsmlogo.c:530
#define chk_fwrite(data, size, count, file)
Definition: gsmlogo.c:20
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156

§ savenlm()

static GSM_Error savenlm ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 493 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, chk_fwrite, ERR_NONE, ERR_UNKNOWN, ERR_WRITING_FILE, GSM_CallerGroupLogo, GSM_OperatorLogo, GSM_PictureImage, GSM_StartupLogo, GSM_MultiBitmap::Number, PrivSaveNLMWBMP(), and GSM_Bitmap::Type.

Referenced by GSM_SaveBitmapFile().

494 {
495  int i;
496  GSM_Error error;
497  char header[]={
498  'N','L','M',' ', /* Nokia Logo Manager file ID. */
499  0x01,
500  0x00, /* 0x00 (OP), 0x01 (CLI), 0x02 (Startup), 0x03 (Picture)*/
501  0x00, /* Number of images inside file - 1. 0x01==2 images, 0x03==4 images, etc. */
502  0x00, /* Width. */
503  0x00, /* Height. */
504  0x01};
505 
506  switch (bitmap->Bitmap[0].Type) {
507  case GSM_OperatorLogo : header[5]=0x00; break;
508  case GSM_CallerGroupLogo : header[5]=0x01; break;
509  case GSM_StartupLogo : header[5]=0x02; break;
510  case GSM_PictureImage : header[5]=0x03; break;
511  default : return ERR_UNKNOWN;
512  }
513  header[6] = bitmap->Number - 1;
514  header[7] = bitmap->Bitmap[0].BitmapWidth;
515  header[8] = bitmap->Bitmap[0].BitmapHeight;
516  chk_fwrite(header,1,sizeof(header),file);
517 
518  for (i=0;i<bitmap->Number;i++) {
519  error = PrivSaveNLMWBMP(file, &bitmap->Bitmap[i]);
520  if (error != ERR_NONE) {
521  return error;
522  }
523  }
524 
525  return ERR_NONE;
526 fail:
527  return ERR_WRITING_FILE;
528 }
GSM_Bitmap_Types Type
Definition: gammu-bitmap.h:107
static GSM_Error PrivSaveNLMWBMP(FILE *file, GSM_Bitmap *Bitmap)
Definition: gsmlogo.c:463
GSM_Error
Definition: gammu-error.h:23
#define chk_fwrite(data, size, count, file)
Definition: gsmlogo.c:20
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
unsigned char Number
Definition: gammu-bitmap.h:188
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156

§ savenol()

static GSM_Error savenol ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 581 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, chk_fwrite, ERR_WRITING_FILE, GSM_OperatorLogo, GSM_Bitmap::NetworkCode, PrivSaveNGGNOL(), and GSM_Bitmap::Type.

Referenced by GSM_SaveBitmapFile().

582 {
583  int country = 0,net = 0;
584  char header[]={
585  'N','O','L',0x00,0x01,0x00,
586  0x00,0x00, /* MCC */
587  0x00,0x00, /* MNC */
588  0x00,0x00, /* Width */
589  0x00,0x00, /* Height */
590  0x01,0x00,0x01,0x00,
591  0x00, /* Unknown.Can't be checksum - for */
592  /* the same logo files can be different */
593  0x00};
594 
595  if (bitmap->Bitmap[0].Type == GSM_OperatorLogo) {
596  sscanf(bitmap->Bitmap[0].NetworkCode, "%d %d", &country, &net);
597  }
598 
599  header[6] = country%256;
600  header[7] = country/256;
601  header[8] = net%256;
602  header[9] = net/256;
603  header[10] = bitmap->Bitmap[0].BitmapWidth;
604  header[12] = bitmap->Bitmap[0].BitmapHeight;
605  chk_fwrite(header,1,sizeof(header),file);
606 
607  return PrivSaveNGGNOL(file,bitmap);
608 
609 fail:
610  return ERR_WRITING_FILE;
611 }
GSM_Bitmap_Types Type
Definition: gammu-bitmap.h:107
static GSM_Error PrivSaveNGGNOL(FILE *file, GSM_MultiBitmap *bitmap)
Definition: gsmlogo.c:530
#define chk_fwrite(data, size, count, file)
Definition: gsmlogo.c:20
char NetworkCode[10]
Definition: gammu-bitmap.h:160
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156

§ savensl()

static GSM_Error savensl ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 644 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, chk_fwrite, ERR_NONE, ERR_WRITING_FILE, GSM_BITMAP_SIZE, GSM_NokiaStartupLogo, PHONE_EncodeBitmap(), and PHONE_GetBitmapSize().

Referenced by GSM_SaveBitmapFile().

645 {
646  char buffer[GSM_BITMAP_SIZE];
647  unsigned char header[]={
648  'F','O','R','M', 0x01,0xFE, /* File ID block, size 1*256+0xFE=510*/
649  'N','S','L','D', 0x01,0xF8}; /* Startup Logo block, size 1*256+0xF8=504*/
650 
651  chk_fwrite(header,1,sizeof(header),file);
652  PHONE_EncodeBitmap(GSM_NokiaStartupLogo, buffer, &bitmap->Bitmap[0]);
654 
655  return ERR_NONE;
656 fail:
657  return ERR_WRITING_FILE;
658 }
size_t PHONE_GetBitmapSize(GSM_Phone_Bitmap_Types Type, size_t Width, size_t Height)
Definition: gsmlogo.c:44
void PHONE_EncodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
Definition: gsmlogo.c:197
#define GSM_BITMAP_SIZE
Definition: gammu-limits.h:267
#define chk_fwrite(data, size, count, file)
Definition: gsmlogo.c:20
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192

§ savewbmp()

static GSM_Error savewbmp ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 660 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, chk_fwrite, ERR_WRITING_FILE, and PrivSaveNLMWBMP().

Referenced by GSM_SaveBitmapFile().

661 {
662  unsigned char buffer[4];
663 
664  buffer[0] = 0x00;
665  buffer[1] = 0x00;
666  buffer[2] = bitmap->Bitmap[0].BitmapWidth;
667  buffer[3] = bitmap->Bitmap[0].BitmapHeight;
668  chk_fwrite(buffer,1,4,file);
669 
670  return PrivSaveNLMWBMP(file, &bitmap->Bitmap[0]);
671 
672 fail:
673  return ERR_WRITING_FILE;
674 }
static GSM_Error PrivSaveNLMWBMP(FILE *file, GSM_Bitmap *Bitmap)
Definition: gsmlogo.c:463
#define chk_fwrite(data, size, count, file)
Definition: gsmlogo.c:20
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156

§ savexpm()

static GSM_Error savexpm ( FILE *  file,
GSM_MultiBitmap bitmap 
)
static

Definition at line 613 of file gsmlogo.c.

References GSM_MultiBitmap::Bitmap, GSM_Bitmap::BitmapHeight, GSM_Bitmap::BitmapWidth, ERR_NONE, and GSM_IsPointBitmap().

Referenced by GSM_SaveBitmapFile().

614 {
615  size_t x,y;
616 
617  fprintf(file,"/* XPM */\n");
618  fprintf(file,"static char * ala_xpm[] = {\n");
619  fprintf(file,"\"%ld %ld 2 1\",\n",
620  (long)bitmap->Bitmap[0].BitmapWidth,
621  (long)bitmap->Bitmap[0].BitmapHeight);
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");
624 
625  for (y=0;y<bitmap->Bitmap[0].BitmapHeight;y++) {
626  fprintf(file,"\"");
627  for (x=0;x<bitmap->Bitmap[0].BitmapWidth;x++)
628  if (GSM_IsPointBitmap(&bitmap->Bitmap[0],x,y)) {
629  fprintf(file,".");
630  } else {
631  fprintf(file,"#");
632  }
633  fprintf(file,"\"");
634  if (y==bitmap->Bitmap[0].BitmapHeight-1) {
635  fprintf(file,"};\n");
636  } else {
637  fprintf(file,",\n");
638  }
639  }
640 
641  return ERR_NONE;
642 }
gboolean GSM_IsPointBitmap(GSM_Bitmap *bmp, int x, int y)
Definition: gsmlogo.c:238
GSM_Bitmap Bitmap[GSM_MAX_MULTI_BITMAP]
Definition: gammu-bitmap.h:192
size_t BitmapHeight
Definition: gammu-bitmap.h:152
size_t BitmapWidth
Definition: gammu-bitmap.h:156