Mercurial > hg > dmlib
comparison tools/lib64fmts.c @ 1649:dbdff3d50a4e
Clean up fmtDecodeTruePaintPacked() a bit, and fix GCC warnings about
(intentional) switch/case fallthroughs.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 30 May 2018 01:29:09 +0300 |
parents | 52cd979d63fd |
children | 9233da9de92c |
comparison
equal
deleted
inserted
replaced
1648:52cd979d63fd | 1649:dbdff3d50a4e |
---|---|
331 | 331 |
332 // | 332 // |
333 // Based on disassembly of the depacker routine. Encoding seems to be | 333 // Based on disassembly of the depacker routine. Encoding seems to be |
334 // some kind of "improved RLE" variant. | 334 // some kind of "improved RLE" variant. |
335 // | 335 // |
336 static BOOL fmtTruePaintGetByte(const Uint8 *src, size_t *srcOffs, Uint8 *data, int *res, const int mode) | |
337 { | |
338 if (!dmReverseGetByte(src, srcOffs, data)) | |
339 { | |
340 *res = dmError(DMERR_INVALID_DATA, | |
341 "TruePaintRLE: Out of input data (N=%d)\n", mode); | |
342 return FALSE; | |
343 } | |
344 else | |
345 return TRUE; | |
346 } | |
347 | |
348 | |
336 static int fmtDecodeTruePaintPacked(DMC64Image *img, const Uint8 *src, const size_t srcLen, const DMC64ImageFormat *fmt) | 349 static int fmtDecodeTruePaintPacked(DMC64Image *img, const Uint8 *src, const size_t srcLen, const DMC64ImageFormat *fmt) |
337 { | 350 { |
338 int res = DMERR_OK; | 351 int res = DMERR_OK; |
339 Uint8 *dst = NULL; | 352 Uint8 *dst = NULL; |
340 const Uint8 *codeBook1, *codeBook2; | 353 const Uint8 *codeBook1, *codeBook2; |
364 { | 377 { |
365 Uint8 data; | 378 Uint8 data; |
366 int count = 1, scount; | 379 int count = 1, scount; |
367 BOOL found = FALSE; | 380 BOOL found = FALSE; |
368 | 381 |
369 if (!dmReverseGetByte(src, &srcOffs, &data)) | 382 if (!fmtTruePaintGetByte(src, &srcOffs, &data, &res, -1)) |
370 { | |
371 res = dmError(DMERR_INVALID_DATA, | |
372 "TruePaintRLE: Out of source data.\n"); | |
373 goto out; | 383 goto out; |
374 } | |
375 | 384 |
376 for (int n = 0; n < 8; n++) | 385 for (int n = 0; n < 8; n++) |
377 if (codeBook1[n] == data && !found) | 386 if (codeBook1[n] == data && !found) |
378 { | 387 { |
379 found = TRUE; | 388 found = TRUE; |
380 switch (n) | 389 switch (n) |
381 { | 390 { |
382 case 4: // Y = 4, JTO = $0B | 391 case 4: // Y = 4, JTO = $0B |
383 if (!dmReverseGetByte(src, &srcOffs, &data)) | 392 if (!fmtTruePaintGetByte(src, &srcOffs, &data, &res, n)) |
384 { | |
385 res = dmError(DMERR_INVALID_DATA, | |
386 "TruePaintRLE: Y=4, JTO=$0B\n"); | |
387 goto out; | 393 goto out; |
388 } | |
389 | 394 |
390 count = data; | 395 count = data; |
391 if (data == 0) | 396 if (data == 0) |
392 { | |
393 fprintf(stderr, "TruePaintRLE: BAILOUT\n"); | |
394 goto finish; | 397 goto finish; |
395 } | 398 |
396 // NOTE: Intentional fall through here! | 399 // fallthrough |
397 | 400 |
398 case 1: // Y = 1, JTO = $17 | 401 case 1: // Y = 1, JTO = $17 |
399 count += 2; | 402 count += 2; |
400 // NOTE: Intentional fallthrough here! | 403 // fallthrough |
401 | 404 |
402 case 0: // Y = 0, JTO = $19 | 405 case 0: // Y = 0, JTO = $19 |
403 if (!dmReverseGetByte(src, &srcOffs, &data)) | 406 if (!fmtTruePaintGetByte(src, &srcOffs, &data, &res, n)) |
404 { | |
405 res = dmError(DMERR_INVALID_DATA, | |
406 "TruePaintRLE: Y=0, JTO=$19\n"); | |
407 goto out; | 407 goto out; |
408 } | |
409 break; | 408 break; |
410 | 409 |
411 case 2: // Y = 2, JTO = $07 | 410 case 2: // Y = 2, JTO = $07 |
412 if (!dmReverseGetByte(src, &srcOffs, &data)) | 411 if (!fmtTruePaintGetByte(src, &srcOffs, &data, &res, n)) |
413 { | |
414 res = dmError(DMERR_INVALID_DATA, | |
415 "foo: Y=2, JTO=$07\n"); | |
416 goto out; | 412 goto out; |
417 } | 413 |
418 count = data; | 414 count = data; |
419 // NOTE: Intentional fallthrough here! | 415 // fallthrough |
420 | 416 |
421 case 3: // Y = 3, JTO = $0B | 417 case 3: // Y = 3, JTO = $0B |
422 count += 2; | 418 count += 2; |
423 data = 0; | 419 data = 0; |
424 break; | 420 break; |