comparison tools/libgfx.c @ 2586:9807ae37ad69

Require stdbool.h, we require C11 now.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 08 Dec 2022 15:59:22 +0200
parents 92b93a12c014
children c3c1d3c75f53
comparison
equal deleted inserted replaced
2585:ef6c826c5b7a 2586:9807ae37ad69
324 { 324 {
325 if (len == 0x304 && 325 if (len == 0x304 &&
326 buf[0x300] == 0) 326 buf[0x300] == 0)
327 return DM_PROBE_SCORE_MAX; 327 return DM_PROBE_SCORE_MAX;
328 328
329 return DM_PROBE_SCORE_FALSE; 329 return DM_PROBE_SCORE_false;
330 } 330 }
331 331
332 332
333 int dmReadACTPalette(DMResource *fp, DMPalette **pdst) 333 int dmReadACTPalette(DMResource *fp, DMPalette **pdst)
334 { 334 {
393 (void) buf; 393 (void) buf;
394 394
395 if (len == 0x300) 395 if (len == 0x300)
396 return DM_PROBE_SCORE_MAX; 396 return DM_PROBE_SCORE_MAX;
397 397
398 return DM_PROBE_SCORE_FALSE; 398 return DM_PROBE_SCORE_false;
399 } 399 }
400 400
401 401
402 int dmReadRAWPalette(DMResource *fp, DMPalette **pdst) 402 int dmReadRAWPalette(DMResource *fp, DMPalette **pdst)
403 { 403 {
879 "Conversion of non-indexed image to indexed not supported yet.\n"); 879 "Conversion of non-indexed image to indexed not supported yet.\n");
880 } 880 }
881 881
882 // Force non-planar etc 882 // Force non-planar etc
883 memcpy(&tmpSpec, spec, sizeof(DMImageWriteSpec)); 883 memcpy(&tmpSpec, spec, sizeof(DMImageWriteSpec));
884 tmpSpec.planar = FALSE; 884 tmpSpec.planar = false;
885 885
886 switch (tmpSpec.pixfmt) 886 switch (tmpSpec.pixfmt)
887 { 887 {
888 case DM_PIXFMT_RGB: 888 case DM_PIXFMT_RGB:
889 case DM_PIXFMT_RGBA: 889 case DM_PIXFMT_RGBA:
918 return dmWriteImageData(img, (void *) fp, dmWritePPMRow, &tmpSpec); 918 return dmWriteImageData(img, (void *) fp, dmWritePPMRow, &tmpSpec);
919 } 919 }
920 920
921 921
922 // Read a PPM/PGM/PNM header line, skipping comments 922 // Read a PPM/PGM/PNM header line, skipping comments
923 static BOOL dmReadPPMHeader(DMResource *fp, char *buf, const size_t bufLen) 923 static bool dmReadPPMHeader(DMResource *fp, char *buf, const size_t bufLen)
924 { 924 {
925 BOOL end = FALSE, comment = FALSE; 925 bool end = false, comment = false;
926 size_t offs = 0; 926 size_t offs = 0;
927 927
928 do 928 do
929 { 929 {
930 int ch = dmfgetc(fp); 930 int ch = dmfgetc(fp);
931 if (ch == EOF) 931 if (ch == EOF)
932 return FALSE; 932 return false;
933 else 933 else
934 if (ch == '#') 934 if (ch == '#')
935 comment = TRUE; 935 comment = true;
936 else 936 else
937 if (ch == '\n') 937 if (ch == '\n')
938 { 938 {
939 if (!comment) 939 if (!comment)
940 end = TRUE; 940 end = true;
941 else 941 else
942 comment = FALSE; 942 comment = false;
943 } 943 }
944 else 944 else
945 if (!comment) 945 if (!comment)
946 { 946 {
947 if (offs < bufLen - 1) 947 if (offs < bufLen - 1)
948 buf[offs++] = ch; 948 buf[offs++] = ch;
949 } 949 }
950 } while (!end); 950 } while (!end);
951 951
952 buf[offs] = 0; 952 buf[offs] = 0;
953 return TRUE; 953 return true;
954 } 954 }
955 955
956 956
957 int dmReadPPMImage(DMResource *fp, DMImage **pimg) 957 int dmReadPPMImage(DMResource *fp, DMImage **pimg)
958 { 958 {
1031 if (len > 32 && 1031 if (len > 32 &&
1032 buf[0] == 'P' && 1032 buf[0] == 'P' &&
1033 (buf[1] == '5' || buf[1] == '6')) 1033 (buf[1] == '5' || buf[1] == '6'))
1034 return DM_PROBE_SCORE_MAX; 1034 return DM_PROBE_SCORE_MAX;
1035 1035
1036 return DM_PROBE_SCORE_FALSE; 1036 return DM_PROBE_SCORE_false;
1037 } 1037 }
1038 1038
1039 1039
1040 #ifdef DM_USE_LIBPNG 1040 #ifdef DM_USE_LIBPNG
1041 static int fmtProbePNG(const Uint8 *buf, const size_t len) 1041 static int fmtProbePNG(const Uint8 *buf, const size_t len)
1049 return DM_PROBE_SCORE_MAX; 1049 return DM_PROBE_SCORE_MAX;
1050 else 1050 else
1051 return DM_PROBE_SCORE_GOOD; 1051 return DM_PROBE_SCORE_GOOD;
1052 } 1052 }
1053 1053
1054 return DM_PROBE_SCORE_FALSE; 1054 return DM_PROBE_SCORE_false;
1055 } 1055 }
1056 1056
1057 1057
1058 static int dmWritePNGRow(void *cbdata, const Uint8 *row, const size_t len) 1058 static int dmWritePNGRow(void *cbdata, const Uint8 *row, const size_t len)
1059 { 1059 {
1434 buf[2] == 1 && 1434 buf[2] == 1 &&
1435 (buf[3] == 8 || buf[3] == 4 || buf[3] == 3 || buf[3] == 1) && 1435 (buf[3] == 8 || buf[3] == 4 || buf[3] == 3 || buf[3] == 1) &&
1436 buf[65] >= 1 && buf[65] <= 4) 1436 buf[65] >= 1 && buf[65] <= 4)
1437 return DM_PROBE_SCORE_GOOD; 1437 return DM_PROBE_SCORE_GOOD;
1438 1438
1439 return DM_PROBE_SCORE_FALSE; 1439 return DM_PROBE_SCORE_false;
1440 } 1440 }
1441 1441
1442 1442
1443 // Returns one byte from row buffer (of length len) at offset soffs, 1443 // Returns one byte from row buffer (of length len) at offset soffs,
1444 // OR zero if the offset is outside buffer. 1444 // OR zero if the offset is outside buffer.
1445 static inline Uint8 dmPCXGetByte(const Uint8 *row, const size_t len, const size_t soffs) 1445 static inline Uint8 dmPCXGetByte(const Uint8 *row, const size_t len, const size_t soffs)
1446 { 1446 {
1447 return (soffs < len) ? row[soffs] : 0; 1447 return (soffs < len) ? row[soffs] : 0;
1448 } 1448 }
1449 1449
1450 static BOOL dmPCXFlush(DMPCXData *pcx) 1450 static bool dmPCXFlush(DMPCXData *pcx)
1451 { 1451 {
1452 BOOL ret = TRUE; 1452 bool ret = true;
1453 if (pcx->bufOffs > 0) 1453 if (pcx->bufOffs > 0)
1454 ret = dmf_write_str(pcx->fp, pcx->buf, pcx->bufOffs); 1454 ret = dmf_write_str(pcx->fp, pcx->buf, pcx->bufOffs);
1455 1455
1456 pcx->bufOffs = 0; 1456 pcx->bufOffs = 0;
1457 return ret; 1457 return ret;
1458 } 1458 }
1459 1459
1460 static inline BOOL dmPCXPutByte(DMPCXData *pcx, const Uint8 val) 1460 static inline bool dmPCXPutByte(DMPCXData *pcx, const Uint8 val)
1461 { 1461 {
1462 if (pcx->bufOffs < pcx->bufLen) 1462 if (pcx->bufOffs < pcx->bufLen)
1463 { 1463 {
1464 pcx->buf[pcx->bufOffs++] = val; 1464 pcx->buf[pcx->bufOffs++] = val;
1465 return TRUE; 1465 return true;
1466 } 1466 }
1467 else 1467 else
1468 return dmPCXFlush(pcx); 1468 return dmPCXFlush(pcx);
1469 } 1469 }
1470 1470
1535 DMImageWriteSpec spec; 1535 DMImageWriteSpec spec;
1536 int res; 1536 int res;
1537 1537
1538 // Always force planar for PCX 1538 // Always force planar for PCX
1539 memcpy(&spec, pspec, sizeof(DMImageWriteSpec)); 1539 memcpy(&spec, pspec, sizeof(DMImageWriteSpec));
1540 spec.planar = TRUE; 1540 spec.planar = true;
1541 1541
1542 // XXX: 24bit PCX does not work yet .. 1542 // XXX: 24bit PCX does not work yet ..
1543 if ((img->pixfmt != DM_PIXFMT_PALETTE && img->pixfmt != DM_PIXFMT_GRAYSCALE) || 1543 if ((img->pixfmt != DM_PIXFMT_PALETTE && img->pixfmt != DM_PIXFMT_GRAYSCALE) ||
1544 (spec.pixfmt != DM_PIXFMT_PALETTE && spec.pixfmt != DM_PIXFMT_GRAYSCALE)) 1544 (spec.pixfmt != DM_PIXFMT_PALETTE && spec.pixfmt != DM_PIXFMT_GRAYSCALE))
1545 { 1545 {
1669 dmFree(pcx.buf); 1669 dmFree(pcx.buf);
1670 return res; 1670 return res;
1671 } 1671 }
1672 1672
1673 1673
1674 static BOOL dmPCXDecodeRLERow(DMResource *fp, Uint8 *buf, const size_t bufLen) 1674 static bool dmPCXDecodeRLERow(DMResource *fp, Uint8 *buf, const size_t bufLen)
1675 { 1675 {
1676 size_t offs = 0; 1676 size_t offs = 0;
1677 do 1677 do
1678 { 1678 {
1679 int count; 1679 int count;
1680 Uint8 data; 1680 Uint8 data;
1681 1681
1682 if (!dmf_read_byte(fp, &data)) 1682 if (!dmf_read_byte(fp, &data))
1683 return FALSE; 1683 return false;
1684 1684
1685 if ((data & 0xC0) == 0xC0) 1685 if ((data & 0xC0) == 0xC0)
1686 { 1686 {
1687 BOOL skip = FALSE; 1687 bool skip = false;
1688 count = data & 0x3F; 1688 count = data & 0x3F;
1689 if (count == 0) 1689 if (count == 0)
1690 { 1690 {
1691 switch (dmGFXErrorMode) 1691 switch (dmGFXErrorMode)
1692 { 1692 {
1693 case DM_ERRMODE_RECOV_1: 1693 case DM_ERRMODE_RECOV_1:
1694 // Use as literal 1694 // Use as literal
1695 skip = TRUE; 1695 skip = true;
1696 count = 1; 1696 count = 1;
1697 break; 1697 break;
1698 1698
1699 case DM_ERRMODE_RECOV_2: 1699 case DM_ERRMODE_RECOV_2:
1700 // Ignore completely 1700 // Ignore completely
1701 skip = TRUE; 1701 skip = true;
1702 break; 1702 break;
1703 1703
1704 case DM_ERRMODE_FAIL: 1704 case DM_ERRMODE_FAIL:
1705 default: 1705 default:
1706 // Error out on "invalid" data 1706 // Error out on "invalid" data
1707 return FALSE; 1707 return false;
1708 } 1708 }
1709 } 1709 }
1710 1710
1711 if (!skip && !dmf_read_byte(fp, &data)) 1711 if (!skip && !dmf_read_byte(fp, &data))
1712 return FALSE; 1712 return false;
1713 } 1713 }
1714 else 1714 else
1715 count = 1; 1715 count = 1;
1716 1716
1717 while (count-- && offs < bufLen) 1717 while (count-- && offs < bufLen)
1718 buf[offs++] = data; 1718 buf[offs++] = data;
1719 1719
1720 // Check for remaining output count, error out if we wish to 1720 // Check for remaining output count, error out if we wish to
1721 if (count > 0 && dmGFXErrorMode == DM_ERRMODE_FAIL) 1721 if (count > 0 && dmGFXErrorMode == DM_ERRMODE_FAIL)
1722 return FALSE; 1722 return false;
1723 1723
1724 } while (offs < bufLen); 1724 } while (offs < bufLen);
1725 1725
1726 return TRUE; 1726 return true;
1727 } 1727 }
1728 1728
1729 1729
1730 int dmReadPCXImage(DMResource *fp, DMImage **pimg) 1730 int dmReadPCXImage(DMResource *fp, DMImage **pimg)
1731 { 1731 {
1732 DMImage *img; 1732 DMImage *img;
1733 DMPCXData pcx; 1733 DMPCXData pcx;
1734 DMPCXHeader hdr; 1734 DMPCXHeader hdr;
1735 int res = 0; 1735 int res = 0;
1736 BOOL isPaletted; 1736 bool isPaletted;
1737 pcx.buf = NULL; 1737 pcx.buf = NULL;
1738 1738
1739 // Read PCX header 1739 // Read PCX header
1740 if (!dmf_read_byte(fp, &hdr.manufacturer) || 1740 if (!dmf_read_byte(fp, &hdr.manufacturer) ||
1741 !dmf_read_byte(fp, &hdr.version) || 1741 !dmf_read_byte(fp, &hdr.version) ||
1912 // Read additional VGA palette, if available 1912 // Read additional VGA palette, if available
1913 if (isPaletted) 1913 if (isPaletted)
1914 { 1914 {
1915 int ncolors; 1915 int ncolors;
1916 Uint8 tmpb; 1916 Uint8 tmpb;
1917 BOOL read; 1917 bool read;
1918 1918
1919 if (!dmf_read_byte(fp, &tmpb) || tmpb != 0x0C) 1919 if (!dmf_read_byte(fp, &tmpb) || tmpb != 0x0C)
1920 { 1920 {
1921 read = FALSE; 1921 read = false;
1922 ncolors = PCX_PAL_COLORS; 1922 ncolors = PCX_PAL_COLORS;
1923 } 1923 }
1924 else 1924 else
1925 { 1925 {
1926 read = TRUE; 1926 read = true;
1927 ncolors = 256; 1927 ncolors = 256;
1928 } 1928 }
1929 1929
1930 if ((res = dmPaletteAlloc(&(img->pal), ncolors, -1)) != DMERR_OK) 1930 if ((res = dmPaletteAlloc(&(img->pal), ncolors, -1)) != DMERR_OK)
1931 { 1931 {
2038 return DM_PROBE_SCORE_MAX; 2038 return DM_PROBE_SCORE_MAX;
2039 else 2039 else
2040 return DM_PROBE_SCORE_GOOD; 2040 return DM_PROBE_SCORE_GOOD;
2041 } 2041 }
2042 2042
2043 return DM_PROBE_SCORE_FALSE; 2043 return DM_PROBE_SCORE_false;
2044 } 2044 }
2045 2045
2046 2046
2047 static int fmtProbeIFF_ILBM(const Uint8 *buf, const size_t len) 2047 static int fmtProbeIFF_ILBM(const Uint8 *buf, const size_t len)
2048 { 2048 {
2119 return DMERR_OK; 2119 return DMERR_OK;
2120 } 2120 }
2121 2121
2122 2122
2123 static int dmCheckIFFChunk(DMIFFChunk *dest, const DMIFFChunk *chunk, 2123 static int dmCheckIFFChunk(DMIFFChunk *dest, const DMIFFChunk *chunk,
2124 const BOOL multi, const Uint32 minSize) 2124 const bool multi, const Uint32 minSize)
2125 { 2125 {
2126 if (dest->count > 0 && !multi) 2126 if (dest->count > 0 && !multi)
2127 { 2127 {
2128 return dmError(DMERR_INVALID_DATA, 2128 return dmError(DMERR_INVALID_DATA,
2129 "IFF: Multiple instances of chunk %s found.\n", 2129 "IFF: Multiple instances of chunk %s found.\n",
2141 2141
2142 return DMERR_OK; 2142 return DMERR_OK;
2143 } 2143 }
2144 2144
2145 2145
2146 BOOL dmIFFDecodeByteRun1Row(DMResource *fp, Uint8 *buf, const size_t bufLen) 2146 bool dmIFFDecodeByteRun1Row(DMResource *fp, Uint8 *buf, const size_t bufLen)
2147 { 2147 {
2148 size_t offs = 0; 2148 size_t offs = 0;
2149 do 2149 do
2150 { 2150 {
2151 Uint8 data, ucount; 2151 Uint8 data, ucount;
2152 2152
2153 if (!dmf_read_byte(fp, &ucount)) 2153 if (!dmf_read_byte(fp, &ucount))
2154 return FALSE; 2154 return false;
2155 2155
2156 if (ucount == 0x80) 2156 if (ucount == 0x80)
2157 { 2157 {
2158 if (!dmf_read_byte(fp, &data)) 2158 if (!dmf_read_byte(fp, &data))
2159 return FALSE; 2159 return false;
2160 } 2160 }
2161 else 2161 else
2162 if (ucount & 0x80) 2162 if (ucount & 0x80)
2163 { 2163 {
2164 Uint8 count = (ucount ^ 0xff) + 2; 2164 Uint8 count = (ucount ^ 0xff) + 2;
2165 if (!dmf_read_byte(fp, &data)) 2165 if (!dmf_read_byte(fp, &data))
2166 return FALSE; 2166 return false;
2167 2167
2168 while (count-- && offs < bufLen) 2168 while (count-- && offs < bufLen)
2169 buf[offs++] = data; 2169 buf[offs++] = data;
2170 } 2170 }
2171 else 2171 else
2172 { 2172 {
2173 Uint8 count = ucount + 1; 2173 Uint8 count = ucount + 1;
2174 while (count-- && offs < bufLen) 2174 while (count-- && offs < bufLen)
2175 { 2175 {
2176 if (!dmf_read_byte(fp, &data)) 2176 if (!dmf_read_byte(fp, &data))
2177 return FALSE; 2177 return false;
2178 2178
2179 buf[offs++] = data; 2179 buf[offs++] = data;
2180 } 2180 }
2181 } 2181 }
2182 } while (offs < bufLen); 2182 } while (offs < bufLen);
2183 2183
2184 return TRUE; 2184 return true;
2185 } 2185 }
2186 2186
2187 2187
2188 static BOOL dmIFFReadOneRow(DMResource *fp, DMIFF *iff, Uint8 *buf, const size_t bufLen) 2188 static bool dmIFFReadOneRow(DMResource *fp, DMIFF *iff, Uint8 *buf, const size_t bufLen)
2189 { 2189 {
2190 if (iff->bmhd.compression == IFF_COMP_BYTERUN1) 2190 if (iff->bmhd.compression == IFF_COMP_BYTERUN1)
2191 return dmIFFDecodeByteRun1Row(fp, buf, bufLen); 2191 return dmIFFDecodeByteRun1Row(fp, buf, bufLen);
2192 else 2192 else
2193 return dmf_read_str(fp, buf, bufLen); 2193 return dmf_read_str(fp, buf, bufLen);
2321 2321
2322 int dmReadIFFImage(DMResource *fp, DMImage **pimg) 2322 int dmReadIFFImage(DMResource *fp, DMImage **pimg)
2323 { 2323 {
2324 DMIFFChunk chunk; 2324 DMIFFChunk chunk;
2325 DMIFF iff; 2325 DMIFF iff;
2326 BOOL parsed = FALSE; 2326 bool parsed = false;
2327 int res = DMERR_OK; 2327 int res = DMERR_OK;
2328 2328
2329 memset(&iff, 0, sizeof(iff)); 2329 memset(&iff, 0, sizeof(iff));
2330 2330
2331 // Read IFF FORM header 2331 // Read IFF FORM header
2362 2362
2363 switch (chunk.id) 2363 switch (chunk.id)
2364 { 2364 {
2365 case IFF_ID_BMHD: 2365 case IFF_ID_BMHD:
2366 // Check for multiple occurences of BMHD 2366 // Check for multiple occurences of BMHD
2367 if ((res = dmCheckIFFChunk(&iff.chBMHD, &chunk, FALSE, sizeof(iff.bmhd))) != DMERR_OK) 2367 if ((res = dmCheckIFFChunk(&iff.chBMHD, &chunk, false, sizeof(iff.bmhd))) != DMERR_OK)
2368 return res; 2368 return res;
2369 2369
2370 // Read BMHD data 2370 // Read BMHD data
2371 if (!dmf_read_be16(fp, &iff.bmhd.w) || 2371 if (!dmf_read_be16(fp, &iff.bmhd.w) ||
2372 !dmf_read_be16(fp, &iff.bmhd.h) || 2372 !dmf_read_be16(fp, &iff.bmhd.h) ||
2414 break; 2414 break;
2415 2415
2416 2416
2417 case IFF_ID_CMAP: 2417 case IFF_ID_CMAP:
2418 // Check for multiple occurences of CMAP 2418 // Check for multiple occurences of CMAP
2419 if ((res = dmCheckIFFChunk(&iff.chCMAP, &chunk, FALSE, 3)) != DMERR_OK) 2419 if ((res = dmCheckIFFChunk(&iff.chCMAP, &chunk, false, 3)) != DMERR_OK)
2420 return res; 2420 return res;
2421 2421
2422 // Check for sanity 2422 // Check for sanity
2423 if (chunk.size % 3 != 0) 2423 if (chunk.size % 3 != 0)
2424 { 2424 {
2449 return res; 2449 return res;
2450 } 2450 }
2451 } 2451 }
2452 2452
2453 if (iff.chBMHD.count && iff.chBODY.count) 2453 if (iff.chBMHD.count && iff.chBODY.count)
2454 parsed = TRUE; 2454 parsed = true;
2455 break; 2455 break;
2456 2456
2457 case IFF_ID_BODY: 2457 case IFF_ID_BODY:
2458 case IFF_ID_ABIT: 2458 case IFF_ID_ABIT:
2459 // Check for multiple occurences of BODY 2459 // Check for multiple occurences of BODY
2460 if ((res = dmCheckIFFChunk(&iff.chBODY, &chunk, FALSE, 1)) != DMERR_OK) 2460 if ((res = dmCheckIFFChunk(&iff.chBODY, &chunk, false, 1)) != DMERR_OK)
2461 return res; 2461 return res;
2462 2462
2463 // Check for sanity 2463 // Check for sanity
2464 if (!iff.chBMHD.count) 2464 if (!iff.chBMHD.count)
2465 { 2465 {
2495 2495
2496 if ((res = dmSkipIFFChunkRest(fp, &chunk)) != DMERR_OK) 2496 if ((res = dmSkipIFFChunkRest(fp, &chunk)) != DMERR_OK)
2497 return res; 2497 return res;
2498 2498
2499 if (iff.chCMAP.count) 2499 if (iff.chCMAP.count)
2500 parsed = TRUE; 2500 parsed = true;
2501 break; 2501 break;
2502 2502
2503 case IFF_ID_CAMG: 2503 case IFF_ID_CAMG:
2504 if (!dmf_read_be32(fp, &iff.camg)) 2504 if (!dmf_read_be32(fp, &iff.camg))
2505 { 2505 {
2639 DMODE_LIT, 2639 DMODE_LIT,
2640 DMODE_RLE, 2640 DMODE_RLE,
2641 }; 2641 };
2642 2642
2643 2643
2644 static BOOL dmIFFEncodeByteRun1LIT(DMResource *fp, 2644 static bool dmIFFEncodeByteRun1LIT(DMResource *fp,
2645 const Uint8 *buf, const size_t offs, 2645 const Uint8 *buf, const size_t offs,
2646 const size_t count) 2646 const size_t count)
2647 { 2647 {
2648 if (count <= 0) 2648 if (count <= 0)
2649 return TRUE; 2649 return true;
2650 2650
2651 Uint8 tmp = count - 1; 2651 Uint8 tmp = count - 1;
2652 2652
2653 return 2653 return
2654 dmf_write_byte(fp, tmp) && 2654 dmf_write_byte(fp, tmp) &&
2655 dmf_write_str(fp, buf + offs, count); 2655 dmf_write_str(fp, buf + offs, count);
2656 } 2656 }
2657 2657
2658 2658
2659 static BOOL dmIFFEncodeByteRun1RLE(DMResource *fp, 2659 static bool dmIFFEncodeByteRun1RLE(DMResource *fp,
2660 const Uint8 *buf, const size_t offs, 2660 const Uint8 *buf, const size_t offs,
2661 const size_t count) 2661 const size_t count)
2662 { 2662 {
2663 if (count <= 0) 2663 if (count <= 0)
2664 return TRUE; 2664 return true;
2665 2665
2666 Uint8 2666 Uint8
2667 tmp = ((Uint8) count - 2) ^ 0xff, 2667 tmp = ((Uint8) count - 2) ^ 0xff,
2668 data = buf[offs]; 2668 data = buf[offs];
2669 2669
2671 dmf_write_byte(fp, tmp) && 2671 dmf_write_byte(fp, tmp) &&
2672 dmf_write_byte(fp, data); 2672 dmf_write_byte(fp, data);
2673 } 2673 }
2674 2674
2675 2675
2676 BOOL dmIFFEncodeByteRun1Row(DMResource *fp, const Uint8 *buf, const size_t bufLen) 2676 bool dmIFFEncodeByteRun1Row(DMResource *fp, const Uint8 *buf, const size_t bufLen)
2677 { 2677 {
2678 int prev = -1, mode = DMODE_LIT; 2678 int prev = -1, mode = DMODE_LIT;
2679 size_t offs, l_offs, r_offs; 2679 size_t offs, l_offs, r_offs;
2680 BOOL ret = TRUE; 2680 bool ret = true;
2681 2681
2682 for (offs = l_offs = r_offs = 0; offs < bufLen; offs++) 2682 for (offs = l_offs = r_offs = 0; offs < bufLen; offs++)
2683 { 2683 {
2684 Uint8 data = buf[offs]; 2684 Uint8 data = buf[offs];
2685 BOOL flush = FALSE; 2685 bool flush = false;
2686 int pmode = mode; 2686 int pmode = mode;
2687 2687
2688 if (data == prev) 2688 if (data == prev)
2689 { 2689 {
2690 if (mode == DMODE_LIT && 2690 if (mode == DMODE_LIT &&
2715 2715
2716 // Check for last byte of input 2716 // Check for last byte of input
2717 if (offs == bufLen - 1) 2717 if (offs == bufLen - 1)
2718 { 2718 {
2719 offs++; 2719 offs++;
2720 flush = TRUE; 2720 flush = true;
2721 pmode = mode; 2721 pmode = mode;
2722 } 2722 }
2723 2723
2724 if (flush) 2724 if (flush)
2725 { 2725 {
2741 out: 2741 out:
2742 return ret; 2742 return ret;
2743 } 2743 }
2744 2744
2745 2745
2746 static BOOL dmIFFWriteOneRow(DMResource *fp, DMIFF *iff, const Uint8 *buf, const size_t bufLen) 2746 static bool dmIFFWriteOneRow(DMResource *fp, DMIFF *iff, const Uint8 *buf, const size_t bufLen)
2747 { 2747 {
2748 if (iff->bmhd.compression == IFF_COMP_BYTERUN1) 2748 if (iff->bmhd.compression == IFF_COMP_BYTERUN1)
2749 return dmIFFEncodeByteRun1Row(fp, buf, bufLen); 2749 return dmIFFEncodeByteRun1Row(fp, buf, bufLen);
2750 else 2750 else
2751 return dmf_write_str(fp, buf, bufLen); 2751 return dmf_write_str(fp, buf, bufLen);
3053 const int ndmImageFormatList = sizeof(dmImageFormatList) / sizeof(dmImageFormatList[0]); 3053 const int ndmImageFormatList = sizeof(dmImageFormatList) / sizeof(dmImageFormatList[0]);
3054 3054
3055 3055
3056 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **pfmt, int *index) 3056 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **pfmt, int *index)
3057 { 3057 {
3058 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; 3058 int scoreMax = DM_PROBE_SCORE_false, scoreIndex = -1;
3059 3059
3060 for (int i = 0; i < ndmImageFormatList; i++) 3060 for (int i = 0; i < ndmImageFormatList; i++)
3061 { 3061 {
3062 const DMImageFormat *fmt = &dmImageFormatList[i]; 3062 const DMImageFormat *fmt = &dmImageFormatList[i];
3063 if (fmt->probe != NULL) 3063 if (fmt->probe != NULL)
3076 *pfmt = &dmImageFormatList[scoreIndex]; 3076 *pfmt = &dmImageFormatList[scoreIndex];
3077 *index = scoreIndex; 3077 *index = scoreIndex;
3078 return scoreMax; 3078 return scoreMax;
3079 } 3079 }
3080 else 3080 else
3081 return DM_PROBE_SCORE_FALSE; 3081 return DM_PROBE_SCORE_false;
3082 } 3082 }
3083 3083
3084 3084
3085 // 3085 //
3086 // List of formats 3086 // List of formats
3102 const int ndmPaletteFormatList = sizeof(dmPaletteFormatList) / sizeof(dmPaletteFormatList[0]); 3102 const int ndmPaletteFormatList = sizeof(dmPaletteFormatList) / sizeof(dmPaletteFormatList[0]);
3103 3103
3104 3104
3105 int dmPaletteProbeGeneric(const Uint8 *buf, const size_t len, const DMPaletteFormat **pfmt, int *index) 3105 int dmPaletteProbeGeneric(const Uint8 *buf, const size_t len, const DMPaletteFormat **pfmt, int *index)
3106 { 3106 {
3107 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; 3107 int scoreMax = DM_PROBE_SCORE_false, scoreIndex = -1;
3108 3108
3109 for (int i = 0; i < ndmPaletteFormatList; i++) 3109 for (int i = 0; i < ndmPaletteFormatList; i++)
3110 { 3110 {
3111 const DMPaletteFormat *fmt = &dmPaletteFormatList[i]; 3111 const DMPaletteFormat *fmt = &dmPaletteFormatList[i];
3112 if (fmt->probe != NULL) 3112 if (fmt->probe != NULL)
3125 *pfmt = &dmPaletteFormatList[scoreIndex]; 3125 *pfmt = &dmPaletteFormatList[scoreIndex];
3126 *index = scoreIndex; 3126 *index = scoreIndex;
3127 return scoreMax; 3127 return scoreMax;
3128 } 3128 }
3129 else 3129 else
3130 return DM_PROBE_SCORE_FALSE; 3130 return DM_PROBE_SCORE_false;
3131 } 3131 }