# HG changeset patch # User Matti Hamalainen # Date 1560489420 -10800 # Node ID 8cd2a821e8a075c474b8288a780ac32fd64e3002 # Parent f808d3483d4b6037467ffaafe4ae09c5f42f97ce Cleanups. diff -r f808d3483d4b -r 8cd2a821e8a0 tools/libgfx.c --- a/tools/libgfx.c Fri Jun 14 07:44:22 2019 +0300 +++ b/tools/libgfx.c Fri Jun 14 08:17:00 2019 +0300 @@ -1583,6 +1583,7 @@ hdr.bitsPerPlane = 8; hdr.nplanes = dmImageGetBytesPerPixel(spec.pixfmt); + // Compute bytes per line res = img->width * spec.scaleX; hdr.bpl = res / 2; if (res % 2) hdr.bpl++; @@ -1601,7 +1602,7 @@ ); // TODO XXX this is also bogus - pcx.bufLen = hdr.bpl * 4; + pcx.bufLen = hdr.bpl * 4; if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL) { res = dmError(DMERR_MALLOC, @@ -1614,33 +1615,15 @@ if (!dmf_write_byte(pcx.fp, hdr.manufacturer) || !dmf_write_byte(pcx.fp, hdr.version) || !dmf_write_byte(pcx.fp, hdr.encoding) || - !dmf_write_byte(pcx.fp, hdr.bitsPerPlane)) - { - res = dmError(DMERR_FWRITE, - "PCX: Could not write basic header data.\n"); - goto error; - } - - if (!dmf_write_le16(pcx.fp, hdr.xmin) || + !dmf_write_byte(pcx.fp, hdr.bitsPerPlane) || + !dmf_write_le16(pcx.fp, hdr.xmin) || !dmf_write_le16(pcx.fp, hdr.ymin) || !dmf_write_le16(pcx.fp, hdr.xmax) || !dmf_write_le16(pcx.fp, hdr.ymax) || !dmf_write_le16(pcx.fp, hdr.hres) || - !dmf_write_le16(pcx.fp, hdr.vres)) - { - res = dmError(DMERR_FWRITE, - "PCX: Could not write image dimensions.\n"); - goto error; - } - - if (!dmf_write_str(pcx.fp, (Uint8 *) &hdr.colorMap, sizeof(hdr.colorMap))) - { - res = dmError(DMERR_FWRITE, - "PCX: Could not write colormap.\n"); - goto error; - } - - if (!dmf_write_byte(pcx.fp, hdr.reserved) || + !dmf_write_le16(pcx.fp, hdr.vres) || + !dmf_write_str(pcx.fp, (Uint8 *) &hdr.colorMap, sizeof(hdr.colorMap)) || + !dmf_write_byte(pcx.fp, hdr.reserved) || !dmf_write_byte(pcx.fp, hdr.nplanes) || !dmf_write_le16(pcx.fp, hdr.bpl) || !dmf_write_le16(pcx.fp, hdr.palInfo) || @@ -1649,7 +1632,7 @@ !dmf_write_str(pcx.fp, (Uint8 *) &hdr.filler, sizeof(hdr.filler))) { res = dmError(DMERR_FWRITE, - "PCX: Could not write header remainder.\n"); + "PCX: Could not write header data.\n"); goto error; }