# HG changeset patch # User Matti Hamalainen # Date 1543944160 -7200 # Node ID 020f2151949a0b131c0a2b1b2de55428a1b4b3e7 # Parent 02fa60b27af506561dffe70be1d09a51d62b6591 Implement support for the c64 format aspect rations and automatic scaling. diff -r 02fa60b27af5 -r 020f2151949a tools/gfxconv.c --- a/tools/gfxconv.c Tue Dec 04 19:05:33 2018 +0200 +++ b/tools/gfxconv.c Tue Dec 04 19:22:40 2018 +0200 @@ -64,6 +64,14 @@ }; +enum +{ + SCALE_SET, + SCALE_RELATIVE, + SCALE_AUTO, +}; + + typedef struct { char *name; // Descriptive name of the format @@ -120,7 +128,8 @@ optSequential = FALSE, optRemapColors = FALSE, optRemapRemove = FALSE; -int optNRemapTable = 0; +int optNRemapTable = 0, + optScaleMode = SCALE_AUTO; DMMapValue optRemapTable[DM_MAX_COLORS]; int optColorMap[C64_NCOLORS]; @@ -149,9 +158,7 @@ { 6, 'm', "colormap", "Set color index mapping (see below for information)", OPT_ARGREQ }, { 7, 'n', "numitems", "How many 'items' to output (default: all)", OPT_ARGREQ }, { 11, 'w', "width", "Item width (number of items per row, min 1)", OPT_ARGREQ }, - { 9, 'S', "scale", "Scale output image by , :, :* integer factor(s). " - "-S scales both height and width by . -S :* scales " - "width by X*n and height Y*n.", OPT_ARGREQ }, + { 9, 'S', "scale", "Scale output image by specified value(s) (see below)", OPT_ARGREQ }, { 12, 'P', "paletted", "Use indexed/paletted output IF possible.", OPT_NONE }, { 13, 'N', "nplanes", "# of bitplanes (some output formats)", OPT_ARGREQ }, { 18, 'B', "bpp", "Bits per pixel (some output formats)", OPT_ARGREQ }, @@ -213,6 +220,14 @@ printf( "\n" + "Output image scaling (-S)\n" + "-------------------------\n" + "Scaling option -S , :, :* can be used to set the direct or\n" + "relative scale integer factor(s). -S scales both height and width by .\n" + "-S :* scales width by X*n and height Y*n. Certain input formats set\n" + "their default aspect/scale factors. By prepending -S parameters with asterisk\n" + "('*') you can scale relative to those values. (e.g. '-S *2' for example.)\n" + "\n" "Palette remapping (-R)\n" "----------------------\n" "Indexed palette color remapping can be performed via the -R option, either\n" @@ -727,6 +742,16 @@ char *tmpStr = dm_strdup(optArg), *tmpOpt = tmpStr, sep; + // Check for "relative scale mode specifier + if (*tmpOpt == '*') + { + tmpOpt++; + optScaleMode = SCALE_RELATIVE; + } + else + optScaleMode = SCALE_SET; + + // Parse the values if (dmParseIntValWithSep(&tmpOpt, &tmpUInt, &sep, ':')) { if (sep == ':' && @@ -1708,7 +1733,8 @@ dmMsg(1, "Outputting sequence of %d images @ %d x %d -> %d x %d.\n", optItemCount, outImage->width, outImage->height, - outImage->width * optSpec.scaleX, outImage->height * optSpec.scaleY); + outImage->width * optSpec.scaleX, + outImage->height * optSpec.scaleY); } else { @@ -2005,6 +2031,29 @@ outFormat.name, outFormat.fext); } + if (optScaleMode != SCALE_SET) + { + int scaleX = 1, scaleY = 1; + if (inC64Fmt != NULL) + { + scaleX = inC64Fmt->format->aspectX; + scaleY = inC64Fmt->format->aspectY; + } + + switch (optScaleMode) + { + case SCALE_AUTO: + optSpec.scaleX = scaleX; + optSpec.scaleY = scaleY; + break; + + case SCALE_RELATIVE: + optSpec.scaleX *= scaleX; + optSpec.scaleY *= scaleY; + break; + } + } + switch (optInType) { case FFMT_SPRITE: