# HG changeset patch # User Matti Hamalainen # Date 1503132409 -10800 # Node ID 38614c07c2e2fbac42ddb2e48fbd281a5da6f166 # Parent e03f20d0f7859b369217add82ee91fdcc3bc97af Now with "almost" working 24bit PCX output. Almost. diff -r e03f20d0f785 -r 38614c07c2e2 src/libgfx.c --- a/src/libgfx.c Sat Aug 19 04:25:02 2017 +0300 +++ b/src/libgfx.c Sat Aug 19 11:46:49 2017 +0300 @@ -742,7 +742,6 @@ DMPCXHeader *header; Uint8 *buf; size_t bufLen, bufOffs; - int format; FILE *fp; } DMPCXData; @@ -836,21 +835,25 @@ } -int dmWritePCXImageFILE(FILE *fp, DMImage *img, const DMImageConvSpec *spec) +int dmWritePCXImageFILE(FILE *fp, DMImage *img, const DMImageConvSpec *pspec) { DMPCXData pcx; DMPCXHeader hdr; int res; + DMImageConvSpec spec; + + memcpy(&spec, pspec, sizeof(DMImageConvSpec)); + spec.format = spec.paletted ? DM_IFMT_PALETTE : DM_IFMT_RGB; + spec.planar = TRUE; // Create output file pcx.buf = NULL; - pcx.format = spec->paletted ? DM_IFMT_PALETTE : DM_IFMT_RGB; pcx.header = &hdr; pcx.fp = fp; // Create PCX header dmMemset(&hdr, 0, sizeof(hdr)); - if (spec->paletted && img->pal != NULL) + if (spec.paletted && img->pal != NULL) { for (int i = 0; i < (img->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->ncolors); i++) { @@ -862,20 +865,20 @@ hdr.manufacturer = 10; hdr.version = 5; hdr.encoding = 1; - hdr.hres = img->width * spec->scaleX; - hdr.vres = img->height * spec->scaleY; + hdr.hres = img->width * spec.scaleX; + hdr.vres = img->height * spec.scaleY; hdr.xmin = hdr.ymin = 0; - hdr.xmax = (img->width * spec->scaleX) - 1; - hdr.ymax = (img->height * spec->scaleY) - 1; + hdr.xmax = (img->width * spec.scaleX) - 1; + hdr.ymax = (img->height * spec.scaleY) - 1; hdr.palInfo = 1; hdr.hScreenSize = hdr.hres; hdr.vScreenSize = hdr.vres; // TODO XXX .. maybe actually compute these asdf hdr.bitsPerPlane = 8; - hdr.nplanes = dmImageGetBytesPerPixel(pcx.format); + hdr.nplanes = dmImageGetBytesPerPixel(spec.format); - res = img->width * spec->scaleX; + res = img->width * spec.scaleX; hdr.bpl = res / 2; if (res % 2) hdr.bpl++; hdr.bpl *= 2; @@ -886,8 +889,11 @@ hdr.hres, hdr.vres, hdr.hScreenSize, hdr.vScreenSize); - dmMsg(2, "PCX: nplanes=%d, bpp=%d, bpl=%d, isPaletted=%s\n", - hdr.nplanes, hdr.bitsPerPlane, hdr.bpl, spec->paletted ? "yes" : "no"); + dmMsg(2, "PCX: nplanes=%d, bpp=%d, bpl=%d, isPaletted=%s, planar=%s\n", + hdr.nplanes, hdr.bitsPerPlane, hdr.bpl, + spec.paletted ? "yes" : "no", + spec.planar ? "yes" : "no" + ); // TODO XXX this is also bogus pcx.bufLen = hdr.bpl * 4; @@ -943,10 +949,10 @@ } // Write image data - res = dmWriteImageData(img, (void *) &pcx, dmWritePCXRow, spec); + res = dmWriteImageData(img, (void *) &pcx, dmWritePCXRow, &spec); // Write VGA palette - if (spec->paletted) + if (spec.paletted) { int i; dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->ncolors);