changeset 2058:020f2151949a

Implement support for the c64 format aspect rations and automatic scaling.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 04 Dec 2018 19:22:40 +0200
parents 02fa60b27af5
children 5b7f5505267c
files tools/gfxconv.c
diffstat 1 files changed, 54 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- 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 <n>, <x>:<y>, <x>:<y>*<n> integer factor(s). "
-                                "-S <n> scales both height and width by <n>. -S <x>:<y>*<n> 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 <n>, <x>:<y>, <x>:<y>*<n> can be used to set the direct or\n"
+    "relative scale integer factor(s). -S <n> scales both height and width by <n>.\n"
+    "-S <x>:<y>*<n> 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: