annotate tools/gfxconv.c @ 818:a6452b575c63

Add some online documentation.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 16 May 2014 20:07:38 +0300
parents 5753d7f24106
children 0177d4a66d48
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * gfxconv - Convert various graphics formats
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Programmed and designed by Matti 'ccr' Hamalainen
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * (C) Copyright 2012 Tecnic Software productions (TNSP)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 *
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Please read file 'COPYING' for information on license and distribution.
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 */
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #include "dmlib.h"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 #include "dmargs.h"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "dmfile.h"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include "dmmutex.h"
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
12 #include "libgfx.h"
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #include "lib64gfx.h"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 //#define UNFINISHED 1
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
17 #define DM_MAX_COLORS 256
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
18
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
19 #define ASC_NBITS 8
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
20 #define ASC_NCOLORS 4
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
21 static const char dmASCIIPalette[ASC_NCOLORS] = ".:X#";
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
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
39 typedef struct
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
40 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
41 char *name;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
42 char *fext;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
43 BOOL in, out;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
44 int format;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
45 int subformat;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
46 } DMConvFormat;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
47
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 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
50 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
51 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
52 "ASCII text", "asc", FALSE, TRUE,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
53 FFMT_ASCII , 0,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
54 },
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 "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
57 FFMT_ANSI , 0,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
58 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
59 {
454
2f820412d356 Mark PNG as available input format.
Matti Hamalainen <ccr@tnsp.org>
parents: 446
diff changeset
60 "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
61 FFMT_IMAGE , IMGFMT_PNG,
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 "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
65 FFMT_IMAGE , IMGFMT_PPM,
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 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
68 "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
69 FFMT_IMAGE , IMGFMT_PCX,
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 {
443
f7c9d1619c74 Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents: 441
diff changeset
72 "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
73 FFMT_IMAGE , IMGFMT_ILBM,
f7c9d1619c74 Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents: 441
diff changeset
74 },
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
75 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
76 "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
77 FFMT_IMAGE , IMGFMT_RAW,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
78 },
443
f7c9d1619c74 Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents: 441
diff changeset
79 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
80 "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
81 FFMT_IMAGE , IMGFMT_ARAW,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
82 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
83
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
84 {
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
85 "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
86 FFMT_BITMAP , -1,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
87 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
88
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
89 {
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
90 "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
91 FFMT_CHAR , 0
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
92 },
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
93 {
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
94 "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
95 FFMT_SPRITE , 0
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
96 },
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
99 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
100
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
102 typedef struct
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
103 {
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
104 BOOL triplet, alpha;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
105 DMColor color;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
106 int from, to;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
107 } DMMapValue;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
108
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 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
112 *optOutFilename = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
113 int optInFormat = FFMT_AUTO,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
114 optOutFormat = FFMT_ASCII,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
115 optInSubFormat = IMGFMT_PNG,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
116 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
117 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
118 optPlanedWidth = 1,
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
119 optForcedFormat = -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
120 int optInSkip = 0;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 BOOL optInMulticolor = FALSE,
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
122 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
123 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
124 optRemapRemove = FALSE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
125 int optNRemapTable = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
126 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
127 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
128
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
129 DMImageSpec optSpec =
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
130 {
457
9a5ceedf0972 Set default scaling to 1.
Matti Hamalainen <ccr@tnsp.org>
parents: 456
diff changeset
131 .scale = 1,
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
132 .nplanes = 4,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
133 .interleave = FALSE,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
134 .paletted = FALSE,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
135 .format = 0,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
136 };
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138 static DMOptArg optList[] =
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139 {
431
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
140 { 0, '?', "help", "Show this help", OPT_NONE },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
141 { 15, 'v', "verbose", "Increase verbosity", OPT_NONE },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
142 { 3, 'o', "output", "Output filename", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
143 { 1, 'i', "informat", "Set input format ([s]prite, [c]har, [b]itmap, [i]mage)", OPT_ARGREQ },
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
144 { 2, 'm', "multicolor", "Input is multicolor / output in multicolor", OPT_NONE },
431
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
145 { 4, 's', "skip", "Skip bytes in input", OPT_ARGREQ },
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
146 { 5, 'f', "format", "Output format (see --formats)", OPT_ARGREQ },
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
147 { 17, 'F', "formats", "Output format (see list below)", OPT_NONE },
431
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
148 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
149 { 6, 'c', "colormap", "Color mappings (see below for information)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
150 { 7, 'n', "numitems", "How many 'items' to view (default: all)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
151 { 9, 'S', "scale", "Scale output by x (image output only)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
152 { 10, 'b', "bformat", "Force input bitmap format (see below)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
153 { 11, 'w', "width", "Item width (number of items per row, min 1)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
154 { 12, 'P', "paletted", "Use indexed/paletted output (png, pcx output only)", OPT_NONE },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
155 { 13, 'B', "bplanes", "Bits per pixel OR # of bitplanes (certain output formats)", OPT_ARGREQ },
e3ebcbc4ace2 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 430
diff changeset
156 { 14, 'I', "interleave", "Interleave scanlines (default: output whole planes)", OPT_NONE },
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
157 { 16, 'R', "remap", "Remap output image colors (-R <(#RRGGBB|index):index>[,<..>] | -R @map.txt)", OPT_ARGREQ },
480
d7fc7e011c90 Oops, the option help had \n. Fixed.
Matti Hamalainen <ccr@tnsp.org>
parents: 479
diff changeset
158 { 18, 'r', "remap-remove", "Remove unused colors from remapped palette (requires -R)", OPT_NONE },
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 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
162
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
164 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
165 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 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
167
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
168 printf(
432
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
169 "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
170 " 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
171 "------+---+---+-----------------------------------------------\n"
432
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
172 );
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
173
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
174 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
175 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
176 DMConvFormat *fmt = &convFormatList[i];
432
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
177 printf("%-5s | %c | %c | %s\n",
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
178 fmt->fext ? fmt->fext : "",
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
179 fmt->in ? 'X' : ' ',
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
180 fmt->out ? 'X' : ' ',
b583a682f12d Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents: 431
diff changeset
181 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
182 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
184 printf(
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
185 "\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
186 "(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
187 "\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
188 "Available bitmap formats:\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
189 " Ext | Type | Description\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
190 "------+-----------------+-------------------------------------\n"
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
191 );
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
192
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193 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
194 {
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
195 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
196 char buf[64];
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
197 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
198 fmt->fext,
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
199 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
200 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
201 }
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
202 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
203
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
204
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
205 void argShowHelp()
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
206 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
207 dmPrintBanner(stdout, dmProgName, "[options] <input file>");
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
208 dmArgsPrintHelp(stdout, optList, optListN);
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 printf(
818
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
211 "Palette / color remapping (-R)\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
212 "------------------------------\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
213 "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
214 "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
215 "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
216 "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
217 "-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
218 "\n"
818
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
219 "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
220 "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
221 "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
222 "\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
223 "Color map defs\n"
a6452b575c63 Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents: 814
diff changeset
224 "--------------\n"
456
20122cffde2f Clarify help.
Matti Hamalainen <ccr@tnsp.org>
parents: 455
diff changeset
225 "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
226 "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
227 "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
228 "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
229 "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
230 "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
231 "special color that can be used for transparency.\n"
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 );
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
236 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
237 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
238 int i;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
239 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
240 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
241 DMConvFormat *fmt = &convFormatList[i];
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
242 if (fmt->format == format &&
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
243 fmt->subformat == subformat)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
244 return i;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
245 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
246 return -1;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
247 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
248
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
249
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
250 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
251 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
252 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
253 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
254 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
255
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
256 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
257 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
258 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
259 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
260 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
261 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
262 *format = fmt->format;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
263 *subformat = fmt->subformat;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
264 return TRUE;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
265 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
266 }
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
267
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
268 for (i = 0; i < ndmC64ImageFormats; i++)
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
269 {
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
270 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
271 if (fmt->fext != NULL &&
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
272 strcasecmp(fext, fmt->fext) == 0)
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
273 {
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
274 *format = FFMT_BITMAP;
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
275 *subformat = i;
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
276 return TRUE;
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
277 }
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
278 }
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
279
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
280 return FALSE;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
281 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
282
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
283
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
284 static BOOL dmParseMapOptionMapItem(const char *popt, DMMapValue *value, const int nmax, const char *msg)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
285 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
286 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
287
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
288 if (opt == NULL)
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
289 goto error;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
290
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
291 if ((end = split = strchr(opt, ':')) == NULL)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
292 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
293 dmError("Invalid %s value '%s', expected <(#|%)RRGGBB|[$|0x]index>:<[$|0x]index>.\n", msg, opt);
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
294 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
295 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
296
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
297 // Trim whitespace
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
298 *end = 0;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
299 for (end--; end > opt && *end && isspace(*end); end--)
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
300 *end = 0;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
301
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
302 // 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
303 if (*opt == '#' || *opt == '%')
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
304 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
305 int colR, colG, colB, colA;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
306
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
307 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
308 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
309 {
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
310 value->alpha = TRUE;
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
311 value->color.a = colA;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
312 }
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
313 else
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
314 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
315 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
316 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
317 dmError("Invalid %s value '%s', expected a hex triplet, got '%s'.\n", msg, popt, opt + 1);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
318 goto error;
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
319 }
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
320
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
321 value->color.r = colR;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
322 value->color.g = colG;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
323 value->color.b = colB;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
324 value->triplet = TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
325 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
326 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
327 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
328 if (!dmGetIntVal(opt, &value->from))
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 dmError("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
331 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
332 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
333 value->triplet = FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
334 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
335
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
336 // Trim whitespace
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
337 split++;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
338 while (*split && isspace(*split)) split++;
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
339
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
340 // Parse destination value
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
341 if (!dmGetIntVal(split, &value->to))
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
342 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
343 dmError("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
344 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
345 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
346
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
347 if (!value->triplet && (value->from < 0 || value->from > 255))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
348 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
349 dmError("Invalid %s map source color index value %d, must be [0..255].\n", msg, value->from);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
350 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
351 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
352
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
353 if (value->to < 0 || value->to > nmax)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
354 {
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
355 dmError("Invalid %s map destination color index value %d, must be [0..%d].\n", msg, value->to, nmax);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
356 goto error;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
357 }
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
358
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
359 dmFree(opt);
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
360 return TRUE;
481
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
361
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
362 error:
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
363 dmFree(opt);
c3f0fca5b596 Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents: 480
diff changeset
364 return FALSE;
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
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
367
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
368 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
369 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
370 // Trim whitespace
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
371 if (end != NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
372 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
373 *end = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
374 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
375 *end = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
376 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
377 while (*opt && isspace(*opt)) opt++;
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 // Parse item based on mode
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
380 if (requireIndex)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
381 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
382 DMMapValue *value = (DMMapValue *) pvalue;
475
c0dedfef3edf Fix option parsing of mappings.
Matti Hamalainen <ccr@tnsp.org>
parents: 474
diff changeset
383 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
384 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
385 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
386 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
387 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
388 int *value = (int *) pvalue;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
389 char *split = strchr(opt, ':');
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
390 if (split != NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
391 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
392 dmError("Unexpected ':' in indexed %s '%s'.\n", msg, opt);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
393 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
394 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
395
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
396 if (!dmGetIntVal(opt, &value[index]))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
397 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
398 dmError("Invalid %s value '%s', could not parse.\n", msg, opt);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
399 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
400 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
401 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
402
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
403 return TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
404 }
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
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
407 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
408 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
409 char *end, *start = opt;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
410
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
411 *nvalues = 0;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
412 while (*nvalues < nmax && *start && (end = strchr(start, ',')) != NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
413 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
414 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
415 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
416
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
417 start = end + 1;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
418 (*nvalues)++;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
419 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
420
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
421 if (*start && *nvalues < nmax)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
422 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
423 if (!dmParseMapOptionItem(start, NULL, values, *nvalues, nmax, requireIndex, msg))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
424 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
425
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
426 (*nvalues)++;
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 return TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
430 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
431
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
432
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
433 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
434 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
435 FILE *fp;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
436 char line[512];
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
437 int res = DMERR_OK;
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 if ((fp = fopen(filename, "r")) == NULL)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
440 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
441 res = dmGetErrno();
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
442 dmError("Could not open color remap file '%s' for reading, %d: %s\n",
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
443 res, dmErrorStr(res));
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
444 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
445 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
446
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
447 while (fgets(line, sizeof(line), fp))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
448 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
449 char *start = line;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
450 while (*start && isspace(*start)) start++;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
451
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
452 if (*start != 0 && *start != ';')
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
453 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
454 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
455 goto error;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
456 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
457 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
458 (*nvalue)++;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
459 if (*nvalue >= nmax)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
460 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
461 dmError("Too many mapping pairs in '%s', maximum is %d.\n",
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
462 filename, nmax);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
463 goto error;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
464 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
465 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
466 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
467 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
468
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
469 error:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
470 fclose(fp);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
471 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
472 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
474
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
475 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
476 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
477 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
478 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
479 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
480 argShowHelp();
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
481 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
482 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
483
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
484 case 17:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
485 argShowFormats();
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
486 exit(0);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
487 break;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
488
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
489 case 15:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
490 dmVerbosity++;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
491 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
492
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
493 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
494 switch (tolower(optArg[0]))
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
495 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
496 case 's':
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
497 optInFormat = 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
498 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
499 case 'c':
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
500 optInFormat = 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
501 break;
416
238e6baf01a8 Add bitmap and image input selectors to -i option.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
502 case 'b':
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
503 optInFormat = FFMT_BITMAP;
416
238e6baf01a8 Add bitmap and image input selectors to -i option.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
504 break;
238e6baf01a8 Add bitmap and image input selectors to -i option.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
505 case 'i':
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
506 optInFormat = FFMT_IMAGE;
416
238e6baf01a8 Add bitmap and image input selectors to -i option.
Matti Hamalainen <ccr@tnsp.org>
parents: 415
diff changeset
507 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
508 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 dmError("Invalid input format '%s'.\n", optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 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
511 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 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
515 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
516 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
518 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
519 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
520 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
522 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
523 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
524 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
525 dmError("Invalid skip value argument '%s'.\n", optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
526 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
527 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
528 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
529
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
530 case 5:
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
531 if (!dmGetFormatByExt(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
532 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
533 dmError("Invalid output format '%s'.\n", optArg);
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
534 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
535 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
536 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
537
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
538 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
539 {
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
540 int index, ncolors;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
541 if (!dmParseMapOptionString(optArg, optColors,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
542 &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
543 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
544
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
545 dmMsg(1, "Set color table: ");
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
546 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
547 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
548 dmPrint(1, "[%d:%d]%s",
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
549 index, optColors[index],
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
550 (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
551 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
552 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
553 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
554 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
555
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
556 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
557 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
558 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
559 dmError("Invalid count value argument '%s'.\n", optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
560 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
561 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
562 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
563
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
564 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
565 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
566 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
567
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
568 case 9:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
569 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
570 int tmp = atoi(optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
571 if (tmp < 1 || tmp > 50)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
572 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
573 dmError("Invalid scale value '%s'.\n", optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
574 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
575 }
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
576 optSpec.scale = tmp;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
577 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
578 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
579
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
580 case 11:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
581 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
582 int tmp = atoi(optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
583 if (tmp < 1 || tmp > 512)
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 dmError("Invalid width value '%s'.\n", optArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
586 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
587 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
588 optPlanedWidth = tmp;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
589 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
590 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
591
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
592 case 12:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
593 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
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
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
596 case 13:
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
597 {
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
598 int tmp = atoi(optArg);
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
599 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
600 {
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
601 dmError("Invalid bitplanes/bpp value '%s'.\n", optArg);
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
602 return FALSE;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
603 }
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
604 optSpec.nplanes = tmp;
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
605 }
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
606 break;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
607
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
608 case 14:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
609 optSpec.interleave = TRUE;
415
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
610 break;
d94f4bcb4be3 IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents: 409
diff changeset
611
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
612
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
613 case 16:
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
614 if (optArg[0] == '@')
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
615 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
616 if (optArg[1] != 0)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
617 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
618 int res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
619 if ((res = dmParseColorRemapFile(optArg + 1,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
620 optRemapTable, &optNRemapTable, DM_MAX_COLORS)) != DMERR_OK)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
621 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
622 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
623 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
624 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
625 dmError("No remap filename given.\n");
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
626 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
627 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
628 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
629 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
630 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
631 if (!dmParseMapOptionString(optArg, optRemapTable,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
632 &optNRemapTable, DM_MAX_COLORS, TRUE, "color remap option"))
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
633 return FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
634 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
635
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
636 optRemapColors = TRUE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
637 break;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
638
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
639 case 18:
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
640 optRemapRemove = 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
641 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
642
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
643 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
644 dmError("Unknown option '%s'.\n", currArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
645 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
648 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
649 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
650
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
651
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
652 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
653 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
654 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
655 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
656 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
657 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
658 dmError("Source filename already specified, extraneous argument '%s'.\n",
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
659 currArg);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
660 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
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
663 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
664 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
665
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
666
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
667 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
668 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
669 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
670
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
671 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
672 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
673 for (i = ASC_NBITS; i; 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
674 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
675 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
676 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
677 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
678 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
679 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
680 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
681 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
682 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
683 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
684 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
685 0x1b,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
686 1,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
687 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
688 0x1b);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
689 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
690 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
691 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
692 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
693 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
694 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
695 for (i = ASC_NBITS; i; i--)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
696 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
697 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
698 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
699 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
700 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
701 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
702 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
703 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
704 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
705 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
706 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
707 0x1b,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
708 1,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
709 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
710 0x1b);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
711 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
712 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
713 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
714 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
715 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
716
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
717
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
718 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
719 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
720 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
721
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
722 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
723 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
724 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
725 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
726 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
727 (*offs)++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
728 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
729 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
730
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
731
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
732 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
733 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
734 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
735
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
736 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
737 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
738 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
739 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
740 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
741 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
742 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
743 bufOffs++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
744 (*offs)++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
745 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
746 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
747 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748 (*offs)++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
751
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
752 #ifdef UNFINISHED
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
753 int dmConvertBMP2(DMImage *screen, const DM64Image *img)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755 int yc;
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
756 Uint8 *dp = screen->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
757
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
758 for (yc = 0; yc < screen->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
759 {
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
760 Uint8 *d = dp;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
761 const int y = yc / 8, yb = yc & 7;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
762 const int scroffsy = y * C64_SCR_CH_WIDTH;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
763 const int bmoffsy = y * C64_SCR_WIDTH;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
764 int xc;
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 for (xc = 0; xc < screen->width / 2; xc++)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
767 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
768 const int x = xc / 4;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
769 const int scroffs = scroffsy + x;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
770 const int b = img->bitmap[0][bmoffsy + (x * 8) + yb];
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
771 const int v = 6 - ((xc * 2) & 6);
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
772 Uint8 c;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
773
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
774 switch ((b >> v) & 3)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
775 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
776 case 0: c = img->bgcolor; break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
777 case 1: c = img->screen[0][scroffs] >> 4; break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
778 case 2: c = img->screen[0][scroffs] & 15; break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
779 case 3: c = img->color[0][scroffs] & 15; break;
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 *d++ = c;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
783 *d++ = c;
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 dp += screen->pitch;
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
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
789 return 0;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
790 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
791 #endif
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
792
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
793
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
794 int dmRemapImageColors(DMImage *image)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
795 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
796 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
797 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
798 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
799 BOOL *used = dmMalloc(image->ncolors * sizeof(BOOL));
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
800 int n, index, xc, yc, ncolors;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
801
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
802 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
803
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
804 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
805 {
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
806 dmError("Could not allocate memory for reused palette.\n");
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
807 return DMERR_MALLOC;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
808 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
809
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
810 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
811 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
812 mapping[index] = -1;
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
813 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
814 }
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
815
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
816 // 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
817 dmMsg(2, "Scanning image for used colors...\n");
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
818 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
819 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
820 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
821 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
822 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
823 Uint8 col = dp[xc];
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
824 if (col < image->ncolors && !used[col])
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
825 {
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
826 used[col] = TRUE;
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
827 ncolors++;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
828 }
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
829 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
830 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
831 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
832
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
833 // Match and mark mapped colors
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
834 for (index = 0; index < optNRemapTable; index++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
835 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
836 DMMapValue *map = &optRemapTable[index];
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
837 if (map->triplet)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
838 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
839 BOOL found = FALSE;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
840 for (n = 0; n < image->ncolors; n++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
841 {
474
95d1facfdb77 Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents: 473
diff changeset
842 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
843 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
844 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
845 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
846 n,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
847 map->to);
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
848
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
849 mapping[n] = map->to;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
850 mapped[map->to] = TRUE;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
851 found = TRUE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
852 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
853 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
854
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
855 if (!found)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
856 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
857 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
858 index,
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
859 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
860 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
861 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
862 else
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
863 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
864 dmMsg(3, "Map index: %d -> %d\n",
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
865 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
866
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
867 mapping[map->from] = map->to;
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
868 mapped[map->to] = TRUE;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
869 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
870 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
871
473
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 // 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
874 if (optRemapRemove)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
875 {
479
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
876 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
877 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
878 if (mapping[index] < 0 && used[index])
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
879 {
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
880 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
881 if (!mapped[n])
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
882 {
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
883 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
884 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
885 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
886 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
887 }
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 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
890 {
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 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
892 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
893 {
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 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
895 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
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 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
898 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
899 break;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
900 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
901 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
902 }
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
903
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
904 // 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
905 ncolors = 0;
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
906 for (index = 0; index < image->ncolors; index++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
907 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
908 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
909 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
910 }
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
911
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
912 // Copy palette entries
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
913 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
914 {
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
915 if (mapping[index] >= 0)
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
916 {
482
6fdee3ec2894 Improve remapping.
Matti Hamalainen <ccr@tnsp.org>
parents: 481
diff changeset
917 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
918 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
919 }
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 // 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
922 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
923 for (yc = 0; yc < image->height; yc++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
924 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
925 Uint8 *dp = image->data + image->pitch * yc;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
926 for (xc = 0; xc < image->width; xc++)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
927 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
928 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
929 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
930 dp[xc] = mapping[col];
478
7c7a57590236 Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents: 477
diff changeset
931 else
7c7a57590236 Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents: 477
diff changeset
932 dp[xc] = 0;
473
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 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
935
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
936 // Set new palette, free memory
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
937 dmFree(image->pal);
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
938 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
939 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
940
b768bfb0b364 Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 478
diff changeset
941 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
942 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
943 dmFree(used);
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
944 return DMERR_OK;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
945 }
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
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
948 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
949 {
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
950 FILE *outFile = NULL;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
951 Uint8 *buf = NULL;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
952 size_t bufSize;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
953 int res = DMERR_OK;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
954 const DMC64ImageFormat *fmt = &dmC64ImageFormats[iformat];
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
955
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
956 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
957 if (image->type != fmt->type && enableFixUps)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
958 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
959 // Try to do some simple fixups
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
960 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
961 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
962 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
963 int i;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
964 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
965 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
966 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
967 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
968 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
969 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
970 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
971
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
972
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
973 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
974 goto error;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
975
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
976 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
977
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
978 if ((outFile = fopen(filename, "wb")) == NULL)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
979 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
980 res = dmGetErrno();
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
981 dmError("Error opening output file '%s', %d: %s\n",
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
982 filename, res, dmErrorStr(res));
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
983 goto error;
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
984 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
985
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
986 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
987 {
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
988 res = dmGetErrno();
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
989 dmError("Error writing image data to '%s', %d: %s\n",
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
990 filename, res, dmErrorStr(res));
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
991 }
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
992
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
993 error:
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
994 if (outFile != NULL)
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
995 fclose(outFile);
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
996 dmFree(buf);
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
997 return res;
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
998 }
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
999
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1000
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1001 int dmWriteImage(const char *filename, DMImage *image, DMImageSpec *spec, int iformat, BOOL info)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1002 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1003 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
1004 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1005 dmMsg(1, "Outputting %s image %d x %d -> %d x %d [%d]\n",
446
a6d0e101cd16 Oops, correct the use of dmImageFormatList[] entry pointer to entry.fext.
Matti Hamalainen <ccr@tnsp.org>
parents: 443
diff changeset
1006 dmImageFormatList[iformat].fext,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1007 image->width, image->height,
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1008 image->width * spec->scale, image->height * spec->scale,
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1009 spec->scale);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1010 }
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1011
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1012 // Perform color remapping
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1013 if (optRemapColors)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1014 {
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1015 int res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1016 if ((res = dmRemapImageColors(image)) != DMERR_OK)
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1017 return res;
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1018 }
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1019
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1020 switch (iformat)
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1021 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1022 #ifdef DM_USE_LIBPNG
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1023 case IMGFMT_PNG:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1024 if (info) dmMsg(2, "%s output.\n", spec->paletted ? "Indexed 8bpp" : "32bit RGBA");
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1025 spec->format = spec->paletted ? DM_IFMT_PALETTE : DM_IFMT_RGBA;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1026 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
1027 #endif
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1028
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1029 case IMGFMT_PPM:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1030 if (info) dmMsg(2, "24bit RGB output.\n");
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1031 spec->format = DM_IFMT_RGB;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1032 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
1033
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1034 case IMGFMT_PCX:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1035 if (info) dmMsg(2, "%s output.\n", spec->paletted ? "Indexed 8bpp" : "24bit RGB");
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1036 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
1037
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1038 case IMGFMT_RAW:
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1039 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
1040 {
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1041 FILE *fp;
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1042 char *dataFilename, *fext, *tmpFilename = dm_strdup(filename);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1043
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1044 // Form data file filename
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1045 if (tmpFilename == NULL)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1046 return DMERR_MALLOC;
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1047
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1048 fext = strrchr(tmpFilename, '.');
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1049 if (fext != NULL)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1050 *fext = 0;
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1051 dataFilename = dm_strdup_printf("%s.inc", tmpFilename);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1052 dmFree(tmpFilename);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1053
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1054 // Open data file for writing
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1055 if ((fp = fopen(dataFilename, "w")) == NULL)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1056 dmError("Could not create '%s'.\n", dataFilename);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1057 dmFree(dataFilename);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1058
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1059 if (fp != NULL)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1060 {
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1061 // Strip extension
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1062 int i;
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1063 char *palID = dm_strdup_printf("img_%s", filename);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1064 char *fext = strrchr(palID, '.');
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1065 if (fext != NULL)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1066 *fext = 0;
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1067
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1068 // Replace any non-alphanumerics
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1069 for (i = 0; palID[i]; i++)
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1070 {
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1071 if (isalnum(palID[i]))
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1072 palID[i] = tolower(palID[i]);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1073 else
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1074 palID[i] = '_';
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1075 }
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1076
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1077 if (iformat == IMGFMT_ARAW)
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1078 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1079 fprintf(fp,
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1080 "%s_width: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1081 "%s_height: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1082 "%s_nplanes: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1083 "%s_ncolors: dw.w %d\n"
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1084 "%s_palette:\n",
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1085 palID, image->width,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1086 palID, image->height,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1087 palID, spec->nplanes,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1088 palID, image->ncolors,
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1089 palID);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1090
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1091 dmWriteIFFMasterRAWPalette(fp, image, 1 << optSpec.nplanes, NULL, NULL);
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1092
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1093 fprintf(fp,
477
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1094 "%s: incbin \"%s\"\n",
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1095 palID, filename);
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1096 }
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1097 else
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1098 {
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1099 fprintf(fp,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1100 "%s_width: dw.w %d\n"
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1101 "%s_height: dw.w %d\n"
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1102 "%s_nplanes: dw.w %d\n",
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1103 palID, image->width,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1104 palID, image->height,
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1105 palID, spec->nplanes);
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1106 }
477
0fd0e301b6fc Add incbin line for ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 476
diff changeset
1107
462
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1108 fclose(fp);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1109 dmFree(palID);
ab401a5087f9 Improve ARAW output.
Matti Hamalainen <ccr@tnsp.org>
parents: 460
diff changeset
1110 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1111
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1112 if (info) dmMsg(2, "%d bitplanes, %s interleave.\n", spec->nplanes, spec->interleave ? "with" : "without");
566
d400e32b62d9 Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents: 557
diff changeset
1113 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
1114 }
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1115 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
1116
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1117 default:
473
73bfe73553eb Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents: 471
diff changeset
1118 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
1119 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1120 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1121
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1122
547
ca5ad51c6479 Make dmConvertByte() static.
Matti Hamalainen <ccr@tnsp.org>
parents: 546
diff changeset
1123 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
1124 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1125 Uint8 byte = 0;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1126 int xc;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1127
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1128 if (multicolor)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1129 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1130 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
1131 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1132 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
1133 byte |= pixel << (6 - (xc * 2));
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1134 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1135 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1136 else
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1137 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1138 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
1139 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1140 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
1141 byte |= pixel << (7 - xc);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1142 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1143 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1144
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1145 return byte;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1146 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1147
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1148
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1149 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
1150 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
1151 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1152 int yc;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1153
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1154 if (xoffs < 0 || yoffs < 0 ||
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1155 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
1156 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
1157 return FALSE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1158
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1159 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
1160 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1161 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
1162 buf[yc] = dmConvertByte(sp, multicolor);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1163 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1164
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1165 return TRUE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1166 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1167
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1168
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1169 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
1170 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
1171 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1172 int yc, xc;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1173
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1174 if (xoffs < 0 || yoffs < 0 ||
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1175 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
1176 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
1177 return FALSE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1178
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1179 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
1180 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1181 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
1182 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1183 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
1184 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
1185 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1186 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1187
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1188 return TRUE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1189 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1190
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1191
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1192 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
1193 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1194 int outBlockW, outBlockH, bx, by;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1195 FILE *outFile = NULL;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1196 Uint8 *buf = NULL;
546
e74a0e027681 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
1197 size_t bufSize;
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1198 char *outType;
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 switch (outFormat)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1201 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1202 case FFMT_CHAR:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1203 bufSize = C64_CHR_SIZE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1204 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
1205 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
1206 outType = "char";
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1207 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1208
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1209 case FFMT_SPRITE:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1210 bufSize = C64_SPR_SIZE;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1211 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
1212 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
1213 outType = "sprite";
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1214 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1215
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1216 default:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1217 dmError("Invalid output format %d, internal error.\n", outFormat);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1218 goto error;
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
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1221 if (outBlockW <= 0 || outBlockH <= 0)
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 dmError("Source image dimensions too small for conversion, block dimensions %d x %d.\n",
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1224 outBlockW, outBlockH);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1225 goto error;
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
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1228 if ((outFile = fopen(filename, "wb")) == NULL)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1229 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1230 int err = dmGetErrno();
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1231 dmError("Could not open '%s' for writing, %d: %s.\n",
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1232 filename, err, dmErrorStr(err));
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1233 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1234 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1235
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1236 if ((buf = dmMalloc(bufSize)) == NULL)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1237 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1238 dmError("Could not allocate %d bytes for conversion buffer.\n",
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1239 bufSize);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1240 goto error;
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 dmMsg(1, "Writing %d x %d = %d blocks of %s data...\n",
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1244 outBlockW, outBlockH, outBlockW * outBlockH, outType);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1245
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1246 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
1247 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
1248 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1249 switch (outFormat)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1250 {
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1251 case FFMT_CHAR:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1252 if (!dmConvertImage2Char(buf, image,
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1253 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
1254 multicolor))
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1255 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1256 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1257
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1258 case FFMT_SPRITE:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1259 if (!dmConvertImage2Sprite(buf, image,
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1260 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
1261 multicolor))
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1262 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1263 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1264
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1265 if (!dm_fwrite_str(outFile, buf, bufSize))
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 err = dmGetErrno();
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1268 dmError("Error writing data block %d,%d to '%s', %d: %s\n",
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1269 bx, by, filename, err, dmErrorStr(err));
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1270 goto error;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1271 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1272 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1273
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1274 fclose(outFile);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1275 dmFree(buf);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1276 return 0;
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 error:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1279 if (outFile != NULL)
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1280 fclose(outFile);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1281 dmFree(buf);
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1282 return -1;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1283 }
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1284
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1285
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1286 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
1287 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1288 int dataOffs, itemCount, outWidth, outWidthPX, outHeight;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1289 size_t bufSize;
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1290 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
1291
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1292 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
1293 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1294 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
1295 bufSize = C64_CHR_SIZE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1296 outWidth = C64_CHR_WIDTH;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1297 outWidthPX = C64_CHR_WIDTH_PX;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1298 outHeight = C64_CHR_HEIGHT;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1299 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1300
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1301 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
1302 bufSize = C64_SPR_SIZE;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1303 outWidth = C64_SPR_WIDTH;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1304 outWidthPX = C64_SPR_WIDTH_PX;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1305 outHeight = C64_SPR_HEIGHT;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1306 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1307
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1308 default:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1309 dmError("Invalid input format %d, internal error.\n", optInFormat);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1310 return -1;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1311 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1312
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1313 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
1314 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1315 dmError("Could not allocate temporary buffer of %d bytes.\n", bufSize);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1316 return -2;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1317 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1318
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1319
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1320 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
1321 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
1322
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1323 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
1324 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1325 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
1326 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
1327
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1328 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
1329 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
1330 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1331 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
1332 {
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1333 int res = dmGetErrno();
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1334 dmError("Error opening output file '%s', %d: %s\n",
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1335 optOutFilename, res, dmErrorStr(res));
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1336 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
1337 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1338
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1339 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
1340 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1341 memset(bufData, 0, bufSize);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1342
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1343 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
1344 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1345 dmError("Could not read full bufferful (%d bytes) of data at 0x%x.\n",
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1346 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
1347 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
1348 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1349
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1350 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
1351
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1352 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
1353 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1354 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
1355 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
1356 break;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1357 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
1358 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
1359 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1360 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1361 itemCount++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1362 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1363
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1364 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
1365 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1366 else
423
11b3adb3bdb1 Fix image format output.
Matti Hamalainen <ccr@tnsp.org>
parents: 422
diff changeset
1367 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
1368 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1369 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
1370 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
1371 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
1372
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1373 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
1374 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1375 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
1376 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1377 dmError("Sequential image output requires filename template.\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1378 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
1379 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1380
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1381 outImage = dmImageAlloc(outWidthPX, outHeight);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1382 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
1383 optItemCount,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1384 outImage->width, outImage->height,
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1385 outImage->width * optSpec.scale, outImage->height * optSpec.scale);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1386 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1387 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1388 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1389 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
1390 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
1391 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1392 dmError("Single-image output requires count to be set (-n).\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1393 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
1394 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1395
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1396 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
1397 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
1398 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
1399 outIHeight++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1400
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1401 outImage = dmImageAlloc(outWidthPX * outIWidth, outIHeight * outHeight);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1402 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1403
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1404 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
1405 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
1406 outImage->ncolors = C64_NCOLORS;
460
0af039b6c0ae Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 457
diff changeset
1407 outImage->ctransp = 255;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1408
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1409 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
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 memset(bufData, 0, bufSize);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1412
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1413 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
1414 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1415 dmError("Could not read full bufferful (%d bytes) of data at 0x%x.\n",
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1416 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
1417 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1418 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1419
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1420 if ((err = dmC64ConvertCSData(outImage, outX * outWidthPX, outY * outHeight,
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1421 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
1422 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1423 dmError("Internal error in conversion of raw data to bitmap: %d.\n", err);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1424 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1425 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1426
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1427 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
1428 {
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1429 int eres;
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1430
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1431 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
1432 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
1433 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1434 dmError("Could not allocate memory for filename template?\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1435 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
1436 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1437
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1438 eres = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1439 if (eres != DMERR_OK)
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1440 {
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1441 dmError("Error writing output image, %s.\n",
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1442 dmErrorStr(eres));
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1443 }
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1444
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1445 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
1446 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1447 else
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 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
1450 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1451 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
1452 outY++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1453 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1454 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1455
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1456 itemCount++;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1457 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1458
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 {
799
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1461 int eres = dmWriteImage(optOutFilename, outImage, &optSpec, optOutSubFormat, TRUE);
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1462 if (eres != DMERR_OK)
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1463 {
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1464 dmError("Error writing output image, %s.\n",
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1465 dmErrorStr(eres));
5ec451795ab2 Add some error checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 652
diff changeset
1466 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1467 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1468
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1469 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
1470 }
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1471 else
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1472 if (optOutFormat == FFMT_BITMAP)
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1473 {
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1474 if (optSequential)
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1475 {
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1476 dmError("Sequential output not supported for spr/char -> bitmap conversion.\n");
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1477 goto error;
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1478 }
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1479 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1480
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1481 dmFree(bufData);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1482 return 0;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1483
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1484 error:
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1485 dmFree(bufData);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1486 return -1;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1487 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1488
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 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
1491 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1492 FILE *inFile;
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1493 const DMC64ImageFormat *cfmt;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1494 DMC64Image cimage;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1495 Uint8 *dataBuf = NULL;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1496 size_t dataSize;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1497 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
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 // 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
1500 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
1501 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
1502
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1503 // Initialize and parse commandline
814
5753d7f24106 Bump version for gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
1504 dmInitProg("gfxconv", "Simple graphics converter", "0.80", NULL, NULL);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1505
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1506 if (!dmArgsProcess(argc, argv, optList, optListN,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1507 argHandleOpt, argHandleFile, TRUE))
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1508 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
1509
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1510 #ifndef DM_USE_LIBPNG
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1511 if (optOutFormat == IMGFMT_PNG)
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1512 {
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1513 dmError("PNG output format support not compiled in, sorry.\n");
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1514 goto error;
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1515 }
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1516 #endif
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1517
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1518 // 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
1519 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
1520 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1521 char *dext = strrchr(optInFilename, '.');
465
ffd5e730d313 Adjust verbosity levels.
Matti Hamalainen <ccr@tnsp.org>
parents: 463
diff changeset
1522 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
1523 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
1524 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1525 dmGetFormatByExt(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
1526 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1527 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1528
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1529 if (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
1530 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1531 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
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 dmError("Standard input cannot be used without specifying input format.\n");
492
5672dc238904 Add a note to default error message about using --help option.
Matti Hamalainen <ccr@tnsp.org>
parents: 490
diff changeset
1534 dmError("Perhaps you should try using --help\n");
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1535 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
1536 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1537 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
1538 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1539 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1540 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
1541 {
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1542 int res = dmGetErrno();
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1543 dmError("Error opening input file '%s', %d: %s\n",
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1544 optInFilename, res, dmErrorStr(res));
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1545 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
1546 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1547
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1548 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
1549 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1550
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1551 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
1552 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1553 // Probe for format
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
1554 const DMC64ImageFormat *forced = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1555 int res;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1556
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1557 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
1558 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1559 forced = &dmC64ImageFormats[optForcedFormat];
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1560 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
1561 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
1562 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1563
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1564 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
1565 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
1566 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1567 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
1568 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
1569 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1570
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1571 if (res == 0)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1572 optInFormat = FFMT_BITMAP;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1573 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1574
463
4204e9ea8ae1 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
1575 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
1576 {
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1577 DMImageFormat *ifmt = NULL;
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1578 int index;
465
ffd5e730d313 Adjust verbosity levels.
Matti Hamalainen <ccr@tnsp.org>
parents: 463
diff changeset
1579 dmMsg(4, "Trying to probe image formats.\n");
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1580 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
1581 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1582 optInFormat = FFMT_IMAGE;
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1583 optInSubFormat = index;
463
4204e9ea8ae1 Improve probing.
Matti Hamalainen <ccr@tnsp.org>
parents: 462
diff changeset
1584 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
1585 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1586 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1587
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1588 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
1589 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1590 dmError("No input format specified, and could not be determined automatically.\n");
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1591 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
1592 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1593
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1594 // 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
1595 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
1596 {
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1597 int res = dmGetErrno();
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1598 dmError("Could not seek to file position %d (0x%x): %s\n",
488
49f0ce2cc347 Error printing cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 487
diff changeset
1599 optInSkip, optInSkip, dmErrorStr(res));
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1600 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1601 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1602
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1603 int inFormat = dmGetConvFormat(optInFormat, optInSubFormat),
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1604 outFormat = dmGetConvFormat(optOutFormat, optOutSubFormat);
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1605
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1606 if (inFormat != -1 && outFormat != -1)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1607 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1608 char *inFmtName = convFormatList[inFormat].name,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1609 *inFmtExt = convFormatList[inFormat].fext,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1610 *outFmtName = convFormatList[outFormat].name,
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1611 *outFmtExt = convFormatList[outFormat].fext;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1612
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1613 if (optInFormat == FFMT_BITMAP)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1614 inFmtExt = cfmt->name;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1615
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1616 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
1617 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
1618 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1619
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1620 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
1621 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1622 case FFMT_SPRITE:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1623 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
1624 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
1625 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1626
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1627 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
1628 {
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1629 DMImage *outImage = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1630 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
1631
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1632 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
1633 {
810
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1634 dmError("Output filename not set, required for bitmap formats.\n");
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
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
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1638 switch (optOutFormat)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1639 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1640 case FFMT_IMAGE:
810
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1641 res = dmC64ConvertBMP2Image(&outImage, &cimage, cfmt, FALSE);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1642
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1643 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
1644 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1645 dmError("Error in bitmap to image conversion.\n");
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1646 goto error;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1647 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1648
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1649 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
1650 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1651
534
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1652
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1653 case FFMT_BITMAP:
550
12854cbd6fab Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents: 547
diff changeset
1654 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
1655 break;
fbfdc9e4fe2b Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents: 530
diff changeset
1656
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1657 case FFMT_CHAR:
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1658 case FFMT_SPRITE:
810
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1659 res = dmC64ConvertBMP2Image(&outImage, &cimage, cfmt, TRUE);
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1660
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1661 if (res != DMERR_OK || outImage == NULL)
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1662 {
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1663 dmError("Error in bitmap to template image conversion.\n");
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1664 goto error;
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1665 }
cbe263ad963c Some work on charset conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 806
diff changeset
1666
607
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1667 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
1668 break;
360b1ad83ed9 Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents: 566
diff changeset
1669
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1670 default:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1671 dmError("Unsupported output format for bitmap/image conversion.\n");
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1672 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1673 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1674
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1675 dmImageFree(outImage);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1676 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1677 break;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1678
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1679 case FFMT_IMAGE:
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1680 {
441
2a4de5fe4003 Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1681 DMImage *outImage = NULL;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1682 int res = DMERR_OK;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1683
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1684 if (optOutFilename == NULL)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1685 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1686 dmError("Output filename not set, required for image formats.\n");
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1687 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
1688 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1689
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1690 // 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
1691 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
1692 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
1693 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
1694 else
2a4de5fe4003 Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 435
diff changeset
1695 dmError("Unsupported input image format for bitmap/image conversion.\n");
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1696
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1697 if (res != DMERR_OK || outImage == NULL)
409
b529b7e8ff83 Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
1698 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
1699
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1700 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
1701 {
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1702 case FFMT_IMAGE:
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1703 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
1704 break;
417
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1705
489
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1706 case FFMT_CHAR:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1707 case FFMT_SPRITE:
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1708 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
1709 break;
fca3c240ccac Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 488
diff changeset
1710
417
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1711 default:
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1712 dmError("Unsupported output format for bitmap/image conversion.\n");
9ace8a5c58d9 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 416
diff changeset
1713 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
1714 }
806
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1715
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1716 if (res != DMERR_OK)
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1717 {
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1718 dmError("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n",
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1719 dmErrorStr(res));
1e4d88fbce19 Error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 799
diff changeset
1720 }
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1721
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 432
diff changeset
1722 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
1723 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1724 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1725 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1726
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1727 fclose(inFile);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1728
466
0bfa6a15bb46 Plug (non-dangerous) memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
1729 dmFree(dataBuf);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1730 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
1731 return 0;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1732
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1733 error:
466
0bfa6a15bb46 Plug (non-dangerous) memory leaks.
Matti Hamalainen <ccr@tnsp.org>
parents: 465
diff changeset
1734 dmFree(dataBuf);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1735 return -3;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 417
diff changeset
1736 exit(3);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1737 }