summaryrefslogtreecommitdiffabout
path: root/gammu/emb/common/service/gsmlogo.c
Unidiff
Diffstat (limited to 'gammu/emb/common/service/gsmlogo.c') (more/less context) (show whitespace changes)
-rw-r--r--gammu/emb/common/service/gsmlogo.c47
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,28 +1,29 @@
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
11void PHONE_GetBitmapWidthHeight(GSM_Phone_Bitmap_Types Type, int *width, int *height) 12void 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;
17 case GSM_EMSMediumPicture: *width=16; *height=16; break; 18 case GSM_EMSMediumPicture: *width=16; *height=16; break;
18 case GSM_EMSBigPicture : *width=32; *height=32; break; 19 case GSM_EMSBigPicture : *width=32; *height=32; break;
19 case GSM_NokiaOperatorLogo: 20 case GSM_NokiaOperatorLogo:
20 case GSM_NokiaCallerLogo: *width=72; *height=14; break; 21 case GSM_NokiaCallerLogo: *width=72; *height=14; break;
21 case GSM_NokiaPictureImage: *width=72; *height=28; break; 22 case GSM_NokiaPictureImage: *width=72; *height=28; break;
22 case GSM_Nokia7110OperatorLogo: 23 case GSM_Nokia7110OperatorLogo:
23 case GSM_Nokia6510OperatorLogo: *width=78; *height=21; break; 24 case GSM_Nokia6510OperatorLogo: *width=78; *height=21; break;
24 case GSM_NokiaStartupLogo: *width=84; *height=48; break; 25 case GSM_NokiaStartupLogo: *width=84; *height=48; break;
25 case GSM_Nokia6210StartupLogo: *width=96; *height=60; break; 26 case GSM_Nokia6210StartupLogo: *width=96; *height=60; break;
26 case GSM_Nokia7110StartupLogo: *width=96; *height=65; break; 27 case GSM_Nokia7110StartupLogo: *width=96; *height=65; break;
27 case GSM_EMSVariablePicture : break; 28 case GSM_EMSVariablePicture : break;
28 case GSM_AlcatelBMMIPicture : break; 29 case GSM_AlcatelBMMIPicture : break;
@@ -140,48 +141,49 @@ void PHONE_DecodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *B
140 case GSM_NokiaCallerLogo : Bitmap->Type=GSM_CallerGroupLogo;break; 141 case GSM_NokiaCallerLogo : Bitmap->Type=GSM_CallerGroupLogo;break;
141 case GSM_AlcatelBMMIPicture : 142 case GSM_AlcatelBMMIPicture :
142 case GSM_NokiaStartupLogo: 143 case GSM_NokiaStartupLogo:
143 case GSM_Nokia7110StartupLogo: 144 case GSM_Nokia7110StartupLogo:
144 case GSM_Nokia6210StartupLogo : Bitmap->Type=GSM_StartupLogo; break; 145 case GSM_Nokia6210StartupLogo : Bitmap->Type=GSM_StartupLogo; break;
145 case GSM_NokiaPictureImage: 146 case GSM_NokiaPictureImage:
146 case GSM_EMSVariablePicture: 147 case GSM_EMSVariablePicture:
147 case GSM_EMSSmallPicture: 148 case GSM_EMSSmallPicture:
148 case GSM_EMSMediumPicture: 149 case GSM_EMSMediumPicture:
149 case GSM_EMSBigPicture : Bitmap->Type=GSM_PictureImage;break; 150 case GSM_EMSBigPicture : Bitmap->Type=GSM_PictureImage;break;
150 } 151 }
151 152
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
175void PHONE_ClearBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int width, int height) 177void PHONE_ClearBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, int width, int height)
176{ 178{
177 memset(buffer,0,PHONE_GetBitmapSize(Type,width,height)); 179 memset(buffer,0,PHONE_GetBitmapSize(Type,width,height));
178} 180}
179 181
180void PHONE_EncodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap) 182void PHONE_EncodeBitmap(GSM_Phone_Bitmap_Types Type, char *buffer, GSM_Bitmap *Bitmap)
181{ 183{
182 int width, height, x, y; 184 int width, height, x, y;
183 GSM_Bitmapdest; 185 GSM_Bitmapdest;
184 186
185 PHONE_GetBitmapWidthHeight(Type, &width, &height); 187 PHONE_GetBitmapWidthHeight(Type, &width, &height);
186 if (width == 0 && height == 0) { 188 if (width == 0 && height == 0) {
187 width = Bitmap->BitmapWidth; 189 width = Bitmap->BitmapWidth;
@@ -605,59 +607,59 @@ static GSM_Error savensl(FILE *file, GSM_MultiBitmap *bitmap)
605static GSM_Error savewbmp(FILE *file, GSM_MultiBitmap *bitmap) 607static GSM_Error savewbmp(FILE *file, GSM_MultiBitmap *bitmap)
606{ 608{
607 unsigned char buffer[4]; 609 unsigned char buffer[4];
608 610
609 buffer[0] = 0x00; 611 buffer[0] = 0x00;
610 buffer[1] = 0x00; 612 buffer[1] = 0x00;
611 buffer[2] = bitmap->Bitmap[0].BitmapWidth; 613 buffer[2] = bitmap->Bitmap[0].BitmapWidth;
612 buffer[3] = bitmap->Bitmap[0].BitmapHeight; 614 buffer[3] = bitmap->Bitmap[0].BitmapHeight;
613 fwrite(buffer,1,4,file); 615 fwrite(buffer,1,4,file);
614 616
615 PrivSaveNLMWBMP(file, &bitmap->Bitmap[0]); 617 PrivSaveNLMWBMP(file, &bitmap->Bitmap[0]);
616 618
617 return ERR_NONE; 619 return ERR_NONE;
618} 620}
619 621
620GSM_Error GSM_SaveBitmapFile(char *FileName, GSM_MultiBitmap *bitmap) 622GSM_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
649GSM_Error BMP2Bitmap(unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap) 651GSM_Error BMP2Bitmap(unsigned char *buffer, FILE *file,GSM_Bitmap *bitmap)
650{ 652{
651 bool first_white,isfile=false; 653 bool first_white,isfile=false;
652 unsigned char buff[34]; 654 unsigned char buff[34];
653 int w,h,pos,y,x,i,buffpos=0; 655 int w,h,pos,y,x,i,buffpos=0;
654#ifdef DEBUG 656#ifdef DEBUG
655 int sizeimage=0; 657 int sizeimage=0;
656#endif 658#endif
657 659
658 if (bitmap->Type == GSM_None) bitmap->Type = GSM_StartupLogo; 660 if (bitmap->Type == GSM_None) bitmap->Type = GSM_StartupLogo;
659 if (file!=NULL) isfile=true; 661 if (file!=NULL) isfile=true;
660 if (isfile) { 662 if (isfile) {
661 fread(buff, 1, 34, file); 663 fread(buff, 1, 34, file);
662 } else { 664 } else {
663 memcpy(buff,buffer,34); 665 memcpy(buff,buffer,34);
@@ -934,70 +936,103 @@ static GSM_Error loadnsl(FILE *file, GSM_MultiBitmap *bitmap)
934 } 936 }
935 } 937 }
936 } 938 }
937 } 939 }
938 bitmap->Number = 1; 940 bitmap->Number = 1;
939 return(ERR_NONE); 941 return(ERR_NONE);
940} 942}
941 943
942static GSM_Error loadwbmp(FILE *file, GSM_MultiBitmap *bitmap) 944static GSM_Error loadwbmp(FILE *file, GSM_MultiBitmap *bitmap)
943{ 945{
944 unsigned char buffer[10000]; 946 unsigned char buffer[10000];
945 947
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
960static 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
958GSM_Error GSM_ReadBitmapFile(char *FileName, GSM_MultiBitmap *bitmap) 987GSM_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
988void NOKIA_CopyBitmap(GSM_Phone_Bitmap_Types Type, GSM_Bitmap *Bitmap, char *Buffer, int *Length) 1023void 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;
996 Buffer[(*Length)++] = 0x01; 1031 Buffer[(*Length)++] = 0x01;
997 PHONE_EncodeBitmap(Type, Buffer + (*Length), Bitmap); 1032 PHONE_EncodeBitmap(Type, Buffer + (*Length), Bitmap);
998 (*Length) = (*Length) + PHONE_GetBitmapSize(Type,0,0); 1033 (*Length) = (*Length) + PHONE_GetBitmapSize(Type,0,0);
999} 1034}
1000 1035
1001/* How should editor hadle tabs in this file? Add editor commands here. 1036/* How should editor hadle tabs in this file? Add editor commands here.
1002 * vim: noexpandtab sw=8 ts=8 sts=8: 1037 * vim: noexpandtab sw=8 ts=8 sts=8:
1003 */ 1038 */