@@ -125,6 +125,89 @@ void SaveTIM_4bit(char* filename,
125125 fwrite (&datahdr, 1 , sizeof (datahdr), pFile);
126126 fwrite (image_data, 1 , datahdr.len - sizeof (TIMIMAGEHDR), pFile);
127127
128+ // dun
129+ fclose (pFile);
130+ }
131+
132+ void SaveTIM_8bit (char * filename,
133+ ubyte* image_data, int image_size,
134+ int x, int y, int w, int h,
135+ ubyte* clut_data, int clut_h)
136+ {
137+ // compose TIMs
138+ //
139+ // prep headers
140+ TIMHDR hdr;
141+ hdr.magic = 0x10 ;
142+ hdr.flags = 0x09 ; // for 8bpp
143+
144+ TIMIMAGEHDR cluthdr;
145+ TIMIMAGEHDR datahdr;
146+
147+ cluthdr.origin_x = 0 ;
148+ cluthdr.origin_y = 0 ;
149+
150+ cluthdr.width = 256 ; // CLUTs always 16 bit color
151+ cluthdr.height = clut_h;
152+ cluthdr.len = (cluthdr.width * cluthdr.height * sizeof (ushort)) + sizeof (TIMIMAGEHDR);
153+
154+ datahdr.origin_x = x;
155+ datahdr.origin_y = y;
156+
157+ datahdr.width = (w >> 1 );
158+ datahdr.height = h;
159+ datahdr.len = image_size + sizeof (TIMIMAGEHDR);
160+
161+ FILE* pFile = fopen (filename, " wb" );
162+ if (!pFile)
163+ return ;
164+
165+ // write header
166+ fwrite (&hdr, 1 , sizeof (hdr), pFile);
167+
168+ // write clut
169+ fwrite (&cluthdr, 1 , sizeof (cluthdr), pFile);
170+ fwrite (clut_data, 1 , cluthdr.len - sizeof (TIMIMAGEHDR), pFile);
171+
172+ // write data
173+ fwrite (&datahdr, 1 , sizeof (datahdr), pFile);
174+ fwrite (image_data, 1 , datahdr.len - sizeof (TIMIMAGEHDR), pFile);
175+
176+ // dun
177+ fclose (pFile);
178+ }
179+
180+ void SaveTIM_16bit (char * filename,
181+ ubyte* image_data, int image_size,
182+ int x, int y, int w, int h)
183+ {
184+ // compose TIMs
185+ //
186+ // prep headers
187+ TIMHDR hdr;
188+ hdr.magic = 0x10 ;
189+ hdr.flags = 0x02 ; // for 16bpp
190+
191+ TIMIMAGEHDR datahdr;
192+
193+ datahdr.origin_x = x;
194+ datahdr.origin_y = y;
195+
196+ datahdr.width = w;
197+ datahdr.height = h;
198+ datahdr.len = image_size + sizeof (TIMIMAGEHDR);
199+
200+ FILE* pFile = fopen (filename, " wb" );
201+ if (!pFile)
202+ return ;
203+
204+ // write header
205+ fwrite (&hdr, 1 , sizeof (hdr), pFile);
206+
207+ // write data
208+ fwrite (&datahdr, 1 , sizeof (datahdr), pFile);
209+ fwrite (image_data, 1 , datahdr.len - sizeof (TIMIMAGEHDR), pFile);
210+
128211 // dun
129212 fclose (pFile);
130213}
0 commit comments