Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 1369:3a94c0e8297f
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 24 Sep 2017 13:13:04 +0300 |
parents | d4387509a363 |
children | 53358cc2f9ff |
comparison
equal
deleted
inserted
replaced
1368:95e416830490 | 1369:3a94c0e8297f |
---|---|
178 | 178 |
179 return DMERR_OK; | 179 return DMERR_OK; |
180 } | 180 } |
181 | 181 |
182 | 182 |
183 static int dmDecodeGenericRLE(Uint8 **mem, Uint8 **pdstEnd, const Uint8 *src, const Uint8 *srcEnd, const Uint8 rleMarker) | |
184 { | |
185 Uint8 *dst, *dstEnd; | |
186 | |
187 if ((*mem = dmMalloc(C64_RAM_SIZE)) == NULL) | |
188 return DMERR_MALLOC; | |
189 | |
190 dst = *mem; | |
191 dstEnd = *mem + C64_RAM_SIZE; | |
192 | |
193 while (src <= srcEnd && dst <= dstEnd) | |
194 { | |
195 int c = *src++; | |
196 if (c == rleMarker && src + 2 <= srcEnd) | |
197 { | |
198 int cnt = *src++; | |
199 c = *src++; | |
200 while (cnt-- && dst <= dstEnd) | |
201 *dst++ = c; | |
202 } | |
203 else | |
204 *dst++ = c; | |
205 } | |
206 | |
207 *pdstEnd = dst; | |
208 | |
209 return DMERR_OK; | |
210 } | |
211 | |
212 | |
213 static BOOL fmtSetFLIType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len) | |
214 { | |
215 (void) buf; | |
216 (void) len; | |
217 img->fliType = op->bank; | |
218 return TRUE; | |
219 } | |
220 | |
221 | |
183 static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 222 static int fmtProbeDrazPaint20Packed(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
184 { | 223 { |
185 const char *ident = (const char *) buf + 2; | 224 const char *ident = (const char *) buf + 2; |
186 | 225 |
187 if (len > 22 && | 226 if (len > 22 && |
195 | 234 |
196 return DM_PROBE_SCORE_FALSE; | 235 return DM_PROBE_SCORE_FALSE; |
197 } | 236 } |
198 | 237 |
199 | 238 |
200 static int dmDecodeGenericRLE(Uint8 **mem, Uint8 **pdstEnd, const Uint8 *src, const Uint8 *srcEnd, const Uint8 rleMarker) | |
201 { | |
202 Uint8 *dst, *dstEnd; | |
203 | |
204 if ((*mem = dmMalloc(C64_RAM_SIZE)) == NULL) | |
205 return DMERR_MALLOC; | |
206 | |
207 dst = *mem; | |
208 dstEnd = *mem + C64_RAM_SIZE; | |
209 | |
210 while (src <= srcEnd && dst <= dstEnd) | |
211 { | |
212 int c = *src++; | |
213 if (c == rleMarker && src + 2 <= srcEnd) | |
214 { | |
215 int cnt = *src++; | |
216 c = *src++; | |
217 while (cnt-- && dst <= dstEnd) | |
218 *dst++ = c; | |
219 } | |
220 else | |
221 *dst++ = c; | |
222 } | |
223 | |
224 *pdstEnd = dst; | |
225 | |
226 return DMERR_OK; | |
227 } | |
228 | |
229 | |
230 static int fmtDecodeDrazPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 239 static int fmtDecodeDrazPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
231 { | 240 { |
232 int res; | 241 int res; |
233 Uint8 *mem = NULL, *dstEnd; | 242 Uint8 *mem = NULL, *dstEnd; |
234 | 243 |
283 return DM_PROBE_SCORE_GOOD; | 292 return DM_PROBE_SCORE_GOOD; |
284 if (n > 25) | 293 if (n > 25) |
285 return DM_PROBE_SCORE_AVG; | 294 return DM_PROBE_SCORE_AVG; |
286 if (n > 10) | 295 if (n > 10) |
287 return DM_PROBE_SCORE_MAYBE; | 296 return DM_PROBE_SCORE_MAYBE; |
297 | |
288 return DM_PROBE_SCORE_FALSE; | 298 return DM_PROBE_SCORE_FALSE; |
289 } | 299 } |
290 | 300 |
291 | 301 |
292 static int fmtDecodeAmicaPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 302 static int fmtDecodeAmicaPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
315 img->laceBank2 = 1; | 325 img->laceBank2 = 1; |
316 return TRUE; | 326 return TRUE; |
317 } | 327 } |
318 | 328 |
319 | 329 |
320 static BOOL fmtSetFLIType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len) | 330 #define XX2_MIN_SIZE 4000 |
321 { | |
322 (void) buf; | |
323 (void) len; | |
324 img->fliType = op->bank; | |
325 return TRUE; | |
326 } | |
327 | |
328 | 331 |
329 static int fmtProbeFormatXX2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 332 static int fmtProbeFormatXX2(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
330 { | 333 { |
331 if (len >= 4000 && len <= 4008 && | 334 if (len >= XX2_MIN_SIZE && len <= XX2_MIN_SIZE + 8 && |
332 dmCompareAddr16(buf, 0, fmt->addr)) | 335 dmCompareAddr16(buf, 0, fmt->addr)) |
333 return DM_PROBE_SCORE_MAYBE; | 336 return DM_PROBE_SCORE_MAYBE; |
334 | 337 |
335 return DM_PROBE_SCORE_FALSE; | 338 return DM_PROBE_SCORE_FALSE; |
336 } | 339 } |
337 | 340 |
338 | 341 |
339 static int fmtDecodeFormatXX2(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 342 static int fmtDecodeFormatXX2(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
340 { | 343 { |
341 int res; | 344 int res; |
342 size_t nlen = len < 4000 ? 4000 : len; | 345 // If there is only data for less than XX2_MIN_SIZE bytes, |
343 Uint8 *mem = dmMalloc(nlen); | 346 // allocate a buffer of that size and copy data there. |
347 // Otherwise allocate len bytes. | |
348 size_t nlen = len < XX2_MIN_SIZE ? XX2_MIN_SIZE : len; | |
349 Uint8 *mem = dmMalloc0(nlen); | |
344 if (mem == NULL) | 350 if (mem == NULL) |
345 return DMERR_MALLOC; | 351 return DMERR_MALLOC; |
346 | 352 |
347 memcpy(mem, buf, len); | 353 memcpy(mem, buf, len); |
348 res = dmC64DecodeGenericBMP(img, mem, nlen, fmt); | 354 res = dmC64DecodeGenericBMP(img, mem, nlen, fmt); |
352 } | 358 } |
353 | 359 |
354 | 360 |
355 | 361 |
356 | 362 |
363 // | |
364 // Array with data for supported formats | |
365 // | |
357 const DMC64ImageFormat dmC64ImageFormats[] = | 366 const DMC64ImageFormat dmC64ImageFormats[] = |
358 { | 367 { |
359 { | 368 { |
360 D64_FMT_MC, "d2p", "DrazPaint 2.0 (packed)", 0x5800, 0, | 369 D64_FMT_MC, "d2p", "DrazPaint 2.0 (packed)", 0x5800, 0, |
361 C64_SCR_WIDTH / 2, C64_SCR_HEIGHT, | 370 C64_SCR_WIDTH / 2, C64_SCR_HEIGHT, |