Mercurial > hg > dmlib
comparison tools/libgfx.c @ 1655:a05e3fcc60ec
Cleanups.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 30 May 2018 13:20:40 +0300 |
parents | 92656ad7f706 |
children | 2de258f2eb2e |
comparison
equal
deleted
inserted
replaced
1654:92656ad7f706 | 1655:a05e3fcc60ec |
---|---|
156 return FALSE; | 156 return FALSE; |
157 | 157 |
158 // Set alpha values to max, except for transparent color | 158 // Set alpha values to max, except for transparent color |
159 for (int i = 0; i < ncolors; i++) | 159 for (int i = 0; i < ncolors; i++) |
160 { | 160 { |
161 (*ppal)[i].a = (i == ctransp) ? 0 : 255; | 161 (*ppal)[i].a = (i == ctransp) ? 0x00 : 0xff; |
162 } | 162 } |
163 | 163 |
164 return TRUE; | 164 return TRUE; |
165 } | 165 } |
166 | 166 |
167 | 167 |
168 BOOL dmImageAllocPalette(DMImage *img, int ncolors, int ctransp) | 168 BOOL dmImagePaletteAlloc(DMImage *img, int ncolors, int ctransp) |
169 { | 169 { |
170 if (img == NULL) | 170 if (img == NULL) |
171 return FALSE; | 171 return FALSE; |
172 | 172 |
173 img->ncolors = ncolors; | 173 img->ncolors = ncolors; |
174 img->ctransp = ctransp; | 174 img->ctransp = ctransp; |
175 return dmPaletteAlloc(&(img->pal), ncolors, ctransp); | 175 return dmPaletteAlloc(&(img->pal), ncolors, ctransp); |
176 } | 176 } |
177 | 177 |
178 | 178 |
179 static BOOL dmReadPaletteData(DMResource *fp, DMColor *pal, int ncolors) | 179 static BOOL dmPaletteReadData(DMResource *fp, DMColor *pal, int ncolors) |
180 { | 180 { |
181 for (int i = 0; i < ncolors; i++) | 181 for (int i = 0; i < ncolors; i++) |
182 { | 182 { |
183 Uint8 colR, colG, colB; | 183 Uint8 colR, colG, colB; |
184 if (!dmf_read_byte(fp, &colR) || | 184 if (!dmf_read_byte(fp, &colR) || |
709 { | 709 { |
710 case PNG_COLOR_TYPE_GRAY: | 710 case PNG_COLOR_TYPE_GRAY: |
711 ncolors = 256; | 711 ncolors = 256; |
712 dmMsg(2, "PNG: Generating %d color grayscale palette.\n", ncolors); | 712 dmMsg(2, "PNG: Generating %d color grayscale palette.\n", ncolors); |
713 | 713 |
714 if (!dmImageAllocPalette(img, ncolors, -1)) | 714 if (!dmImagePaletteAlloc(img, ncolors, -1)) |
715 { | 715 { |
716 res = DMERR_MALLOC; | 716 res = DMERR_MALLOC; |
717 goto error; | 717 goto error; |
718 } | 718 } |
719 | 719 |
726 case PNG_COLOR_TYPE_PALETTE: | 726 case PNG_COLOR_TYPE_PALETTE: |
727 png_get_PLTE(png_ptr, info_ptr, &palette, &ncolors); | 727 png_get_PLTE(png_ptr, info_ptr, &palette, &ncolors); |
728 dmMsg(2, "PNG: Palette of %d colors found.\n", ncolors); | 728 dmMsg(2, "PNG: Palette of %d colors found.\n", ncolors); |
729 if (ncolors > 0 && palette != NULL) | 729 if (ncolors > 0 && palette != NULL) |
730 { | 730 { |
731 if (!dmImageAllocPalette(img, ncolors, -1)) | 731 if (!dmImagePaletteAlloc(img, ncolors, -1)) |
732 { | 732 { |
733 res = DMERR_MALLOC; | 733 res = DMERR_MALLOC; |
734 goto error; | 734 goto error; |
735 } | 735 } |
736 | 736 |
1362 { | 1362 { |
1363 read = TRUE; | 1363 read = TRUE; |
1364 ncolors = 256; | 1364 ncolors = 256; |
1365 } | 1365 } |
1366 | 1366 |
1367 if (!dmImageAllocPalette(img, ncolors, -1)) | 1367 if (!dmImagePaletteAlloc(img, ncolors, -1)) |
1368 { | 1368 { |
1369 res = dmError(DMERR_MALLOC, | 1369 res = dmError(DMERR_MALLOC, |
1370 "PCX: Could not allocate palette data!\n"); | 1370 "PCX: Could not allocate palette data!\n"); |
1371 goto error; | 1371 goto error; |
1372 } | 1372 } |
1373 | 1373 |
1374 if (read) | 1374 if (read) |
1375 { | 1375 { |
1376 // Okay, attempt to read the palette data | 1376 // Okay, attempt to read the palette data |
1377 dmMsg(2, "PCX: Reading palette of %d colors\n", ncolors); | 1377 dmMsg(2, "PCX: Reading palette of %d colors\n", ncolors); |
1378 if (!dmReadPaletteData(fp, img->pal, ncolors)) | 1378 if (!dmPaletteReadData(fp, img->pal, ncolors)) |
1379 { | 1379 { |
1380 res = dmError(DMERR_FREAD, | 1380 res = dmError(DMERR_FREAD, |
1381 "PCX: Error reading palette.\n"); | 1381 "PCX: Error reading palette.\n"); |
1382 goto error; | 1382 goto error; |
1383 } | 1383 } |
1784 { | 1784 { |
1785 return dmError(DMERR_FREAD, | 1785 return dmError(DMERR_FREAD, |
1786 "ILBM: Error reading BMHD chunk.\n"); | 1786 "ILBM: Error reading BMHD chunk.\n"); |
1787 } | 1787 } |
1788 | 1788 |
1789 dmMsg(2, "ILBM: BMHD %d x %d @ %d, %d : nplanes=%d, comp=%d, mask=%d\n", | 1789 dmMsg(2, "ILBM: BMHD %d x %d @ %d, %d : nplanes=%d, comp=%d, mask=%d, transp=%d\n", |
1790 iff.bmhd.w, iff.bmhd.h, iff.bmhd.x, iff.bmhd.y, | 1790 iff.bmhd.w, iff.bmhd.h, iff.bmhd.x, iff.bmhd.y, |
1791 iff.bmhd.nplanes, iff.bmhd.compression, iff.bmhd.masking); | 1791 iff.bmhd.nplanes, iff.bmhd.compression, iff.bmhd.masking, |
1792 iff.bmhd.transp); | |
1792 | 1793 |
1793 // Sanity check | 1794 // Sanity check |
1794 if (iff.bmhd.nplanes < 1 || iff.bmhd.nplanes > 8 || | 1795 if (iff.bmhd.nplanes < 1 || iff.bmhd.nplanes > 8 || |
1795 (iff.bmhd.compression != IFF_COMP_NONE && | 1796 (iff.bmhd.compression != IFF_COMP_NONE && |
1796 iff.bmhd.compression != IFF_COMP_BYTERUN1) || | 1797 iff.bmhd.compression != IFF_COMP_BYTERUN1) || |
1834 (iff.bmhd.masking == IFF_MASK_TRANSP) ? iff.bmhd.transp : -1)) | 1835 (iff.bmhd.masking == IFF_MASK_TRANSP) ? iff.bmhd.transp : -1)) |
1835 { | 1836 { |
1836 return dmError(DMERR_MALLOC, | 1837 return dmError(DMERR_MALLOC, |
1837 "ILBM: Could not allocate palette data.\n"); | 1838 "ILBM: Could not allocate palette data.\n"); |
1838 } | 1839 } |
1839 if (!dmReadPaletteData(fp, iff.pal, iff.ncolors)) | 1840 if (!dmPaletteReadData(fp, iff.pal, iff.ncolors)) |
1840 { | 1841 { |
1841 return dmError(DMERR_FREAD, | 1842 return dmError(DMERR_FREAD, |
1842 "ILBM: Error reading CMAP.\n"); | 1843 "ILBM: Error reading CMAP.\n"); |
1843 } | 1844 } |
1844 } | 1845 } |