Diffstat (limited to 'gammu/emb/common/service/gsmlogo.c') (more/less context) (ignore whitespace changes)
-rw-r--r-- | gammu/emb/common/service/gsmlogo.c | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/gammu/emb/common/service/gsmlogo.c b/gammu/emb/common/service/gsmlogo.c index c992915..7c19967 100644 --- a/gammu/emb/common/service/gsmlogo.c +++ b/gammu/emb/common/service/gsmlogo.c @@ -1,16 +1,17 @@ /* (c) 2001-2004 by Marcin Wiacek */ #include <string.h> #include <stdlib.h> +#include <sys/stat.h> #include "../misc/misc.h" #include "../misc/coding/coding.h" #include "gsmlogo.h" #include "gsmnet.h" void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, int *width, int *height) { *width = 0; *height = 0; switch (Type) { case GSM_EMSSmallPicture : *width=8; *height=8; break; @@ -152,24 +153,25 @@ void PHONE_DecodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *B Bitmap->Location = 0; Bitmap->Text[0] = 0; Bitmap->Text[1] = 0; Bitmap->BitmapEnabled = false; Bitmap->DefaultName = false; Bitmap->DefaultBitmap = false; Bitmap->DefaultRingtone = false; Bitmap->RingtoneID = 0; Bitmap->NetworkCode[0] = 0; Bitmap->Sender[0] = 0; Bitmap->Sender[1] = 0; Bitmap->ID = 0; + Bitmap->Name = NULL; GSM_ClearBitmap(Bitmap); for (x=0;x<Bitmap->BitmapWidth;x++) { for (y=0;y<Bitmap->BitmapHeight;y++) { if (PHONE_IsPointBitmap(Type, buffer, x, y, Bitmap->BitmapWidth, Bitmap->BitmapHeight)) { GSM_SetPointBitmap(Bitmap,x,y); } } } } void PHONE_ClearBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int width, int height) @@ -617,35 +619,35 @@ static GSM_Error savewbmp(FILE *file, GSM_MultiBitmap *bitmap) return ERR_NONE; } GSM_Error GSM_SaveBitmapFile(char *FileName, GSM_MultiBitmap *bitmap) { FILE *file; GSM_Error error=ERR_NONE; file = fopen(FileName, "wb"); if (file == NULL) return ERR_CANTOPENFILE; /* Attempt to identify filetype */ - if (strstr(FileName,".nlm")) { + if (mystrcasestr(FileName,".nlm")) { error=savenlm(file,bitmap); - } else if (strstr(FileName,".ngg")) { + } else if (mystrcasestr(FileName,".ngg")) { error=savengg(file,bitmap); - } else if (strstr(FileName,".nol")) { + } else if (mystrcasestr(FileName,".nol")) { error=savenol(file,bitmap); - } else if (strstr(FileName,".xpm")) { + } else if (mystrcasestr(FileName,".xpm")) { error=savexpm(file,bitmap); - } else if (strstr(FileName,".nsl")) { + } else if (mystrcasestr(FileName,".nsl")) { error=savensl(file,bitmap); - } else if (strstr(FileName,".wbmp")) { + } else if (mystrcasestr(FileName,".wbmp")) { error=savewbmp(file,bitmap); } else { error=savebmp(file,bitmap); } fclose(file); return error; } GSM_Error BMP2Bitmap(unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap) { bool first_white,isfile=false; @@ -946,50 +948,83 @@ static GSM_Error loadwbmp(FILE *file, GSM_MultiBitmap *bitmap) fread(buffer,1,4,file); bitmap->Bitmap[0].BitmapWidth = buffer[2]; bitmap->Bitmap[0].BitmapHeight = buffer[3]; bitmap->Number = 1; fread(buffer,1,10000,file); PHONE_DecodeBitmap(GSM_Nokia7110OperatorLogo, buffer, &bitmap->Bitmap[0]); GSM_ReverseBitmap(&bitmap->Bitmap[0]); return ERR_NONE; } +static GSM_Error loadgif(FILE *file, GSM_MultiBitmap *bitmap) +{ + GSM_Bitmap *bmap = &bitmap->Bitmap[0]; + char *buffer; + struct stat st; + int length; + + dbgprintf("loading gif file\n"); + fstat(fileno(file), &st); + bmap->BinaryPic.Length = length = st.st_size; + bmap->BinaryPic.Buffer = buffer = malloc(length); + if (bmap->BinaryPic.Buffer == NULL) + return ERR_MOREMEMORY; + + fread(buffer, 1, length, file); + dbgprintf("Length %i name \"%s\"\n", length, + DecodeUnicodeString(bmap->Name)); + + bmap->Type = GSM_PictureBinary; + bmap->BinaryPic.Type = PICTURE_GIF; + bmap->BitmapWidth = 256 * buffer[7] + buffer[6]; + bmap->BitmapHeight = 256 * buffer[9] + buffer[8]; + bitmap->Number = 1; + + return ERR_NONE; +} + GSM_Error GSM_ReadBitmapFile(char *FileName, GSM_MultiBitmap *bitmap) { FILE *file; unsigned char buffer[300]; file = fopen(FileName, "rb"); if (file == NULL) return ERR_CANTOPENFILE; + bitmap->Bitmap[0].Name = malloc((strlen(FileName) + 1) * 2); + if (bitmap->Bitmap[0].Name == NULL) return ERR_MOREMEMORY; + EncodeUnicode(bitmap->Bitmap[0].Name, FileName, strlen(FileName)); + fread(buffer, 1, 9, file); /* Read the header of the file. */ rewind(file); bitmap->Bitmap[0].DefaultBitmap = false; /* Attempt to identify filetype */ if (memcmp(buffer, "BM",2)==0) { return loadbmp(file,bitmap); } else if (buffer[0] == 0x00 && buffer[1] == 0x00) { return loadwbmp(file,bitmap); } else if (memcmp(buffer, "NLM",3)==0) { return loadnlm(file,bitmap); } else if (memcmp(buffer, "NOL",3)==0) { return loadnolngg(file,bitmap,true); } else if (memcmp(buffer, "NGG",3)==0) { return loadnolngg(file,bitmap,false); } else if (memcmp(buffer, "FORM",4)==0) { return loadnsl(file,bitmap); + } else if (memcmp(buffer, "GIF",3)==0) { + return loadgif(file,bitmap); } return ERR_UNKNOWN; } void NOKIA_CopyBitmap(GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, int *Length) { int Width, Height; Buffer[(*Length)++] = 0x00; PHONE_GetBitmapWidthHeight(Type, &Width, &Height); Buffer[(*Length)++] = Width; Buffer[(*Length)++] = Height; |