annotate tools/gfxconv.c @ 1543:416d7b3ba3b2

Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 12 May 2018 17:48:56 +0300
parents 776aa43b2c57
children 3b613fcbf3ff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
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
d8a83582f78f Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1432
diff changeset
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
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
19 #define DM_ASC_NBITS 8
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
20 #define DM_ASC_NCOLORS 4
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
21 static const char dmASCIIPalette[DM_ASC_NCOLORS] = ".:X#";
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
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
1f8687c61891 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1330
diff changeset
50 char *name; // Descriptive name of the format
1f8687c61891 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1330
diff changeset
51 char *fext; // File extension
1f8687c61891 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1330
diff changeset
52 BOOL in, out; // Can read/write?
1f8687c61891 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1330
diff changeset
53 int format; // Format identifier
1f8687c61891 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1330
diff changeset
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
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
58 static DMConvFormat convFormatList[] =
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 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
60 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
61 "ASCII text", "asc", FALSE, TRUE,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
62 FFMT_ASCII , 0,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
63 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
64 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
65 "ANSI colored text", "ansi", FALSE, TRUE,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
66 FFMT_ANSI , 0,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
67 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
68 {
454
2f820412d356 Mark PNG as available input format.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
69 "PNG image file", "png", TRUE, TRUE,
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
70 FFMT_IMAGE , DM_IMGFMT_PNG,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
71 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
72 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
73 "PPM image file", "ppm", FALSE, TRUE,
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
74 FFMT_IMAGE , DM_IMGFMT_PPM,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
75 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
76 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
77 "PCX image file", "pcx", TRUE, TRUE,
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
78 FFMT_IMAGE , DM_IMGFMT_PCX,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
79 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
80 {
443
f7c9d1619c74 Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents: 441
diff changeset
81 "IFF ILBM file", "lbm", TRUE, FALSE,
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
82 FFMT_IMAGE , DM_IMGFMT_ILBM,
443
f7c9d1619c74 Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents: 441
diff changeset
83 },
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
84 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
85 "Bitplaned RAW (intl/non-intl) image file", "raw", FALSE, TRUE,
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
86 FFMT_IMAGE , DM_IMGFMT_RAW,
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
87 },
443
f7c9d1619c74 Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents: 441
diff changeset
88 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
89 "IFFMaster RAW image file", "araw", FALSE, TRUE,
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
90 FFMT_IMAGE , DM_IMGFMT_ARAW,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
91 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
92
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
93 {
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
94 "C64 bitmap image file", NULL, TRUE, TRUE,
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
95 FFMT_BITMAP , -1,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
96 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
97
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
98 {
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
99 "C64 character/font data", "chr", TRUE, TRUE,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
100 FFMT_CHAR , 0
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
101 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
102 {
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
103 "C64 sprite data", "spr", TRUE, TRUE,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
104 FFMT_SPRITE , 0
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
105 },
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 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
108 static const int nconvFormatList = sizeof(convFormatList) / sizeof(convFormatList[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
109
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
111 typedef struct
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
112 {
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
113 BOOL triplet, alpha;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
114 DMColor color;
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
115 unsigned int from, to;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
116 } DMMapValue;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
117
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 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
121 *optOutFilename = NULL;
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
122
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
123 int optInFormat = FFMT_AUTO,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
124 optOutFormat = FFMT_ASCII,
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
125 optInSubFormat = DM_IMGFMT_PNG,
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
126 optOutSubFormat = DM_IMGFMT_PNG,
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 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
128 optPlanedWidth = 1,
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
129 optForcedFormat = -1;
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
130 unsigned int optInSkip = 0;
838
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
131
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
132 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
133 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
134 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
135
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 BOOL optInMulticolor = FALSE,
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
137 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
138 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
139 optRemapRemove = FALSE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
140 int optNRemapTable = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
141 DMMapValue optRemapTable[DM_MAX_COLORS];
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 int optColors[C64_MAX_COLORS];
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143
1290
e7dc9bb9777e Rename struct DMImageSpec to DMImageConvSpec.
Matti Hamalainen <ccr@tnsp.org>
parents: 1288
diff changeset
144 DMImageConvSpec optSpec =
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
145 {
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
146 .scaleX = 1,
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
147 .scaleY = 1,
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
148 .nplanes = 4,
1288
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
149 .bpp = 8,
1291
2c4acbc3e7bf More work on libgfx etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1290
diff changeset
150 .planar = FALSE,
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
151 .paletted = FALSE,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
152 .format = 0,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
153 };
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 854
diff changeset
155 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
156 {
983
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
157 { 0, '?', "help", "Show this help", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
158 { 15, 'v', "verbose", "Increase verbosity", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
159 { 3, 'o', "output", "Output filename", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
160 { 1, 'i', "informat", "Set input format (sprite[:mc:sc], char[:mc|sc], bitmap[:<bformat>], image)", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
161 { 2, 'm', "multicolor", "Input is multicolor / output in multicolor", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
162 { 4, 's', "skip", "Skip bytes in input", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
163 { 5, 'f', "format", "Output format (see --formats)", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
164 { 17, 0 , "formats", "List available input/output formats", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
165 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
166 { 6, 'c', "colormap", "Color mappings (see below for information)", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
167 { 7, 'n', "numitems", "How many 'items' to output (default: all)", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
168 { 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
169 { 9, 'S', "scale", "Scale output image by <n> or <x>:<y> integer factor(s). "
983
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
170 "-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
171 { 12, 'P', "paletted", "Use indexed/paletted output IF possible.", OPT_NONE },
1291
2c4acbc3e7bf More work on libgfx etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1290
diff changeset
172 { 13, 'N', "nplanes", "# of bitplanes (some output formats)", OPT_ARGREQ },
2c4acbc3e7bf More work on libgfx etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1290
diff changeset
173 { 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
174 { 14, 'I', "interleave", "Interleaved/planar output (some output formats)", OPT_NONE },
983
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
175 { 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
176 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 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
179
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
181 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
182 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
184 printf(
432
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
185 "Available input/output formats:\n"
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
186 " Ext | I | O | Description\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
187 "------+---+---+-----------------------------------------------\n"
432
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
188 );
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
189
1532
74febc66d90d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1526
diff changeset
190 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
191 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
192 DMConvFormat *fmt = &convFormatList[i];
432
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
193 printf("%-5s | %c | %c | %s\n",
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
194 fmt->fext ? fmt->fext : "",
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
195 fmt->in ? 'X' : ' ',
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
196 fmt->out ? 'X' : ' ',
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
197 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
198 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
200 printf(
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
201 "\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
202 "(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
203 "\n"
1502
aa87cb6cf33b Fix gfxconv help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
204 "Available bitmap formats (-f <bfrm>):\n"
1329
a8850642d0d2 Clarify --formats help slightly.
Matti Hamalainen <ccr@tnsp.org>
parents: 1303
diff changeset
205 " bfrm | Type | Description\n"
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
206 "------+-----------------+-------------------------------------\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
207 );
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
208
1532
74febc66d90d Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1526
diff changeset
209 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
210 {
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
211 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
212 char buf[64];
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
213 printf("%-5s | %-15s | %s\n",
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
214 fmt->fext,
1494
3b220604ae3c Add short format attribute names to dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents: 1493
diff changeset
215 dmC64GetImageTypeString(buf, sizeof(buf), fmt->type, 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
216 fmt->name);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 }
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
218 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
219
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
220
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
221 void argShowHelp()
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
222 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
223 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
224 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
225
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 printf(
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
227 "\n"
818
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
228 "Palette / color remapping (-R)\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
229 "------------------------------\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
230 "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
231 "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
232 "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
233 "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
234 "-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
235 "\n"
1330
62ef5cc2b475 Clarify help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1329
diff changeset
236 "Remap file can be specified as \"-R @filename\", and it is a text file with\n"
62ef5cc2b475 Clarify help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1329
diff changeset
237 "one remap definition per line in same format as above. All empty lines and\n"
62ef5cc2b475 Clarify help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1329
diff changeset
238 "lines starting with a semicolor (;) will be ignored as comments. Any extra\n"
62ef5cc2b475 Clarify help.
Matti Hamalainen <ccr@tnsp.org>
parents: 1329
diff changeset
239 "whitespace separating items will be ignored as well.\n"
818
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
240 "\n"
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
241 "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
242 "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
243 "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
244 "\n"
818
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
245 "Color map defs\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
246 "--------------\n"
456
20122cffde2f Clarify help.
Matti Hamalainen <ccr@tnsp.org>
parents: 455
diff changeset
247 "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
248 "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
249 "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
250 "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
251 "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
252 "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
253 "special color that can be used for transparency.\n"
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
254 "\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
255 );
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
259 int dmGetConvFormat(int format, int subformat)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
260 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
261 int i;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
262 for (i = 0; i < nconvFormatList; i++)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
263 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
264 DMConvFormat *fmt = &convFormatList[i];
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
265 if (fmt->format == format &&
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
266 fmt->subformat == subformat)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
267 return i;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
268 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
269 return -1;
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
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
272
819
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
273 BOOL dmGetC64FormatByExt(const char *fext, int *format, int *subformat)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
274 {
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
275 int i;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
276 if (fext == NULL)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
277 return FALSE;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
278
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
279 for (i = 0; i < ndmC64ImageFormats; i++)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
280 {
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
281 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
282 if (fmt->fext != NULL &&
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
283 strcasecmp(fext, fmt->fext) == 0)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
284 {
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
285 *format = FFMT_BITMAP;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
286 *subformat = i;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
287 return TRUE;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
288 }
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
289 }
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
290
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
291 return FALSE;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
292 }
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
293
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
294
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
295
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
296 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
297 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
298 int 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
299 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
300 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
301
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
302 for (i = 0; i < nconvFormatList; i++)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
303 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
304 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
305 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
306 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
307 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
308 *format = fmt->format;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
309 *subformat = fmt->subformat;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
310 return TRUE;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
311 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
312 }
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
313
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
314 return FALSE;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
315 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
316
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
317
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
318 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
319 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
320 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
321
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
322 if (opt == NULL)
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
323 goto error;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
324
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
325 if ((end = split = strchr(opt, ':')) == NULL)
473
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', expected <(#|%)RRGGBB|[$|0x]index>:<[$|0x]index>.\n", msg, 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
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
331 // Trim whitespace
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
332 *end = 0;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
333 for (end--; end > opt && *end && isspace(*end); end--)
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
334 *end = 0;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
335
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
336 // 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
337 if (*opt == '#' || *opt == '%')
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
338 {
867
56e12109b936 Portability warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
339 unsigned int colR, colG, colB, colA;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
340
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
341 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
342 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
343 {
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
344 value->alpha = TRUE;
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
345 value->color.a = colA;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
346 }
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
347 else
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
348 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
349 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
350 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
351 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
352 goto error;
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
353 }
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
354
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
355 value->color.r = colR;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
356 value->color.g = colG;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
357 value->color.b = colB;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
358 value->triplet = TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
359 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
360 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
361 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
362 if (!dmGetIntVal(opt, &value->from))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
363 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
364 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
365 goto error;
473
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 value->triplet = FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
368 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
369
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
370 // Trim whitespace
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
371 split++;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
372 while (*split && isspace(*split)) split++;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
373
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
374 // Parse destination value
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
375 if (!dmGetIntVal(split, &value->to))
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
376 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
377 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
378 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
379 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
380
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
381 if (!value->triplet && value->from > 255)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
382 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
383 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
384 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
385 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
386
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
387 if (value->to > nmax)
473
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("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
390 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
391 }
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
392
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
393 dmFree(opt);
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
394 return TRUE;
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
395
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
396 error:
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
397 dmFree(opt);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
398 return FALSE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
399 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
400
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 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
403 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
404 // Trim whitespace
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
405 if (end != NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
406 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
407 *end = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
408 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
409 *end = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
410 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
411 while (*opt && isspace(*opt)) opt++;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
412
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
413 // Parse item based on mode
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
414 if (requireIndex)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
415 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
416 DMMapValue *value = (DMMapValue *) pvalue;
475
c0dedfef3edf Fix option parsing of mappings.
Matti Hamalainen <ccr@tnsp.org>
parents: 474
diff changeset
417 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
418 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
419 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
420 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
421 {
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
422 unsigned int *value = (unsigned int *) pvalue;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
423 char *split = strchr(opt, ':');
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
424 if (split != NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
425 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
426 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
427 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
428 }
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 if (!dmGetIntVal(opt, &value[index]))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
431 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
432 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
433 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
434 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
435 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
436
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
437 return TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
438 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
439
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 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
442 {
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
443 char *start = opt;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
444
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
445 *nvalues = 0;
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
446 while (*start && *nvalues < nmax)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
447 {
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
448 char *end = strchr(start, ',');
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
449
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
450 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
451 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
452
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
453 (*nvalues)++;
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
454
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
455 if (!end)
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
456 break;
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
457
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
458 start = end + 1;
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
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
461 return TRUE;
473
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
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
465 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
466 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
467 FILE *fp;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
468 char line[512];
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
469 int res = DMERR_OK;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
470
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
471 if ((fp = fopen(filename, "r")) == NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
472 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
473 res = dmGetErrno();
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
474 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
475 res, dmErrorStr(res));
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
476 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
477 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
478
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
479 while (fgets(line, sizeof(line), fp))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
480 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
481 char *start = line;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
482 while (*start && isspace(*start)) start++;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
483
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
484 if (*start != 0 && *start != ';')
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
485 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
486 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
487 goto error;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
488 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
489 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
490 (*nvalue)++;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
491 if (*nvalue >= nmax)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
492 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
493 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
494 filename, nmax);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
495 goto error;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
496 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
497 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
498 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
499 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
500
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
501 error:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
502 fclose(fp);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
503 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
504 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
505
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
506
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 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
508 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 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
510 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511 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
512 argShowHelp();
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 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
514 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
516 case 17:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
517 argShowFormats();
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
518 exit(0);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
519 break;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
520
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
521 case 15:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
522 dmVerbosity++;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
523 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
524
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 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
526 {
824
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
527 switch (tolower(optArg[0]))
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
528 {
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
529 case 's': optInFormat = FFMT_SPRITE; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
530 case 'c': optInFormat = FFMT_CHAR; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
531 case 'b': optInFormat = FFMT_BITMAP; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
532 case 'i': optInFormat = FFMT_IMAGE; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
533 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
534 dmErrorMsg("Invalid input format '%s'.\n", optArg);
824
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
535 return FALSE;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
536 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
537
838
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
538 char *tmp = strchr(optArg, ':');
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
539 if (tmp != NULL)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
540 {
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
541 tmp++;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
542 switch (optInFormat)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
543 {
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
544 case FFMT_SPRITE:
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
545 case FFMT_CHAR:
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
546 if (strcasecmp(tmp, "mc") == 0)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
547 optInMulticolor = TRUE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
548 else
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
549 if (strcasecmp(tmp, "sc") == 0)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
550 optInMulticolor = FALSE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
551 else
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
552 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
553 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
554 tmp);
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
555 return FALSE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
556 }
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
557 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
558
838
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
559 case FFMT_BITMAP:
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
560 if (!dmGetC64FormatByExt(tmp, &optInFormat, &optInSubFormat))
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
561 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
562 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
563 tmp);
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
564 return FALSE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
565 }
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
566 break;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
567 }
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
568 }
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 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
571
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 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
573 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
574 break;
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 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
577 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
578 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
579
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 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
581 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
582 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
583 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
584 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
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 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 case 5:
819
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
589 if (!dmGetFormatByExt(optArg, &optOutFormat, &optOutSubFormat) &&
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
590 !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
591 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
592 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
593 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
594 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
597 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
598 {
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
599 int index, ncolors;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
600 if (!dmParseMapOptionString(optArg, optColors,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
601 &ncolors, C64_MAX_COLORS, FALSE, "color table option"))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
602 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
603
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
604 dmMsg(1, "Set color table: ");
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
605 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
606 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607 dmPrint(1, "[%d:%d]%s",
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
608 index, optColors[index],
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
609 (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
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 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
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 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 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
616 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
617 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
618 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
619 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
620 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 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
624 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
625 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
627 case 9:
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
628 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
629 {
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
630 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
631 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
632 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
633 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
634 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
635 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
636 }
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
637 }
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
638 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
639 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
640 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
641 return FALSE;
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
642 }
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
643 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
644 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
645 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
646 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
647 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650 case 11:
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
651 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
652 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
653 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
654 return FALSE;
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
655 }
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
656 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
657 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
658 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
659 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
660 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
661 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 case 12:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
664 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
665 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
666
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
667 case 13:
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
668 {
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
669 int tmp = atoi(optArg);
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
670 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
671 {
1288
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
672 dmErrorMsg("Invalid number of bitplanes value '%s'.\n", optArg);
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
673 return FALSE;
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
674 }
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
675 optSpec.nplanes = tmp;
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
676 }
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
677 break;
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
678
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
679 case 18:
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
680 {
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
681 int tmp = atoi(optArg);
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
682 if (tmp < 1 || tmp > 32)
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
683 {
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
684 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
685 return FALSE;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
686 }
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
687 optSpec.nplanes = tmp;
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
688 }
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
689 break;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
690
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
691 case 14:
1291
2c4acbc3e7bf More work on libgfx etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1290
diff changeset
692 optSpec.planar = TRUE;
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
693 break;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
694
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
695 case 16:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
696 {
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
697 char *tmp;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
698 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
699 {
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
700 optRemapRemove = TRUE;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
701 *tmp = 0;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
702 }
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
703
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
704 if (optArg[0] == '@')
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
705 {
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
706 if (optArg[1] != 0)
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
707 {
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
708 int res;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
709 if ((res = dmParseColorRemapFile(optArg + 1,
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
710 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
711 return FALSE;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
712 }
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
713 else
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
714 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
715 dmErrorMsg("No remap filename given.\n");
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
716 return FALSE;
823
f0429dbd77ec Oops, missing } from one of the previous commits. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents: 822
diff changeset
717 }
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
718 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
719 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
720 {
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
721 if (!dmParseMapOptionString(optArg, optRemapTable,
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
722 &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
723 return FALSE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
724 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
725 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
726
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
727 optRemapColors = TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
728 break;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
729
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
730 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
731 {
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
732 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
733 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
734 {
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
735 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
736 }
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
737 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
738 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
739 {
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
740 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
741 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
742 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
743 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
744 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
745 }
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
746 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
747 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
748 {
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
749 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
750 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
751 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
752 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
753 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
754 }
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
755 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
756 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
757 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
758 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
759 }
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
760 }
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
761 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
762
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 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
764 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
765 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
766 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
767
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768 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
769 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
772 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
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 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
775 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
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 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
778 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
779 currArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
780 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
781 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
782
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783 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
784 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
785
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
786
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
787 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
788 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
789 int i;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
790
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 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
792 {
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
793 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
794 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 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
796 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
797 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
798 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
799 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
800 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
801 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
802 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
803 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
804 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
805 0x1b,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806 1,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
807 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
808 0x1b);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 break;
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 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
814 {
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
815 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
816 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817 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
818 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
819 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
820 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
821 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
822 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
823 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
824 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
825 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
826 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
827 0x1b,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
828 1,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
829 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
830 0x1b);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
831 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
832 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
833 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
834 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
835 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
836
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
837
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
838 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
839 {
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
840 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
841 {
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
842 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
843 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
844 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
845 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
846 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
847
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
848
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
849 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
850 {
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
851 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
852
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
853 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
854 {
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
855 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
856 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
857 {
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
858 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
859 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
860 bufOffs++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
861 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
862 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
863 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
864 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
865
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
866
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 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
868 {
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
869 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
870 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
871 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
872 BOOL *used = dmMalloc(src->ncolors * sizeof(BOOL));
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
873 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
874 DMImage *dst;
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
875
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
876 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
877 {
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
878 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
879 "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
880 }
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
881
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
882 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
883
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
884 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
885 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
886 return dmError(DMERR_MALLOC,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
887 "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
888 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
889
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
890 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
891 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
892 mapping[index] = -1;
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
893 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
894 }
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
895
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
896 // 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
897 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
898 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
899 {
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
900 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
901 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
902 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
903 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
904 if (col < src->ncolors && !used[col])
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
905 {
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
906 used[col] = TRUE;
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
907 ncolors++;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
908 }
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 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
910 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
911 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
912
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
913 // Match and mark mapped colors
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
914 for (index = 0; index < optNRemapTable; index++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
915 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
916 DMMapValue *map = &optRemapTable[index];
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
917 if (map->triplet)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
918 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
919 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
920 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
921 {
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
922 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
923 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
924 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
925 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
926 n,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
927 map->to);
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
928
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
929 mapping[n] = map->to;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
930 mapped[map->to] = TRUE;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
931 found = TRUE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
932 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
933 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
934
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
935 if (!found)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
936 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
937 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
938 index,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
939 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
940 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
941 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
942 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
943 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
944 dmMsg(3, "Map index: %d -> %d\n",
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
945 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
946
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
947 mapping[map->from] = map->to;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
948 mapped[map->to] = TRUE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
949 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
950 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
951
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
952
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
953 // 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
954 if (optRemapRemove)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
955 {
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
956 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
957 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
958 if (mapping[index] < 0 && used[index])
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 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
961 if (!mapped[n])
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
962 {
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
963 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
964 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
965 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
966 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
967 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
968 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
969 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
970 {
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
971 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
972 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
973 {
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
974 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
975 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
976 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
977 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
978 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
979 break;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
980 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
981 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
982 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
983
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
984 // 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
985 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
986 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
987 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
988 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
989 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
990 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
991
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
992 // 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
993 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
994 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
995 if (mapping[index] >= 0)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
996 {
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
997 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
998 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
999 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1000
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1001 // 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
1002 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
1003 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
1004 {
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
1005 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
1006 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
1007 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
1008 {
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
1009 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
1010 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
1011 dp[xc] = mapping[col];
478
7c7a57590236 Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents: 477
diff changeset
1012 else
7c7a57590236 Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents: 477
diff changeset
1013 dp[xc] = 0;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1014 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1015 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1016
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1017 // 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
1018 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
1019 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
1020
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
1021 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
1022 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
1023 dmFree(used);
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1024 return DMERR_OK;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1025 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1026
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1027
1490
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1028 int dmConvertC64Bitmap(DMC64Image **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt)
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1029 {
1493
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1030 DMC64Image *dst;
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1031
1490
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1032 if (pdst == NULL || fmt == NULL || src == NULL)
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1033 return DMERR_NULLPTR;
1493
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1034
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1035 if ((dst = *pdst = dmC64ImageAlloc(fmt)) == NULL)
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1036 return DMERR_MALLOC;
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1037
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1038 if (src->type == dst->type)
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1039 {
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1040 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
1041 {
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1042 memcpy(dst->color[i], src->color[i], dst->screenSize);
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1043 memcpy(dst->bitmap[i], src->bitmap[i], dst->bitmapSize);
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1044 memcpy(dst->screen[i], src->screen[i], dst->screenSize);
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1045 memcpy(dst->charmem[i], src->charmem[i], dst->charmemSize);
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1046 }
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1047 }
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1048 else
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 // Try to do some simple fixups
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1051 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
1052 {
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1053 dmMsg(1, "Upconverting multicolor to FLI.\n");
1537
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1054 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
1055 {
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1056 memcpy(dst->color[i], src->color[0], dst->screenSize);
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1057 memcpy(dst->screen[i], src->screen[0], dst->screenSize);
1537
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1058 memcpy(dst->bitmap[i], src->bitmap[0], dst->bitmapSize);
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1059 memcpy(dst->charmem[i], src->charmem[0], dst->charmemSize);
1493
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1060 }
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1061
1537
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1062 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++)
1493
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1063 {
1537
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1064 const DMC64EncDecOp *op = &fmt->encdecOps[i];
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1065 size_t size;
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1066
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1067 // Check for last operator
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1068 if (op->type == DT_LAST)
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1069 break;
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1070
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1071 // Check size
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1072 if (!dmC64GetOpSize(op, fmt, &size))
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1073 return DMERR_INVALID_DATA;
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1074
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1075 // Perform operation
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1076 switch (op->type)
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1077 {
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1078 case DT_EXTRA_DATA:
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1079 dst->extraData[op->bank] = dmMalloc0(size);
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1080 dst->extraDataSizes[op->bank] = size;
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1081 break;
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1532
diff changeset
1082 }
1493
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1083 }
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1084 }
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1085 }
d987a4933e1c Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1490
diff changeset
1086
1490
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1087 return DMERR_OK;
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1088 }
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1089
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1090
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1091 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
1092 {
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1093 int res = DMERR_OK;
1481
e967e8e3b8c3 Sanitize dmWriteBitmap().
Matti Hamalainen <ccr@tnsp.org>
parents: 1480
diff changeset
1094 DMGrowBuf buf;
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1095
1481
e967e8e3b8c3 Sanitize dmWriteBitmap().
Matti Hamalainen <ccr@tnsp.org>
parents: 1480
diff changeset
1096 // Encode to target format
e967e8e3b8c3 Sanitize dmWriteBitmap().
Matti Hamalainen <ccr@tnsp.org>
parents: 1480
diff changeset
1097 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
1098 if ((res = dmC64EncodeBMP(&buf, image, fmt)) != DMERR_OK)
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1099 goto error;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1100
1481
e967e8e3b8c3 Sanitize dmWriteBitmap().
Matti Hamalainen <ccr@tnsp.org>
parents: 1480
diff changeset
1101 // And output the file
e967e8e3b8c3 Sanitize dmWriteBitmap().
Matti Hamalainen <ccr@tnsp.org>
parents: 1480
diff changeset
1102 dmMsg(1, "Writing output file '%s'\n", filename);
e967e8e3b8c3 Sanitize dmWriteBitmap().
Matti Hamalainen <ccr@tnsp.org>
parents: 1480
diff changeset
1103 if ((res = dmWriteDataFile(NULL, filename, buf.data, buf.len)) != DMERR_OK)
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1104 goto error;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1105
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1106 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
1107 dmGrowBufFree(&buf);
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1108 return res;
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1109 }
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1110
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1111
1303
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1112 void dmOutputImageBitFormat(const int format, const BOOL info)
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1113 {
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1114 if (info)
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1115 {
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1116 char *str;
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1117 switch (format)
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1118 {
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1119 case DM_IFMT_PALETTE : str = "Indexed 8bpp"; break;
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1120 case DM_IFMT_RGB : str = "24bit RGB"; break;
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1121 case DM_IFMT_RGBA : str = "32bit RGBA"; break;
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1122 default : str = "???"; break;
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1123 }
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1124 dmMsg(2, "%s output.\n", str);
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1125 }
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1126 }
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1127
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
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 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
1130 {
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
1131 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
1132
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1133 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
1134 {
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
1135 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
1136 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
1137 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
1138 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
1139 spec->scaleX, spec->scaleY);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1140 }
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1141
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1142 // 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
1143 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
1144 BOOL allocated = FALSE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1145 if (optRemapColors)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1146 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1147 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
1148 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
1149 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
1150
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
1151 allocated = TRUE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1152 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1153
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1154 switch (iformat)
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1155 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1156 #ifdef DM_USE_LIBPNG
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
1157 case DM_IMGFMT_PNG:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1158 spec->format = spec->paletted ? DM_IFMT_PALETTE : DM_IFMT_RGBA;
1303
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1159 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
1160 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
1161 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
1162 #endif
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1163
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
1164 case DM_IMGFMT_PPM:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1165 spec->format = DM_IFMT_RGB;
1303
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1166 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
1167 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
1168 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
1169
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
1170 case DM_IMGFMT_PCX:
1303
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1171 spec->format = spec->paletted ? DM_IFMT_PALETTE : DM_IFMT_RGB;
be30466fbc47 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1293
diff changeset
1172 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
1173 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
1174 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
1175
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
1176 case DM_IMGFMT_RAW:
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
1177 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
1178 {
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 // Open data file for writing
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1180 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
1181 char * dataFilename = dm_strdup_fext(filename, "%s.inc");
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1182 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
1183 {
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 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
1185 "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
1186 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
1187 }
820
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1188
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1189 dmFree(dataFilename);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1190
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1191 if (fp != NULL)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1192 {
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1193 // Strip extension
820
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1194 char *palID = dm_strdup_fext(filename, "img_%s");
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1195
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1196 // 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
1197 for (int i = 0; palID[i]; i++)
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1198 {
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1199 if (isalnum(palID[i]))
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1200 palID[i] = tolower(palID[i]);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1201 else
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1202 palID[i] = '_';
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1203 }
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1204
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
1205 if (iformat == DM_IMGFMT_ARAW)
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1206 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1207 fprintf(fp,
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1208 "%s_width: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1209 "%s_height: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1210 "%s_nplanes: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1211 "%s_ncolors: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1212 "%s_palette:\n",
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1213 palID, image->width,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1214 palID, image->height,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1215 palID, spec->nplanes,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1216 palID, image->ncolors,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1217 palID);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1218
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1219 dmWriteIFFMasterRAWPalette(fp, image, 1 << optSpec.nplanes, NULL, NULL);
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1220
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1221 fprintf(fp,
477
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1222 "%s: incbin \"%s\"\n",
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1223 palID, filename);
566
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 else
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1226 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1227 fprintf(fp,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1228 "%s_width: dw.w %d\n"
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1229 "%s_height: dw.w %d\n"
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1230 "%s_nplanes: dw.w %d\n",
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1231 palID, image->width,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1232 palID, image->height,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1233 palID, spec->nplanes);
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1234 }
477
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1235
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1236 fclose(fp);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1237 dmFree(palID);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1238 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1239
1291
2c4acbc3e7bf More work on libgfx etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1290
diff changeset
1240 if (info)
2c4acbc3e7bf More work on libgfx etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1290
diff changeset
1241 {
2c4acbc3e7bf More work on libgfx etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1290
diff changeset
1242 dmMsg(2, "%d bitplanes, %s planes.\n",
2c4acbc3e7bf More work on libgfx etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1290
diff changeset
1243 spec->nplanes,
2c4acbc3e7bf More work on libgfx etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1290
diff changeset
1244 spec->planar ? "planar/interleaved" : "non-interleaved");
2c4acbc3e7bf More work on libgfx etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 1290
diff changeset
1245 }
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
1246 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
1247 }
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1248 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
1249
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1250 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
1251 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
1252 }
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
1253
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 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
1255 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
1256 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
1257
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
1258 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
1259 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1260
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1261
547
ca5ad51c6479 Make dmConvertByte() static.
Matti Hamalainen <ccr@tnsp.org>
parents: 546
diff changeset
1262 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
1263 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1264 Uint8 byte = 0;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1265 int xc;
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 if (multicolor)
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 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
1270 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1271 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
1272 byte |= pixel << (6 - (xc * 2));
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1273 }
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 else
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 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
1278 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1279 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
1280 byte |= pixel << (7 - xc);
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 }
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 return byte;
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
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1287
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1288 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
1289 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
1290 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1291 int yc;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1292
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1293 if (xoffs < 0 || yoffs < 0 ||
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1294 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
1295 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
1296 return FALSE;
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 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
1299 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1300 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
1301 buf[yc] = dmConvertByte(sp, multicolor);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1302 }
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 return TRUE;
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
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1307
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1308 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
1309 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
1310 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1311 int yc, xc;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1312
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1313 if (xoffs < 0 || yoffs < 0 ||
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1314 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
1315 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
1316 return FALSE;
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 (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
1319 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1320 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
1321 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1322 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
1323 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
1324 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1325 }
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 return TRUE;
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
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1330
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1331 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
1332 {
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1333 int ret = DMERR_OK;
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1334 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
1335 FILE *outFile = NULL;
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1336 Uint8 *buf = NULL;
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1337 size_t outBufSize;
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1338 char *outType;
489
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 switch (outFormat)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1341 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1342 case FFMT_CHAR:
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1343 outBufSize = C64_CHR_SIZE;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1344 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
1345 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
1346 outType = "char";
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1347 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1348
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1349 case FFMT_SPRITE:
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1350 outBufSize = C64_SPR_SIZE;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1351 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
1352 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
1353 outType = "sprite";
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1354 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1355
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1356 default:
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1357 ret = dmError(DMERR_INVALID_ARGS,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1358 "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
1359 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1360 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1361
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1362 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
1363 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1364 ret = dmError(DMERR_INVALID_ARGS,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1365 "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
1366 outBlockW, outBlockH);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1367 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1368 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1369
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1370 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
1371 {
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1372 ret = dmGetErrno();
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1373 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
1374 filename, ret, dmErrorStr(ret));
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1375 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1376 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1377
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1378 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
1379 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1380 dmErrorMsg("Could not allocate %d bytes for conversion buffer.\n",
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1381 outBufSize);
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1382 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1383 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1384
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1385 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
1386 outBlockW, outBlockH, outBlockW * outBlockH, outType);
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1387
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1388 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
1389 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
1390 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1391 switch (outFormat)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1392 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1393 case FFMT_CHAR:
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1394 if (!dmConvertImage2Char(buf, image,
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1395 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
1396 multicolor))
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1397 {
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1398 ret = DMERR_DATA_ERROR;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1399 goto error;
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1400 }
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1401 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1402
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1403 case FFMT_SPRITE:
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1404 if (!dmConvertImage2Sprite(buf, image,
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1405 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
1406 multicolor))
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1407 {
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1408 ret = DMERR_DATA_ERROR;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1409 goto error;
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1410 }
910
Matti Hamalainen <ccr@tnsp.org>
parents: 909
diff changeset
1411 break;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1412 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1413
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1414 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
1415 {
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1416 ret = dmGetErrno();
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1417 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
1418 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
1419 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1420 }
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1421 }
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1422
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1423 fclose(outFile);
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1424 dmFree(buf);
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1425 return 0;
828
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1426
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1427 error:
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1428 if (outFile != NULL)
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1429 fclose(outFile);
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1430 dmFree(buf);
910
Matti Hamalainen <ccr@tnsp.org>
parents: 909
diff changeset
1431 return ret;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1432 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1433
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1434
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1435 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
1436 {
1524
532c3ceaec1a Fix uninitilized variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1522
diff changeset
1437 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
1438 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
1439
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1440 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
1441 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1442 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
1443 outSize = C64_CHR_SIZE;
975
139b801f8d1c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 974
diff changeset
1444 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
1445 outWidthPX = C64_CHR_WIDTH_PX;
975
139b801f8d1c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 974
diff changeset
1446 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
1447 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1448
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1449 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
1450 outSize = C64_SPR_SIZE;
975
139b801f8d1c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 974
diff changeset
1451 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
1452 outWidthPX = C64_SPR_WIDTH_PX;
975
139b801f8d1c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 974
diff changeset
1453 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
1454 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1455
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1456 default:
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1457 return dmError(DMERR_INTERNAL,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1458 "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
1459 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1460
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1461 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
1462 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
1463
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1464 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
1465 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1466 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
1467 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
1468
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1469 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
1470 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
1471 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1472 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
1473 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1474 ret = dmGetErrno();
1525
9602f7ea1e7e Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 1524
diff changeset
1475 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
1476 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
1477 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
1478 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1479
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1480 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
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 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
1483
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1484 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
1485 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1486 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
1487 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
1488 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1489 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
1490 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
1491 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1492 }
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1493 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
1494 itemCount++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1495 }
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 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
1498 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1499 else
423
11b3adb3bdb1 Fix image format output.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1500 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
1501 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1502 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
1503 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
1504 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
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 (optSequential)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1507 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1508 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
1509 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1510 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
1511 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
1512 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1513
1288
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
1514 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
1515 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
1516 optItemCount,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1517 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
1518 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
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 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1521 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1522 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
1523 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
1524 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1525 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
1526 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
1527 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1528
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1529 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
1530 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
1531 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
1532 outIHeight++;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1533
1288
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
1534 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
1535 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1536
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
1537 dmSetDefaultC64Palette(outImage);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1538
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1539 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
1540 {
827
c8beac5313c3 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
1541 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
1542 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
1543 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1544 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
1545 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1546 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1547
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1548 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
1549 {
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1550 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
1551 optOutFilename,
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1552 itemCount,
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1553 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
1554
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1555 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
1556 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1557 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
1558 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
1559 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1560
1526
e0cd0fc8c753 Oops. Actually use the generated filename for writing the output files in here.
Matti Hamalainen <ccr@tnsp.org>
parents: 1525
diff changeset
1561 ret = dmWriteImage(outFilename, outImage, &optSpec, optOutSubFormat, TRUE);
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1562 if (ret != DMERR_OK)
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1563 {
1525
9602f7ea1e7e Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 1524
diff changeset
1564 dmErrorMsg("Error writing output image '%s': %s.\n",
9602f7ea1e7e Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 1524
diff changeset
1565 outFilename, dmErrorStr(ret));
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1566 }
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1567
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1568 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
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 else
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 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
1573 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1574 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
1575 outY++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1576 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1577 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1578
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1579 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
1580 itemCount++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1581 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1582
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1583 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
1584 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1585 ret = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1586 if (ret != DMERR_OK)
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1587 {
1525
9602f7ea1e7e Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 1524
diff changeset
1588 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
1589 optOutFilename, dmErrorStr(ret));
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
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 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1592
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1593 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
1594 }
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1595 else
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1596 if (optOutFormat == FFMT_BITMAP)
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1597 {
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1598 if (optSequential)
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1599 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1600 ret = dmError(DMERR_INVALID_ARGS,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1601 "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
1602 goto error;
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1603 }
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1604 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1605
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1606 error:
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1607 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1610
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1611 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
1612 {
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1613 FILE *inFile = NULL;
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1614 const DMC64ImageFormat *inC64Fmt = NULL;
1490
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1615 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
1616 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
1617 size_t dataSize, dataSizeOrig;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1618 int 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
1619
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1620 // Default colors
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1621 for (i = 0; i < C64_MAX_COLORS; i++)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1622 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
1623
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1624 // Initialize and parse commandline
1280
300a51e98fc3 Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 1278
diff changeset
1625 dmInitProg("gfxconv", "Simple graphics converter", "0.91", 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
1626
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1627 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
1628 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
1629 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
1630
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1631 #ifndef DM_USE_LIBPNG
1543
416d7b3ba3b2 Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
1632 if (optOutFormat == DM_IMGFMT_PNG)
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1633 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1634 dmErrorMsg("PNG output format support not compiled in, sorry.\n");
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1635 goto error;
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1636 }
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1637 #endif
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1638
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1639 // 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
1640 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
1641 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1642 char *dext = strrchr(optInFilename, '.');
465
ffd5e730d313 Adjust verbosity levels.
Matti Hamalainen <ccr@tnsp.org>
parents: 463
diff changeset
1643 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
1644 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
1645 {
819
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
1646 if (!dmGetFormatByExt(dext + 1, &optInFormat, &optInSubFormat))
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
1647 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
1648 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1649 }
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 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
1652 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1653 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
1654 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1655 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
1656 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
1657 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
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 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
1660 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
1661 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1662 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1663 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
1664 {
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1665 int res = dmGetErrno();
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1666 dmErrorMsg("Error opening input file '%s', %d: %s\n",
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1667 optInFilename, res, dmErrorStr(res));
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1668 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
1669 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1670
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1671 // 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
1672 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
1673
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1674 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
1675 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1676
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1677 // 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
1678 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
1679 {
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1680 dmErrorMsg("Input skip value %d is larger than input size %d.\n",
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1681 optInSkip, dataSizeOrig);
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1682 goto error;
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1683 }
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1684
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1685 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
1686 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
1687
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1688
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1689 // Perform probing, if required
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1690 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
1691 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1692 // Probe for format
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1693 const DMC64ImageFormat *forced = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1694 int res;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1695
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1696 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
1697 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1698 forced = &dmC64ImageFormats[optForcedFormat];
1480
c3eba254bcc2 Change some message priorities.
Matti Hamalainen <ccr@tnsp.org>
parents: 1479
diff changeset
1699 dmMsg(0, "Forced %s format image, type %d, %s\n",
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1700 forced->name, forced->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
1701 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1702
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1703 res = dmC64DecodeBMP(&inC64Image, dataBuf, dataSize, optInSkip, optInSkip + 2, &inC64Fmt, forced);
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1704 if (forced == NULL && inC64Fmt != 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
1705 {
1522
0d1cf72fb732 Clarify the "probed" messages of gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 1514
diff changeset
1706 dmMsg(1, "Probed '%s' format image, type %d, %s\n",
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1707 inC64Fmt->name, inC64Fmt->type, inC64Fmt->fext);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1708 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1709
897
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1710 if (res == DMERR_OK)
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1711 optInFormat = FFMT_BITMAP;
897
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1712 else
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1713 {
1464
73e00bf7531c Improve one error message by showing the error code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
1714 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
1715 goto error;
897
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1716 }
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1717 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1718
463
4204e9ea8ae1 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
1719 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
1720 {
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1721 DMImageFormat *ifmt = NULL;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1722 int index;
465
ffd5e730d313 Adjust verbosity levels.
Matti Hamalainen <ccr@tnsp.org>
parents: 463
diff changeset
1723 dmMsg(4, "Trying to probe image formats.\n");
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1724 if (dmImageProbeGeneric(dataBuf + optInSkip, dataSize - optInSkip, &ifmt, &index) > 0)
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1725 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1726 optInFormat = FFMT_IMAGE;
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1727 optInSubFormat = index;
1522
0d1cf72fb732 Clarify the "probed" messages of gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 1514
diff changeset
1728 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
1729 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1730 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1731
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1732 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
1733 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1734 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
1735 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
1736 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1737
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1738 int inFormat = dmGetConvFormat(optInFormat, optInSubFormat),
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1739 outFormat = dmGetConvFormat(optOutFormat, optOutSubFormat);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1740
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1741 if (inFormat != -1 && outFormat != -1)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1742 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1743 char *inFmtName = convFormatList[inFormat].name,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1744 *inFmtExt = convFormatList[inFormat].fext,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1745 *outFmtName = convFormatList[outFormat].name,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1746 *outFmtExt = convFormatList[outFormat].fext;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1747
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1748 if (optInFormat == FFMT_BITMAP)
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1749 inFmtExt = inC64Fmt->name;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1750
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1751 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
1752 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
1753 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1754
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1755 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
1756 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1757 case FFMT_SPRITE:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1758 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
1759 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
1760 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1761
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1762 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
1763 {
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1764 DMImage *outImage = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1765 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
1766
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1767 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
1768 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1769 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
1770 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1771 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1772
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1773 switch (optOutFormat)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1774 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1775 case FFMT_IMAGE:
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1776 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
1777
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1778 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
1779 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1780 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
1781 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1782 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1783
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
1784 dmSetDefaultC64Palette(outImage);
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1785 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
1786 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1787
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1788 case FFMT_BITMAP:
1490
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1789 if ((res = dmConvertC64Bitmap(&outC64Image, inC64Image, &dmC64ImageFormats[optOutSubFormat])) != DMERR_OK)
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1790 {
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1791 dmErrorMsg("Error in bitmap format conversion.\n");
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1792 goto error;
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1793 }
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1794 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
1795 break;
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1796
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1797 case FFMT_CHAR:
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1798 case FFMT_SPRITE:
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1799 res = dmC64ConvertBMP2Image(&outImage, inC64Image, inC64Fmt);
810
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1800
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1801 if (res != DMERR_OK || outImage == NULL)
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1802 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1803 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
1804 goto error;
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1805 }
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1806
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
1807 dmSetDefaultC64Palette(outImage);
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1808 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
1809 break;
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1810
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1811 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1812 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
1813 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1814 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1815
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1816 dmImageFree(outImage);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1817 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1818 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1819
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1820 case FFMT_IMAGE:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1821 {
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1822 DMImage *inImage = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1823 int res = DMERR_OK;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1824
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1825 if (optOutFilename == NULL)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1826 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1827 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
1828 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
1829 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1830
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1831 // 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
1832 DMImageFormat *ifmt = &dmImageFormatList[optInSubFormat];
2a4de5fe4003 Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1833 if (ifmt->readFILE != NULL)
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1834 res = ifmt->readFILE(inFile, &inImage);
441
2a4de5fe4003 Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1835 else
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1836 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
1837
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1838 if (res != DMERR_OK || inImage == NULL)
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1839 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1840
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1841 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
1842 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1843 case FFMT_IMAGE:
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1844 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
1845 break;
417
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1846
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1847 case FFMT_CHAR:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1848 case FFMT_SPRITE:
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1849 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
1850 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1851
417
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1852 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1853 dmErrorMsg("Unsupported output format for bitmap/image conversion.\n");
417
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1854 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
1855 }
806
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1856
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1857 if (res != DMERR_OK)
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1858 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1859 dmErrorMsg("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n",
806
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1860 dmErrorStr(res));
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1861 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1862
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1863 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
1864 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1865 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1866 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1867
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1868 error:
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1869 if (inFile != NULL)
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1870 fclose(inFile);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1871
1479
c4755b73b93c Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents: 1470
diff changeset
1872 dmFree(dataBufOrig);
1440
a602488830fc Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1439
diff changeset
1873 dmC64ImageFree(inC64Image);
1490
665a0b917d22 Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents: 1481
diff changeset
1874 dmC64ImageFree(outC64Image);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1875
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1876 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
1877 }