comparison tools/gfxconv.c @ 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 aa8df4f1b785
children 5b7f5505267c
comparison
equal deleted inserted replaced
2057:02fa60b27af5 2058:020f2151949a
62 CROP_AUTO, 62 CROP_AUTO,
63 CROP_SIZE, 63 CROP_SIZE,
64 }; 64 };
65 65
66 66
67 enum
68 {
69 SCALE_SET,
70 SCALE_RELATIVE,
71 SCALE_AUTO,
72 };
73
74
67 typedef struct 75 typedef struct
68 { 76 {
69 char *name; // Descriptive name of the format 77 char *name; // Descriptive name of the format
70 char *fext; // File extension 78 char *fext; // File extension
71 int flags; // DM_FMT_* flags, see libgfx.h 79 int flags; // DM_FMT_* flags, see libgfx.h
118 126
119 BOOL optInMulticolor = FALSE, 127 BOOL optInMulticolor = FALSE,
120 optSequential = FALSE, 128 optSequential = FALSE,
121 optRemapColors = FALSE, 129 optRemapColors = FALSE,
122 optRemapRemove = FALSE; 130 optRemapRemove = FALSE;
123 int optNRemapTable = 0; 131 int optNRemapTable = 0,
132 optScaleMode = SCALE_AUTO;
124 DMMapValue optRemapTable[DM_MAX_COLORS]; 133 DMMapValue optRemapTable[DM_MAX_COLORS];
125 int optColorMap[C64_NCOLORS]; 134 int optColorMap[C64_NCOLORS];
126 135
127 DMImageConvSpec optSpec = 136 DMImageConvSpec optSpec =
128 { 137 {
147 { 17, 'F', "formats", "List supported input/output formats", OPT_NONE }, 156 { 17, 'F', "formats", "List supported input/output formats", OPT_NONE },
148 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE }, 157 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE },
149 { 6, 'm', "colormap", "Set color index mapping (see below for information)", OPT_ARGREQ }, 158 { 6, 'm', "colormap", "Set color index mapping (see below for information)", OPT_ARGREQ },
150 { 7, 'n', "numitems", "How many 'items' to output (default: all)", OPT_ARGREQ }, 159 { 7, 'n', "numitems", "How many 'items' to output (default: all)", OPT_ARGREQ },
151 { 11, 'w', "width", "Item width (number of items per row, min 1)", OPT_ARGREQ }, 160 { 11, 'w', "width", "Item width (number of items per row, min 1)", OPT_ARGREQ },
152 { 9, 'S', "scale", "Scale output image by <n>, <x>:<y>, <x>:<y>*<n> integer factor(s). " 161 { 9, 'S', "scale", "Scale output image by specified value(s) (see below)", OPT_ARGREQ },
153 "-S <n> scales both height and width by <n>. -S <x>:<y>*<n> scales "
154 "width by X*n and height Y*n.", OPT_ARGREQ },
155 { 12, 'P', "paletted", "Use indexed/paletted output IF possible.", OPT_NONE }, 162 { 12, 'P', "paletted", "Use indexed/paletted output IF possible.", OPT_NONE },
156 { 13, 'N', "nplanes", "# of bitplanes (some output formats)", OPT_ARGREQ }, 163 { 13, 'N', "nplanes", "# of bitplanes (some output formats)", OPT_ARGREQ },
157 { 18, 'B', "bpp", "Bits per pixel (some output formats)", OPT_ARGREQ }, 164 { 18, 'B', "bpp", "Bits per pixel (some output formats)", OPT_ARGREQ },
158 { 14, 'I', "interleave", "Interleaved/planar output (some output formats)", OPT_NONE }, 165 { 14, 'I', "interleave", "Interleaved/planar output (some output formats)", OPT_NONE },
159 { 20, 'C', "compress", "Use compression -C <level 0-9>, 0 = disable, default is 9", OPT_ARGREQ }, 166 { 20, 'C', "compress", "Use compression -C <level 0-9>, 0 = disable, default is 9", OPT_ARGREQ },
210 { 217 {
211 dmPrintBanner(stdout, dmProgName, "[options] <input file>"); 218 dmPrintBanner(stdout, dmProgName, "[options] <input file>");
212 dmArgsPrintHelp(stdout, optList, optListN, 0); 219 dmArgsPrintHelp(stdout, optList, optListN, 0);
213 220
214 printf( 221 printf(
222 "\n"
223 "Output image scaling (-S)\n"
224 "-------------------------\n"
225 "Scaling option -S <n>, <x>:<y>, <x>:<y>*<n> can be used to set the direct or\n"
226 "relative scale integer factor(s). -S <n> scales both height and width by <n>.\n"
227 "-S <x>:<y>*<n> scales width by X*n and height Y*n. Certain input formats set\n"
228 "their default aspect/scale factors. By prepending -S parameters with asterisk\n"
229 "('*') you can scale relative to those values. (e.g. '-S *2' for example.)\n"
215 "\n" 230 "\n"
216 "Palette remapping (-R)\n" 231 "Palette remapping (-R)\n"
217 "----------------------\n" 232 "----------------------\n"
218 "Indexed palette color remapping can be performed via the -R option, either\n" 233 "Indexed palette color remapping can be performed via the -R option, either\n"
219 "specifying single colors or filename of file containing remap definitions.\n" 234 "specifying single colors or filename of file containing remap definitions.\n"
725 BOOL error = FALSE; 740 BOOL error = FALSE;
726 unsigned int tmpUInt2; 741 unsigned int tmpUInt2;
727 char *tmpStr = dm_strdup(optArg), 742 char *tmpStr = dm_strdup(optArg),
728 *tmpOpt = tmpStr, sep; 743 *tmpOpt = tmpStr, sep;
729 744
745 // Check for "relative scale mode specifier
746 if (*tmpOpt == '*')
747 {
748 tmpOpt++;
749 optScaleMode = SCALE_RELATIVE;
750 }
751 else
752 optScaleMode = SCALE_SET;
753
754 // Parse the values
730 if (dmParseIntValWithSep(&tmpOpt, &tmpUInt, &sep, ':')) 755 if (dmParseIntValWithSep(&tmpOpt, &tmpUInt, &sep, ':'))
731 { 756 {
732 if (sep == ':' && 757 if (sep == ':' &&
733 dmParseIntValWithSep(&tmpOpt, &tmpUInt2, &sep, '*')) 758 dmParseIntValWithSep(&tmpOpt, &tmpUInt2, &sep, '*'))
734 { 759 {
1706 1731
1707 outImage = dmImageAlloc(outWidthPX, outHeight, DM_COLFMT_PALETTE, -1); 1732 outImage = dmImageAlloc(outWidthPX, outHeight, DM_COLFMT_PALETTE, -1);
1708 dmMsg(1, "Outputting sequence of %d images @ %d x %d -> %d x %d.\n", 1733 dmMsg(1, "Outputting sequence of %d images @ %d x %d -> %d x %d.\n",
1709 optItemCount, 1734 optItemCount,
1710 outImage->width, outImage->height, 1735 outImage->width, outImage->height,
1711 outImage->width * optSpec.scaleX, outImage->height * optSpec.scaleY); 1736 outImage->width * optSpec.scaleX,
1737 outImage->height * optSpec.scaleY);
1712 } 1738 }
1713 else 1739 else
1714 { 1740 {
1715 int outIWidth, outIHeight; 1741 int outIWidth, outIHeight;
1716 if (optItemCount <= 0) 1742 if (optItemCount <= 0)
2001 dmGetConvFormat(optOutType, optOutFormat, &outFormat)) 2027 dmGetConvFormat(optOutType, optOutFormat, &outFormat))
2002 { 2028 {
2003 dmMsg(1, "Attempting conversion %s (%s) -> %s (%s)\n", 2029 dmMsg(1, "Attempting conversion %s (%s) -> %s (%s)\n",
2004 inFormat.name, inFormat.fext, 2030 inFormat.name, inFormat.fext,
2005 outFormat.name, outFormat.fext); 2031 outFormat.name, outFormat.fext);
2032 }
2033
2034 if (optScaleMode != SCALE_SET)
2035 {
2036 int scaleX = 1, scaleY = 1;
2037 if (inC64Fmt != NULL)
2038 {
2039 scaleX = inC64Fmt->format->aspectX;
2040 scaleY = inC64Fmt->format->aspectY;
2041 }
2042
2043 switch (optScaleMode)
2044 {
2045 case SCALE_AUTO:
2046 optSpec.scaleX = scaleX;
2047 optSpec.scaleY = scaleY;
2048 break;
2049
2050 case SCALE_RELATIVE:
2051 optSpec.scaleX *= scaleX;
2052 optSpec.scaleY *= scaleY;
2053 break;
2054 }
2006 } 2055 }
2007 2056
2008 switch (optInType) 2057 switch (optInType)
2009 { 2058 {
2010 case FFMT_SPRITE: 2059 case FFMT_SPRITE: