Mercurial > hg > dmlib
annotate tools/gfxconv.c @ 1775:4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 12 Jun 2018 17:12:48 +0300 |
parents | 027fb7313d85 |
children | 0562dd55a1f6 |
rev | line source |
---|---|
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * gfxconv - Convert various graphics formats |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * Programmed and designed by Matti 'ccr' Hamalainen |
1280
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1278
diff
changeset
|
4 * (C) Copyright 2012-2017 Tecnic Software productions (TNSP) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 */ |
1432
a9516570cc26
Improve build, so that we can build the tools and tests with minimal
Matti Hamalainen <ccr@tnsp.org>
parents:
1426
diff
changeset
|
8 #include "dmtool.h" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include "dmlib.h" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include "dmargs.h" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include "dmfile.h" |
435 | 12 #include "libgfx.h" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
13 #include "lib64gfx.h" |
1433 | 14 #include "dmmutex.h" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
15 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
17 #define DM_MAX_COLORS 256 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
18 |
837 | 19 #define DM_ASC_NBITS 8 |
20 #define DM_ASC_NCOLORS 4 | |
21 static const char dmASCIIPalette[DM_ASC_NCOLORS] = ".:X#"; | |
22 | |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
23 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
24 enum |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
26 FFMT_AUTO = 0, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
27 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
28 FFMT_ASCII, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
29 FFMT_ANSI, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
30 FFMT_IMAGE, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
31 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
32 FFMT_CHAR, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
33 FFMT_SPRITE, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
34 FFMT_BITMAP, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
35 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
36 FFMT_LAST |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
39 |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
40 enum |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
41 { |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
42 CROP_NONE = 0, |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
43 CROP_AUTO, |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
44 CROP_SIZE, |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
45 }; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
46 |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
47 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
48 typedef struct |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
49 { |
1340 | 50 char *name; // Descriptive name of the format |
51 char *fext; // File extension | |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
52 int flags; // DM_FMT_* flags, see libgfx.h |
1340 | 53 int format; // Format identifier |
54 int subformat; // Subformat identifier | |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
55 } DMConvFormat; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
56 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
57 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
58 static const DMConvFormat baseFormatList[] = |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 { |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
60 { "ASCII text" , "asc" , DM_FMT_WR , FFMT_ASCII , 0 }, |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
61 { "ANSI colored text" , "ansi" , DM_FMT_WR , FFMT_ANSI , 0 }, |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
62 { "C64 bitmap image" , NULL , DM_FMT_RDWR , FFMT_BITMAP , -1 }, |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
63 { "C64 character/font data" , "chr" , DM_FMT_RDWR , FFMT_CHAR , 0 }, |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
64 { "C64 sprite data" , "spr" , DM_FMT_RDWR , FFMT_SPRITE , 0 }, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
65 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
66 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
67 static const int nbaseFormatList = sizeof(baseFormatList) / sizeof(baseFormatList[0]); |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
68 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
69 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
70 static DMConvFormat *convFormatList = NULL; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
71 static int nconvFormatList = 0; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
72 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
73 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
74 typedef struct |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
75 { |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
76 BOOL triplet, alpha; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
77 DMColor color; |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
78 unsigned int from, to; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
79 } DMMapValue; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
80 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
81 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
82 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
83 char *optInFilename = NULL, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
84 *optOutFilename = NULL; |
837 | 85 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
86 int optInFormat = FFMT_AUTO, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
87 optOutFormat = FFMT_ASCII, |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
88 optInSubFormat = -1, |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
89 optOutSubFormat = -1, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
90 optItemCount = -1, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
91 optPlanedWidth = 1, |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
92 optForcedFormat = -1; |
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
93 unsigned int optInSkip = 0; |
838
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
94 |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
95 int optCropMode = CROP_NONE, |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
96 optCropX0, optCropY0, |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
97 optCropW, optCropH; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
98 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
99 BOOL optInMulticolor = FALSE, |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
100 optSequential = FALSE, |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
101 optRemapColors = FALSE, |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
102 optRemapRemove = FALSE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
103 int optNRemapTable = 0; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
104 DMMapValue optRemapTable[DM_MAX_COLORS]; |
1584
f1b279ba47a8
Remove some useless constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
1569
diff
changeset
|
105 int optColors[C64_NCOLORS]; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 |
1290
e7dc9bb9777e
Rename struct DMImageSpec to DMImageConvSpec.
Matti Hamalainen <ccr@tnsp.org>
parents:
1288
diff
changeset
|
107 DMImageConvSpec optSpec = |
435 | 108 { |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
109 .scaleX = 1, |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
110 .scaleY = 1, |
435 | 111 .nplanes = 4, |
1288 | 112 .bpp = 8, |
1291 | 113 .planar = FALSE, |
435 | 114 .paletted = FALSE, |
115 .format = 0, | |
116 }; | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
117 |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
854
diff
changeset
|
118 static const DMOptArg optList[] = |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
119 { |
983 | 120 { 0, '?', "help", "Show this help", OPT_NONE }, |
121 { 15, 'v', "verbose", "Increase verbosity", OPT_NONE }, | |
122 { 3, 'o', "output", "Output filename", OPT_ARGREQ }, | |
123 { 1, 'i', "informat", "Set input format (sprite[:mc:sc], char[:mc|sc], bitmap[:<bformat>], image)", OPT_ARGREQ }, | |
124 { 2, 'm', "multicolor", "Input is multicolor / output in multicolor", OPT_NONE }, | |
125 { 4, 's', "skip", "Skip bytes in input", OPT_ARGREQ }, | |
126 { 5, 'f', "format", "Output format (see --formats)", OPT_ARGREQ }, | |
1640
e9a43ee46f71
Add '-F' short option alias for '--formats'.
Matti Hamalainen <ccr@tnsp.org>
parents:
1638
diff
changeset
|
127 { 17, 'F', "formats", "List supported input/output formats", OPT_NONE }, |
983 | 128 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE }, |
129 { 6, 'c', "colormap", "Color mappings (see below for information)", OPT_ARGREQ }, | |
130 { 7, 'n', "numitems", "How many 'items' to output (default: all)", OPT_ARGREQ }, | |
131 { 11, 'w', "width", "Item width (number of items per row, min 1)", OPT_ARGREQ }, | |
987
5af2097ab284
Cleanup gfxconv option help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
132 { 9, 'S', "scale", "Scale output image by <n> or <x>:<y> integer factor(s). " |
983 | 133 "-S <n> scales both height and width by <n>.", OPT_ARGREQ }, |
987
5af2097ab284
Cleanup gfxconv option help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
134 { 12, 'P', "paletted", "Use indexed/paletted output IF possible.", OPT_NONE }, |
1291 | 135 { 13, 'N', "nplanes", "# of bitplanes (some output formats)", OPT_ARGREQ }, |
136 { 18, 'B', "bpp", "Bits per pixel (some output formats)", OPT_ARGREQ }, | |
1293
1dce9e5f4a2f
Oops, two options were overlapping, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
1291
diff
changeset
|
137 { 14, 'I', "interleave", "Interleaved/planar output (some output formats)", OPT_NONE }, |
983 | 138 { 16, 'R', "remap", "Remap output image colors (-R <(#RRGGBB|index):index>[,<..>][+remove] | -R @map.txt[+remove])", OPT_ARGREQ }, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
139 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
140 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
141 static const int optListN = sizeof(optList) / sizeof(optList[0]); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
142 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
143 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
144 void argShowFormats() |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 { |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
146 printf( |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
147 "Available input/output formats (-f <frmt>):\n" |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
148 " frmt | RW | Description\n" |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
149 "------+----+-------------------------------------------------------\n" |
432
b583a682f12d
Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
150 ); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
151 |
1532 | 152 for (int i = 0; i < nconvFormatList; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
153 { |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
154 const DMConvFormat *fmt = &convFormatList[i]; |
1638
07f27ec0801e
Adjust "gfxconv --formats" output.
Matti Hamalainen <ccr@tnsp.org>
parents:
1630
diff
changeset
|
155 printf("%-6s| %c%c | %s\n", |
432
b583a682f12d
Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
156 fmt->fext ? fmt->fext : "", |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
157 (fmt->flags & DM_FMT_RD) ? 'R' : ' ', |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
158 (fmt->flags & DM_FMT_WR) ? 'W' : ' ', |
432
b583a682f12d
Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
159 fmt->name); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
160 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
161 |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
162 printf( |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
163 "\n" |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
164 "(Not all input->output combinations are actually supported.)\n" |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
165 "\n" |
1604 | 166 "Available C64 bitmap formats (-f <frmt>):\n" |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
167 " frmt | RW | Type | Description\n" |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
168 "------+----+-----------------+-------------------------------------\n" |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
169 ); |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
170 |
1532 | 171 for (int i = 0; i < ndmC64ImageFormats; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
172 { |
516 | 173 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; |
530
5b37a2e427b7
Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
174 char buf[64]; |
1759
027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
175 printf("%-6s| %c%c | %-15s | %s%s\n", |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
176 fmt->fext, |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
177 (fmt->flags & DM_FMT_RD) ? 'R' : ' ', |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
178 (fmt->flags & DM_FMT_WR) ? 'W' : ' ', |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1759
diff
changeset
|
179 dmC64GetImageTypeString(buf, sizeof(buf), fmt->format->type, FALSE), |
1759
027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
180 fmt->name, |
027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
181 fmt->flags & DM_FMT_BROKEN ? " [BROKEN]" : ""); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 } |
1667
7f74073813c6
Display number of supported C64 image formats in --formats list of 64vw and gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1664
diff
changeset
|
183 printf("%d formats supported.\n", ndmC64ImageFormats); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
184 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
185 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
186 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
187 void argShowHelp() |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
188 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
189 dmPrintBanner(stdout, dmProgName, "[options] <input file>"); |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
854
diff
changeset
|
190 dmArgsPrintHelp(stdout, optList, optListN, 0); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
191 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
192 printf( |
837 | 193 "\n" |
818
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
194 "Palette / color remapping (-R)\n" |
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
195 "------------------------------\n" |
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
196 "Indexed palette/color remapping can be performed via the -R option, either\n" |
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
197 "specifying single colors or filename of file containing remap definitions.\n" |
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
198 "Colors to be remapped can be specified either by their palette index or by\n" |
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
199 "their RGB values as a hex triplet (#rrggbb). Example of a remap definition:\n" |
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
200 "-R #000000:0,#ffffff:1 would remap black and white to indices 0 and 1.\n" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
201 "\n" |
1330 | 202 "Remap file can be specified as \"-R @filename\", and it is a text file with\n" |
203 "one remap definition per line in same format as above. All empty lines and\n" | |
204 "lines starting with a semicolor (;) will be ignored as comments. Any extra\n" | |
205 "whitespace separating items will be ignored as well.\n" | |
818
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
206 "\n" |
821
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
207 "Optional +remove can be specified (-R <...>+remove), which will remove all\n" |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
208 "unused colors from the palette. This is not usually desirable, for example\n" |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
209 "when converting multiple images to same palette.\n" |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
210 "\n" |
818
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
211 "Color map defs\n" |
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
212 "--------------\n" |
456 | 213 "Color map definitions are used for ANSI and image output, to declare what\n" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
214 "output colors of the C64 palette are used for each single color/multi color\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
215 "bit-combination. For example, if the input is multi color sprite or char,\n" |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
216 "you can define colors like: -c 0,8,3,15 .. for single color: -c 0,1\n" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
217 "The numbers are palette indexes, and the order is for bit(pair)-values\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
218 "00, 01, 10, 11 (multi color) and 0, 1 (single color). NOTICE! 255 is the\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
219 "special color that can be used for transparency.\n" |
837 | 220 "\n" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
221 ); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
222 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 |
1546 | 225 int dmGetConvFormat(const int format, const int subformat) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
226 { |
1546 | 227 for (int i = 0; i < nconvFormatList; i++) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
228 { |
1546 | 229 const DMConvFormat *fmt = &convFormatList[i]; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
230 if (fmt->format == format && |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
231 fmt->subformat == subformat) |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
232 return i; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
233 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
234 return -1; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
235 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
236 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
237 |
819
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
238 BOOL dmGetC64FormatByExt(const char *fext, int *format, int *subformat) |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
239 { |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
240 if (fext == NULL) |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
241 return FALSE; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
242 |
1569 | 243 for (int i = 0; i < ndmC64ImageFormats; i++) |
819
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
244 { |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
245 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
246 if (fmt->fext != NULL && |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
247 strcasecmp(fext, fmt->fext) == 0) |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
248 { |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
249 *format = FFMT_BITMAP; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
250 *subformat = i; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
251 return TRUE; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
252 } |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
253 } |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
254 |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
255 return FALSE; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
256 } |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
257 |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
258 |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
259 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
260 BOOL dmGetFormatByExt(const char *fext, int *format, int *subformat) |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
261 { |
430
77fae3e4e4d3
Fix a segfault due to not checking for NULL file extension entries in dmGetFormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
262 if (fext == NULL) |
77fae3e4e4d3
Fix a segfault due to not checking for NULL file extension entries in dmGetFormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
263 return FALSE; |
77fae3e4e4d3
Fix a segfault due to not checking for NULL file extension entries in dmGetFormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
264 |
1569 | 265 for (int i = 0; i < nconvFormatList; i++) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
266 { |
1546 | 267 const DMConvFormat *fmt = &convFormatList[i]; |
430
77fae3e4e4d3
Fix a segfault due to not checking for NULL file extension entries in dmGetFormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
268 if (fmt->fext != NULL && |
77fae3e4e4d3
Fix a segfault due to not checking for NULL file extension entries in dmGetFormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
429
diff
changeset
|
269 strcasecmp(fext, fmt->fext) == 0) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
270 { |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
271 *format = fmt->format; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
272 *subformat = fmt->subformat; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
273 return TRUE; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
274 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
275 } |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
276 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
277 return FALSE; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
278 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
279 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
280 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
281 static BOOL dmParseMapOptionMapItem(const char *popt, DMMapValue *value, const unsigned int nmax, const char *msg) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
282 { |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
283 char *end, *split, *opt = dm_strdup(popt); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
284 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
285 if (opt == NULL) |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
286 goto error; |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
287 |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
288 if ((end = split = strchr(opt, ':')) == NULL) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
289 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
290 dmErrorMsg("Invalid %s value '%s', expected <(#|%)RRGGBB|[$|0x]index>:<[$|0x]index>.\n", msg, opt); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
291 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
292 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
293 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
294 // Trim whitespace |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
295 *end = 0; |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
296 for (end--; end > opt && *end && isspace(*end); end--) |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
297 *end = 0; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
298 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
299 // Parse either a hex triplet color definition or a normal value |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
300 if (*opt == '#' || *opt == '%') |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
301 { |
867 | 302 unsigned int colR, colG, colB, colA; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
303 |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
304 if (sscanf(opt + 1, "%2x%2x%2x%2x", &colR, &colG, &colB, &colA) == 4 || |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
305 sscanf(opt + 1, "%2X%2X%2X%2X", &colR, &colG, &colB, &colA) == 4) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
306 { |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
307 value->alpha = TRUE; |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
308 value->color.a = colA; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
309 } |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
310 else |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
311 if (sscanf(opt + 1, "%2x%2x%2x", &colR, &colG, &colB) != 3 && |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
312 sscanf(opt + 1, "%2X%2X%2X", &colR, &colG, &colB) != 3) |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
313 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
314 dmErrorMsg("Invalid %s value '%s', expected a hex triplet, got '%s'.\n", msg, popt, opt + 1); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
315 goto error; |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
316 } |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
317 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
318 value->color.r = colR; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
319 value->color.g = colG; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
320 value->color.b = colB; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
321 value->triplet = TRUE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
322 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
323 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
324 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
325 if (!dmGetIntVal(opt, &value->from)) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
326 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
327 dmErrorMsg("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
328 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
329 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
330 value->triplet = FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
331 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
332 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
333 // Trim whitespace |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
334 split++; |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
335 while (*split && isspace(*split)) split++; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
336 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
337 // Parse destination value |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
338 if (!dmGetIntVal(split, &value->to)) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
339 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
340 dmErrorMsg("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
341 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
342 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
343 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
344 if (!value->triplet && value->from > 255) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
345 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
346 dmErrorMsg("Invalid %s map source color index value %d, must be [0..255].\n", msg, value->from); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
347 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
348 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
349 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
350 if (value->to > nmax) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
351 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
352 dmErrorMsg("Invalid %s map destination color index value %d, must be [0..%d].\n", msg, value->to, nmax); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
353 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
354 } |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
355 |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
356 dmFree(opt); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
357 return TRUE; |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
358 |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
359 error: |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
360 dmFree(opt); |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
361 return FALSE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
362 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
363 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
364 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
365 static BOOL dmParseMapOptionItem(char *opt, char *end, void *pvalue, const int index, const int nmax, const BOOL requireIndex, const char *msg) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
366 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
367 // Trim whitespace |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
368 if (end != NULL) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
369 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
370 *end = 0; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
371 for (end--; end > opt && *end && isspace(*end); end--) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
372 *end = 0; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
373 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
374 while (*opt && isspace(*opt)) opt++; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
375 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
376 // Parse item based on mode |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
377 if (requireIndex) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
378 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
379 DMMapValue *value = (DMMapValue *) pvalue; |
475
c0dedfef3edf
Fix option parsing of mappings.
Matti Hamalainen <ccr@tnsp.org>
parents:
474
diff
changeset
|
380 if (!dmParseMapOptionMapItem(opt, &value[index], nmax, msg)) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
381 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
382 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
383 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
384 { |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
385 unsigned int *value = (unsigned int *) pvalue; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
386 char *split = strchr(opt, ':'); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
387 if (split != NULL) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
388 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
389 dmErrorMsg("Unexpected ':' in indexed %s '%s'.\n", msg, opt); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
390 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
391 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
392 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
393 if (!dmGetIntVal(opt, &value[index])) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
394 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
395 dmErrorMsg("Invalid %s value '%s', could not parse.\n", msg, opt); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
396 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
397 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
398 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
399 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
400 return TRUE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
401 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
402 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
403 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
404 BOOL dmParseMapOptionString(char *opt, void *values, int *nvalues, const int nmax, const BOOL requireIndex, const char *msg) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
405 { |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
406 char *start = opt; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
407 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
408 *nvalues = 0; |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
409 while (*start && *nvalues < nmax) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
410 { |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
411 char *end = strchr(start, ','); |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
412 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
413 if (!dmParseMapOptionItem(start, end, values, *nvalues, nmax, requireIndex, msg)) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
414 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
415 |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
416 (*nvalues)++; |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
417 |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
418 if (!end) |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
419 break; |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
420 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
421 start = end + 1; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
422 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
423 |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
424 return TRUE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
425 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
426 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
427 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
428 int dmParseColorRemapFile(const char *filename, DMMapValue *values, int *nvalue, const int nmax) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
429 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
430 FILE *fp; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
431 char line[512]; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
432 int res = DMERR_OK; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
433 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
434 if ((fp = fopen(filename, "r")) == NULL) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
435 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
436 res = dmGetErrno(); |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
437 dmError(res, "Could not open color remap file '%s' for reading, %d: %s\n", |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
438 res, dmErrorStr(res)); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
439 return res; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
440 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
441 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
442 while (fgets(line, sizeof(line), fp)) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
443 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
444 char *start = line; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
445 while (*start && isspace(*start)) start++; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
446 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
447 if (*start != 0 && *start != ';') |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
448 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
449 if (!dmParseMapOptionMapItem(line, &values[*nvalue], nmax, "mapping file")) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
450 goto error; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
451 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
452 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
453 (*nvalue)++; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
454 if (*nvalue >= nmax) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
455 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
456 dmErrorMsg("Too many mapping pairs in '%s', maximum is %d.\n", |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
457 filename, nmax); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
458 goto error; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
459 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
460 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
461 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
462 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
463 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
464 error: |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
465 fclose(fp); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
466 return res; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
467 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
468 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
469 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
470 BOOL argHandleOpt(const int optN, char *optArg, char *currArg) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
471 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
472 switch (optN) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
473 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
474 case 0: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
475 argShowHelp(); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
476 exit(0); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
477 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
478 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
479 case 17: |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
480 argShowFormats(); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
481 exit(0); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
482 break; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
483 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
484 case 15: |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
485 dmVerbosity++; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
486 break; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
487 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
488 case 1: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
489 { |
824 | 490 switch (tolower(optArg[0])) |
491 { | |
492 case 's': optInFormat = FFMT_SPRITE; break; | |
493 case 'c': optInFormat = FFMT_CHAR; break; | |
494 case 'b': optInFormat = FFMT_BITMAP; break; | |
495 case 'i': optInFormat = FFMT_IMAGE; break; | |
496 default: | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
497 dmErrorMsg("Invalid input format '%s'.\n", optArg); |
824 | 498 return FALSE; |
499 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
500 |
838
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
501 char *tmp = strchr(optArg, ':'); |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
502 if (tmp != NULL) |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
503 { |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
504 tmp++; |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
505 switch (optInFormat) |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
506 { |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
507 case FFMT_SPRITE: |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
508 case FFMT_CHAR: |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
509 if (strcasecmp(tmp, "mc") == 0) |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
510 optInMulticolor = TRUE; |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
511 else |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
512 if (strcasecmp(tmp, "sc") == 0) |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
513 optInMulticolor = FALSE; |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
514 else |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
515 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
516 dmErrorMsg("Invalid input subformat for sprite/char: '%s', should be 'mc' or 'sc'.\n", |
838
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
517 tmp); |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
518 return FALSE; |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
519 } |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
520 break; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
521 |
838
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
522 case FFMT_BITMAP: |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
523 if (!dmGetC64FormatByExt(tmp, &optInFormat, &optInSubFormat)) |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
524 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
525 dmErrorMsg("Invalid bitmap subformat '%s', see format list for valid bformats.\n", |
838
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
526 tmp); |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
527 return FALSE; |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
528 } |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
529 break; |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
530 } |
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
531 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
532 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
533 break; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
534 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
535 case 2: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
536 optInMulticolor = TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
537 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
538 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
539 case 3: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
540 optOutFilename = optArg; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
541 break; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
542 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
543 case 4: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
544 if (!dmGetIntVal(optArg, &optInSkip)) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
545 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
546 dmErrorMsg("Invalid skip value argument '%s'.\n", optArg); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
547 return FALSE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
548 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
549 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
550 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
551 case 5: |
819
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
552 if (!dmGetFormatByExt(optArg, &optOutFormat, &optOutSubFormat) && |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
553 !dmGetC64FormatByExt(optArg, &optOutFormat, &optOutSubFormat)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
554 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
555 dmErrorMsg("Invalid output format '%s'.\n", optArg); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
556 return FALSE; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
557 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
558 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
559 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
560 case 6: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
561 { |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
562 int index, ncolors; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
563 if (!dmParseMapOptionString(optArg, optColors, |
1584
f1b279ba47a8
Remove some useless constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
1569
diff
changeset
|
564 &ncolors, C64_NCOLORS, FALSE, "color table option")) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
565 return FALSE; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
566 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
567 dmMsg(1, "Set color table: "); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
568 for (index = 0; index < ncolors; index++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
569 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
570 dmPrint(1, "[%d:%d]%s", |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
571 index, optColors[index], |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
572 (index < ncolors) ? ", " : ""); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
573 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
574 dmPrint(1, "\n"); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
575 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
576 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
577 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
578 case 7: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
579 if (sscanf(optArg, "%d", &optItemCount) != 1) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
580 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
581 dmErrorMsg("Invalid count value argument '%s'.\n", optArg); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
582 return FALSE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
583 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
584 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
585 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
586 case 8: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
587 optSequential = TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
588 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
589 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
590 case 9: |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
591 if (sscanf(optArg, "%d:%d", &optSpec.scaleX, &optSpec.scaleY) != 2) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
592 { |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
593 if (sscanf(optArg, "%d", &optSpec.scaleX) == 1) |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
594 optSpec.scaleY = optSpec.scaleX; |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
595 else |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
596 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
597 dmErrorMsg("Invalid scale option value '%s', should be <n> or <w>:<h>.\n", optArg); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
598 return FALSE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
599 } |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
600 } |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
601 if (optSpec.scaleX < 1 || optSpec.scaleX > 50) |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
602 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
603 dmErrorMsg("Invalid X scale value '%d'.\n", optSpec.scaleX); |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
604 return FALSE; |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
605 } |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
606 if (optSpec.scaleY < 1 || optSpec.scaleY > 50) |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
607 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
608 dmErrorMsg("Invalid Y scale value '%d'.\n", optSpec.scaleY); |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
609 return FALSE; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
610 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
611 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
612 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
613 case 11: |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
614 if (sscanf(optArg, "%d", &optPlanedWidth) != 1) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
615 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
616 dmErrorMsg("Invalid planed width value argument '%s'.\n", optArg); |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
617 return FALSE; |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
618 } |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
619 if (optPlanedWidth < 1 || optPlanedWidth > 512) |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
620 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
621 dmErrorMsg("Invalid planed width value '%d' [1..512].\n", optPlanedWidth); |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
622 return FALSE; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
623 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
624 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
625 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
626 case 12: |
435 | 627 optSpec.paletted = TRUE; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
628 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
629 |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
630 case 13: |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
631 { |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
632 int tmp = atoi(optArg); |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
633 if (tmp < 1 || tmp > 8) |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
634 { |
1288 | 635 dmErrorMsg("Invalid number of bitplanes value '%s'.\n", optArg); |
636 return FALSE; | |
637 } | |
638 optSpec.nplanes = tmp; | |
639 } | |
640 break; | |
641 | |
642 case 18: | |
643 { | |
644 int tmp = atoi(optArg); | |
645 if (tmp < 1 || tmp > 32) | |
646 { | |
647 dmErrorMsg("Invalid number of bits per pixel value '%s'.\n", optArg); | |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
648 return FALSE; |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
649 } |
435 | 650 optSpec.nplanes = tmp; |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
651 } |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
652 break; |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
653 |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
654 case 14: |
1291 | 655 optSpec.planar = TRUE; |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
656 break; |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
657 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
658 case 16: |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
659 { |
821
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
660 char *tmp; |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
661 if ((tmp = dm_strrcasecmp(optArg, "+remove")) != NULL) |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
662 { |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
663 optRemapRemove = TRUE; |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
664 *tmp = 0; |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
665 } |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
666 |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
667 if (optArg[0] == '@') |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
668 { |
821
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
669 if (optArg[1] != 0) |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
670 { |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
671 int res; |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
672 if ((res = dmParseColorRemapFile(optArg + 1, |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
673 optRemapTable, &optNRemapTable, DM_MAX_COLORS)) != DMERR_OK) |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
674 return FALSE; |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
675 } |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
676 else |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
677 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
678 dmErrorMsg("No remap filename given.\n"); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
679 return FALSE; |
823
f0429dbd77ec
Oops, missing } from one of the previous commits. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents:
822
diff
changeset
|
680 } |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
681 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
682 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
683 { |
821
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
684 if (!dmParseMapOptionString(optArg, optRemapTable, |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
685 &optNRemapTable, DM_MAX_COLORS, TRUE, "color remap option")) |
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
686 return FALSE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
687 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
688 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
689 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
690 optRemapColors = TRUE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
691 break; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
692 |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
693 case 19: |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
694 { |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
695 int tx0, ty0, tx1, ty1; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
696 if (strcasecmp(optArg, "auto") == 0) |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
697 { |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
698 optCropMode = CROP_AUTO; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
699 } |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
700 else |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
701 if (sscanf(optArg, "%d:%d-%d:%d", &tx0, &ty0, &tx1, &ty1) == 4) |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
702 { |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
703 optCropMode = CROP_SIZE; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
704 optCropX0 = tx0; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
705 optCropY0 = ty0; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
706 optCropW = tx1 - tx0 + 1; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
707 optCropH = ty1 - ty0 + 1; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
708 } |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
709 else |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
710 if (sscanf(optArg, "%d:%d:%d:%d", &tx0, &ty0, &tx1, &ty1) == 4) |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
711 { |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
712 optCropMode = CROP_SIZE; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
713 optCropX0 = tx0; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
714 optCropY0 = ty0; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
715 optCropW = tx1; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
716 optCropH = ty1; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
717 } |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
718 else |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
719 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
720 dmErrorMsg("Invalid crop mode / argument '%s'.\n", optArg); |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
721 return FALSE; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
722 } |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
723 } |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
724 break; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
725 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
726 default: |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
727 dmErrorMsg("Unknown option '%s'.\n", currArg); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
728 return FALSE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
729 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
730 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
731 return TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
732 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
733 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
734 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
735 BOOL argHandleFile(char *currArg) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
736 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
737 if (!optInFilename) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
738 optInFilename = currArg; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
739 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
740 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
741 dmErrorMsg("Source filename already specified, extraneous argument '%s'.\n", |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
742 currArg); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
743 return FALSE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
744 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
745 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
746 return TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
747 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
748 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
749 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
750 void dmPrintByte(FILE *out, int byte, int format, BOOL multicolor) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
751 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
752 int i; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
753 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
754 if (multicolor) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
755 { |
837 | 756 for (i = DM_ASC_NBITS; i; i -= 2) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
757 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
758 int val = (byte & (3ULL << (i - 2))) >> (i - 2); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
759 char ch; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
760 switch (format) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
761 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
762 case FFMT_ASCII: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
763 ch = dmASCIIPalette[val]; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
764 fprintf(out, "%c%c", ch, ch); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
765 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
766 case FFMT_ANSI: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
767 fprintf(out, "%c[0;%d;%dm##%c[0m", |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
768 0x1b, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
769 1, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
770 31 + optColors[val], |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
771 0x1b); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
772 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
773 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
774 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
775 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
776 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
777 { |
837 | 778 for (i = DM_ASC_NBITS; i; i--) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
779 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
780 int val = (byte & (1ULL << (i - 1))) >> (i - 1); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
781 char ch; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
782 switch (format) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
783 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
784 case FFMT_ASCII: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
785 ch = val ? '#' : '.'; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
786 fputc(ch, out); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
787 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
788 case FFMT_ANSI: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
789 fprintf(out, "%c[0;%d;%dm %c[0m", |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
790 0x1b, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
791 1, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
792 31 + optColors[val], |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
793 0x1b); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
794 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
795 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
796 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
797 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
798 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
799 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
800 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
801 void dmDumpCharASCII(FILE *outFile, const Uint8 *buf, const size_t offs, const int fmt, const BOOL multicolor) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
802 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
803 for (size_t yc = 0; yc < C64_CHR_HEIGHT; yc++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
804 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
805 fprintf(outFile, "%04" DM_PRIx_SIZE_T " : ", offs + yc); |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
806 dmPrintByte(outFile, buf[yc], fmt, multicolor); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
807 fprintf(outFile, "\n"); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
808 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
809 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
810 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
811 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
812 void dmDumpSpriteASCII(FILE *outFile, const Uint8 *buf, const size_t offs, const int fmt, BOOL multicolor) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
813 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
814 size_t bufOffs, xc, yc; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
815 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
816 for (bufOffs = yc = 0; yc < C64_SPR_HEIGHT; yc++) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
817 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
818 fprintf(outFile, "%04" DM_PRIx_SIZE_T " ", offs + bufOffs); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
819 for (xc = 0; xc < C64_SPR_WIDTH; xc++) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
820 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
821 dmPrintByte(outFile, buf[bufOffs], fmt, multicolor); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
822 fprintf(outFile, " "); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
823 bufOffs++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
824 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
825 fprintf(outFile, "\n"); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
826 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
827 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
828 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
829 |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
830 int dmRemapImageColors(DMImage **pdst, const DMImage *src) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
831 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
832 DMColor *npal = dmCalloc(src->ncolors, sizeof(DMColor)); |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
833 int *mapping = dmMalloc(src->ncolors * sizeof(int)); |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
834 BOOL *mapped = dmMalloc(src->ncolors * sizeof(BOOL)); |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
835 BOOL *used = dmMalloc(src->ncolors * sizeof(BOOL)); |
482 | 836 int n, index, xc, yc, ncolors; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
837 DMImage *dst; |
482 | 838 |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
839 if ((dst = *pdst = dmImageAlloc(src->width, src->height, src->format, src->bpp)) == NULL) |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
840 { |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
841 return dmError(DMERR_MALLOC, |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
842 "Could not allocate memory for remapped image.\n"); |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
843 } |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
844 |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
845 dmMsg(1, "Remapping %d output image colors of %d colors.\n", optNRemapTable, src->ncolors); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
846 |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
847 if (npal == NULL || mapping == NULL || mapped == NULL || used == NULL) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
848 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
849 return dmError(DMERR_MALLOC, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
850 "Could not allocate memory for reused palette.\n"); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
851 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
852 |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
853 for (index = 0; index < src->ncolors; index++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
854 { |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
855 mapping[index] = -1; |
482 | 856 mapped[index] = used[index] = FALSE; |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
857 } |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
858 |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
859 // Find used colors |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
860 dmMsg(2, "Scanning image for used colors...\n"); |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
861 for (ncolors = yc = 0; yc < src->height; yc++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
862 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
863 const Uint8 *dp = src->data + src->pitch * yc; |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
864 for (xc = 0; xc < src->width; xc++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
865 { |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
866 Uint8 col = dp[xc]; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
867 if (col < src->ncolors && !used[col]) |
482 | 868 { |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
869 used[col] = TRUE; |
482 | 870 ncolors++; |
871 } | |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
872 } |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
873 } |
482 | 874 dmMsg(2, "Found %d used colors, creating remap-table.\n", ncolors); |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
875 |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
876 // Match and mark mapped colors |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
877 for (index = 0; index < optNRemapTable; index++) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
878 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
879 DMMapValue *map = &optRemapTable[index]; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
880 if (map->triplet) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
881 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
882 BOOL found = FALSE; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
883 for (n = 0; n < src->ncolors; n++) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
884 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
885 if (dmCompareColor(&(src->pal[n]), &(map->color), map->alpha)) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
886 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
887 dmMsg(3, "RGBA match #%02x%02x%02x%02x: %d -> %d\n", |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
888 map->color.r, map->color.g, map->color.b, map->color.a, |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
889 n, |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
890 map->to); |
482 | 891 |
892 mapping[n] = map->to; | |
893 mapped[map->to] = TRUE; | |
894 found = TRUE; | |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
895 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
896 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
897 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
898 if (!found) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
899 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
900 dmMsg(3, "No RGBA match found for map index %d, #%02x%02x%02x%02x\n", |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
901 index, |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
902 map->color.r, map->color.g, map->color.b, map->color.a); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
903 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
904 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
905 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
906 { |
482 | 907 dmMsg(3, "Map index: %d -> %d\n", |
908 map->from, map->to); | |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
909 |
482 | 910 mapping[map->from] = map->to; |
911 mapped[map->to] = TRUE; | |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
912 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
913 } |
482 | 914 |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
915 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
916 // Fill in the rest |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
917 if (optRemapRemove) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
918 { |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
919 dmMsg(2, "Removing unused colors.\n"); |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
920 for (index = 0; index < src->ncolors; index++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
921 if (mapping[index] < 0 && used[index]) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
922 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
923 for (n = 0; n < src->ncolors; n++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
924 if (!mapped[n]) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
925 { |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
926 mapping[index] = n; |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
927 mapped[n] = TRUE; |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
928 break; |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
929 } |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
930 } |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
931 } |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
932 else |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
933 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
934 for (index = 0; index < src->ncolors; index++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
935 if (mapping[index] < 0) |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
936 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
937 for (n = 0; n < src->ncolors; n++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
938 if (!mapped[n]) |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
939 { |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
940 mapping[index] = n; |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
941 mapped[n] = TRUE; |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
942 break; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
943 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
944 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
945 } |
482 | 946 |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
947 // Calculate final number of palette colors |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
948 ncolors = 0; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
949 for (index = 0; index < src->ncolors; index++) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
950 { |
482 | 951 if (mapping[index] + 1 > ncolors) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
952 ncolors = mapping[index] + 1; |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
953 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
954 |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
955 // Copy palette entries |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
956 for (index = 0; index < src->ncolors; index++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
957 { |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
958 if (mapping[index] >= 0) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
959 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
960 memcpy(&npal[mapping[index]], &(src->pal[index]), sizeof(DMColor)); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
961 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
962 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
963 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
964 // Remap image |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
965 dmMsg(1, "Remapping image to %d colors...\n", ncolors); |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
966 for (yc = 0; yc < src->height; yc++) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
967 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
968 Uint8 *sp = src->data + src->pitch * yc; |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
969 Uint8 *dp = dst->data + dst->pitch * yc; |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
970 for (xc = 0; xc < src->width; xc++) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
971 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
972 Uint8 col = sp[xc]; |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
973 if (col < src->ncolors && mapping[col] >= 0 && mapping[col] < src->ncolors) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
974 dp[xc] = mapping[col]; |
478
7c7a57590236
Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents:
477
diff
changeset
|
975 else |
7c7a57590236
Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents:
477
diff
changeset
|
976 dp[xc] = 0; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
977 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
978 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
979 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
980 // Set new palette, free memory |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
981 dst->pal = npal; |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
982 dst->ncolors = ncolors; |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
983 |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
984 dmFree(mapping); |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
985 dmFree(mapped); |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
986 dmFree(used); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
987 return DMERR_OK; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
988 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
989 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
990 |
1550 | 991 int dmConvertC64Bitmap(DMC64Image **pdst, const DMC64Image *src, |
992 const DMC64ImageFormat *dstFmt, const DMC64ImageFormat *srcFmt) | |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
993 { |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
994 DMC64Image *dst; |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
995 |
1550 | 996 if (pdst == NULL || dstFmt == NULL || src == NULL || srcFmt == NULL) |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
997 return DMERR_NULLPTR; |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
998 |
1550 | 999 if ((dst = *pdst = dmC64ImageAlloc(dstFmt)) == NULL) |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1000 return DMERR_MALLOC; |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1001 |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1002 if (src->type == dst->type) |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1003 { |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1004 for (int i = 0; i < dst->nbanks; i++) |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1005 { |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1006 dmC64MemBlockCopy(&dst->color[i], &src->color[i]); |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1007 dmC64MemBlockCopy(&dst->screen[i], &src->screen[i]); |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1008 dmC64MemBlockCopy(&dst->bitmap[i], &src->bitmap[i]); |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1009 } |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1010 } |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1011 else |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1012 { |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1013 // Try to do some simple fixups |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1014 if ((dst->type & D64_FMT_FLI) && (src->type & D64_FMT_FLI) == 0) |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1015 { |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1016 dmMsg(1, "Upconverting multicolor to FLI.\n"); |
1537
776aa43b2c57
Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1532
diff
changeset
|
1017 for (int i = 0; i < dst->nbanks; i++) |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1018 { |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1019 dmC64MemBlockCopy(&dst->color[i], &src->color[0]); |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1020 dmC64MemBlockCopy(&dst->screen[i], &src->screen[0]); |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1021 dmC64MemBlockCopy(&dst->bitmap[i], &src->bitmap[0]); |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1022 } |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1023 } |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1024 |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1025 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1026 { |
1591
3cc7b2aadda3
Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1588
diff
changeset
|
1027 const DMC64EncDecOp *op = fmtGetEncDecOp(dstFmt, i); |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1028 size_t size; |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1029 |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1030 // Check for last operator |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1667
diff
changeset
|
1031 if (op->type == DO_LAST) |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1032 break; |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1033 |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1034 // Check size |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1035 if (!dmC64GetOpSize(op, dstFmt, &size)) |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1036 return DMERR_INVALID_DATA; |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1037 |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1038 // Perform operation |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1585
diff
changeset
|
1039 switch (op->type) |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1040 { |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1667
diff
changeset
|
1041 case DO_COPY: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1667
diff
changeset
|
1042 switch (op->subject) |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1667
diff
changeset
|
1043 { |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1667
diff
changeset
|
1044 case DS_EXTRA_DATA: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1667
diff
changeset
|
1045 dmC64MemBlockAlloc(&dst->extraData[op->bank], size); |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1667
diff
changeset
|
1046 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1667
diff
changeset
|
1047 } |
1537
776aa43b2c57
Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1532
diff
changeset
|
1048 break; |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1049 } |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1050 } |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1051 } |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1052 |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1053 return DMERR_OK; |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1054 } |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1055 |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1056 |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1057 int dmWriteBitmap(const char *filename, const DMC64Image *image, const DMC64ImageFormat *fmt) |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1058 { |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1059 int res = DMERR_OK; |
1481 | 1060 DMGrowBuf buf; |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1061 |
1694
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1692
diff
changeset
|
1062 dmGrowBufInit(&buf); |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1692
diff
changeset
|
1063 |
1481 | 1064 // Encode to target format |
1065 dmMsg(1, "Encoding C64 bitmap data to format '%s'\n", fmt->name); | |
1470
499835ba215c
Use dmC64EncodeBMP() in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1465
diff
changeset
|
1066 if ((res = dmC64EncodeBMP(&buf, image, fmt)) != DMERR_OK) |
1585 | 1067 { |
1068 dmErrorMsg("Error encoding bitmap data: %s\n", dmErrorStr(res)); | |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1069 goto error; |
1585 | 1070 } |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1071 |
1481 | 1072 // And output the file |
1696
cf0fddd4bf52
When writing a C64 bitmap output, inform the user about the output file size.
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
1073 dmMsg(1, "Writing output file '%s', %" DM_PRIu_SIZE_T " bytes.\n", |
cf0fddd4bf52
When writing a C64 bitmap output, inform the user about the output file size.
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
1074 filename, buf.len); |
cf0fddd4bf52
When writing a C64 bitmap output, inform the user about the output file size.
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
1075 |
1550 | 1076 res = dmWriteDataFile(NULL, filename, buf.data, buf.len); |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1077 |
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1078 error: |
1465
88845f95e791
Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1464
diff
changeset
|
1079 dmGrowBufFree(&buf); |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1080 return res; |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1081 } |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1082 |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1083 |
1303 | 1084 void dmOutputImageBitFormat(const int format, const BOOL info) |
1085 { | |
1086 if (info) | |
1087 { | |
1088 char *str; | |
1089 switch (format) | |
1090 { | |
1091 case DM_IFMT_PALETTE : str = "Indexed 8bpp"; break; | |
1092 case DM_IFMT_RGB : str = "24bit RGB"; break; | |
1093 case DM_IFMT_RGBA : str = "32bit RGBA"; break; | |
1094 default : str = "???"; break; | |
1095 } | |
1096 dmMsg(2, "%s output.\n", str); | |
1097 } | |
1098 } | |
1099 | |
1100 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1101 #define DMCOL(x) (((x) >> 4) & 0xf) |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1102 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1103 void dmWriteIFFMasterRAWPalette(FILE *fp, |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1104 const DMImage *img, int ncolors, |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1105 const char *indent, const char *type) |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1106 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1107 for (int i = 0; i < ncolors; i++) |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1108 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1109 int color; |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1110 if (i < img->ncolors) |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1111 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1112 color = (DMCOL(img->pal[i].r) << 8) | |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1113 (DMCOL(img->pal[i].g) << 4) | |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1114 (DMCOL(img->pal[i].b)); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1115 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1116 else |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1117 color = 0; |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1118 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1119 fprintf(fp, "%s%s $%04X\n", |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1120 indent != NULL ? indent : "\t", |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1121 type != NULL ? type : "dc.w", |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1122 color); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1123 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1124 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1125 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1126 |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1127 int dmWriteImage(const char *filename, DMImage *pimage, DMImageConvSpec *spec, int iformat, BOOL info) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1128 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1129 int res = DMERR_OK; |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1130 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1131 if (info) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1132 { |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
1133 dmMsg(1, "Outputting %s image %d x %d -> %d x %d [%d x %d]\n", |
446
a6d0e101cd16
Oops, correct the use of dmImageFormatList[] entry pointer to entry.fext.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1134 dmImageFormatList[iformat].fext, |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1135 pimage->width, pimage->height, |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1136 pimage->width * spec->scaleX, pimage->height * spec->scaleY, |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
1137 spec->scaleX, spec->scaleY); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1138 } |
435 | 1139 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1140 // Perform color remapping |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1141 DMImage *image = pimage; |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1142 BOOL allocated = FALSE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1143 if (optRemapColors) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1144 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1145 int res; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1146 if ((res = dmRemapImageColors(&image, pimage)) != DMERR_OK) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1147 return res; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1148 |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1149 allocated = TRUE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1150 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1151 |
435 | 1152 switch (iformat) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1153 { |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1154 #ifdef DM_USE_LIBPNG |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
1155 case DM_IMGFMT_PNG: |
435 | 1156 spec->format = spec->paletted ? DM_IFMT_PALETTE : DM_IFMT_RGBA; |
1303 | 1157 dmOutputImageBitFormat(spec->format, info); |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1158 res = dmWritePNGImage(filename, image, spec); |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1159 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1160 #endif |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1161 |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
1162 case DM_IMGFMT_PPM: |
435 | 1163 spec->format = DM_IFMT_RGB; |
1303 | 1164 dmOutputImageBitFormat(spec->format, info); |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1165 res = dmWritePPMImage(filename, image, spec); |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1166 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1167 |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
1168 case DM_IMGFMT_PCX: |
1303 | 1169 spec->format = spec->paletted ? DM_IFMT_PALETTE : DM_IFMT_RGB; |
1170 dmOutputImageBitFormat(spec->format, info); | |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1171 res = dmWritePCXImage(filename, image, spec); |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1172 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1173 |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
1174 case DM_IMGFMT_RAW: |
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
1175 case DM_IMGFMT_ARAW: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1176 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1177 // Open data file for writing |
462 | 1178 FILE *fp; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1179 char * dataFilename = dm_strdup_fext(filename, "%s.inc"); |
462 | 1180 if ((fp = fopen(dataFilename, "w")) == NULL) |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1181 { |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1182 res = dmError(DMERR_FOPEN, |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1183 "Could not create '%s'.\n", dataFilename); |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1184 goto err; |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1185 } |
820 | 1186 |
462 | 1187 dmFree(dataFilename); |
1188 | |
1189 if (fp != NULL) | |
1190 { | |
1191 // Strip extension | |
820 | 1192 char *palID = dm_strdup_fext(filename, "img_%s"); |
462 | 1193 |
1194 // Replace any non-alphanumerics | |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1195 for (int i = 0; palID[i]; i++) |
462 | 1196 { |
1197 if (isalnum(palID[i])) | |
1198 palID[i] = tolower(palID[i]); | |
1199 else | |
1200 palID[i] = '_'; | |
1201 } | |
1202 | |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
1203 if (iformat == DM_IMGFMT_ARAW) |
566
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1204 { |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1205 fprintf(fp, |
462 | 1206 "%s_width: dw.w %d\n" |
1207 "%s_height: dw.w %d\n" | |
1208 "%s_nplanes: dw.w %d\n" | |
1209 "%s_ncolors: dw.w %d\n" | |
1210 "%s_palette:\n", | |
1211 palID, image->width, | |
1212 palID, image->height, | |
1213 palID, spec->nplanes, | |
1214 palID, image->ncolors, | |
1215 palID); | |
1216 | |
566
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1217 dmWriteIFFMasterRAWPalette(fp, image, 1 << optSpec.nplanes, NULL, NULL); |
462 | 1218 |
566
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1219 fprintf(fp, |
477
0fd0e301b6fc
Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents:
476
diff
changeset
|
1220 "%s: incbin \"%s\"\n", |
0fd0e301b6fc
Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents:
476
diff
changeset
|
1221 palID, filename); |
566
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1222 } |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1223 else |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1224 { |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1225 fprintf(fp, |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1226 "%s_width: dw.w %d\n" |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1227 "%s_height: dw.w %d\n" |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1228 "%s_nplanes: dw.w %d\n", |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1229 palID, image->width, |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1230 palID, image->height, |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1231 palID, spec->nplanes); |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
557
diff
changeset
|
1232 } |
477
0fd0e301b6fc
Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents:
476
diff
changeset
|
1233 |
462 | 1234 fclose(fp); |
1235 dmFree(palID); | |
1236 } | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1237 |
1291 | 1238 if (info) |
1239 { | |
1240 dmMsg(2, "%d bitplanes, %s planes.\n", | |
1241 spec->nplanes, | |
1242 spec->planar ? "planar/interleaved" : "non-interleaved"); | |
1243 } | |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1244 res = dmWriteRAWImage(filename, image, spec); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1245 } |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1246 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1247 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1248 default: |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1249 res = DMERR_INVALID_DATA; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1250 } |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1251 |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1252 err: |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1253 if (allocated) |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1254 dmImageFree(image); |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1255 |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1256 return res; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1257 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1258 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1259 |
547
ca5ad51c6479
Make dmConvertByte() static.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1260 static Uint8 dmConvertByte(const Uint8 *sp, const BOOL multicolor) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1261 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1262 Uint8 byte = 0; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1263 int xc; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1264 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1265 if (multicolor) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1266 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1267 for (xc = 0; xc < 8 / 2; xc++) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1268 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1269 Uint8 pixel = sp[xc * 2] & 3; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1270 byte |= pixel << (6 - (xc * 2)); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1271 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1272 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1273 else |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1274 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1275 for (xc = 0; xc < 8; xc++) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1276 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1277 Uint8 pixel = sp[xc] == 0 ? 0 : 1; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1278 byte |= pixel << (7 - xc); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1279 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1280 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1281 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1282 return byte; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1283 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1284 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1285 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1286 BOOL dmConvertImage2Char(Uint8 *buf, const DMImage *image, |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1287 const int xoffs, const int yoffs, const BOOL multicolor) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1288 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1289 int yc; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1290 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1291 if (xoffs < 0 || yoffs < 0 || |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1292 xoffs + C64_CHR_WIDTH_PX > image->width || |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1293 yoffs + C64_CHR_HEIGHT > image->height) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1294 return FALSE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1295 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1296 for (yc = 0; yc < C64_CHR_HEIGHT; yc++) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1297 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1298 const Uint8 *sp = image->data + ((yc + yoffs) * image->pitch) + xoffs; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1299 buf[yc] = dmConvertByte(sp, multicolor); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1300 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1301 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1302 return TRUE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1303 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1304 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1305 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1306 BOOL dmConvertImage2Sprite(Uint8 *buf, const DMImage *image, |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1307 const int xoffs, const int yoffs, const BOOL multicolor) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1308 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1309 int yc, xc; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1310 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1311 if (xoffs < 0 || yoffs < 0 || |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1312 xoffs + C64_SPR_WIDTH_PX > image->width || |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1313 yoffs + C64_SPR_HEIGHT > image->height) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1314 return FALSE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1315 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1316 for (yc = 0; yc < C64_SPR_HEIGHT; yc++) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1317 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1318 for (xc = 0; xc < C64_SPR_WIDTH_PX / C64_SPR_WIDTH; xc++) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1319 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1320 const Uint8 *sp = image->data + ((yc + yoffs) * image->pitch) + (xc * 8) + xoffs; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1321 buf[(yc * C64_SPR_WIDTH) + xc] = dmConvertByte(sp, multicolor); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1322 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1323 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1324 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1325 return TRUE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1326 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1327 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1328 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1329 int dmWriteSpritesAndChars(const char *filename, DMImage *image, int outFormat, BOOL multicolor) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1330 { |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1331 int ret = DMERR_OK; |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1332 int outBlockW, outBlockH, bx, by; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1333 FILE *outFile = NULL; |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1334 Uint8 *buf = NULL; |
907 | 1335 size_t outBufSize; |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1336 char *outType; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1337 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1338 switch (outFormat) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1339 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1340 case FFMT_CHAR: |
907 | 1341 outBufSize = C64_CHR_SIZE; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1342 outBlockW = image->width / C64_CHR_WIDTH_PX; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1343 outBlockH = image->height / C64_CHR_HEIGHT; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1344 outType = "char"; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1345 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1346 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1347 case FFMT_SPRITE: |
907 | 1348 outBufSize = C64_SPR_SIZE; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1349 outBlockW = image->width / C64_SPR_WIDTH_PX; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1350 outBlockH = image->height / C64_SPR_HEIGHT; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1351 outType = "sprite"; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1352 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1353 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1354 default: |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1355 ret = dmError(DMERR_INVALID_ARGS, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1356 "Invalid output format %d, internal error.\n", outFormat); |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1357 goto error; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1358 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1359 |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1360 if (outBlockW < 1 || outBlockH < 1) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1361 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1362 ret = dmError(DMERR_INVALID_ARGS, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1363 "Source image dimensions too small for conversion, block dimensions %d x %d.\n", |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1364 outBlockW, outBlockH); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1365 goto error; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1366 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1367 |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1368 if ((outFile = fopen(filename, "wb")) == NULL) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1369 { |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1370 ret = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1371 dmErrorMsg("Could not open '%s' for writing, %d: %s.\n", |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1372 filename, ret, dmErrorStr(ret)); |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1373 goto error; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1374 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1375 |
907 | 1376 if ((buf = dmMalloc(outBufSize)) == NULL) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1377 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1378 dmErrorMsg("Could not allocate %d bytes for conversion buffer.\n", |
907 | 1379 outBufSize); |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1380 goto error; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1381 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1382 |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1383 dmMsg(1, "Writing %d x %d = %d blocks of %s data...\n", |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1384 outBlockW, outBlockH, outBlockW * outBlockH, outType); |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1385 |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1386 for (by = 0; by < outBlockH; by++) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1387 for (bx = 0; bx < outBlockW; bx++) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1388 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1389 switch (outFormat) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1390 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1391 case FFMT_CHAR: |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1392 if (!dmConvertImage2Char(buf, image, |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1393 bx * C64_CHR_WIDTH_PX, by * C64_CHR_HEIGHT, |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1394 multicolor)) |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1395 { |
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1396 ret = DMERR_DATA_ERROR; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1397 goto error; |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1398 } |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1399 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1400 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1401 case FFMT_SPRITE: |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1402 if (!dmConvertImage2Sprite(buf, image, |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1403 bx * C64_SPR_WIDTH_PX, by * C64_SPR_HEIGHT, |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1404 multicolor)) |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1405 { |
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1406 ret = DMERR_DATA_ERROR; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1407 goto error; |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1408 } |
910 | 1409 break; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1410 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1411 |
907 | 1412 if (!dm_fwrite_str(outFile, buf, outBufSize)) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1413 { |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1414 ret = dmGetErrno(); |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1415 dmError(ret, "Error writing data block %d,%d to '%s', %d: %s\n", |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1416 bx, by, filename, ret, dmErrorStr(ret)); |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1417 goto error; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1418 } |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1419 } |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1420 |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1421 fclose(outFile); |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1422 dmFree(buf); |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1423 return 0; |
828 | 1424 |
1425 error: | |
1426 if (outFile != NULL) | |
1427 fclose(outFile); | |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1428 dmFree(buf); |
910 | 1429 return ret; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1430 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1431 |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1432 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1433 int dmDumpSpritesAndChars(const Uint8 *dataBuf, const size_t dataSize, const size_t realOffs) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1434 { |
1524
532c3ceaec1a
Fix uninitilized variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1522
diff
changeset
|
1435 int ret = DMERR_OK, itemCount, outWidth, outWidthPX, outHeight; |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1436 size_t offs, outSize; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1437 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1438 switch (optInFormat) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1439 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1440 case FFMT_CHAR: |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1441 outSize = C64_CHR_SIZE; |
975 | 1442 outWidth = C64_CHR_WIDTH; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1443 outWidthPX = C64_CHR_WIDTH_PX; |
975 | 1444 outHeight = C64_CHR_HEIGHT; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1445 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1446 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1447 case FFMT_SPRITE: |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1448 outSize = C64_SPR_SIZE; |
975 | 1449 outWidth = C64_SPR_WIDTH; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1450 outWidthPX = C64_SPR_WIDTH_PX; |
975 | 1451 outHeight = C64_SPR_HEIGHT; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1452 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1453 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1454 default: |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1455 return dmError(DMERR_INTERNAL, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1456 "Invalid input format %d, internal error.\n", optInFormat); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1457 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1458 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1459 offs = 0; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1460 itemCount = 0; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1461 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1462 if (optOutFormat == FFMT_ANSI || optOutFormat == FFMT_ASCII) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1463 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1464 BOOL error = FALSE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1465 FILE *outFile; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1466 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1467 if (optOutFilename == NULL) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1468 outFile = stdout; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1469 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1470 if ((outFile = fopen(optOutFilename, "w")) == NULL) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1471 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1472 ret = dmGetErrno(); |
1525
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1473 dmError(ret, "Error opening output file '%s': %s\n", |
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1474 optOutFilename, dmErrorStr(ret)); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1475 goto error; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1476 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1477 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1478 while (offs + outSize < dataSize && !error && (optItemCount < 0 || itemCount < optItemCount)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1479 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1480 fprintf(outFile, "---- : -------------- #%d\n", itemCount); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1481 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1482 switch (optInFormat) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1483 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1484 case FFMT_CHAR: |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1485 dmDumpCharASCII(outFile, dataBuf + offs, realOffs + offs, optOutFormat, optInMulticolor); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1486 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1487 case FFMT_SPRITE: |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1488 dmDumpSpriteASCII(outFile, dataBuf + offs, realOffs + offs, optOutFormat, optInMulticolor); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1489 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1490 } |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1491 offs += outSize; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1492 itemCount++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1493 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1494 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1495 fclose(outFile); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1496 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1497 else |
423 | 1498 if (optOutFormat == FFMT_IMAGE) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1499 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1500 DMImage *outImage = NULL; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1501 char *outFilename = NULL; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1502 int outX = 0, outY = 0, err; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1503 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1504 if (optSequential) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1505 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1506 if (optOutFilename == NULL) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1507 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1508 dmErrorMsg("Sequential image output requires filename template.\n"); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1509 goto error; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1510 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1511 |
1288 | 1512 outImage = dmImageAlloc(outWidthPX, outHeight, DM_IFMT_PALETTE, -1); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1513 dmMsg(1, "Outputting sequence of %d images @ %d x %d -> %d x %d.\n", |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1514 optItemCount, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1515 outImage->width, outImage->height, |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
1516 outImage->width * optSpec.scaleX, outImage->height * optSpec.scaleY); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1517 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1518 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1519 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1520 int outIWidth, outIHeight; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1521 if (optItemCount <= 0) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1522 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1523 dmErrorMsg("Single-image output requires count to be set (-n).\n"); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1524 goto error; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1525 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1526 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1527 outIWidth = optPlanedWidth; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1528 outIHeight = (optItemCount / optPlanedWidth); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1529 if (optItemCount % optPlanedWidth) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1530 outIHeight++; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1531 |
1288 | 1532 outImage = dmImageAlloc(outWidthPX * outIWidth, outIHeight * outHeight, DM_IFMT_PALETTE, -1); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1533 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1534 |
1457
dcff9ac95d3f
Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1441
diff
changeset
|
1535 dmSetDefaultC64Palette(outImage); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1536 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1537 while (offs + outSize < dataSize && (optItemCount < 0 || itemCount < optItemCount)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1538 { |
827 | 1539 if ((err = dmC64ConvertCSDataToImage(outImage, outX * outWidthPX, outY * outHeight, |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1540 dataBuf + offs, outWidth, outHeight, optInMulticolor, optColors)) != DMERR_OK) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1541 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1542 dmErrorMsg("Internal error in conversion of raw data to bitmap: %d.\n", err); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1543 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1544 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1545 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1546 if (optSequential) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1547 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1548 outFilename = dm_strdup_printf("%s%04d.%s", |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1549 optOutFilename, |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1550 itemCount, |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1551 convFormatList[optOutFormat].fext); |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1552 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1553 if (outFilename == NULL) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1554 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1555 dmErrorMsg("Could not allocate memory for filename template?\n"); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1556 goto error; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1557 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1558 |
1526
e0cd0fc8c753
Oops. Actually use the generated filename for writing the output files in here.
Matti Hamalainen <ccr@tnsp.org>
parents:
1525
diff
changeset
|
1559 ret = dmWriteImage(outFilename, outImage, &optSpec, optOutSubFormat, TRUE); |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1560 if (ret != DMERR_OK) |
799 | 1561 { |
1525
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1562 dmErrorMsg("Error writing output image '%s': %s.\n", |
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1563 outFilename, dmErrorStr(ret)); |
799 | 1564 } |
1565 | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1566 dmFree(outFilename); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1567 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1568 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1569 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1570 if (++outX >= optPlanedWidth) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1571 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1572 outX = 0; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1573 outY++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1574 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1575 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1576 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1577 offs += outSize; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1578 itemCount++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1579 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1580 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1581 if (!optSequential) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1582 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1583 ret = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE); |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1584 if (ret != DMERR_OK) |
799 | 1585 { |
1525
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1586 dmError(ret, "Error writing output image '%s': %s.\n", |
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1587 optOutFilename, dmErrorStr(ret)); |
799 | 1588 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1589 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1590 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1591 dmImageFree(outImage); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1592 } |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1593 else |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1594 if (optOutFormat == FFMT_BITMAP) |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1595 { |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1596 if (optSequential) |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1597 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1598 ret = dmError(DMERR_INVALID_ARGS, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1599 "Sequential output not supported for spr/char -> bitmap conversion.\n"); |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1600 goto error; |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1601 } |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1602 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1603 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1604 error: |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1605 return ret; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1606 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1607 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1608 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1609 int main(int argc, char *argv[]) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1610 { |
933 | 1611 FILE *inFile = NULL; |
1440 | 1612 const DMC64ImageFormat *inC64Fmt = NULL; |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1613 DMC64Image *inC64Image = NULL, *outC64Image = NULL; |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1614 Uint8 *dataBuf = NULL, *dataBufOrig = NULL; |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1615 size_t dataSize, dataSizeOrig; |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1616 int i, n; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1617 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1618 // Default colors |
1584
f1b279ba47a8
Remove some useless constants.
Matti Hamalainen <ccr@tnsp.org>
parents:
1569
diff
changeset
|
1619 for (i = 0; i < C64_NCOLORS; i++) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1620 optColors[i] = i; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1621 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1622 // Initialize list of additional conversion formats |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1759
diff
changeset
|
1623 dmC64InitializeFormats(); |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1624 nconvFormatList = ndmImageFormatList + nbaseFormatList; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1625 convFormatList = dmCalloc(nconvFormatList, sizeof(DMConvFormat)); |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1626 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1627 for (n = i = 0; i < ndmImageFormatList; i++) |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1628 { |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1629 const DMImageFormat *sfmt = &dmImageFormatList[i]; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1630 DMConvFormat *dfmt = &convFormatList[n++]; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1631 dfmt->name = sfmt->name; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1632 dfmt->fext = sfmt->fext; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1633 dfmt->flags = sfmt->flags; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1634 dfmt->format = FFMT_IMAGE; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1635 dfmt->subformat = sfmt->fmtid; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1636 } |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1637 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1638 for (i = 0; i < nbaseFormatList; i++) |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1639 memcpy(&convFormatList[n++], &baseFormatList[i], sizeof(DMConvFormat)); |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1640 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1641 // Initialize and parse commandline |
1617 | 1642 dmInitProg("gfxconv", "Simple graphics converter", "0.92", NULL, NULL); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1643 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1644 if (!dmArgsProcess(argc, argv, optList, optListN, |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
854
diff
changeset
|
1645 argHandleOpt, argHandleFile, OPTH_BAILOUT)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1646 exit(1); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1647 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1648 // Determine input format, if not specified' |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1649 if (optInFormat == FFMT_AUTO && optInFilename != NULL) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1650 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1651 char *dext = strrchr(optInFilename, '.'); |
465 | 1652 dmMsg(4, "Trying to determine file format by extension.\n"); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1653 if (dext) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1654 { |
819
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
1655 if (!dmGetFormatByExt(dext + 1, &optInFormat, &optInSubFormat)) |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
1656 dmGetC64FormatByExt(dext + 1, &optInFormat, &optInSubFormat); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1657 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1658 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1659 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1660 if (optInFilename == NULL) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1661 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1662 if (optInFormat == FFMT_AUTO) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1663 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1664 dmErrorMsg("Standard input cannot be used without specifying input format.\n"); |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1665 dmErrorMsg("Perhaps you should try using --help\n"); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1666 goto error; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1667 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1668 inFile = stdin; |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1669 optInFilename = "stdin"; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1670 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1671 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1672 if ((inFile = fopen(optInFilename, "rb")) == NULL) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1673 { |
488 | 1674 int res = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1675 dmErrorMsg("Error opening input file '%s', %d: %s\n", |
488 | 1676 optInFilename, res, dmErrorStr(res)); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1677 goto error; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1678 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1679 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1680 // Read the input .. |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1681 dmMsg(1, "Reading input from '%s'.\n", optInFilename); |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1682 |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1683 if (dmReadDataFile(inFile, NULL, &dataBufOrig, &dataSizeOrig) != 0) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1684 goto error; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1685 |
1664
9181d9148654
Fix a minor memory leak and file descriptor leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1640
diff
changeset
|
1686 fclose(inFile); |
9181d9148654
Fix a minor memory leak and file descriptor leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1640
diff
changeset
|
1687 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1688 // Check and compute the input skip |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1689 if (optInSkip > dataSizeOrig) |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1690 { |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1696
diff
changeset
|
1691 dmErrorMsg("Input skip value %d is larger than input size %" DM_PRIu_SIZE_T ".\n", |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1692 optInSkip, dataSizeOrig); |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1693 goto error; |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1694 } |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1695 |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1696 dataBuf = dataBufOrig + optInSkip; |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1697 dataSize = dataSizeOrig - optInSkip; |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1698 |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1699 // Perform probing, if required |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1700 if (optInFormat == FFMT_AUTO || optInFormat == FFMT_BITMAP) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1701 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1702 // Probe for format |
516 | 1703 const DMC64ImageFormat *forced = NULL; |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1696
diff
changeset
|
1704 DMGrowBuf tbuf; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1705 int res; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1706 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1707 if (optForcedFormat >= 0) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1708 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1709 forced = &dmC64ImageFormats[optForcedFormat]; |
1480
c3eba254bcc2
Change some message priorities.
Matti Hamalainen <ccr@tnsp.org>
parents:
1479
diff
changeset
|
1710 dmMsg(0, "Forced %s format image, type %d, %s\n", |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1759
diff
changeset
|
1711 forced->name, forced->format->type, forced->fext); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1712 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1713 |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1714 res = dmC64DecodeBMP(&inC64Image, |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1715 dmGrowBufConstCreateFrom(&tbuf, dataBuf, dataSize), |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1716 0, 2, &inC64Fmt, forced); |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1717 |
1630
00e0d345e7f1
Improve autoprobing error handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1629
diff
changeset
|
1718 if (forced == NULL && inC64Fmt != NULL && res == DMERR_OK) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1719 { |
1522
0d1cf72fb732
Clarify the "probed" messages of gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1514
diff
changeset
|
1720 dmMsg(1, "Probed '%s' format image, type %d, %s\n", |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1759
diff
changeset
|
1721 inC64Fmt->name, inC64Fmt->format->type, inC64Fmt->fext); |
1630
00e0d345e7f1
Improve autoprobing error handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1629
diff
changeset
|
1722 |
00e0d345e7f1
Improve autoprobing error handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1629
diff
changeset
|
1723 optInFormat = FFMT_BITMAP; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1724 } |
897 | 1725 else |
1630
00e0d345e7f1
Improve autoprobing error handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1629
diff
changeset
|
1726 if (res != DMERR_OK && (forced != NULL || optInFormat == FFMT_BITMAP)) |
897 | 1727 { |
1464
73e00bf7531c
Improve one error message by showing the error code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1457
diff
changeset
|
1728 dmErrorMsg("Could not decode input image: %s.\n", dmErrorStr(res)); |
1514
61a5bbaf8d5c
Plug some minor memory leaks in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1502
diff
changeset
|
1729 goto error; |
897 | 1730 } |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1731 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1732 |
463 | 1733 if (optInFormat == FFMT_AUTO || optInFormat == FFMT_IMAGE) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1734 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1735 const DMImageFormat *ifmt = NULL; |
435 | 1736 int index; |
465 | 1737 dmMsg(4, "Trying to probe image formats.\n"); |
1708
55db8d6dffa5
Do not apply input skip offset here anymore, it's handled more generally elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
1707
diff
changeset
|
1738 if (dmImageProbeGeneric(dataBuf, dataSize, &ifmt, &index) > 0) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1739 { |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1740 optInFormat = FFMT_IMAGE; |
435 | 1741 optInSubFormat = index; |
1522
0d1cf72fb732
Clarify the "probed" messages of gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1514
diff
changeset
|
1742 dmMsg(1, "Probed '%s' format image.\n", ifmt->fext); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1743 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1744 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1745 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1746 if (optInFormat == FFMT_AUTO) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1747 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1748 dmErrorMsg("No input format specified, and could not be determined automatically.\n"); |
1514
61a5bbaf8d5c
Plug some minor memory leaks in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1502
diff
changeset
|
1749 goto error; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1750 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1751 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1752 int inFormat = dmGetConvFormat(optInFormat, optInSubFormat), |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1753 outFormat = dmGetConvFormat(optOutFormat, optOutSubFormat); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1754 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1755 if (inFormat != -1 && outFormat != -1) |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1756 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1757 const char |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1758 *inFmtName = convFormatList[inFormat].name, |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1759 *inFmtExt = convFormatList[inFormat].fext, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1760 *outFmtName = convFormatList[outFormat].name, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1761 *outFmtExt = convFormatList[outFormat].fext; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1762 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1763 if (optInFormat == FFMT_BITMAP) |
1440 | 1764 inFmtExt = inC64Fmt->name; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1765 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1766 dmMsg(1, "Attempting conversion %s (%s) -> %s (%s)\n", |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1767 inFmtName, inFmtExt, outFmtName, outFmtExt); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1768 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1769 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1770 switch (optInFormat) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1771 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1772 case FFMT_SPRITE: |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1773 case FFMT_CHAR: |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1774 dmDumpSpritesAndChars(dataBuf, dataSize, optInSkip); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1775 break; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1776 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1777 case FFMT_BITMAP: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1778 { |
435 | 1779 DMImage *outImage = NULL; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1780 int res = DMERR_OK; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1781 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1782 if (optOutFilename == NULL) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1783 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1784 dmErrorMsg("Output filename not set, required for bitmap formats.\n"); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1785 goto error; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1786 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1787 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1788 switch (optOutFormat) |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1789 { |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1790 case FFMT_IMAGE: |
1440 | 1791 res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1792 |
435 | 1793 if (res != DMERR_OK || outImage == NULL) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1794 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1795 dmErrorMsg("Error in bitmap to image conversion.\n"); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1796 goto error; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1797 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1798 |
435 | 1799 res = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1800 break; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1801 |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1802 case FFMT_BITMAP: |
1550 | 1803 if ((res = dmConvertC64Bitmap(&outC64Image, inC64Image, &dmC64ImageFormats[optOutSubFormat], inC64Fmt)) != DMERR_OK) |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1804 { |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1805 dmErrorMsg("Error in bitmap format conversion.\n"); |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1806 goto error; |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1807 } |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1808 res = dmWriteBitmap(optOutFilename, outC64Image, &dmC64ImageFormats[optOutSubFormat]); |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1809 break; |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1810 |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1811 case FFMT_CHAR: |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1812 case FFMT_SPRITE: |
1440 | 1813 res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt); |
810
cbe263ad963c
Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
806
diff
changeset
|
1814 |
cbe263ad963c
Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
806
diff
changeset
|
1815 if (res != DMERR_OK || outImage == NULL) |
cbe263ad963c
Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
806
diff
changeset
|
1816 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1817 dmErrorMsg("Error in bitmap to template image conversion.\n"); |
810
cbe263ad963c
Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
806
diff
changeset
|
1818 goto error; |
cbe263ad963c
Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
806
diff
changeset
|
1819 } |
cbe263ad963c
Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
806
diff
changeset
|
1820 |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1821 res = dmWriteSpritesAndChars(optOutFilename, outImage, optOutFormat, optInMulticolor); |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1822 break; |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1823 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1824 default: |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1825 dmErrorMsg("Unsupported output format for bitmap/image conversion.\n"); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1826 break; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1827 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1828 |
435 | 1829 dmImageFree(outImage); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1830 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1831 break; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1832 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1833 case FFMT_IMAGE: |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1834 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1835 const DMImageFormat *ifmt = &dmImageFormatList[optInSubFormat]; |
1440 | 1836 DMImage *inImage = NULL; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1837 int res = DMERR_OK; |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1838 DMResource *fp; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1839 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1840 if (optOutFilename == NULL) |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1841 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1842 dmErrorMsg("Output filename not set, required for image formats.\n"); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1843 goto error; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1844 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1845 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1846 if ((res = dmf_open_memio(NULL, optInFilename, dataBuf, dataSize, &fp)) != DMERR_OK) |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1847 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1848 dmErrorMsg("Could not create MemIO handle for input.\n"); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1849 goto error; |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1850 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1851 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1852 // Read input |
441
2a4de5fe4003
Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
435
diff
changeset
|
1853 if (ifmt->readFILE != NULL) |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1854 res = ifmt->readFILE(fp, &inImage); |
441
2a4de5fe4003
Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
435
diff
changeset
|
1855 else |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1856 dmErrorMsg("Unsupported input image format for bitmap/image conversion.\n"); |
409
b529b7e8ff83
Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
1857 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1858 dmf_close(fp); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
1859 |
1440 | 1860 if (res != DMERR_OK || inImage == NULL) |
409
b529b7e8ff83
Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
1861 break; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1862 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1863 switch (optOutFormat) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1864 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1865 case FFMT_IMAGE: |
1440 | 1866 res = dmWriteImage(optOutFilename, inImage, &optSpec, optOutSubFormat, TRUE); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1867 break; |
417 | 1868 |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1869 case FFMT_CHAR: |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1870 case FFMT_SPRITE: |
1440 | 1871 res = dmWriteSpritesAndChars(optOutFilename, inImage, optOutFormat, optInMulticolor); |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1872 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1873 |
417 | 1874 default: |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1875 dmErrorMsg("Unsupported output format for bitmap/image conversion.\n"); |
417 | 1876 break; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1877 } |
806 | 1878 |
1879 if (res != DMERR_OK) | |
1880 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1881 dmErrorMsg("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n", |
806 | 1882 dmErrorStr(res)); |
1883 } | |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1884 |
1440 | 1885 dmImageFree(inImage); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1886 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1887 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1888 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1889 |
933 | 1890 error: |
1664
9181d9148654
Fix a minor memory leak and file descriptor leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1640
diff
changeset
|
1891 dmFree(convFormatList); |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1892 dmFree(dataBufOrig); |
1440 | 1893 dmC64ImageFree(inC64Image); |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1894 dmC64ImageFree(outC64Image); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1895 |
933 | 1896 return 0; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1897 } |