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