1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <string.h>
4 #include <ctype.h>
5
6 #include "general.h"
7 #include "fileoutput.h"
8
9 /*
10
11 Ringtone Tools - Copyright 2001-2005 Michael Kohn (mike@mikekohn.net)
12 This falls under the Kohnian license. Please read
13 it at http://ringtonetools.mikekohn.net/
14
15 This program is NOT opensourced. You may not use any part
16 of this program for your own software.
17
18 */
19
parse_ems(FILE * in,FILE * out,int out_type,struct note_t * note)20 int parse_ems(FILE *in, FILE *out, int out_type, struct note_t *note)
21 {
22 unsigned char buffer[8192];
23 int s,t,ch,c,ptr,k;
24
25 ptr=0;
26 t=0; c=0;
27 while((ch=getc(in))!=EOF)
28 {
29 ch=tolower(ch);
30 if ((ch>='0' && ch<='9') || (ch>='a' && ch<='f'))
31 {
32 if (ch>='0' && ch<='9')
33 { t=(t<<4)+(ch-'0'); }
34 else
35 { t=(t<<4)+(ch-'a')+10; }
36 c++;
37
38 if ((c%2)==0)
39 {
40 buffer[ptr++]=t;
41 t=0;
42 }
43 }
44 }
45
46 s=4;
47 if (buffer[1]==0x11)
48 {
49 note->width=16;
50 note->height=16;
51 }
52 else
53 if (buffer[1]==0x10)
54 {
55 note->width=32;
56 note->height=32;
57 }
58 else
59 if (buffer[1]==0x12)
60 {
61 note->width=buffer[4]*8;
62 note->height=buffer[5];
63 s=s+2;
64 }
65 else
66 {
67 printf("Unknown or unsupported EMS type\n");
68 return 1;
69 }
70
71 logo_header_route(out,note,out_type);
72
73 k=0;
74 for (c=s; c<ptr; c++)
75 {
76 /* ring_stack[stackptr++]=buffer[t]; */
77 for (t=7; t>=0; t--)
78 {
79 if (((buffer[c]>>t)&1)==0)
80 { note->picture[k++]=0; }
81 else
82 { note->picture[k++]=0xffffff; }
83 }
84 }
85
86 logo_footer_route(out,note,out_type);
87
88 return (0);
89 }
90
91
92
93