annotate tools/gfxconv.c @ 933:8fe48c08dbca

Fix some memory leaks etc.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 25 Feb 2015 19:51:14 +0200
parents 2270d7f3af77
children ff18d2511843
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
825
c5b768c8e641 Update copyright.
Matti Hamalainen <ccr@tnsp.org>
parents: 824
diff changeset
4 * (C) Copyright 2012-2014 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,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
148 .interleave = FALSE,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
149 .paletted = FALSE,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
150 .format = 0,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
151 };
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152
860
daebbf28953d The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents: 854
diff changeset
153 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
154 {
431
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
155 { 0, '?', "help", "Show this help", OPT_NONE },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
156 { 15, 'v', "verbose", "Increase verbosity", OPT_NONE },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
157 { 3, 'o', "output", "Output filename", OPT_ARGREQ },
838
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
158 { 1, 'i', "informat", "Set input format (sprite[:mc:sc], char[:mc|sc], bitmap[:<bformat>], image)", OPT_ARGREQ },
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
159 { 2, 'm', "multicolor", "Input is multicolor / output in multicolor", OPT_NONE },
431
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
160 { 4, 's', "skip", "Skip bytes in input", OPT_ARGREQ },
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
161 { 5, 'f', "format", "Output format (see --formats)", OPT_ARGREQ },
822
b034c1457aa5 Remove -F, leave only --formats option.
Matti Hamalainen <ccr@tnsp.org>
parents: 821
diff changeset
162 { 17, 0 , "formats", "List available input/output formats", OPT_NONE },
431
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
163 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
164 { 6, 'c', "colormap", "Color mappings (see below for information)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
165 { 7, 'n', "numitems", "How many 'items' to view (default: all)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
166 { 9, 'S', "scale", "Scale output by x (image output only)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
167 { 11, 'w', "width", "Item width (number of items per row, min 1)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
168 { 12, 'P', "paletted", "Use indexed/paletted output (png, pcx output only)", OPT_NONE },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
169 { 13, 'B', "bplanes", "Bits per pixel OR # of bitplanes (certain output formats)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
170 { 14, 'I', "interleave", "Interleave scanlines (default: output whole planes)", OPT_NONE },
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
171 { 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
172 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 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
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
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
177 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
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 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
180
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
181 printf(
432
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
182 "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
183 " 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
184 "------+---+---+-----------------------------------------------\n"
432
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
185 );
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
186
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
187 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
188 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
189 DMConvFormat *fmt = &convFormatList[i];
432
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
190 printf("%-5s | %c | %c | %s\n",
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
191 fmt->fext ? fmt->fext : "",
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
192 fmt->in ? 'X' : ' ',
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
193 fmt->out ? 'X' : ' ',
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
194 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
195 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
197 printf(
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
198 "\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
199 "(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
200 "\n"
838
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
201 "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
202 " Ext | Type | Description\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
203 "------+-----------------+-------------------------------------\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
204 );
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
205
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 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
207 {
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
208 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
209 char buf[64];
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
210 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
211 fmt->fext,
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
212 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
213 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
214 }
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
215 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
216
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
217
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
218 void argShowHelp()
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 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
221 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
222
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 printf(
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
224 "\n"
818
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
225 "Palette / color remapping (-R)\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
226 "------------------------------\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
227 "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
228 "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
229 "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
230 "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
231 "-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
232 "\n"
818
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
233 "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
234 "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
235 "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
236 "\n"
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
237 "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
238 "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
239 "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
240 "\n"
818
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
241 "Color map defs\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
242 "--------------\n"
456
20122cffde2f Clarify help.
Matti Hamalainen <ccr@tnsp.org>
parents: 455
diff changeset
243 "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
244 "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
245 "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
246 "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
247 "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
248 "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
249 "special color that can be used for transparency.\n"
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
250 "\n"
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 );
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
255 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
256 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
257 int i;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
258 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
259 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
260 DMConvFormat *fmt = &convFormatList[i];
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
261 if (fmt->format == format &&
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
262 fmt->subformat == subformat)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
263 return i;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
264 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
265 return -1;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
266 }
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
819
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
269 BOOL dmGetC64FormatByExt(const char *fext, int *format, int *subformat)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
270 {
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
271 int i;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
272 if (fext == NULL)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
273 return FALSE;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
274
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
275 for (i = 0; i < ndmC64ImageFormats; i++)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
276 {
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
277 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
278 if (fmt->fext != NULL &&
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
279 strcasecmp(fext, fmt->fext) == 0)
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
280 {
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
281 *format = FFMT_BITMAP;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
282 *subformat = i;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
283 return TRUE;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
284 }
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
285 }
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
286
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
287 return FALSE;
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
288 }
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
289
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
290
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
291
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
292 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
293 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
294 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
295 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
296 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
297
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
298 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
299 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
300 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
301 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
302 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
303 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
304 *format = fmt->format;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
305 *subformat = fmt->subformat;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
306 return TRUE;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
307 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
308 }
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
309
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
310 return FALSE;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
311 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
312
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
313
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
314 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
315 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
316 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
317
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
318 if (opt == NULL)
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
319 goto error;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
320
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
321 if ((end = split = strchr(opt, ':')) == NULL)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
322 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
323 dmError("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
324 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
325 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
326
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
327 // Trim whitespace
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
328 *end = 0;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
329 for (end--; end > opt && *end && isspace(*end); end--)
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
330 *end = 0;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
331
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
332 // 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
333 if (*opt == '#' || *opt == '%')
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
334 {
867
56e12109b936 Portability warning fixes.
Matti Hamalainen <ccr@tnsp.org>
parents: 860
diff changeset
335 unsigned int colR, colG, colB, colA;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
336
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
337 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
338 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
339 {
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
340 value->alpha = TRUE;
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
341 value->color.a = colA;
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 else
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
344 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
345 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
346 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
347 dmError("Invalid %s value '%s', expected a hex triplet, got '%s'.\n", msg, popt, opt + 1);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
348 goto error;
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
349 }
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
350
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
351 value->color.r = colR;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
352 value->color.g = colG;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
353 value->color.b = colB;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
354 value->triplet = TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
355 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
356 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
357 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
358 if (!dmGetIntVal(opt, &value->from))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
359 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
360 dmError("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
361 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
362 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
363 value->triplet = FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
364 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
365
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
366 // Trim whitespace
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
367 split++;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
368 while (*split && isspace(*split)) split++;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
369
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
370 // Parse destination value
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
371 if (!dmGetIntVal(split, &value->to))
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
372 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
373 dmError("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
374 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
375 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
376
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
377 if (!value->triplet && value->from > 255)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
378 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
379 dmError("Invalid %s map source color index value %d, must be [0..255].\n", msg, value->from);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
380 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
381 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
382
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
383 if (value->to > nmax)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
384 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
385 dmError("Invalid %s map destination color index value %d, must be [0..%d].\n", msg, value->to, nmax);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
386 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
387 }
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
388
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
389 dmFree(opt);
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
390 return TRUE;
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 error:
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
393 dmFree(opt);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
394 return FALSE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
395 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
396
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
397
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
398 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
399 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
400 // Trim whitespace
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
401 if (end != NULL)
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 *end = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
404 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
405 *end = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
406 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
407 while (*opt && isspace(*opt)) opt++;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
408
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
409 // Parse item based on mode
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
410 if (requireIndex)
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 DMMapValue *value = (DMMapValue *) pvalue;
475
c0dedfef3edf Fix option parsing of mappings.
Matti Hamalainen <ccr@tnsp.org>
parents: 474
diff changeset
413 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
414 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
415 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
416 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
417 {
871
fc272f5f2d15 Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents: 867
diff changeset
418 unsigned int *value = (unsigned int *) pvalue;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
419 char *split = strchr(opt, ':');
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
420 if (split != NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
421 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
422 dmError("Unexpected ':' in indexed %s '%s'.\n", msg, opt);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
423 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
424 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
425
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
426 if (!dmGetIntVal(opt, &value[index]))
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 dmError("Invalid %s value '%s', could not parse.\n", msg, opt);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
429 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
430 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
431 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
432
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
433 return TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
434 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
435
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
436
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
437 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
438 {
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
439 char *start = opt;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
440
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
441 *nvalues = 0;
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
442 while (*start && *nvalues < nmax)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
443 {
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
444 char *end = strchr(start, ',');
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
445
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
446 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
447 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
448
853
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
449 (*nvalues)++;
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
450
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
451 if (!end)
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
452 break;
b2140d41785a Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents: 838
diff changeset
453
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
454 start = end + 1;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
455 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
456
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
457 return TRUE;
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
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
460
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
461 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
462 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
463 FILE *fp;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
464 char line[512];
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
465 int res = DMERR_OK;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
466
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
467 if ((fp = fopen(filename, "r")) == NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
468 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
469 res = dmGetErrno();
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
470 dmError("Could not open color remap file '%s' for reading, %d: %s\n",
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
471 res, dmErrorStr(res));
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
472 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
473 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
474
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
475 while (fgets(line, sizeof(line), fp))
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 char *start = line;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
478 while (*start && isspace(*start)) start++;
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 if (*start != 0 && *start != ';')
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
481 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
482 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
483 goto error;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
484 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
485 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
486 (*nvalue)++;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
487 if (*nvalue >= nmax)
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 dmError("Too many mapping pairs in '%s', maximum is %d.\n",
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
490 filename, nmax);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
491 goto error;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
492 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
493 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
494 }
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 error:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
498 fclose(fp);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
499 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
500 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
501
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
502
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
503 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
504 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 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
506 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 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
508 argShowHelp();
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 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
510 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
512 case 17:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
513 argShowFormats();
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
514 exit(0);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
515 break;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
516
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
517 case 15:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
518 dmVerbosity++;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
519 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
520
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521 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
522 {
824
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
523 switch (tolower(optArg[0]))
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
524 {
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
525 case 's': optInFormat = FFMT_SPRITE; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
526 case 'c': optInFormat = FFMT_CHAR; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
527 case 'b': optInFormat = FFMT_BITMAP; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
528 case 'i': optInFormat = FFMT_IMAGE; break;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
529 default:
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
530 dmError("Invalid input format '%s'.\n", optArg);
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
531 return FALSE;
705e2e4ed45a Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 823
diff changeset
532 }
838
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
533
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
534 char *tmp = strchr(optArg, ':');
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
535 if (tmp != NULL)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
536 {
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
537 tmp++;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
538 switch (optInFormat)
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 case FFMT_SPRITE:
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
541 case FFMT_CHAR:
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
542 if (strcasecmp(tmp, "mc") == 0)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
543 optInMulticolor = TRUE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
544 else
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
545 if (strcasecmp(tmp, "sc") == 0)
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
546 optInMulticolor = FALSE;
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 {
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
549 dmError("Invalid input subformat for sprite/char: '%s', should be 'mc' or 'sc'.\n",
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
550 tmp);
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
551 return FALSE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
552 }
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
553 break;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
554
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
555 case FFMT_BITMAP:
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
556 if (!dmGetC64FormatByExt(tmp, &optInFormat, &optInSubFormat))
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
557 {
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
558 dmError("Invalid bitmap subformat '%s', see format list for valid bformats.\n",
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
559 tmp);
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
560 return FALSE;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
561 }
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
562 break;
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
563 }
f2ac9877263e Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 837
diff changeset
564 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
565 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
566 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 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
569 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
570 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 case 3:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573 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
574 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
575
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
576 case 4:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 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
578 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579 dmError("Invalid skip value argument '%s'.\n", optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 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
581 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
584 case 5:
819
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
585 if (!dmGetFormatByExt(optArg, &optOutFormat, &optOutSubFormat) &&
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
586 !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
587 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
588 dmError("Invalid output format '%s'.\n", optArg);
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
589 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
590 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
593 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
594 {
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
595 int index, ncolors;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
596 if (!dmParseMapOptionString(optArg, optColors,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
597 &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
598 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
599
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600 dmMsg(1, "Set color table: ");
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
601 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
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 dmPrint(1, "[%d:%d]%s",
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
604 index, optColors[index],
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
605 (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
606 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
607 dmPrint(1, "\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
608 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
609 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
610
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
611 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
612 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
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 dmError("Invalid count value argument '%s'.\n", optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
615 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
616 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
617 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
618
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
619 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
620 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
621 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
622
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
623 case 9:
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
624 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
625 {
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
626 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
627 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
628 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
629 {
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
630 dmError("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
631 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
632 }
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
633 }
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
634 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
635 {
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
636 dmError("Invalid X scale value '%d'.\n", optSpec.scaleX);
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
637 return FALSE;
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
638 }
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
639 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
640 {
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
641 dmError("Invalid Y scale value '%d'.\n", optSpec.scaleY);
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
642 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
643 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
645
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646 case 11:
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
647 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
648 {
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
649 dmError("Invalid planed width value argument '%s'.\n", optArg);
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
650 return FALSE;
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
651 }
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
652 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
653 {
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
654 dmError("Invalid planed width value '%d' [1..512].\n", optPlanedWidth);
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
655 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
656 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 case 12:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
660 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
661 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
662
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
663 case 13:
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
664 {
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
665 int tmp = atoi(optArg);
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
666 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
667 {
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
668 dmError("Invalid bitplanes/bpp value '%s'.\n", optArg);
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
669 return FALSE;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
670 }
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
671 optSpec.nplanes = tmp;
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
672 }
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
673 break;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
674
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
675 case 14:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
676 optSpec.interleave = TRUE;
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
677 break;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
678
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
679 case 16:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
680 {
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
681 char *tmp;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
682 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
683 {
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
684 optRemapRemove = TRUE;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
685 *tmp = 0;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
686 }
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
687
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
688 if (optArg[0] == '@')
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
689 {
821
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
690 if (optArg[1] != 0)
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
691 {
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
692 int res;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
693 if ((res = dmParseColorRemapFile(optArg + 1,
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
694 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
695 return FALSE;
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
696 }
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
697 else
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 dmError("No remap filename given.\n");
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
700 return FALSE;
823
f0429dbd77ec Oops, missing } from one of the previous commits. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents: 822
diff changeset
701 }
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
702 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
703 else
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 (!dmParseMapOptionString(optArg, optRemapTable,
8ec16cca0eef Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents: 820
diff changeset
706 &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
707 return FALSE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
708 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
709 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
710
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
711 optRemapColors = TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
712 break;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
713
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
714 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
715 {
ca5b4696be21 Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents: 853
diff changeset
716 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
717 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
718 {
ca5b4696be21 Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents: 853
diff changeset
719 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
720 }
ca5b4696be21 Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents: 853
diff changeset
721 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
722 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
723 {
ca5b4696be21 Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents: 853
diff changeset
724 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
725 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
726 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
727 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
728 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
729 }
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 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
731 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
732 {
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 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
734 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
735 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
736 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
737 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
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 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
740 {
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 dmError("Invalid crop mode / argument '%s'.\n", optArg);
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 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
743 }
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 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
746
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748 dmError("Unknown option '%s'.\n", currArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 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
750 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
751
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 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
753 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
756 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
757 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758 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
759 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
760 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762 dmError("Source filename already specified, extraneous argument '%s'.\n",
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763 currArg);
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 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
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 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
774
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
775 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
776 {
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
777 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
778 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779 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
780 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
781 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
782 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
783 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
784 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
785 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
786 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
787 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
788 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
789 0x1b,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 1,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 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
792 0x1b);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
794 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
795 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
796 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
797 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
798 {
837
5333dd4a99e4 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 829
diff changeset
799 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
800 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
801 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
802 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
803 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
804 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
805 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
806 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
807 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
808 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
809 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
810 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
811 0x1b,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
812 1,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
813 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
814 0x1b);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
815 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
816 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
817 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
818 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
819 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
820
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
821
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
822 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
823 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
824 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
825
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
826 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
827 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
828 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
829 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
830 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
831 (*offs)++;
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
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
836 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
837 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
838 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
839
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
840 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
841 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
842 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
843 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
844 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
845 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
846 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
847 bufOffs++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
848 (*offs)++;
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 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
851 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
852 (*offs)++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
853 }
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
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
856 int dmRemapImageColors(DMImage *image)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
857 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
858 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
859 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
860 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
861 BOOL *used = dmMalloc(image->ncolors * sizeof(BOOL));
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
862 int n, index, xc, yc, ncolors;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
863
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
864 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
865
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
866 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
867 {
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
868 dmError("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
869 return DMERR_MALLOC;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
870 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
871
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
872 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
873 {
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 mapping[index] = -1;
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
875 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
876 }
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
877
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
878 // 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
879 dmMsg(2, "Scanning image for used colors...\n");
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
880 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
881 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
882 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
883 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
884 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
885 Uint8 col = dp[xc];
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
886 if (col < image->ncolors && !used[col])
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
887 {
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 used[col] = TRUE;
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
889 ncolors++;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
890 }
479
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
891 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
892 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
893 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
894
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
895 // Match and mark mapped colors
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
896 for (index = 0; index < optNRemapTable; index++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
897 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
898 DMMapValue *map = &optRemapTable[index];
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
899 if (map->triplet)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
900 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
901 BOOL found = FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
902 for (n = 0; n < image->ncolors; n++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
903 {
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
904 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
905 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
906 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
907 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
908 n,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
909 map->to);
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
910
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
911 mapping[n] = map->to;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
912 mapped[map->to] = TRUE;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
913 found = TRUE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
914 }
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
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
917 if (!found)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
918 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
919 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
920 index,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
921 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
922 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
923 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
924 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
925 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
926 dmMsg(3, "Map index: %d -> %d\n",
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
927 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
928
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
929 mapping[map->from] = map->to;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
930 mapped[map->to] = TRUE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
931 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
932 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
933
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
934
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
935 // 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
936 if (optRemapRemove)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
937 {
479
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
938 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
939 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
940 if (mapping[index] < 0 && used[index])
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
941 {
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
942 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
943 if (!mapped[n])
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
944 {
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
945 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
946 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
947 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
948 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
949 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
950 }
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 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
952 {
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 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
954 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
955 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
956 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
957 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
958 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
959 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
960 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
961 break;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
962 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
963 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
964 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
965
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
966 // 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
967 ncolors = 0;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
968 for (index = 0; index < image->ncolors; index++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
969 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
970 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
971 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
972 }
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 // Copy palette entries
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
975 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
976 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
977 if (mapping[index] >= 0)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
978 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
979 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
980 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
981 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
982
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
983 // 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
984 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
985 for (yc = 0; yc < image->height; yc++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
986 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
987 Uint8 *dp = image->data + image->pitch * yc;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
988 for (xc = 0; xc < image->width; xc++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
989 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
990 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
991 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
992 dp[xc] = mapping[col];
478
7c7a57590236 Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents: 477
diff changeset
993 else
7c7a57590236 Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents: 477
diff changeset
994 dp[xc] = 0;
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 // Set new palette, free memory
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
999 dmFree(image->pal);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1000 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
1001 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
1002
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
1003 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
1004 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
1005 dmFree(used);
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1006 return DMERR_OK;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1007 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1008
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1009
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1010 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
1011 {
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1012 FILE *outFile = NULL;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1013 Uint8 *buf = NULL;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1014 size_t bufSize;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1015 int res = DMERR_OK;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1016 const DMC64ImageFormat *fmt = &dmC64ImageFormats[iformat];
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1017
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1018 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
1019 if (image->type != fmt->type && enableFixUps)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1020 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1021 // Try to do some simple fixups
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1022 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
1023 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1024 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
1025 int i;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1026 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
1027 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1028 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
1029 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
1030 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1031 }
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
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1034
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1035 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
1036 goto error;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1037
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1038 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
1039
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1040 if ((outFile = fopen(filename, "wb")) == NULL)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1041 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1042 res = dmGetErrno();
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1043 dmError("Error opening output file '%s', %d: %s\n",
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1044 filename, res, dmErrorStr(res));
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1045 goto error;
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 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
1049 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1050 res = dmGetErrno();
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1051 dmError("Error writing image data to '%s', %d: %s\n",
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1052 filename, res, dmErrorStr(res));
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1053 }
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 error:
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1056 if (outFile != NULL)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1057 fclose(outFile);
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1058 dmFree(buf);
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1059 return res;
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1060 }
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1061
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1062
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1063 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
1064 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1065 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
1066 {
902
c6c480e8e1c8 Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents: 897
diff changeset
1067 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
1068 dmImageFormatList[iformat].fext,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1069 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
1070 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
1071 spec->scaleX, spec->scaleY);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1072 }
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1073
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1074 // Perform color remapping
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1075 if (optRemapColors)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1076 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1077 int res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1078 if ((res = dmRemapImageColors(image)) != DMERR_OK)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1079 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1080 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1081
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1082 switch (iformat)
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1083 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1084 #ifdef DM_USE_LIBPNG
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1085 case IMGFMT_PNG:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1086 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
1087 spec->format = spec->paletted ? DM_IFMT_PALETTE : DM_IFMT_RGBA;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1088 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
1089 #endif
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1090
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1091 case IMGFMT_PPM:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1092 if (info) dmMsg(2, "24bit RGB output.\n");
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1093 spec->format = DM_IFMT_RGB;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1094 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
1095
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1096 case IMGFMT_PCX:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1097 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
1098 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
1099
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1100 case IMGFMT_RAW:
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1101 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
1102 {
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1103 FILE *fp;
820
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1104 char *dataFilename;
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1105
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1106 // Form data file filename
820
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1107 dataFilename = dm_strdup_fext(filename, "%s.inc");
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1108 if (dataFilename == NULL)
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1109 return DMERR_MALLOC;
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1110
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1111 // Open data file for writing
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1112 if ((fp = fopen(dataFilename, "w")) == NULL)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1113 dmError("Could not create '%s'.\n", dataFilename);
820
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1114
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1115 dmFree(dataFilename);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1116
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1117 if (fp != NULL)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1118 {
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1119 // Strip extension
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1120 int i;
820
e3fa646aef0d Use dm_strdup_fext().
Matti Hamalainen <ccr@tnsp.org>
parents: 819
diff changeset
1121 char *palID = dm_strdup_fext(filename, "img_%s");
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1122
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1123 // Replace any non-alphanumerics
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1124 for (i = 0; palID[i]; i++)
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 if (isalnum(palID[i]))
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1127 palID[i] = tolower(palID[i]);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1128 else
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1129 palID[i] = '_';
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1130 }
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1131
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1132 if (iformat == IMGFMT_ARAW)
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1133 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1134 fprintf(fp,
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1135 "%s_width: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1136 "%s_height: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1137 "%s_nplanes: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1138 "%s_ncolors: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1139 "%s_palette:\n",
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1140 palID, image->width,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1141 palID, image->height,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1142 palID, spec->nplanes,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1143 palID, image->ncolors,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1144 palID);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1145
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1146 dmWriteIFFMasterRAWPalette(fp, image, 1 << optSpec.nplanes, NULL, NULL);
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1147
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1148 fprintf(fp,
477
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1149 "%s: incbin \"%s\"\n",
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1150 palID, filename);
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1151 }
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1152 else
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1153 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1154 fprintf(fp,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1155 "%s_width: dw.w %d\n"
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1156 "%s_height: dw.w %d\n"
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1157 "%s_nplanes: dw.w %d\n",
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1158 palID, image->width,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1159 palID, image->height,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1160 palID, spec->nplanes);
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1161 }
477
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1162
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1163 fclose(fp);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1164 dmFree(palID);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1165 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1166
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1167 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
1168 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
1169 }
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1170 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
1171
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1172 default:
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1173 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
1174 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1175 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1176
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1177
547
ca5ad51c6479 Make dmConvertByte() static.
Matti Hamalainen <ccr@tnsp.org>
parents: 546
diff changeset
1178 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
1179 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1180 Uint8 byte = 0;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1181 int xc;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1182
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1183 if (multicolor)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1184 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1185 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
1186 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1187 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
1188 byte |= pixel << (6 - (xc * 2));
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1189 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1190 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1191 else
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1192 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1193 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
1194 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1195 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
1196 byte |= pixel << (7 - 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 }
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 return byte;
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
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1203
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1204 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
1205 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
1206 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1207 int yc;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1208
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1209 if (xoffs < 0 || yoffs < 0 ||
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1210 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
1211 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
1212 return FALSE;
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 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
1215 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1216 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
1217 buf[yc] = dmConvertByte(sp, multicolor);
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
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1220 return TRUE;
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
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 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
1225 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
1226 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1227 int yc, xc;
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 if (xoffs < 0 || yoffs < 0 ||
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1230 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
1231 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
1232 return FALSE;
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 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
1235 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1236 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
1237 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1238 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
1239 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
1240 }
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
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1243 return TRUE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1244 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1245
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1246
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1247 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
1248 {
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1249 int ret = DMERR_OK;
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1250 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
1251 FILE *outFile = NULL;
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1252 Uint8 *buf = NULL;
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1253 size_t outBufSize;
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1254 char *outType;
489
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 switch (outFormat)
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 case FFMT_CHAR:
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1259 outBufSize = C64_CHR_SIZE;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1260 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
1261 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
1262 outType = "char";
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1263 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1264
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1265 case FFMT_SPRITE:
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1266 outBufSize = C64_SPR_SIZE;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1267 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
1268 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
1269 outType = "sprite";
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1270 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1271
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1272 default:
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1273 ret = DMERR_INVALID_ARGS;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1274 dmError("Invalid output format %d, internal error.\n", outFormat);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1275 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1276 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1277
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1278 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
1279 {
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1280 ret = DMERR_INVALID_ARGS;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1281 dmError("Source image dimensions too small for conversion, block dimensions %d x %d.\n",
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1282 outBlockW, outBlockH);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1283 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1284 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1285
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1286 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
1287 {
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1288 ret = dmGetErrno();
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1289 dmError("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
1290 filename, ret, dmErrorStr(ret));
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1291 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1292 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1293
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1294 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
1295 {
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1296 dmError("Could not allocate %d bytes for conversion buffer.\n",
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1297 outBufSize);
489
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 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
1302 outBlockW, outBlockH, outBlockW * outBlockH, outType);
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1303
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1304 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
1305 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
1306 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1307 switch (outFormat)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1308 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1309 case FFMT_CHAR:
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1310 if (!dmConvertImage2Char(buf, image,
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1311 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
1312 multicolor))
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1313 {
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1314 ret = DMERR_DATA_ERROR;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1315 goto error;
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1316 }
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1317 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1318
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1319 case FFMT_SPRITE:
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1320 if (!dmConvertImage2Sprite(buf, image,
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1321 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
1322 multicolor))
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1323 {
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1324 ret = DMERR_DATA_ERROR;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1325 goto error;
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1326 }
910
Matti Hamalainen <ccr@tnsp.org>
parents: 909
diff changeset
1327 break;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1328 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1329
907
bc6c338295e5 Rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents: 902
diff changeset
1330 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
1331 {
909
be5d276f8a6c Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 907
diff changeset
1332 ret = dmGetErrno();
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1333 dmError("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
1334 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
1335 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1336 }
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1337 }
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1338
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1339 fclose(outFile);
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1340 dmFree(buf);
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1341 return 0;
828
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1342
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1343 error:
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1344 if (outFile != NULL)
c20a99411a1a Fix a silly segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 827
diff changeset
1345 fclose(outFile);
829
97700378ecd8 Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents: 828
diff changeset
1346 dmFree(buf);
910
Matti Hamalainen <ccr@tnsp.org>
parents: 909
diff changeset
1347 return ret;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1348 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1349
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1350
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1351 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
1352 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1353 int dataOffs, itemCount, outWidth, outWidthPX, outHeight;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1354 size_t bufSize;
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1355 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
1356
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1357 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
1358 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1359 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
1360 bufSize = C64_CHR_SIZE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1361 outWidth = C64_CHR_WIDTH;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1362 outWidthPX = C64_CHR_WIDTH_PX;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1363 outHeight = C64_CHR_HEIGHT;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1364 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1365
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1366 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
1367 bufSize = C64_SPR_SIZE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1368 outWidth = C64_SPR_WIDTH;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1369 outWidthPX = C64_SPR_WIDTH_PX;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1370 outHeight = C64_SPR_HEIGHT;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1371 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1372
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1373 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1374 dmError("Invalid input format %d, internal error.\n", optInFormat);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1375 return -1;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1376 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1377
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1378 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
1379 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1380 dmError("Could not allocate temporary buffer of %d bytes.\n", bufSize);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1381 return -2;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1382 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1383
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1384
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1385 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
1386 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
1387
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1388 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
1389 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1390 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
1391 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
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 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
1394 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
1395 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1396 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
1397 {
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1398 int res = dmGetErrno();
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1399 dmError("Error opening output file '%s', %d: %s\n",
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1400 optOutFilename, res, dmErrorStr(res));
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1401 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
1402 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1403
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1404 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
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 memset(bufData, 0, bufSize);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1408 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
1409 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1410 dmError("Could not read full bufferful (%d bytes) of data at 0x%x.\n",
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1411 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
1412 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
1413 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1414
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1415 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
1416
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1417 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
1418 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1419 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
1420 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
1421 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1422 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
1423 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
1424 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1425 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1426 itemCount++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1427 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1428
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1429 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
1430 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1431 else
423
11b3adb3bdb1 Fix image format output.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1432 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
1433 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1434 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
1435 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
1436 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
1437
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1438 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
1439 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1440 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
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 dmError("Sequential image output requires filename template.\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1443 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1446 outImage = dmImageAlloc(outWidthPX, outHeight);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1447 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
1448 optItemCount,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1449 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
1450 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
1451 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1452 else
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 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
1455 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
1456 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1457 dmError("Single-image output requires count to be set (-n).\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1458 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
1459 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1460
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1461 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
1462 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
1463 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
1464 outIHeight++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1465
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1466 outImage = dmImageAlloc(outWidthPX * outIWidth, outIHeight * outHeight);
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1469 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
1470 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
1471 outImage->ncolors = C64_NCOLORS;
460
0af039b6c0ae Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
1472 outImage->ctransp = 255;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1473
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1474 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
1475 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1476 memset(bufData, 0, bufSize);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1477
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1478 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
1479 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1480 dmError("Could not read full bufferful (%d bytes) of data at 0x%x.\n",
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1481 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
1482 break;
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
827
c8beac5313c3 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 826
diff changeset
1485 if ((err = dmC64ConvertCSDataToImage(outImage, outX * outWidthPX, outY * outHeight,
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1486 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
1487 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1488 dmError("Internal error in conversion of raw data to bitmap: %d.\n", err);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1489 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1490 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1491
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1492 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
1493 {
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1494 int eres;
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1495
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1496 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
1497 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
1498 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1499 dmError("Could not allocate memory for filename template?\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1500 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
1501 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1502
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1503 eres = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1504 if (eres != DMERR_OK)
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1505 {
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1506 dmError("Error writing output image, %s.\n",
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1507 dmErrorStr(eres));
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1508 }
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1509
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1510 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
1511 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1512 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1513 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1514 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
1515 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1516 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
1517 outY++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1518 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1519 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1520
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1521 itemCount++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1522 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1523
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1524 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
1525 {
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1526 int eres = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1527 if (eres != DMERR_OK)
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1528 {
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1529 dmError("Error writing output image, %s.\n",
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1530 dmErrorStr(eres));
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1531 }
407
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1534 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
1535 }
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1536 else
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1537 if (optOutFormat == FFMT_BITMAP)
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1538 {
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1539 if (optSequential)
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1540 {
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1541 dmError("Sequential output not supported for spr/char -> bitmap conversion.\n");
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1542 goto error;
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1543 }
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1544 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1545
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1546 dmFree(bufData);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1547 return 0;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1548
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1549 error:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1550 dmFree(bufData);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1551 return -1;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1552 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1553
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1554
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1555 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
1556 {
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1557 FILE *inFile = NULL;
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1558 const DMC64ImageFormat *cfmt;
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 911
diff changeset
1559 DMC64Image *cimage = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1560 Uint8 *dataBuf = NULL;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1561 size_t dataSize;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1562 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
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 // 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
1565 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
1566 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
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 // Initialize and parse commandline
814
5753d7f24106 Bump version for gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
1569 dmInitProg("gfxconv", "Simple graphics converter", "0.80", 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
1570
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1571 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
1572 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
1573 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
1574
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1575 #ifndef DM_USE_LIBPNG
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1576 if (optOutFormat == IMGFMT_PNG)
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1577 {
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1578 dmError("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
1579 goto error;
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1580 }
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1581 #endif
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1582
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1583 // 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
1584 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
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 char *dext = strrchr(optInFilename, '.');
465
ffd5e730d313 Adjust verbosity levels.
Matti Hamalainen <ccr@tnsp.org>
parents: 463
diff changeset
1587 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
1588 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
1589 {
819
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
1590 if (!dmGetFormatByExt(dext + 1, &optInFormat, &optInSubFormat))
0177d4a66d48 Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents: 818
diff changeset
1591 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
1592 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1593 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1594
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1595 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
1596 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1597 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
1598 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1599 dmError("Standard input cannot be used without specifying input format.\n");
492
5672dc238904 Add a note to default error message about using --help option.
Matti Hamalainen <ccr@tnsp.org>
parents: 490
diff changeset
1600 dmError("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
1601 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
1602 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1603 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
1604 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1605 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1606 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
1607 {
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1608 int res = dmGetErrno();
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1609 dmError("Error opening input file '%s', %d: %s\n",
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1610 optInFilename, res, dmErrorStr(res));
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1611 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
1612 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1613
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1614 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
1615 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1616
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1617 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
1618 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1619 // Probe for format
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1620 const DMC64ImageFormat *forced = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1621 int res;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1622
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1623 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
1624 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1625 forced = &dmC64ImageFormats[optForcedFormat];
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1626 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
1627 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
1628 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1629
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1630 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
1631 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
1632 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1633 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
1634 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
1635 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1636
897
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1637 if (res == DMERR_OK)
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1638 optInFormat = FFMT_BITMAP;
897
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1639 else
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1640 {
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1641 dmError("Could not decode input image.\n");
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1642 exit(3);
9541ea963e75 Add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 871
diff changeset
1643 }
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1644 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1645
463
4204e9ea8ae1 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
1646 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
1647 {
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1648 DMImageFormat *ifmt = NULL;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1649 int index;
465
ffd5e730d313 Adjust verbosity levels.
Matti Hamalainen <ccr@tnsp.org>
parents: 463
diff changeset
1650 dmMsg(4, "Trying to probe image formats.\n");
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1651 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
1652 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1653 optInFormat = FFMT_IMAGE;
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1654 optInSubFormat = index;
463
4204e9ea8ae1 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
1655 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
1656 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1657 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1658
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1659 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
1660 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1661 dmError("No input format specified, and could not be determined automatically.\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1662 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
1663 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1664
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1665 // 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
1666 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
1667 {
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1668 int res = dmGetErrno();
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1669 dmError("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
1670 optInSkip, optInSkip, dmErrorStr(res));
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1671 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1672 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1673
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1674 int inFormat = dmGetConvFormat(optInFormat, optInSubFormat),
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1675 outFormat = dmGetConvFormat(optOutFormat, optOutSubFormat);
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1676
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1677 if (inFormat != -1 && outFormat != -1)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1678 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1679 char *inFmtName = convFormatList[inFormat].name,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1680 *inFmtExt = convFormatList[inFormat].fext,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1681 *outFmtName = convFormatList[outFormat].name,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1682 *outFmtExt = convFormatList[outFormat].fext;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1683
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1684 if (optInFormat == FFMT_BITMAP)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1685 inFmtExt = cfmt->name;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1686
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1687 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
1688 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
1689 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1690
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1691 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
1692 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1693 case FFMT_SPRITE:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1694 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
1695 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
1696 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1697
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1698 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
1699 {
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1700 DMImage *outImage = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1701 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
1702
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1703 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
1704 {
810
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1705 dmError("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
1706 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1707 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1708
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1709 switch (optOutFormat)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1710 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1711 case FFMT_IMAGE:
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 911
diff changeset
1712 res = dmC64ConvertBMP2Image(&outImage, cimage, cfmt, FALSE);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1713
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1714 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
1715 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1716 dmError("Error in bitmap to image conversion.\n");
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1717 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1718 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1719
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1720 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
1721 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1722
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1723
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1724 case FFMT_BITMAP:
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 911
diff changeset
1725 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
1726 break;
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1727
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1728 case FFMT_CHAR:
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1729 case FFMT_SPRITE:
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 911
diff changeset
1730 res = dmC64ConvertBMP2Image(&outImage, cimage, cfmt, TRUE);
810
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1731
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1732 if (res != DMERR_OK || outImage == NULL)
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1733 {
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1734 dmError("Error in bitmap to template image conversion.\n");
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1735 goto error;
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1736 }
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1737
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1738 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
1739 break;
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1740
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1741 default:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1742 dmError("Unsupported output format for bitmap/image conversion.\n");
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1743 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1744 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1745
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1746 dmImageFree(outImage);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1747 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1748 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1749
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1750 case FFMT_IMAGE:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1751 {
441
2a4de5fe4003 Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1752 DMImage *outImage = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1753 int res = DMERR_OK;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1754
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1755 if (optOutFilename == NULL)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1756 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1757 dmError("Output filename not set, required for image formats.\n");
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1758 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
1759 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1760
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1761 // 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
1762 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
1763 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
1764 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
1765 else
2a4de5fe4003 Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1766 dmError("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
1767
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1768 if (res != DMERR_OK || outImage == NULL)
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1769 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
1770
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1771 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
1772 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1773 case FFMT_IMAGE:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1774 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
1775 break;
417
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1776
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1777 case FFMT_CHAR:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1778 case FFMT_SPRITE:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1779 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
1780 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1781
417
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1782 default:
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1783 dmError("Unsupported output format for bitmap/image conversion.\n");
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1784 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
1785 }
806
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1786
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1787 if (res != DMERR_OK)
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1788 {
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1789 dmError("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n",
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1790 dmErrorStr(res));
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1791 }
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1792
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1793 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
1794 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1795 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1796 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1797
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1798 error:
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1799 if (inFile != NULL)
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1800 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
1801
466
0bfa6a15bb46 Plug (non-dangerous) memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
1802 dmFree(dataBuf);
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1803 dmC64ImageFree(cimage);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1804
933
8fe48c08dbca Fix some memory leaks etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
1805 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
1806 }