# HG changeset patch # User Matti Hamalainen # Date 1503071769 -10800 # Node ID 2c4acbc3e7bf414280bded1b26dca9584b757224 # Parent e7dc9bb9777e67d789c26f3e2a5e72819103b2af More work on libgfx etc. diff -r e7dc9bb9777e -r 2c4acbc3e7bf src/libgfx.c --- 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, diff -r e7dc9bb9777e -r 2c4acbc3e7bf src/libgfx.h --- a/src/libgfx.h Fri Aug 18 17:47:30 2017 +0300 +++ b/src/libgfx.h Fri Aug 18 18:56:09 2017 +0300 @@ -34,7 +34,6 @@ DM_IFMT_PALETTE, DM_IFMT_RGB, DM_IFMT_RGBA, - DM_IFMT_RGB_PLANE, }; @@ -69,7 +68,7 @@ int format; int scaleX, scaleY; int nplanes, bpp; - BOOL interleave, paletted; + BOOL planar, paletted; } DMImageConvSpec; diff -r e7dc9bb9777e -r 2c4acbc3e7bf tools/gfxconv.c --- a/tools/gfxconv.c Fri Aug 18 17:47:30 2017 +0300 +++ b/tools/gfxconv.c Fri Aug 18 18:56:09 2017 +0300 @@ -146,7 +146,7 @@ .scaleY = 1, .nplanes = 4, .bpp = 8, - .interleave = FALSE, + .planar = FALSE, .paletted = FALSE, .format = 0, }; @@ -168,9 +168,9 @@ { 9, 'S', "scale", "Scale output image by or : integer factor(s). " "-S scales both height and width by .", OPT_ARGREQ }, { 12, 'P', "paletted", "Use indexed/paletted output IF possible.", OPT_NONE }, - { 13, 'N', "nplanes", "# of bitplanes (certain output formats)", OPT_ARGREQ }, - { 18, 'B', "bpp", "Bits per pixel (certain output formats)", OPT_ARGREQ }, - { 14, 'I', "interleave", "Interleave output image scanlines (default: output whole planes)", OPT_NONE }, + { 13, 'N', "nplanes", "# of bitplanes (some output formats)", OPT_ARGREQ }, + { 18, 'B', "bpp", "Bits per pixel (some output formats)", OPT_ARGREQ }, + { 14, 'P', "planar", "Interleaved/planar output (some output formats)", OPT_NONE }, { 16, 'R', "remap", "Remap output image colors (-R <(#RRGGBB|index):index>[,<..>][+remove] | -R @map.txt[+remove])", OPT_ARGREQ }, }; @@ -688,7 +688,7 @@ break; case 14: - optSpec.interleave = TRUE; + optSpec.planar = TRUE; break; case 16: @@ -1179,7 +1179,12 @@ dmFree(palID); } - if (info) dmMsg(2, "%d bitplanes, %s interleave.\n", spec->nplanes, spec->interleave ? "with" : "without"); + if (info) + { + dmMsg(2, "%d bitplanes, %s planes.\n", + spec->nplanes, + spec->planar ? "planar/interleaved" : "non-interleaved"); + } return dmWriteRAWImage(filename, image, spec); } break;