Mercurial > hg > dmlib
diff src/libgfx.c @ 1291:2c4acbc3e7bf
More work on libgfx etc.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 18 Aug 2017 18:56:09 +0300 |
parents | e7dc9bb9777e |
children | 92e99ea23811 |
line wrap: on
line diff
--- a/src/libgfx.c Fri Aug 18 17:47:30 2017 +0300 +++ b/src/libgfx.c Fri Aug 18 18:56:09 2017 +0300 @@ -35,12 +35,8 @@ switch (format) { case DM_IFMT_PALETTE : return 1; - - case DM_IFMT_RGB_PLANE : case DM_IFMT_RGB : return 3; - case DM_IFMT_RGBA : return 4; - default: return -1; } } @@ -163,11 +159,14 @@ { Uint8 *ptr1 = row, *ptr2 = ptr1 + rowWidth, - *ptr3 = ptr2 + rowWidth; + *ptr3 = ptr2 + rowWidth, + *ptr4 = ptr3 + rowWidth; for (x = 0; x < img->width; x++) { - Uint8 c = img->data[(y * img->pitch) + (x * img->bpp)], qr, qg, qb, qa; + Uint8 c = img->data[(y * img->pitch) + (x * img->bpp) / 8], + qr, qg, qb, qa; + switch (spec->format) { case DM_IFMT_PALETTE: @@ -180,13 +179,25 @@ qg = img->pal[c].g; qb = img->pal[c].b; qa = img->pal[c].a; - - for (xscale = 0; xscale < spec->scaleX; xscale++) + if (spec->planar) { - *ptr1++ = qr; - *ptr1++ = qg; - *ptr1++ = qb; - *ptr1++ = qa; + for (xscale = 0; xscale < spec->scaleX; xscale++) + { + *ptr1++ = qr; + *ptr2++ = qg; + *ptr3++ = qb; + *ptr4++ = qa; + } + } + else + { + for (xscale = 0; xscale < spec->scaleX; xscale++) + { + *ptr1++ = qr; + *ptr1++ = qg; + *ptr1++ = qb; + *ptr1++ = qa; + } } break; @@ -195,24 +206,23 @@ qg = img->pal[c].g; qb = img->pal[c].b; - for (xscale = 0; xscale < spec->scaleX; xscale++) + if (spec->planar) { - *ptr1++ = qr; - *ptr1++ = qg; - *ptr1++ = qb; + for (xscale = 0; xscale < spec->scaleX; xscale++) + { + *ptr1++ = qr; + *ptr2++ = qg; + *ptr3++ = qb; + } } - break; - - case DM_IFMT_RGB_PLANE: - qr = img->pal[c].r; - qg = img->pal[c].g; - qb = img->pal[c].b; - - for (xscale = 0; xscale < spec->scaleX; xscale++) + else { - *ptr1++ = qr; - *ptr2++ = qg; - *ptr3++ = qb; + for (xscale = 0; xscale < spec->scaleX; xscale++) + { + *ptr1++ = qr; + *ptr1++ = qg; + *ptr1++ = qb; + } } break; } @@ -268,9 +278,9 @@ if ((res = dmInitBitStreamFILE(&bs, fp)) != DMERR_OK) return res; - if (spec->interleave) + if (spec->planar) { - // Output bitplanes in interleaved format (each plane of line sequentially) + // Output bitplanes in planerd format (each plane of line sequentially) for (yc = 0; yc < img->height; yc++) { for (plane = 0; plane < spec->nplanes; plane++) @@ -547,7 +557,7 @@ if (setjmp(png_jmpbuf(png_ptr))) { res = dmError(DMERR_INIT_FAIL, - "PNG: Error during image reading..\n"); + "PNG: Error during image reading.\n"); goto error; } @@ -830,7 +840,7 @@ // Create output file pcx.buf = NULL; - pcx.format = spec->paletted ? DM_IFMT_PALETTE : DM_IFMT_RGB_PLANE; + pcx.format = spec->paletted ? DM_IFMT_PALETTE : DM_IFMT_RGB; pcx.header = &hdr; pcx.fp = fp; @@ -848,17 +858,19 @@ hdr.manufacturer = 10; hdr.version = 5; hdr.encoding = 1; - hdr.bitsPerPlane = 8; hdr.hres = img->width * spec->scaleX; hdr.vres = img->height * spec->scaleY; hdr.xmin = hdr.ymin = 0; hdr.xmax = hdr.hres - 1; hdr.ymax = hdr.vres - 1; - hdr.nplanes = dmImageGetBytesPerPixel(pcx.format); 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); + res = img->width * spec->scaleX; hdr.bpl = res / 2; if (res % 2) hdr.bpl++; @@ -867,6 +879,7 @@ dmMsg(2, "PCX: paletted=%d, nplanes=%d, bpp=%d, bpl=%d\n", spec->paletted, hdr.nplanes, hdr.bitsPerPlane, hdr.bpl); + // TODO XXX this is also bogus pcx.bufLen = hdr.bpl * 4; if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL) { @@ -1088,6 +1101,18 @@ goto error; } + isPaletted = (hdr.bitsPerPlane * hdr.nplanes) < 8; + + dmMsg(2, + "PCX: xmin=%d, ymin=%d, xmax=%d, ymax=%d, res=%dx%d, scr=%dx%d\n", + hdr.xmin, hdr.ymin, hdr.xmax, hdr.ymax, + 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, isPaletted ? "yes" : "no"); + if (hdr.nplanes < 1 || hdr.nplanes > 8) { res = dmError(DMERR_NOT_SUPPORTED, @@ -1096,17 +1121,6 @@ goto error; } - dmMsg(2, - "PCX: xmin=%d, ymin=%d, xmax=%d, ymax=%d, res=%dx%d, scr=%dx%d\n", - hdr.xmin, hdr.ymin, hdr.xmax, hdr.ymax, - hdr.hres, hdr.vres, - hdr.hScreenSize, hdr.vScreenSize); - - dmMsg(2, - "PCX: nplanes=%d, bpp=%d, bpl=%d, bitsPerPlane=%d\n", - hdr.nplanes, hdr.bitsPerPlane, hdr.bpl, hdr.bitsPerPlane); - - isPaletted = (hdr.bitsPerPlane * hdr.nplanes) < 8; if (!isPaletted) { res = dmError(DMERR_NOT_SUPPORTED, @@ -1902,7 +1916,7 @@ NULL, NULL, }, { - "RAW", "Plain bitplaned (interleaved or non-interleaved) RAW", + "RAW", "Plain bitplaned (planar or non-planar) RAW", NULL, NULL, NULL, dmWriteRAWImage, dmWriteRAWImageFILE,