annotate tools/gfxconv.c @ 1288:6c8b19d1d196

More work on libgfx.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 18 Aug 2017 17:32:19 +0300
parents 300a51e98fc3
children e7dc9bb9777e
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 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #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
9 #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
10 #include "dmfile.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 "dmmutex.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"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
16 #define DM_MAX_COLORS 256
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
17
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
18 #define DM_ASC_NBITS 8
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
19 #define DM_ASC_NCOLORS 4
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
20 static const char dmASCIIPalette[DM_ASC_NCOLORS] = ".:X#";
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
21
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
22
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 enum
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
25 FFMT_AUTO = 0,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
26
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
27 FFMT_ASCII,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
28 FFMT_ANSI,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
29 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
30
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
31 FFMT_CHAR,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
32 FFMT_SPRITE,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
33 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
34
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
35 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
36 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
38
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
39 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
40 {
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 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
42 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
43 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
44 };
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
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
47 typedef struct
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
48 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
49 char *name;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
50 char *fext;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
51 BOOL in, out;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
52 int format;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
53 int subformat;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
54 } DMConvFormat;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
55
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 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
58 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
59 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
60 "ASCII text", "asc", FALSE, TRUE,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
61 FFMT_ASCII , 0,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
62 },
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 "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
65 FFMT_ANSI , 0,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
66 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
67 {
454
2f820412d356 Mark PNG as available input format.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
68 "PNG image file", "png", TRUE, TRUE,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
69 FFMT_IMAGE , IMGFMT_PNG,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
70 },
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 "PPM image file", "ppm", FALSE, TRUE,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
73 FFMT_IMAGE , IMGFMT_PPM,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
74 },
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 "PCX image file", "pcx", TRUE, TRUE,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
77 FFMT_IMAGE , IMGFMT_PCX,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
78 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
79 {
443
f7c9d1619c74 Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents: 441
diff changeset
80 "IFF ILBM file", "lbm", TRUE, FALSE,
f7c9d1619c74 Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents: 441
diff changeset
81 FFMT_IMAGE , IMGFMT_ILBM,
f7c9d1619c74 Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents: 441
diff changeset
82 },
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
83 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
84 "Bitplaned RAW (intl/non-intl) image file", "raw", FALSE, TRUE,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
85 FFMT_IMAGE , IMGFMT_RAW,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
86 },
443
f7c9d1619c74 Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents: 441
diff changeset
87 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
88 "IFFMaster RAW image file", "araw", FALSE, TRUE,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
89 FFMT_IMAGE , IMGFMT_ARAW,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
90 },
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 {
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
93 "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
94 FFMT_BITMAP , -1,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
95 },
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 {
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
98 "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
99 FFMT_CHAR , 0
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
100 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
101 {
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
102 "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
103 FFMT_SPRITE , 0
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
104 },
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
107 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
108
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
110 typedef struct
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
111 {
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
112 BOOL triplet, alpha;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
113 DMColor color;
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
114 unsigned int from, to;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
115 } DMMapValue;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
116
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
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 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
120 *optOutFilename = NULL;
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
121
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
122 int optInFormat = FFMT_AUTO,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
123 optOutFormat = FFMT_ASCII,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
124 optInSubFormat = IMGFMT_PNG,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
125 optOutSubFormat = 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
126 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
127 optPlanedWidth = 1,
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
128 optForcedFormat = -1;
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
129 unsigned int optInSkip = 0;
838
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
130
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
131 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
132 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
133 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
134
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 BOOL optInMulticolor = FALSE,
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
136 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
137 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
138 optRemapRemove = FALSE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
139 int optNRemapTable = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
140 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
141 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
142
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
143 DMImageSpec optSpec =
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
144 {
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
145 .scaleX = 1,
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
146 .scaleY = 1,
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
147 .nplanes = 4,
1288
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
148 .bpp = 8,
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
149 .interleave = FALSE,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
150 .paletted = FALSE,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
151 .format = 0,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
152 };
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 854
diff changeset
154 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
155 {
983
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
156 { 0, '?', "help", "Show this help", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
157 { 15, 'v', "verbose", "Increase verbosity", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
158 { 3, 'o', "output", "Output filename", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
159 { 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
160 { 2, 'm', "multicolor", "Input is multicolor / output in multicolor", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
161 { 4, 's', "skip", "Skip bytes in input", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
162 { 5, 'f', "format", "Output format (see --formats)", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
163 { 17, 0 , "formats", "List available input/output formats", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
164 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
165 { 6, 'c', "colormap", "Color mappings (see below for information)", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
166 { 7, 'n', "numitems", "How many 'items' to output (default: all)", OPT_ARGREQ },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
167 { 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
168 { 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
169 "-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
170 { 12, 'P', "paletted", "Use indexed/paletted output IF possible.", OPT_NONE },
1288
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
171 { 13, 'N', "nplanes", "# of bitplanes (certain output formats)", OPT_ARGREQ },
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
172 { 18, 'B', "bpp", "Bits per pixel (certain output formats)", OPT_ARGREQ },
983
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
173 { 14, 'I', "interleave", "Interleave output image scanlines (default: output whole planes)", OPT_NONE },
98e749d990b0 Improve help.
Matti Hamalainen <ccr@tnsp.org>
parents: 975
diff changeset
174 { 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
175 };
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 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
178
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
180 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
181 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182 int i;
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
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
190 for (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"
838
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
204 "Available bitmap formats (-f bitmap:<bformat>):\n"
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
205 " Ext | Type | Description\n"
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
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 for (i = 0; i < ndmC64ImageFormats; i++)
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,
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
215 dmC64GetImageTypeString(buf, sizeof(buf), fmt->type),
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"
818
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
236 "Remap file is specified as -R @filename, and it is a plan text file with\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
237 "one remap definition per line. All empty lines and lines starting with a\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
238 "semicolor (;) will be ignored. Whitespace separating items is ignored, too.\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
239 "\n"
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
240 "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
241 "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
242 "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
243 "\n"
818
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
244 "Color map defs\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
245 "--------------\n"
456
20122cffde2f Clarify help.
Matti Hamalainen <ccr@tnsp.org>
parents: 455
diff changeset
246 "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
247 "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
248 "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
249 "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
250 "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
251 "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
252 "special color that can be used for transparency.\n"
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
253 "\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
254 );
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
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
258 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
259 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
260 int i;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
261 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
262 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
263 DMConvFormat *fmt = &convFormatList[i];
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
264 if (fmt->format == format &&
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
265 fmt->subformat == subformat)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
266 return i;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
267 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
268 return -1;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
269 }
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
819
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
272 BOOL dmGetC64FormatByExt(const char *fext, int *format, int *subformat)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
273 {
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
274 int i;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
275 if (fext == NULL)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
276 return FALSE;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
277
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
278 for (i = 0; i < ndmC64ImageFormats; i++)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
279 {
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
280 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
281 if (fmt->fext != NULL &&
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
282 strcasecmp(fext, fmt->fext) == 0)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
283 {
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
284 *format = FFMT_BITMAP;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
285 *subformat = i;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
286 return TRUE;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
287 }
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 return FALSE;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
291 }
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
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
295 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
296 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
297 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
298 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
299 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
300
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
301 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
302 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
303 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
304 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
305 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
306 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
307 *format = fmt->format;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
308 *subformat = fmt->subformat;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
309 return TRUE;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
310 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
311 }
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
312
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
313 return FALSE;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
314 }
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
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
317 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
318 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
319 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
320
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
321 if (opt == NULL)
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
322 goto error;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
323
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
324 if ((end = split = strchr(opt, ':')) == NULL)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
325 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
326 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
327 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
328 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
329
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
330 // Trim whitespace
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
331 *end = 0;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
332 for (end--; end > opt && *end && isspace(*end); end--)
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
333 *end = 0;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
334
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
335 // 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
336 if (*opt == '#' || *opt == '%')
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
337 {
867
56e12109b936 Portability warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
338 unsigned int colR, colG, colB, colA;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
339
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
340 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
341 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
342 {
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
343 value->alpha = TRUE;
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
344 value->color.a = colA;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
345 }
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
346 else
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
347 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
348 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 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
350 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
351 goto error;
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
352 }
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
353
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
354 value->color.r = colR;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
355 value->color.g = colG;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
356 value->color.b = colB;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
357 value->triplet = TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
358 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
359 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
360 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
361 if (!dmGetIntVal(opt, &value->from))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
362 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
363 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
364 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
365 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
366 value->triplet = FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
367 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
368
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
369 // Trim whitespace
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
370 split++;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
371 while (*split && isspace(*split)) split++;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
372
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
373 // Parse destination value
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
374 if (!dmGetIntVal(split, &value->to))
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
375 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
376 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
377 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
378 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
379
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
380 if (!value->triplet && value->from > 255)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
381 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
382 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
383 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
384 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
385
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
386 if (value->to > nmax)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
387 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
388 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
389 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
390 }
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
391
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
392 dmFree(opt);
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
393 return TRUE;
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
394
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
395 error:
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
396 dmFree(opt);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
397 return FALSE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
398 }
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 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
402 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
403 // Trim whitespace
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
404 if (end != NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
405 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
406 *end = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
407 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
408 *end = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
409 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
410 while (*opt && isspace(*opt)) opt++;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
411
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
412 // Parse item based on mode
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
413 if (requireIndex)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
414 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
415 DMMapValue *value = (DMMapValue *) pvalue;
475
c0dedfef3edf Fix option parsing of mappings.
Matti Hamalainen <ccr@tnsp.org>
parents: 474
diff changeset
416 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
417 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
418 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
419 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
420 {
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
421 unsigned int *value = (unsigned int *) pvalue;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
422 char *split = strchr(opt, ':');
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
423 if (split != NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
424 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
425 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
426 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
427 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
428
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
429 if (!dmGetIntVal(opt, &value[index]))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
430 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
431 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
432 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
433 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
434 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
435
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
436 return TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
437 }
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 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
441 {
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
442 char *start = opt;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
443
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
444 *nvalues = 0;
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
445 while (*start && *nvalues < nmax)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
446 {
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
447 char *end = strchr(start, ',');
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
448
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
449 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
450 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
451
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
452 (*nvalues)++;
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
453
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
454 if (!end)
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
455 break;
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
456
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
457 start = end + 1;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
458 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
459
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
460 return TRUE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
461 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
462
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
463
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
464 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
465 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
466 FILE *fp;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
467 char line[512];
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
468 int res = DMERR_OK;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
469
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
470 if ((fp = fopen(filename, "r")) == NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
471 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
472 res = dmGetErrno();
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
473 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
474 res, dmErrorStr(res));
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
475 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
476 }
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 while (fgets(line, sizeof(line), fp))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
479 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
480 char *start = line;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
481 while (*start && isspace(*start)) start++;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
482
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
483 if (*start != 0 && *start != ';')
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
484 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
485 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
486 goto error;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
487 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
488 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
489 (*nvalue)++;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
490 if (*nvalue >= nmax)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
491 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
492 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
493 filename, nmax);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
494 goto error;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
495 }
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 error:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
501 fclose(fp);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
502 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
503 }
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
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 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
507 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 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
509 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 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
511 argShowHelp();
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 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
513 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
515 case 17:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
516 argShowFormats();
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
517 exit(0);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
518 break;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
519
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
520 case 15:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
521 dmVerbosity++;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
522 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
523
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
524 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
525 {
824
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
526 switch (tolower(optArg[0]))
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
527 {
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
528 case 's': optInFormat = FFMT_SPRITE; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
529 case 'c': optInFormat = FFMT_CHAR; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
530 case 'b': optInFormat = FFMT_BITMAP; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
531 case 'i': optInFormat = FFMT_IMAGE; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
532 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
533 dmErrorMsg("Invalid input format '%s'.\n", optArg);
824
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
534 return FALSE;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
535 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
536
838
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
537 char *tmp = strchr(optArg, ':');
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
538 if (tmp != NULL)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
539 {
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
540 tmp++;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
541 switch (optInFormat)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
542 {
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
543 case FFMT_SPRITE:
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
544 case FFMT_CHAR:
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
545 if (strcasecmp(tmp, "mc") == 0)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
546 optInMulticolor = TRUE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
547 else
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
548 if (strcasecmp(tmp, "sc") == 0)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
549 optInMulticolor = FALSE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
550 else
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
551 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
552 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
553 tmp);
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
554 return FALSE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
555 }
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
556 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
557
838
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
558 case FFMT_BITMAP:
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
559 if (!dmGetC64FormatByExt(tmp, &optInFormat, &optInSubFormat))
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
560 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
561 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
562 tmp);
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
563 return FALSE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
564 }
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
565 break;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
566 }
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
567 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
570
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 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
572 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
573 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575 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
576 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
577 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
578
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579 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
580 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
581 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
582 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
583 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
584 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
585 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
587 case 5:
819
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
588 if (!dmGetFormatByExt(optArg, &optOutFormat, &optOutSubFormat) &&
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
589 !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
590 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
591 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
592 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
593 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
594 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
595
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
596 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
597 {
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
598 int index, ncolors;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
599 if (!dmParseMapOptionString(optArg, optColors,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
600 &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
601 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
602
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
603 dmMsg(1, "Set color table: ");
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
604 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
605 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
606 dmPrint(1, "[%d:%d]%s",
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
607 index, optColors[index],
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
608 (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
609 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610 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
611 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
612 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
613
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
614 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
615 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
616 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
617 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
618 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
619 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
620 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
621
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622 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
623 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
624 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
625
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
626 case 9:
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
627 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
628 {
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
629 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
630 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
631 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
632 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
633 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
634 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
635 }
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
636 }
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
637 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
638 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
639 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
640 return FALSE;
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
641 }
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
642 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
643 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
644 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
645 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
646 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649 case 11:
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
650 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
651 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
652 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
653 return FALSE;
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
654 }
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
655 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
656 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
657 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
658 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
659 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
660 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
661
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662 case 12:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
663 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
664 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
666 case 13:
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
667 {
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
668 int tmp = atoi(optArg);
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
669 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
670 {
1288
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
671 dmErrorMsg("Invalid number of bitplanes value '%s'.\n", optArg);
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
672 return FALSE;
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
673 }
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
674 optSpec.nplanes = tmp;
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
675 }
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
676 break;
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
677
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
678 case 18:
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
679 {
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
680 int tmp = atoi(optArg);
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
681 if (tmp < 1 || tmp > 32)
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
682 {
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
683 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
684 return FALSE;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
685 }
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
686 optSpec.nplanes = tmp;
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
687 }
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
688 break;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
689
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
690 case 14:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
691 optSpec.interleave = TRUE;
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
692 break;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
693
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
694 case 16:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
695 {
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
696 char *tmp;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
697 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
698 {
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
699 optRemapRemove = TRUE;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
700 *tmp = 0;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
701 }
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 if (optArg[0] == '@')
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
704 {
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
705 if (optArg[1] != 0)
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
706 {
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
707 int res;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
708 if ((res = dmParseColorRemapFile(optArg + 1,
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
709 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
710 return FALSE;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
711 }
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
712 else
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
713 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
714 dmErrorMsg("No remap filename given.\n");
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
715 return FALSE;
823
f0429dbd77ec Oops, missing } from one of the previous commits. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents: 822
diff changeset
716 }
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
717 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
718 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
719 {
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
720 if (!dmParseMapOptionString(optArg, optRemapTable,
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
721 &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
722 return FALSE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
723 }
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 optRemapColors = TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
727 break;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
728
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
729 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
730 {
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 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
732 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
733 {
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 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
735 }
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 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
737 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
738 {
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 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
740 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
741 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
742 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
743 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
744 }
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 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
746 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
747 {
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 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
749 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
750 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
751 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
752 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
753 }
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 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
755 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
756 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
757 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
758 }
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 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
761
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
763 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
764 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
765 }
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 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
768 }
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 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
772 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
773 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
774 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
775 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
777 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
778 currArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779 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
780 }
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 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
783 }
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 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
787 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
788 int i;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
789
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 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
791 {
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
792 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
793 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 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
795 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
796 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
797 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
798 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
799 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
800 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
801 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
802 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
803 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
804 0x1b,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
805 1,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
806 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
807 0x1b);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
808 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
809 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
810 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
811 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813 {
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
814 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
815 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816 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
817 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
818 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
819 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
820 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
821 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
822 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
823 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
824 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
825 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
826 0x1b,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
827 1,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
828 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
829 0x1b);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
830 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
831 }
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
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
837 void dmDumpCharASCII(FILE *outFile, const Uint8 *buf, int *offs, int format, 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
838 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
839 int yc;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
840
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
841 for (yc = 0; yc < C64_CHR_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
842 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
843 fprintf(outFile, "%04x : ", *offs);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
844 dmPrintByte(outFile, buf[yc], format, multicolor);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
845 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
846 (*offs)++;
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 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
849
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
850
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
851 void dmDumpSpriteASCII(FILE *outFile, const Uint8 *buf, int *offs, int format, 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
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 int bufOffs, xc, 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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
855 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
856 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
857 fprintf(outFile, "%04x : ", *offs);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
858 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
859 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
860 dmPrintByte(outFile, buf[bufOffs], format, multicolor);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
861 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
862 bufOffs++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
863 (*offs)++;
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 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
866 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
867 (*offs)++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
868 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
869
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
870
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
871 int dmRemapImageColors(DMImage *image)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
872 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
873 DMColor *npal = dmCalloc(image->ncolors, sizeof(DMColor));
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
874 int *mapping = dmMalloc(image->ncolors * sizeof(int));
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
875 BOOL *mapped = dmMalloc(image->ncolors * sizeof(BOOL));
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
876 BOOL *used = dmMalloc(image->ncolors * sizeof(BOOL));
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
877 int n, index, xc, yc, ncolors;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
878
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
879 dmMsg(1, "Remapping %d output image colors of %d colors.\n", optNRemapTable, image->ncolors);
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
880
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
881 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
882 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
883 return dmError(DMERR_MALLOC,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
884 "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
885 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
886
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
887 for (index = 0; index < image->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
888 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
889 mapping[index] = -1;
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
890 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
891 }
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
892
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
893 // 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
894 dmMsg(2, "Scanning image for used colors...\n");
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
895 for (ncolors = yc = 0; yc < image->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
896 {
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 Uint8 *dp = image->data + image->pitch * yc;
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
898 for (xc = 0; xc < image->width; xc++)
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 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
900 Uint8 col = dp[xc];
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
901 if (col < image->ncolors && !used[col])
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
902 {
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
903 used[col] = TRUE;
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
904 ncolors++;
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 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
907 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
908 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
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 // Match and mark mapped colors
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
911 for (index = 0; index < optNRemapTable; index++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
912 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
913 DMMapValue *map = &optRemapTable[index];
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
914 if (map->triplet)
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 BOOL found = FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
917 for (n = 0; n < image->ncolors; n++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
918 {
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
919 if (dmCompareColor(&(image->pal[n]), &(map->color), map->alpha))
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
920 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
921 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
922 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
923 n,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
924 map->to);
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
925
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
926 mapping[n] = map->to;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
927 mapped[map->to] = TRUE;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
928 found = TRUE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
929 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
930 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
931
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
932 if (!found)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
933 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
934 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
935 index,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
936 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
937 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
938 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
939 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
940 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
941 dmMsg(3, "Map index: %d -> %d\n",
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
942 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
943
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
944 mapping[map->from] = map->to;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
945 mapped[map->to] = TRUE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
946 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
947 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
948
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
949
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
950 // 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
951 if (optRemapRemove)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
952 {
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
953 dmMsg(2, "Removing unused colors.\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
954 for (index = 0; index < image->ncolors; index++)
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
955 if (mapping[index] < 0 && used[index])
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
956 {
479
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
957 for (n = 0; n < image->ncolors; 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
958 if (!mapped[n])
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
959 {
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
960 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
961 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
962 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
963 }
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 }
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 }
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 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
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 for (index = 0; index < image->ncolors; index++)
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 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
970 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
971 for (n = 0; n < image->ncolors; 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
972 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
973 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
974 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
975 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
976 break;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
977 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
978 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
979 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
980
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
981 // 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
982 ncolors = 0;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
983 for (index = 0; index < image->ncolors; index++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
984 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
985 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
986 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
987 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
988
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 // Copy palette entries
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
990 for (index = 0; index < image->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
991 {
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 if (mapping[index] >= 0)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
993 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
994 memcpy(&npal[mapping[index]], &(image->pal[index]), sizeof(DMColor));
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
995 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
996 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
997
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
998 // 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
999 dmMsg(1, "Remapping image to %d colors...\n", ncolors);
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1000 for (yc = 0; yc < image->height; yc++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1001 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1002 Uint8 *dp = image->data + image->pitch * yc;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1003 for (xc = 0; xc < image->width; xc++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1004 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1005 Uint8 col = dp[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
1006 if (col < image->ncolors && mapping[col] >= 0 && mapping[col] < image->ncolors)
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
1007 dp[xc] = mapping[col];
478
7c7a57590236 Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents: 477
diff changeset
1008 else
7c7a57590236 Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents: 477
diff changeset
1009 dp[xc] = 0;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1010 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1011 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1012
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1013 // Set new palette, free memory
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1014 dmFree(image->pal);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1015 image->pal = npal;
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
1016 image->ncolors = ncolors;
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
1017
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
1018 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
1019 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
1020 dmFree(used);
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1021 return DMERR_OK;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1022 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1023
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1024
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1025 int dmWriteBitmap(const char *filename, DMC64Image *image, int iformat, BOOL enableFixUps)
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1026 {
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1027 FILE *outFile = NULL;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1028 Uint8 *buf = NULL;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1029 size_t bufSize;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1030 int res = DMERR_OK;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1031 const DMC64ImageFormat *fmt = &dmC64ImageFormats[iformat];
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1032
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1033 dmMsg(1, "Converting to %s format bitmap.\n", fmt->name);
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1034 if (image->type != fmt->type && enableFixUps)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1035 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1036 // Try to do some simple fixups
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1037 if ((fmt->type & D64_FMT_FLI) && (image->type & D64_FMT_FLI) == 0)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1038 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1039 dmMsg(1, "Upconverting multicolor to FLI.\n");
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1040 int i;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1041 for (i = 1; i < C64_SCR_MAX_BANK; i++)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1042 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1043 memcpy(image->color[i], image->color[0], C64_SCR_COLOR_SIZE);
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1044 memcpy(image->screen[i], image->screen[0], C64_SCR_SCREEN_SIZE);
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1045 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1046 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1047 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1048
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1049
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1050 if ((res = dmC64EncodeGenericBMP(&buf, &bufSize, image, fmt)) != DMERR_OK)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1051 goto error;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1052
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1053 dmMsg(2, "Result: %d bytes\n", bufSize);
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1054
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1055 if ((outFile = fopen(filename, "wb")) == NULL)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1056 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1057 res = dmGetErrno();
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1058 dmError(res, "Error opening output file '%s', %d: %s\n",
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1059 filename, res, dmErrorStr(res));
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1060 goto error;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1061 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1062
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1063 if (!dm_fwrite_str(outFile, buf, bufSize))
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1064 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1065 res = dmGetErrno();
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1066 dmError(res, "Error writing image data to '%s', %d: %s\n",
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1067 filename, res, dmErrorStr(res));
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1068 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1069
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1070 error:
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1071 if (outFile != NULL)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1072 fclose(outFile);
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1073 dmFree(buf);
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1074 return res;
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1075 }
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1076
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1077
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1078 int dmWriteImage(const char *filename, DMImage *image, DMImageSpec *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
1079 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1080 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
1081 {
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
1082 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
1083 dmImageFormatList[iformat].fext,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1084 image->width, image->height,
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
1085 image->width * spec->scaleX, image->height * spec->scaleY,
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
1086 spec->scaleX, spec->scaleY);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1087 }
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1088
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1089 // Perform color remapping
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1090 if (optRemapColors)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1091 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1092 int res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1093 if ((res = dmRemapImageColors(image)) != DMERR_OK)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1094 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1095 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1096
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1097 switch (iformat)
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1098 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1099 #ifdef DM_USE_LIBPNG
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1100 case IMGFMT_PNG:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1101 if (info) dmMsg(2, "%s output.\n", spec->paletted ? "Indexed 8bpp" : "32bit RGBA");
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1102 spec->format = spec->paletted ? DM_IFMT_PALETTE : DM_IFMT_RGBA;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1103 return dmWritePNGImage(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
1104 #endif
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1105
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1106 case IMGFMT_PPM:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1107 if (info) dmMsg(2, "24bit RGB output.\n");
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1108 spec->format = DM_IFMT_RGB;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1109 return dmWritePPMImage(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
1110
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1111 case IMGFMT_PCX:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1112 if (info) dmMsg(2, "%s output.\n", spec->paletted ? "Indexed 8bpp" : "24bit RGB");
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1113 return dmWritePCXImage(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
1114
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1115 case IMGFMT_RAW:
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1116 case 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
1117 {
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1118 FILE *fp;
820
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1119 char *dataFilename;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1120
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1121 // Form data file filename
820
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1122 dataFilename = dm_strdup_fext(filename, "%s.inc");
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1123 if (dataFilename == NULL)
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1124 return DMERR_MALLOC;
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1125
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1126 // Open data file for writing
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1127 if ((fp = fopen(dataFilename, "w")) == NULL)
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1128 dmErrorMsg("Could not create '%s'.\n", dataFilename);
820
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1129
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1130 dmFree(dataFilename);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1131
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1132 if (fp != NULL)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1133 {
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1134 // Strip extension
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1135 int i;
820
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1136 char *palID = dm_strdup_fext(filename, "img_%s");
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1137
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1138 // Replace any non-alphanumerics
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1139 for (i = 0; palID[i]; i++)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1140 {
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1141 if (isalnum(palID[i]))
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1142 palID[i] = tolower(palID[i]);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1143 else
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1144 palID[i] = '_';
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1145 }
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1146
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1147 if (iformat == IMGFMT_ARAW)
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1148 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1149 fprintf(fp,
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1150 "%s_width: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1151 "%s_height: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1152 "%s_nplanes: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1153 "%s_ncolors: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1154 "%s_palette:\n",
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1155 palID, image->width,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1156 palID, image->height,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1157 palID, spec->nplanes,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1158 palID, image->ncolors,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1159 palID);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1160
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1161 dmWriteIFFMasterRAWPalette(fp, image, 1 << optSpec.nplanes, NULL, NULL);
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1162
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1163 fprintf(fp,
477
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1164 "%s: incbin \"%s\"\n",
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1165 palID, filename);
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1166 }
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1167 else
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1168 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1169 fprintf(fp,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1170 "%s_width: dw.w %d\n"
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1171 "%s_height: dw.w %d\n"
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1172 "%s_nplanes: dw.w %d\n",
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1173 palID, image->width,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1174 palID, image->height,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1175 palID, spec->nplanes);
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1176 }
477
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1177
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1178 fclose(fp);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1179 dmFree(palID);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1180 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1181
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1182 if (info) dmMsg(2, "%d bitplanes, %s interleave.\n", spec->nplanes, spec->interleave ? "with" : "without");
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1183 return 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
1184 }
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1185 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
1186
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1187 default:
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1188 return 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
1189 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1190 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1191
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1192
547
ca5ad51c6479 Make dmConvertByte() static.
Matti Hamalainen <ccr@tnsp.org>
parents: 546
diff changeset
1193 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
1194 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1195 Uint8 byte = 0;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1196 int xc;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1197
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1198 if (multicolor)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1199 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1200 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
1201 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1202 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
1203 byte |= pixel << (6 - (xc * 2));
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1204 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1205 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1206 else
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1207 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1208 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
1209 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1210 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
1211 byte |= pixel << (7 - xc);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1212 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1213 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1214
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1215 return byte;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1216 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1217
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1218
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1219 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
1220 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
1221 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1222 int yc;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1223
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1224 if (xoffs < 0 || yoffs < 0 ||
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1225 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
1226 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
1227 return FALSE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1228
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1229 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
1230 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1231 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
1232 buf[yc] = dmConvertByte(sp, multicolor);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1233 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1234
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1235 return TRUE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1236 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1237
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1238
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1239 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
1240 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
1241 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1242 int yc, xc;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1243
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1244 if (xoffs < 0 || yoffs < 0 ||
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1245 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
1246 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
1247 return FALSE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1248
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1249 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
1250 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1251 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
1252 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1253 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
1254 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
1255 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1256 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1257
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1258 return TRUE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1259 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1260
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1261
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1262 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
1263 {
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1264 int ret = DMERR_OK;
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1265 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
1266 FILE *outFile = NULL;
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1267 Uint8 *buf = NULL;
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1268 size_t outBufSize;
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1269 char *outType;
489
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 switch (outFormat)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1272 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1273 case FFMT_CHAR:
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1274 outBufSize = C64_CHR_SIZE;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1275 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
1276 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
1277 outType = "char";
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1278 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1279
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1280 case FFMT_SPRITE:
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1281 outBufSize = C64_SPR_SIZE;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1282 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
1283 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
1284 outType = "sprite";
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1285 break;
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 default:
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1288 ret = dmError(DMERR_INVALID_ARGS,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1289 "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
1290 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1291 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1292
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1293 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
1294 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1295 ret = dmError(DMERR_INVALID_ARGS,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1296 "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
1297 outBlockW, outBlockH);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1298 goto error;
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
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1301 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
1302 {
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1303 ret = dmGetErrno();
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1304 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
1305 filename, ret, dmErrorStr(ret));
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1306 goto error;
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
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1309 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
1310 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1311 dmErrorMsg("Could not allocate %d bytes for conversion buffer.\n",
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1312 outBufSize);
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1313 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1314 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1315
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1316 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
1317 outBlockW, outBlockH, outBlockW * outBlockH, outType);
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1318
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1319 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
1320 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
1321 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1322 switch (outFormat)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1323 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1324 case FFMT_CHAR:
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1325 if (!dmConvertImage2Char(buf, image,
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1326 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
1327 multicolor))
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1328 {
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1329 ret = DMERR_DATA_ERROR;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1330 goto error;
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1331 }
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1332 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1333
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1334 case FFMT_SPRITE:
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1335 if (!dmConvertImage2Sprite(buf, image,
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1336 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
1337 multicolor))
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1338 {
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1339 ret = DMERR_DATA_ERROR;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1340 goto error;
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1341 }
910
Matti Hamalainen <ccr@tnsp.org>
parents: 909
diff changeset
1342 break;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1343 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1344
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1345 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
1346 {
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1347 ret = dmGetErrno();
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1348 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
1349 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
1350 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1351 }
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1352 }
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1353
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1354 fclose(outFile);
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1355 dmFree(buf);
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1356 return 0;
828
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1357
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1358 error:
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1359 if (outFile != NULL)
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1360 fclose(outFile);
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1361 dmFree(buf);
910
Matti Hamalainen <ccr@tnsp.org>
parents: 909
diff changeset
1362 return ret;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1363 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1364
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1365
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1366 int dmDumpSpritesAndChars(FILE *inFile)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1367 {
974
cbf9b9b4fdea Fix a possibly uninitialized variable warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 973
diff changeset
1368 int dataOffs, itemCount, outWidth, outWidthPX, outHeight;
cbf9b9b4fdea Fix a possibly uninitialized variable warning.
Matti Hamalainen <ccr@tnsp.org>
parents: 973
diff changeset
1369 int ret = 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
1370 size_t bufSize;
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1371 Uint8 *bufData;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1372
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1373 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
1374 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1375 case FFMT_CHAR:
975
139b801f8d1c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 974
diff changeset
1376 bufSize = C64_CHR_SIZE;
139b801f8d1c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 974
diff changeset
1377 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
1378 outWidthPX = C64_CHR_WIDTH_PX;
975
139b801f8d1c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 974
diff changeset
1379 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
1380 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1381
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1382 case FFMT_SPRITE:
975
139b801f8d1c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 974
diff changeset
1383 bufSize = C64_SPR_SIZE;
139b801f8d1c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 974
diff changeset
1384 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
1385 outWidthPX = C64_SPR_WIDTH_PX;
975
139b801f8d1c Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 974
diff changeset
1386 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
1387 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1388
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1389 default:
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1390 return dmError(DMERR_INTERNAL,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1391 "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
1392 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1393
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1394 if ((bufData = dmMalloc(bufSize)) == NULL)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1395 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1396 return dmError(DMERR_INTERNAL,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1397 "Could not allocate temporary buffer of %d bytes.\n", bufSize);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1398 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1399
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1400
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1401 dataOffs = optInSkip;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1402 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
1403
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1404 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
1405 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1406 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
1407 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
1408
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1409 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
1410 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
1411 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1412 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
1413 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1414 ret = dmGetErrno();
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1415 dmError(ret, "Error opening output file '%s', %d: %s\n",
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1416 optOutFilename, ret, 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
1417 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
1418 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1419
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1420 while (!feof(inFile) && !error && (optItemCount < 0 || itemCount < optItemCount))
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1421 {
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
1422 dmMemset(bufData, 0, bufSize);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1423
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1424 if (fread(bufData, 1, bufSize, inFile) != bufSize)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1425 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1426 dmErrorMsg("Could not read full bufferful (%d bytes) of data at 0x%x.\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
1427 bufSize, dataOffs);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1428 error = TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1429 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1430
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1431 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
1432
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1433 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
1434 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1435 case FFMT_CHAR:
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 dmDumpCharASCII(outFile, bufData, &dataOffs, optOutFormat, optInMulticolor);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1437 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1438 case FFMT_SPRITE:
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 dmDumpSpriteASCII(outFile, bufData, &dataOffs, optOutFormat, optInMulticolor);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1440 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1441 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1442 itemCount++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1443 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1444
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1445 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
1446 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1447 else
423
11b3adb3bdb1 Fix image format output.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1448 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
1449 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1450 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
1451 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
1452 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
1453
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1454 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
1455 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1456 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
1457 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1458 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
1459 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
1460 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1461
1288
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
1462 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
1463 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
1464 optItemCount,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1465 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
1466 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
1467 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1468 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1469 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1470 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
1471 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
1472 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1473 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
1474 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
1475 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1476
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 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
1478 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
1479 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
1480 outIHeight++;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1481
1288
6c8b19d1d196 More work on libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 1280
diff changeset
1482 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1485 outImage->constpal = TRUE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1486 outImage->pal = dmC64Palette;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1487 outImage->ncolors = C64_NCOLORS;
460
0af039b6c0ae Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
1488 outImage->ctransp = 255;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1489
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1490 while (!feof(inFile) && (optItemCount < 0 || itemCount < optItemCount))
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1491 {
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 987
diff changeset
1492 dmMemset(bufData, 0, bufSize);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1493
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1494 if (fread(bufData, 1, bufSize, inFile) != bufSize)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1495 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1496 dmErrorMsg("Could not read full bufferful (%d bytes) of data at 0x%x.\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
1497 bufSize, dataOffs);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1498 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1499 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1500
827
c8beac5313c3 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
1501 if ((err = dmC64ConvertCSDataToImage(outImage, outX * outWidthPX, outY * outHeight,
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1502 bufData, 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
1503 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1504 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
1505 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1506 }
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 (optSequential)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1509 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1510 outFilename = dm_strdup_printf("%s%04d.%s", optOutFilename, itemCount, convFormatList[optOutFormat].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
1511 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
1512 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1513 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
1514 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
1515 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1516
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1517 ret = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1518 if (ret != DMERR_OK)
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1519 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1520 dmErrorMsg("Error writing output image, %d: %s.\n",
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1521 ret, dmErrorStr(ret));
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1522 }
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1523
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1524 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
1525 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1526 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1527 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1528 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
1529 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1530 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
1531 outY++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1532 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1533 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1534
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 itemCount++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1536 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1537
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1538 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
1539 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1540 ret = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1541 if (ret != DMERR_OK)
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1542 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1543 dmError(ret, "Error writing output image, %d: %s.\n",
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1544 ret, dmErrorStr(ret));
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1545 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1546 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1547
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1548 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
1549 }
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1550 else
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1551 if (optOutFormat == FFMT_BITMAP)
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1552 {
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1553 if (optSequential)
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1554 {
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1555 ret = dmError(DMERR_INVALID_ARGS,
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1556 "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
1557 goto error;
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1558 }
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1559 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1560
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1561 dmFree(bufData);
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1562 return 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
1563
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1564 error:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1565 dmFree(bufData);
972
6d5edc6af2ad Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
1566 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
1567 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1568
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 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
1571 {
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1572 FILE *inFile = NULL;
1278
5206e3d4e6b7 Fix a segfault by initializing the cfmt struct pointer to NULL. Duh.
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
1573 const DMC64ImageFormat *cfmt = NULL;
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 911
diff changeset
1574 DMC64Image *cimage = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1575 Uint8 *dataBuf = NULL;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1576 size_t dataSize;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1577 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
1578
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1579 // 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
1580 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
1581 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
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 // Initialize and parse commandline
1280
300a51e98fc3 Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 1278
diff changeset
1584 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
1585
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1586 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
1587 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
1588 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
1589
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1590 #ifndef DM_USE_LIBPNG
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1591 if (optOutFormat == IMGFMT_PNG)
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1592 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1593 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
1594 goto error;
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1595 }
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1596 #endif
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1597
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1598 // 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
1599 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
1600 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1601 char *dext = strrchr(optInFilename, '.');
465
ffd5e730d313 Adjust verbosity levels.
Matti Hamalainen <ccr@tnsp.org>
parents: 463
diff changeset
1602 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
1603 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
1604 {
819
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
1605 if (!dmGetFormatByExt(dext + 1, &optInFormat, &optInSubFormat))
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
1606 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
1607 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1608 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1609
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1610 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
1611 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1612 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
1613 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1614 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
1615 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
1616 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
1617 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1618 inFile = stdin;
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 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1621 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
1622 {
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1623 int res = dmGetErrno();
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1624 dmErrorMsg("Error opening input file '%s', %d: %s\n",
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1625 optInFilename, res, dmErrorStr(res));
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1626 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
1627 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1628
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1629 if (dmReadDataFile(inFile, NULL, &dataBuf, &dataSize) != 0)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1630 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1631
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1632 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
1633 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1634 // Probe for format
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1635 const DMC64ImageFormat *forced = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1636 int res;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1637
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1638 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
1639 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1640 forced = &dmC64ImageFormats[optForcedFormat];
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1641 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
1642 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
1643 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1644
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1645 res = dmC64DecodeBMP(&cimage, dataBuf, dataSize, optInSkip, optInSkip + 2, &cfmt, forced);
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1646 if (forced == NULL && cfmt != 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
1647 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1648 dmMsg(1,"Probed %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
1649 cfmt->name, cfmt->type, cfmt->fext);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1650 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1651
897
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1652 if (res == DMERR_OK)
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1653 optInFormat = FFMT_BITMAP;
897
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1654 else
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1655 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1656 dmErrorMsg("Could not decode input image.\n");
897
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1657 exit(3);
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1658 }
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1659 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1660
463
4204e9ea8ae1 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
1661 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
1662 {
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1663 DMImageFormat *ifmt = NULL;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1664 int index;
465
ffd5e730d313 Adjust verbosity levels.
Matti Hamalainen <ccr@tnsp.org>
parents: 463
diff changeset
1665 dmMsg(4, "Trying to probe image formats.\n");
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1666 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
1667 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1668 optInFormat = FFMT_IMAGE;
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1669 optInSubFormat = index;
463
4204e9ea8ae1 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
1670 dmMsg(2, "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
1671 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1672 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1673
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1674 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
1675 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1676 dmErrorMsg("No input format specified, and could not be determined automatically.\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
1677 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
1678 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1679
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1680 // Skip, if needed
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1681 if (fseek(inFile, optInSkip, SEEK_SET) != 0)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1682 {
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1683 int res = dmGetErrno();
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1684 dmErrorMsg("Could not seek to file position %d (0x%x): %s\n",
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1685 optInSkip, optInSkip, dmErrorStr(res));
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1686 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1687 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1688
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1689 int inFormat = dmGetConvFormat(optInFormat, optInSubFormat),
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1690 outFormat = dmGetConvFormat(optOutFormat, optOutSubFormat);
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1691
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1692 if (inFormat != -1 && outFormat != -1)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1693 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1694 char *inFmtName = convFormatList[inFormat].name,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1695 *inFmtExt = convFormatList[inFormat].fext,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1696 *outFmtName = convFormatList[outFormat].name,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1697 *outFmtExt = convFormatList[outFormat].fext;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1698
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1699 if (optInFormat == FFMT_BITMAP)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1700 inFmtExt = cfmt->name;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1701
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1702 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
1703 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
1704 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1705
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1706 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
1707 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1708 case FFMT_SPRITE:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1709 case FFMT_CHAR:
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1710 dmDumpSpritesAndChars(inFile);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1711 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1712
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1713 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
1714 {
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1715 DMImage *outImage = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1716 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
1717
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1718 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
1719 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1720 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
1721 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1722 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1723
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1724 switch (optOutFormat)
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 case FFMT_IMAGE:
940
ff18d2511843 Remove the doubleMC madness completely. Should be replaced with x/y aspect
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
1727 res = dmC64ConvertBMP2Image(&outImage, cimage, cfmt);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1728
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1729 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
1730 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1731 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
1732 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1733 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1734
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1735 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
1736 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1737
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1738
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1739 case FFMT_BITMAP:
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 911
diff changeset
1740 res = dmWriteBitmap(optOutFilename, cimage, optOutSubFormat, TRUE);
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1741 break;
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1742
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1743 case FFMT_CHAR:
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1744 case FFMT_SPRITE:
940
ff18d2511843 Remove the doubleMC madness completely. Should be replaced with x/y aspect
Matti Hamalainen <ccr@tnsp.org>
parents: 933
diff changeset
1745 res = dmC64ConvertBMP2Image(&outImage, cimage, cfmt);
810
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1746
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1747 if (res != DMERR_OK || outImage == NULL)
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1748 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1749 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
1750 goto error;
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1751 }
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1752
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1753 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
1754 break;
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1755
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1756 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1757 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
1758 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1759 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1760
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1761 dmImageFree(outImage);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1762 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1763 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1764
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1765 case FFMT_IMAGE:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1766 {
441
2a4de5fe4003 Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1767 DMImage *outImage = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1768 int res = DMERR_OK;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1769
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1770 if (optOutFilename == NULL)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1771 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1772 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
1773 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
1774 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1775
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1776 // 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
1777 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
1778 if (ifmt->readFILE != NULL)
2a4de5fe4003 Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1779 res = ifmt->readFILE(inFile, &outImage);
2a4de5fe4003 Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1780 else
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1781 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
1782
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1783 if (res != DMERR_OK || outImage == NULL)
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1784 break;
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1785
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1786 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
1787 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1788 case FFMT_IMAGE:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1789 res = dmWriteImage(optOutFilename, outImage, &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
1790 break;
417
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1791
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1792 case FFMT_CHAR:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1793 case FFMT_SPRITE:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1794 res = dmWriteSpritesAndChars(optOutFilename, outImage, optOutFormat, optInMulticolor);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1795 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1796
417
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1797 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1798 dmErrorMsg("Unsupported output format for bitmap/image conversion.\n");
417
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1799 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
1800 }
806
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1801
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1802 if (res != DMERR_OK)
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1803 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 940
diff changeset
1804 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
1805 dmErrorStr(res));
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1806 }
1235
5b8245e5f785 Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents: 1167
diff changeset
1807
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1808 dmImageFree(outImage);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1809 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1810 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1811 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1812
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1813 error:
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1814 if (inFile != NULL)
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1815 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
1816
466
0bfa6a15bb46 Plug (non-dangerous) memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
1817 dmFree(dataBuf);
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1818 dmC64ImageFree(cimage);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1819
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1820 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
1821 }