author | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
---|---|---|
committer | zautrix <zautrix> | 2004-10-05 11:13:51 (UTC) |
commit | 50ab40e1e02ad7c65c17a78d08116a808b1257aa (patch) (unidiff) | |
tree | 0d1939e2297fa7bbd8e1f2030f154463854164c6 /gammu/emb/common/service/gsmlogo.c | |
parent | cf8616f64f20e5448d4ff644f7cc15750cf3f85f (diff) | |
download | kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.zip kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.gz kdepimpi-50ab40e1e02ad7c65c17a78d08116a808b1257aa.tar.bz2 |
updated to latest gammu version
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 @@ | |||
1 | /* (c) 2001-2004 by Marcin Wiacek */ | 1 | /* (c) 2001-2004 by Marcin Wiacek */ |
2 | 2 | ||
3 | #include <string.h> | 3 | #include <string.h> |
4 | #include <stdlib.h> | 4 | #include <stdlib.h> |
5 | #include <sys/stat.h> | ||
5 | 6 | ||
6 | #include "../misc/misc.h" | 7 | #include "../misc/misc.h" |
7 | #include "../misc/coding/coding.h" | 8 | #include "../misc/coding/coding.h" |
8 | #include "gsmlogo.h" | 9 | #include "gsmlogo.h" |
9 | #include "gsmnet.h" | 10 | #include "gsmnet.h" |
10 | 11 | ||
11 | void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, int *width, int *height) | 12 | void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, int *width, int *height) |
12 | { | 13 | { |
13 | *width = 0; | 14 | *width = 0; |
14 | *height= 0; | 15 | *height= 0; |
15 | switch (Type) { | 16 | switch (Type) { |
16 | case GSM_EMSSmallPicture: *width=8; *height=8; break; | 17 | 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 | |||
152 | Bitmap->Location = 0; | 153 | Bitmap->Location = 0; |
153 | Bitmap->Text[0] = 0; | 154 | Bitmap->Text[0] = 0; |
154 | Bitmap->Text[1] = 0; | 155 | Bitmap->Text[1] = 0; |
155 | Bitmap->BitmapEnabled = false; | 156 | Bitmap->BitmapEnabled = false; |
156 | Bitmap->DefaultName = false; | 157 | Bitmap->DefaultName = false; |
157 | Bitmap->DefaultBitmap = false; | 158 | Bitmap->DefaultBitmap = false; |
158 | Bitmap->DefaultRingtone = false; | 159 | Bitmap->DefaultRingtone = false; |
159 | Bitmap->RingtoneID = 0; | 160 | Bitmap->RingtoneID = 0; |
160 | Bitmap->NetworkCode[0] = 0; | 161 | Bitmap->NetworkCode[0] = 0; |
161 | Bitmap->Sender[0] = 0; | 162 | Bitmap->Sender[0] = 0; |
162 | Bitmap->Sender[1] = 0; | 163 | Bitmap->Sender[1] = 0; |
163 | Bitmap->ID = 0; | 164 | Bitmap->ID = 0; |
165 | Bitmap->Name = NULL; | ||
164 | 166 | ||
165 | GSM_ClearBitmap(Bitmap); | 167 | GSM_ClearBitmap(Bitmap); |
166 | for (x=0;x<Bitmap->BitmapWidth;x++) { | 168 | for (x=0;x<Bitmap->BitmapWidth;x++) { |
167 | for (y=0;y<Bitmap->BitmapHeight;y++) { | 169 | for (y=0;y<Bitmap->BitmapHeight;y++) { |
168 | if (PHONE_IsPointBitmap(Type, buffer, x, y, Bitmap->BitmapWidth, Bitmap->BitmapHeight)) { | 170 | if (PHONE_IsPointBitmap(Type, buffer, x, y, Bitmap->BitmapWidth, Bitmap->BitmapHeight)) { |
169 | GSM_SetPointBitmap(Bitmap,x,y); | 171 | GSM_SetPointBitmap(Bitmap,x,y); |
170 | } | 172 | } |
171 | } | 173 | } |
172 | } | 174 | } |
173 | } | 175 | } |
174 | 176 | ||
175 | void PHONE_ClearBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int width, int height) | 177 | 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) | |||
617 | return ERR_NONE; | 619 | return ERR_NONE; |
618 | } | 620 | } |
619 | 621 | ||
620 | GSM_Error GSM_SaveBitmapFile(char *FileName, GSM_MultiBitmap *bitmap) | 622 | GSM_Error GSM_SaveBitmapFile(char *FileName, GSM_MultiBitmap *bitmap) |
621 | { | 623 | { |
622 | FILE *file; | 624 | FILE *file; |
623 | GSM_Error error=ERR_NONE; | 625 | GSM_Error error=ERR_NONE; |
624 | 626 | ||
625 | file = fopen(FileName, "wb"); | 627 | file = fopen(FileName, "wb"); |
626 | if (file == NULL) return ERR_CANTOPENFILE; | 628 | if (file == NULL) return ERR_CANTOPENFILE; |
627 | 629 | ||
628 | /* Attempt to identify filetype */ | 630 | /* Attempt to identify filetype */ |
629 | if (strstr(FileName,".nlm")) { | 631 | if (mystrcasestr(FileName,".nlm")) { |
630 | error=savenlm(file,bitmap); | 632 | error=savenlm(file,bitmap); |
631 | } else if (strstr(FileName,".ngg")) { | 633 | } else if (mystrcasestr(FileName,".ngg")) { |
632 | error=savengg(file,bitmap); | 634 | error=savengg(file,bitmap); |
633 | } else if (strstr(FileName,".nol")) { | 635 | } else if (mystrcasestr(FileName,".nol")) { |
634 | error=savenol(file,bitmap); | 636 | error=savenol(file,bitmap); |
635 | } else if (strstr(FileName,".xpm")) { | 637 | } else if (mystrcasestr(FileName,".xpm")) { |
636 | error=savexpm(file,bitmap); | 638 | error=savexpm(file,bitmap); |
637 | } else if (strstr(FileName,".nsl")) { | 639 | } else if (mystrcasestr(FileName,".nsl")) { |
638 | error=savensl(file,bitmap); | 640 | error=savensl(file,bitmap); |
639 | } else if (strstr(FileName,".wbmp")) { | 641 | } else if (mystrcasestr(FileName,".wbmp")) { |
640 | error=savewbmp(file,bitmap); | 642 | error=savewbmp(file,bitmap); |
641 | } else { | 643 | } else { |
642 | error=savebmp(file,bitmap); | 644 | error=savebmp(file,bitmap); |
643 | } | 645 | } |
644 | fclose(file); | 646 | fclose(file); |
645 | 647 | ||
646 | return error; | 648 | return error; |
647 | } | 649 | } |
648 | 650 | ||
649 | GSM_Error BMP2Bitmap(unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap) | 651 | GSM_Error BMP2Bitmap(unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap) |
650 | { | 652 | { |
651 | bool first_white,isfile=false; | 653 | bool first_white,isfile=false; |
@@ -946,50 +948,83 @@ static GSM_Error loadwbmp(FILE *file, GSM_MultiBitmap *bitmap) | |||
946 | fread(buffer,1,4,file); | 948 | fread(buffer,1,4,file); |
947 | bitmap->Bitmap[0].BitmapWidth = buffer[2]; | 949 | bitmap->Bitmap[0].BitmapWidth = buffer[2]; |
948 | bitmap->Bitmap[0].BitmapHeight = buffer[3]; | 950 | bitmap->Bitmap[0].BitmapHeight = buffer[3]; |
949 | bitmap->Number = 1; | 951 | bitmap->Number = 1; |
950 | 952 | ||
951 | fread(buffer,1,10000,file); | 953 | fread(buffer,1,10000,file); |
952 | PHONE_DecodeBitmap(GSM_Nokia7110OperatorLogo, buffer, &bitmap->Bitmap[0]); | 954 | PHONE_DecodeBitmap(GSM_Nokia7110OperatorLogo, buffer, &bitmap->Bitmap[0]); |
953 | GSM_ReverseBitmap(&bitmap->Bitmap[0]); | 955 | GSM_ReverseBitmap(&bitmap->Bitmap[0]); |
954 | 956 | ||
955 | return ERR_NONE; | 957 | return ERR_NONE; |
956 | } | 958 | } |
957 | 959 | ||
960 | static GSM_Error loadgif(FILE *file, GSM_MultiBitmap *bitmap) | ||
961 | { | ||
962 | GSM_Bitmap *bmap = &bitmap->Bitmap[0]; | ||
963 | char *buffer; | ||
964 | struct stat st; | ||
965 | int length; | ||
966 | |||
967 | dbgprintf("loading gif file\n"); | ||
968 | fstat(fileno(file), &st); | ||
969 | bmap->BinaryPic.Length = length = st.st_size; | ||
970 | bmap->BinaryPic.Buffer = buffer = malloc(length); | ||
971 | if (bmap->BinaryPic.Buffer == NULL) | ||
972 | return ERR_MOREMEMORY; | ||
973 | |||
974 | fread(buffer, 1, length, file); | ||
975 | dbgprintf("Length %i name \"%s\"\n", length, | ||
976 | DecodeUnicodeString(bmap->Name)); | ||
977 | |||
978 | bmap->Type = GSM_PictureBinary; | ||
979 | bmap->BinaryPic.Type = PICTURE_GIF; | ||
980 | bmap->BitmapWidth = 256 * buffer[7] + buffer[6]; | ||
981 | bmap->BitmapHeight = 256 * buffer[9] + buffer[8]; | ||
982 | bitmap->Number = 1; | ||
983 | |||
984 | return ERR_NONE; | ||
985 | } | ||
986 | |||
958 | GSM_Error GSM_ReadBitmapFile(char *FileName, GSM_MultiBitmap *bitmap) | 987 | GSM_Error GSM_ReadBitmapFile(char *FileName, GSM_MultiBitmap *bitmap) |
959 | { | 988 | { |
960 | FILE *file; | 989 | FILE *file; |
961 | unsigned charbuffer[300]; | 990 | unsigned charbuffer[300]; |
962 | 991 | ||
963 | file = fopen(FileName, "rb"); | 992 | file = fopen(FileName, "rb"); |
964 | if (file == NULL) return ERR_CANTOPENFILE; | 993 | if (file == NULL) return ERR_CANTOPENFILE; |
965 | 994 | ||
995 | bitmap->Bitmap[0].Name = malloc((strlen(FileName) + 1) * 2); | ||
996 | if (bitmap->Bitmap[0].Name == NULL) return ERR_MOREMEMORY; | ||
997 | EncodeUnicode(bitmap->Bitmap[0].Name, FileName, strlen(FileName)); | ||
998 | |||
966 | fread(buffer, 1, 9, file); /* Read the header of the file. */ | 999 | fread(buffer, 1, 9, file); /* Read the header of the file. */ |
967 | rewind(file); | 1000 | rewind(file); |
968 | 1001 | ||
969 | bitmap->Bitmap[0].DefaultBitmap = false; | 1002 | bitmap->Bitmap[0].DefaultBitmap = false; |
970 | 1003 | ||
971 | /* Attempt to identify filetype */ | 1004 | /* Attempt to identify filetype */ |
972 | if (memcmp(buffer, "BM",2)==0) { | 1005 | if (memcmp(buffer, "BM",2)==0) { |
973 | return loadbmp(file,bitmap); | 1006 | return loadbmp(file,bitmap); |
974 | } else if (buffer[0] == 0x00 && buffer[1] == 0x00) { | 1007 | } else if (buffer[0] == 0x00 && buffer[1] == 0x00) { |
975 | return loadwbmp(file,bitmap); | 1008 | return loadwbmp(file,bitmap); |
976 | } else if (memcmp(buffer, "NLM",3)==0) { | 1009 | } else if (memcmp(buffer, "NLM",3)==0) { |
977 | return loadnlm(file,bitmap); | 1010 | return loadnlm(file,bitmap); |
978 | } else if (memcmp(buffer, "NOL",3)==0) { | 1011 | } else if (memcmp(buffer, "NOL",3)==0) { |
979 | return loadnolngg(file,bitmap,true); | 1012 | return loadnolngg(file,bitmap,true); |
980 | } else if (memcmp(buffer, "NGG",3)==0) { | 1013 | } else if (memcmp(buffer, "NGG",3)==0) { |
981 | return loadnolngg(file,bitmap,false); | 1014 | return loadnolngg(file,bitmap,false); |
982 | } else if (memcmp(buffer, "FORM",4)==0) { | 1015 | } else if (memcmp(buffer, "FORM",4)==0) { |
983 | return loadnsl(file,bitmap); | 1016 | return loadnsl(file,bitmap); |
1017 | } else if (memcmp(buffer, "GIF",3)==0) { | ||
1018 | return loadgif(file,bitmap); | ||
984 | } | 1019 | } |
985 | return ERR_UNKNOWN; | 1020 | return ERR_UNKNOWN; |
986 | } | 1021 | } |
987 | 1022 | ||
988 | void NOKIA_CopyBitmap(GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, int *Length) | 1023 | void NOKIA_CopyBitmap(GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, int *Length) |
989 | { | 1024 | { |
990 | int Width, Height; | 1025 | int Width, Height; |
991 | 1026 | ||
992 | Buffer[(*Length)++] = 0x00; | 1027 | Buffer[(*Length)++] = 0x00; |
993 | PHONE_GetBitmapWidthHeight(Type, &Width, &Height); | 1028 | PHONE_GetBitmapWidthHeight(Type, &Width, &Height); |
994 | Buffer[(*Length)++] = Width; | 1029 | Buffer[(*Length)++] = Width; |
995 | Buffer[(*Length)++] = Height; | 1030 | Buffer[(*Length)++] = Height; |