1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4
5 #include "general.h"
6 #include "fileoutput.h"
7
8 #define COLOR_BMP 1
9
10 /*
11
12 Ringtone Tools - Copyright 2001-2005 Michael Kohn (mike@mikekohn.net)
13 This falls under the Kohnian license. Please read
14 it at http://ringtonetools.mikekohn.net/
15
16 This program is NOT opensourced. You may not use any part
17 of this program for your own software.
18
19 */
20
parse_text(FILE * in,FILE * out,int out_type,struct note_t * note)21 int parse_text(FILE *in, FILE *out, int out_type, struct note_t *note)
22 {
23 int x,y,lastch,ch;
24
25 logo_header_route(out,note,out_type);
26
27 x=0; y=0; lastch=0;
28 while ((ch=getc(in))!=EOF)
29 {
30 if (ch=='\n' || ch=='\r')
31 {
32 if ((lastch=='\r' || lastch=='\n') && (ch!=lastch && lastch!=0))
33 { continue; }
34
35 x=0; y++;
36 lastch=ch;
37 continue;
38 }
39
40 if (x<note->width)
41 {
42 if (ch==' ')
43 { note->picture[x+(y*note->width)]=0; }
44 else
45 { note->picture[x+(y*note->width)]=0xffffff; }
46 }
47
48 x++;
49 }
50
51 logo_footer_route(out,note,out_type);
52
53 return 0;
54 }
55
parse_ngg(FILE * in,FILE * out,int out_type,struct note_t * note)56 int parse_ngg(FILE *in, FILE *out, int out_type, struct note_t *note)
57 {
58 char temp[7];
59 int t,ptr,count,ch;
60
61 read_chars(in,temp,6);
62 temp[3]=0;
63
64 if (strcasecmp(temp,"nol")==0)
65 {
66 note->mcc=read_word(in);
67 note->mnc=read_word(in);
68 }
69
70 note->width=read_word(in);
71 note->height=read_word(in);
72 read_chars(in,temp,6);
73
74 count=note->width*note->height;
75
76 logo_header_route(out,note,out_type);
77
78 ptr=0;
79 for (t=0; t<count; t++)
80 {
81 ch=(getc(in));
82 if (ch=='0')
83 { note->picture[ptr++]=0; }
84 else
85 { note->picture[ptr++]=0xffffff; }
86 }
87
88 logo_footer_route(out,note,out_type);
89
90 return 0;
91 }
92
93 /*
94 int parse_logo(FILE *in, FILE *out, int in_type, int out_type, struct note_t *note, char *message)
95 {
96 int x,y,reverse;
97 char picture[8192];
98
99 bitptr=7;
100
101 if ((note->bmp_flags&1)==1)
102 { reverse=0; }
103 else
104 { reverse=1; }
105
106 #ifdef DEBUG
107 printf(" Width: %d\n",note->width);
108 printf(" Height: %d\n",note->height);
109 printf(" SMS Size: %d\n",full_sms_size);
110
111 if (note->mcc!=-1 && note->mnc!=-1)
112 {
113 printf(" MCC MNC: %d %d\n",note->mcc,note->mnc);
114 }
115 #endif
116
117 logo_header_route(out,note,out_type,message);
118
119 if (in_type==3)
120 {
121 if (parse_bitmap(in,note->width,note->height,picture)==-1)
122 {
123 printf("Could not read BMP.\n");
124 return -1;
125 }
126
127 for (y=note->height-1; y>=0; y--)
128 {
129 for (x=0; x<note->width; x++)
130 {
131 if (picture[(y*note->width)+x]==' ')
132 {
133 push(1^reverse,1);
134 }
135 else
136 {
137 push(0^reverse,1);
138 }
139 }
140 }
141 }
142 else
143 if (in_type==4)
144 {
145 parse_text(in,note,picture);
146
147 for (y=0; y<note->height; y++)
148 {
149 for (x=0; x<note->width; x++)
150 {
151 if (picture[(y*note->width)+x]==' ')
152 {
153 push(1^reverse,1);
154 }
155 else
156 {
157 push(0^reverse,1);
158 }
159 }
160 }
161 }
162
163 #ifdef DEBUG
164
165 printf("\n");
166 for (y=note->height-1; y>=0; y--)
167 {
168 for (x=0; x<note->width; x++)
169 {
170 if (picture[(y*note->width)+x]==' ')
171 {
172 printf("_");
173 }
174 else
175 {
176 printf("*");
177 }
178 }
179 printf("\n");
180 }
181 #endif
182
183 logo_footer_route(out,note,out_type);
184
185 return (0);
186 }
187 */
188
189 #ifdef DEBUG
debug_logo(struct note_t * note)190 void debug_logo(struct note_t *note)
191 {
192 int x,y,c,ptr;
193
194 printf("%d x %d\n",note->width,note->height);
195
196 ptr=0;
197 for (y=0; y<note->height; y++)
198 {
199 for (x=0; x<note->width; x++)
200 {
201 c=note->picture[ptr++];
202 c=((c&255)+((c>>8)&255)+((c>>16)&255))/3;
203
204 if (COLOR_BMP==1)
205 {
206 if (c<20)
207 { printf(" "); }
208 else
209 if (c<40)
210 { printf("."); }
211 else
212 if (c<60)
213 { printf(","); }
214 else
215 if (c<80)
216 { printf(":"); }
217 else
218 if (c<100)
219 { printf("|"); }
220 else
221 if (c<120)
222 { printf("&"); }
223 else
224 if (c<180)
225 { printf("@"); }
226 else
227 if (c<210)
228 { printf("*"); }
229 else
230 { printf("#"); }
231 }
232 else
233 {
234 if (c>COLOR_THRESHOLD)
235 { printf("*"); }
236 else
237 { printf(" "); }
238 }
239 }
240 printf("|\n");
241 }
242
243 }
244 #endif
245