Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 1466:bc75be0546fc
More work on RLE decoder/encoder changes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 10 May 2018 21:46:50 +0300 |
parents | 88845f95e791 |
children | 32203356c652 |
comparison
equal
deleted
inserted
replaced
1465:88845f95e791 | 1466:bc75be0546fc |
---|---|
223 | 223 |
224 return DMERR_OK; | 224 return DMERR_OK; |
225 } | 225 } |
226 | 226 |
227 | 227 |
228 static int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const Uint8 rleMarker, const Uint8 rleMask, const int rleType) | 228 static int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, |
229 const Uint8 rleMarker, const Uint8 rleMask1, const Uint8 rleMask2, const int rleType) | |
229 { | 230 { |
230 int res; | 231 int res; |
231 | 232 |
232 if ((res = dmGrowBufAlloc(dst, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) | 233 if ((res = dmGrowBufAlloc(dst, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) |
234 { | |
235 dmError(res, | |
236 "Could not allocate RLE decoding buffer.\n"); | |
233 goto err; | 237 goto err; |
238 } | |
234 | 239 |
235 // Perform RLE decode | 240 // Perform RLE decode |
236 while (src < srcEnd) | 241 while (src < srcEnd) |
237 { | 242 { |
238 Uint8 c = *src++; | 243 Uint8 c = *src++; |
243 case DM_RLE_MARKER: | 248 case DM_RLE_MARKER: |
244 if (c == rleMarker) | 249 if (c == rleMarker) |
245 { | 250 { |
246 if (srcEnd - src < 2) | 251 if (srcEnd - src < 2) |
247 { | 252 { |
248 res = dmError(DMERR_INVALID_DATA, | 253 res = DMERR_INVALID_DATA; |
249 "Foobar: %d\n", srcEnd - src); | |
250 goto err; | 254 goto err; |
251 } | 255 } |
252 cnt = *src++; | 256 cnt = *src++; |
253 c = *src++; | 257 c = *src++; |
254 } | 258 } |
255 break; | 259 break; |
256 | 260 |
257 case DM_RLE_MASK: | 261 case DM_RLE_MASK: |
258 if ((c & rleMask) == rleMarker) | 262 if ((c & rleMask1) == rleMarker) |
259 { | 263 { |
260 if (srcEnd - src < 1) | 264 if (srcEnd - src < 1) |
261 { | 265 { |
262 res = dmError(DMERR_INVALID_DATA, | 266 res = DMERR_INVALID_DATA; |
263 "foobar2\n"); | |
264 goto err; | 267 goto err; |
265 } | 268 } |
269 | |
266 // XXX TODO actually we probably want another mask here | 270 // XXX TODO actually we probably want another mask here |
267 cnt = c & (0xff ^ rleMask); | 271 cnt = c & rleMask2; |
268 c = *src++; | 272 c = *src++; |
269 } | 273 } |
270 break; | 274 break; |
271 } | 275 } |
272 | 276 |
273 while (cnt--) | 277 while (cnt--) |
274 { | 278 { |
275 if (!dmGrowBufPutU8(dst, c)) | 279 if (!dmGrowBufPutU8(dst, c)) |
276 { | 280 { |
277 res = dmError(DMERR_MALLOC, | 281 res = DMERR_MALLOC; |
278 "bazzooo\n"); | |
279 goto err; | 282 goto err; |
280 } | 283 } |
281 } | 284 } |
282 } | 285 } |
283 | 286 |
290 err: | 293 err: |
291 return res; | 294 return res; |
292 } | 295 } |
293 | 296 |
294 | 297 |
295 static int dmEncodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const Uint8 rleMarker) | 298 static int dmEncodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, |
299 const Uint8 rleMarker, const Uint8 rleMask1, const Uint8 rleMask2, const int rleType) | |
296 { | 300 { |
297 (void) dst; | 301 (void) dst; |
298 (void) src; | 302 (void) src; |
299 (void) srcEnd; | 303 (void) srcEnd; |
300 (void) rleMarker; | 304 (void) rleMarker; |
305 (void) rleMask1; | |
306 (void) rleMask2; | |
307 (void) rleType; | |
308 | |
301 return DMERR_OK; | 309 return DMERR_OK; |
302 } | 310 } |
303 | 311 |
304 | 312 |
305 static inline Uint8 dmC64GetGenericSCPixel( | 313 static inline Uint8 dmC64GetGenericSCPixel( |
366 static int fmtDecodeDrazPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) | 374 static int fmtDecodeDrazPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) |
367 { | 375 { |
368 int res; | 376 int res; |
369 DMGrowBuf mem; | 377 DMGrowBuf mem; |
370 | 378 |
371 if ((res = dmDecodeGenericRLE(&mem, buf + 0x0e, buf + len, *(buf + 0x0d), 0, DM_RLE_MARKER)) != DMERR_OK) | 379 if ((res = dmDecodeGenericRLE(&mem, buf + 0x0e, buf + len, *(buf + 0x0d), 0, 0, DM_RLE_MARKER)) != DMERR_OK) |
372 goto out; | 380 goto out; |
373 | 381 |
374 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); | 382 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); |
375 | 383 |
376 out: | 384 out: |
448 tmp.len = len; | 456 tmp.len = len; |
449 memcpy(tmp.data, buf, len); | 457 memcpy(tmp.data, buf, len); |
450 tmp.data[tmp.len++] = 0; | 458 tmp.data[tmp.len++] = 0; |
451 | 459 |
452 // Now do an RLE decode on the enlarged buffer | 460 // Now do an RLE decode on the enlarged buffer |
453 if ((res = dmDecodeGenericRLE(&mem, tmp.data, tmp.data + tmp.len, 0xC2, 0, DM_RLE_MARKER)) != DMERR_OK) | 461 if ((res = dmDecodeGenericRLE(&mem, tmp.data, tmp.data + tmp.len, 0xC2, 0, 0, DM_RLE_MARKER)) != DMERR_OK) |
454 goto out; | 462 goto out; |
455 | 463 |
456 // And finally decode to bitmap struct | 464 // And finally decode to bitmap struct |
457 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); | 465 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); |
458 | 466 |
565 { | 573 { |
566 int res; | 574 int res; |
567 DMGrowBuf mem; | 575 DMGrowBuf mem; |
568 dmGrowBufInit(&mem); | 576 dmGrowBufInit(&mem); |
569 | 577 |
570 if ((res = dmDecodeGenericRLE(&mem, buf + FUNPAINT2_HEADER_SIZE, buf + len, *(buf + 15), 0, DM_RLE_MARKER)) != DMERR_OK) | 578 if ((res = dmDecodeGenericRLE(&mem, buf + FUNPAINT2_HEADER_SIZE, buf + len, *(buf + 15), 0, 0, DM_RLE_MARKER)) != DMERR_OK) |
571 goto out; | 579 goto out; |
572 | 580 |
573 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); | 581 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); |
574 | 582 |
575 out: | 583 out: |