# HG changeset patch # User Matti Hamalainen # Date 1526472278 -10800 # Node ID 1793fc1496da2e2ea7aba80f0f24b88945df672a # Parent c8afa3e6c4137b460490461792478e731d379869 Remove some code duplication. diff -r c8afa3e6c413 -r 1793fc1496da tools/libgfx.c --- a/tools/libgfx.c Wed May 16 14:44:49 2018 +0300 +++ b/tools/libgfx.c Wed May 16 15:04:38 2018 +0300 @@ -1607,31 +1607,21 @@ } -void dmDecodeBitPlane(Uint8 *dp, const Uint8 *src, const int width, const int nplane) +static void dmDecodeBitPlane(Uint8 *dp, const Uint8 *src, const int width, const int nplane) { for (int xc = 0; xc < width; xc++) dp[xc] |= dmDecodeBit(src, xc) << nplane; } -int dmDecodeILBMBody(DMResource *fp, DMIFF *iff, DMImage **pimg, Uint32 *read) +static int dmDecodeILBMBody(DMResource *fp, DMIFF *iff, DMImage *img, Uint32 *read) { - DMImage *img; Uint8 *buf; size_t bufLen; int res = DMERR_OK; *read = 0; - // Allocate image - if ((*pimg = img = dmImageAlloc(iff->bmhd.w, iff->bmhd.h, - iff->bmhd.nplanes <= 8 ? DM_IFMT_PALETTE : DM_IFMT_RGBA, - // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp - //iff->bmhd.nplanes <= 8 ? iff->bmhd.nplanes : -1 - -1 - )) == NULL) - return DMERR_MALLOC; - // Allocate planar decoding buffer bufLen = ((img->width + 15) / 16) * 2; if ((buf = dmMalloc(bufLen)) == NULL) @@ -1695,24 +1685,14 @@ } -int dmDecodePBMBody(DMResource *fp, DMIFF *iff, DMImage **pimg, Uint32 *read) +static int dmDecodePBMBody(DMResource *fp, DMIFF *iff, DMImage *img, Uint32 *read) { - DMImage *img; - int yc, res = DMERR_OK; + int res = DMERR_OK; *read = 0; - // Allocate image - if ((*pimg = img = dmImageAlloc(iff->bmhd.w, iff->bmhd.h, - iff->bmhd.nplanes <= 8 ? DM_IFMT_PALETTE : DM_IFMT_RGBA, - // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp - //iff->bmhd.nplanes <= 8 ? iff->bmhd.nplanes : -1 - -1 - )) == NULL) - return DMERR_MALLOC; - // Decode the chunk - for (yc = 0; yc < img->height; yc++) + for (int yc = 0; yc < img->height; yc++) { Uint8 *dp = img->data + (yc * img->pitch); @@ -1871,15 +1851,25 @@ dmMsg(2, "ILBM: BODY chunk size %d bytes\n", chunk.size); + // Allocate image + if ((*pimg = dmImageAlloc(iff.bmhd.w, iff.bmhd.h, + iff.bmhd.nplanes <= 8 ? DM_IFMT_PALETTE : DM_IFMT_RGBA, + // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp + //iff->bmhd.nplanes <= 8 ? iff->bmhd.nplanes : -1 + -1 + )) == NULL) + return DMERR_MALLOC; + + // Decode the body if (iff.planar) { - if ((res = dmDecodeILBMBody(fp, &iff, pimg, &read)) != DMERR_OK) + if ((res = dmDecodeILBMBody(fp, &iff, *pimg, &read)) != DMERR_OK) return res; } else { - if ((res = dmDecodePBMBody(fp, &iff, pimg, &read)) != DMERR_OK) + if ((res = dmDecodePBMBody(fp, &iff, *pimg, &read)) != DMERR_OK) return res; }