Mercurial > hg > dmlib
annotate tools/gfxconv.c @ 2539:c6ee41fd98dd
Bump copyright years.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 02 Jan 2021 11:42:17 +0200 |
parents | 78ece6187a7c |
children | acaf678a2129 |
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 |
2539 | 4 * (C) Copyright 2012-2021 Tecnic Software productions (TNSP) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
5 * |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * Please read file 'COPYING' for information on license and distribution. |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 */ |
1432
a9516570cc26
Improve build, so that we can build the tools and tests with minimal
Matti Hamalainen <ccr@tnsp.org>
parents:
1426
diff
changeset
|
8 #include "dmtool.h" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
9 #include "dmlib.h" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
10 #include "dmargs.h" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
11 #include "dmfile.h" |
435 | 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" |
2204
cbac4912992c
Add new module "lib64util", and move some functions there from lib64gfx
Matti Hamalainen <ccr@tnsp.org>
parents:
2201
diff
changeset
|
14 #include "lib64util.h" |
1433 | 15 #include "dmmutex.h" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
16 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
18 #define DM_MAX_COLORS 256 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
19 |
837 | 20 #define DM_ASC_NBITS 8 |
21 #define DM_ASC_NCOLORS 4 | |
22 static const char dmASCIIPalette[DM_ASC_NCOLORS] = ".:X#"; | |
23 | |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
24 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
25 enum |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
26 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
27 FFMT_AUTO = 0, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
28 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
29 FFMT_ASCII, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
30 FFMT_ANSI, |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
31 FFMT_BITMAP, |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
32 FFMT_CHAR, |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
33 FFMT_SPRITE, |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
34 |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
35 FFMT_IMAGE, |
2226
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
36 FFMT_DUMP, |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
37 FFMT_PALETTE, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
38 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
39 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
|
40 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
42 |
2022
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
43 enum |
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
44 { |
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
45 FCMP_NONE = 0, |
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
46 FCMP_BEST = 9 |
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
47 }; |
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
48 |
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
49 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
50 static const char *formatTypeList[FFMT_LAST] = |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
51 { |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
52 "AUTO", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
53 "ASCII text", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
54 "ANSI text", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
55 "C64 bitmap image", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
56 "C64 character/font data", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
57 "C64 sprite data", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
58 "Image", |
2360
8f015ef431a3
Add missing description string to formatTypeList[].
Matti Hamalainen <ccr@tnsp.org>
parents:
2359
diff
changeset
|
59 "CDump", |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
60 "Palette", |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
61 }; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
62 |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
63 |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
64 enum |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
65 { |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
66 CROP_NONE = 0, |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
67 CROP_AUTO, |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
68 CROP_SIZE, |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
69 }; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
70 |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
71 |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
72 enum |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
73 { |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
74 SCALE_SET, |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
75 SCALE_RELATIVE, |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
76 SCALE_AUTO, |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
77 }; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
78 |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
79 |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
80 enum |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
81 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
82 REMAP_NONE = 0, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
83 REMAP_AUTO, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
84 REMAP_MAPPED, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
85 }; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
86 |
2501 | 87 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
88 typedef struct |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
89 { |
1340 | 90 char *name; // Descriptive name of the format |
91 char *fext; // File extension | |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
92 int flags; // DM_FMT_* flags, see libgfx.h |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
93 int type; // Format type |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
94 int format; // Subformat identifier |
2103
78a9140f02b1
Improve help for spr/chr formats by listing the :mc and :sc flags at their
Matti Hamalainen <ccr@tnsp.org>
parents:
2100
diff
changeset
|
95 char *help; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
96 } DMConvFormat; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
97 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
98 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
99 static const DMConvFormat baseFormatList[] = |
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 { |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
101 { "ASCII text" , "asc" , DM_FMT_WR , FFMT_ASCII , 0 , NULL }, |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
102 { "ANSI colored text" , "ansi" , DM_FMT_WR , FFMT_ANSI , 0 , NULL }, |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
103 { "C64 bitmap image" , "bitmap", DM_FMT_RDWR , FFMT_BITMAP , -1 , NULL }, |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
104 { "C64 character/font data" , "chr" , DM_FMT_RDWR , FFMT_CHAR , 0 , " (chr:mc/chr:sc for multi/singlecolor)" }, |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
105 { "C64 sprite data" , "spr" , DM_FMT_RDWR , FFMT_SPRITE , 0 , " (spr:mc/spr:sc for multi/singlecolor)" }, |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
106 { "C64 bitmap image dump" , "dump" , DM_FMT_WR , FFMT_DUMP , 0 , NULL }, |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
107 { "Palette data" , "pal" , DM_FMT_RDWR , FFMT_PALETTE , -1 , 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
|
108 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
109 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
110 static const int nbaseFormatList = sizeof(baseFormatList) / sizeof(baseFormatList[0]); |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
111 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
112 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
113 static DMConvFormat *convFormatList = NULL; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
114 static int nconvFormatList = 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
|
115 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
116 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
117 typedef struct |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
118 { |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
119 BOOL triplet, alpha; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
120 DMColor color; |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
121 unsigned int from, to; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
122 } DMMapValue; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
123 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
124 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
125 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
126 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
|
127 *optOutFilename = NULL; |
837 | 128 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
129 int optInType = FFMT_AUTO, |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
130 optOutType = FFMT_AUTO, |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
131 optInFormat = -1, |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
132 optOutFormat = -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
|
133 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
|
134 optPlanedWidth = 1, |
2515
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
135 optForcedInSubFormat = -1, |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
136 optShowHelp = 0; |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
137 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
138 unsigned int optInSkip = 0; |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
139 BOOL optInSkipNeg = FALSE; |
838
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
140 |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
141 int optCropMode = CROP_NONE, |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
142 optCropX0, optCropY0, |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
143 optCropW, optCropH; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
144 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
145 BOOL optInMulticolor = FALSE, |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
146 optSequential = FALSE, |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
147 optRemapRemove = FALSE, |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
148 optRemapMatchAlpha = FALSE, |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
149 optUsePalette = FALSE; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
150 int optRemapMode = REMAP_NONE; |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
151 int optNRemapTable = 0, |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
152 optScaleMode = SCALE_AUTO; |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
153 float optRemapMaxDist = -1; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
154 int optRemapNoMatchColor = -1; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
155 DMMapValue optRemapTable[DM_MAX_COLORS]; |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
156 int optColorMap[D64_NCOLORS]; |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
157 char *optCharROMFilename = NULL; |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
158 DMC64Palette *optC64Palette = NULL; |
2214 | 159 char *optPaletteFile = NULL; |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
160 DMPalette *optPaletteData = NULL; |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
161 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
162 |
2156
e6ec7fad9ce2
Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
2155
diff
changeset
|
163 DMImageWriteSpec optSpec = |
435 | 164 { |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
165 .scaleX = 1, |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
166 .scaleY = 1, |
2099
dac89484f143
Fix nplanes and bpp in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2097
diff
changeset
|
167 .nplanes = 0, |
1288 | 168 .bpp = 8, |
1291 | 169 .planar = FALSE, |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
170 .pixfmt = 0, |
2022
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
171 .compression = FCMP_BEST, |
435 | 172 }; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
173 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
174 DMC64ImageConvSpec optC64Spec; |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
175 |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
176 |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
854
diff
changeset
|
177 static const DMOptArg optList[] = |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
178 { |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
179 { 0, '?', "help" , "Show this help", OPT_NONE }, |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
180 { 3, 0, "longhelp" , "Show a longer help", OPT_NONE }, |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
181 { 1, 0, "license" , "Print out this program's license agreement", OPT_NONE }, |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
182 { 2, 'v', "verbose" , "Be more verbose", OPT_NONE }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
183 |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
184 { 10, 'o', "output" , "Output filename", OPT_ARGREQ }, |
2505
9708182ea7f2
Improve the help texts / descriptions of few options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2504
diff
changeset
|
185 { 12, 's', "skip" , "Skip N bytes in input from start " |
9708182ea7f2
Improve the help texts / descriptions of few options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2504
diff
changeset
|
186 "(a negative value will be offset " |
9708182ea7f2
Improve the help texts / descriptions of few options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2504
diff
changeset
|
187 "from end of input data)", OPT_ARGREQ }, |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
188 { 14, 'i', "informat" , "Set input format (see --formats)", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
189 { 16, 'f', "format" , "Set output format (see --formats)", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
190 { 18, 'F', "formats" , "List supported input/output formats", OPT_NONE }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
191 { 20, 'q', "sequential" , "Output sequential files (image output only)", OPT_NONE }, |
2495
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
192 { 22, 'm', "colormap" , "Set color map definitions (see '-m help')", OPT_ARGREQ }, |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
193 { 24, 'n', "numitems" , "How many 'items' to output (default: all)", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
194 { 26, 'w', "width" , "Item width (number of items per row, min 1)", OPT_ARGREQ }, |
2505
9708182ea7f2
Improve the help texts / descriptions of few options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2504
diff
changeset
|
195 { 28, 'S', "scale" , "Scale output image (see '-S help')", OPT_ARGREQ }, |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
196 { 30, 'P', "paletted" , "Use indexed/paletted output IF possible.", OPT_NONE }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
197 { 32, 'N', "nplanes" , "# of bitplanes (some output formats)", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
198 { 34, 'B', "bpp" , "Bits per plane (some output formats)", OPT_ARGREQ }, |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
199 { 36, 'I', "interleave" , "Interleaved/planar output (some output formats)", OPT_NONE }, |
2505
9708182ea7f2
Improve the help texts / descriptions of few options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2504
diff
changeset
|
200 { 38, 'C', "compress" , "Use compression -C <0-9>, 0 = disable, default is 9. " |
9708182ea7f2
Improve the help texts / descriptions of few options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2504
diff
changeset
|
201 "(Not all formats support compression and the meaning " |
9708182ea7f2
Improve the help texts / descriptions of few options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2504
diff
changeset
|
202 "apart from 0 or >= 1 depends on the format.)", OPT_ARGREQ }, |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
203 { 42, 'R', "remap" , "Remap output image colors (see '-R help')", OPT_ARGREQ }, |
2413 | 204 { 44, 0, "char-rom" , "Set character ROM file to be used.", OPT_ARGREQ }, |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
205 { 46, 'p', "palette" , "Set palette to be used (see '-p help'). " |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
206 "For paletted image file input, this will replace the " |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
207 "image's original palette. Color remapping will not be " |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
208 "done unless -R option is also specified.", OPT_ARGREQ }, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
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 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
211 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
|
212 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
213 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
214 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
|
215 { |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
216 printf( |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
217 "Available input/output formats (-f <frmt>):\n" |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
218 " frmt | RW | Description\n" |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
219 "------+----+-------------------------------------------------------\n" |
432
b583a682f12d
Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
220 ); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
221 |
1532 | 222 for (int i = 0; i < nconvFormatList; i++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 { |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
224 const DMConvFormat *fmt = &convFormatList[i]; |
2103
78a9140f02b1
Improve help for spr/chr formats by listing the :mc and :sc flags at their
Matti Hamalainen <ccr@tnsp.org>
parents:
2100
diff
changeset
|
225 printf("%-6s| %c%c | %s%s\n", |
432
b583a682f12d
Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
226 fmt->fext ? fmt->fext : "", |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
227 (fmt->flags & DM_FMT_RD) ? 'R' : ' ', |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
228 (fmt->flags & DM_FMT_WR) ? 'W' : ' ', |
2103
78a9140f02b1
Improve help for spr/chr formats by listing the :mc and :sc flags at their
Matti Hamalainen <ccr@tnsp.org>
parents:
2100
diff
changeset
|
229 fmt->name, |
78a9140f02b1
Improve help for spr/chr formats by listing the :mc and :sc flags at their
Matti Hamalainen <ccr@tnsp.org>
parents:
2100
diff
changeset
|
230 fmt->help != NULL ? fmt->help : ""); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
231 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
232 |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
233 printf( |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
234 "\n" |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
235 "(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
|
236 "\n" |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
237 ); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
238 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
239 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
240 |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
241 void argShowHelp(void) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
242 { |
2442
07b02bb63191
Input file argument is optional for some cases, where stdin can be used.
Matti Hamalainen <ccr@tnsp.org>
parents:
2414
diff
changeset
|
243 dmPrintBanner(stdout, dmProgName, "[options] [<input file>]"); |
2402
b7cd5dd0b82e
Merge one more change from th-libs args processing.
Matti Hamalainen <ccr@tnsp.org>
parents:
2389
diff
changeset
|
244 dmArgsPrintHelp(stdout, optList, optListN, 0, 80 - 2); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 |
2236
57ccd949093f
Show the default chargen/character ROM file path in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2230
diff
changeset
|
246 fprintf(stdout, |
837 | 247 "\n" |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
248 "Default C64 character ROM file for this build is:\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
249 "%s\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
250 "\n", |
2236
57ccd949093f
Show the default chargen/character ROM file path in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2230
diff
changeset
|
251 DM_DEF_CHARGEN |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
252 ); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
253 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
255 |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
256 const char * argGetHelpTopic(const int opt) |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
257 { |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
258 switch (opt) |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
259 { |
2495
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
260 case 22: |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
261 return |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
262 "Color map definitions (-m)\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
263 "--------------------------\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
264 "Color map definitions are used for sprite/char data input (and ANSI text\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
265 "output), to set what colors of the C64 palette are used for each single\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
266 "color/multi color bit-combination.\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
267 "\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
268 "For example, if the input is multi color sprite or char, you can define\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
269 "colors like: -m 0,8,3,15 .. for hires/single color: -m 0,1\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
270 "\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
271 "The numbers are palette indexes, and the order is for bit(pair)-values\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
272 "00, 01, 10, 11 (multi color) and 0, 1 (single color).\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
273 "\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
274 "NOTICE! 255 is a special transparency color index; -m 255,2 would use\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
275 "transparency for '0' bits and and C64 color 2 for '1' bits.\n"; |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
276 |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
277 case 28: |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
278 return |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
279 "Output image scaling (-S)\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
280 "-------------------------\n" |
2495
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
281 "Scaling can be done in direct or relative mode with integer scale factors.\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
282 "\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
283 "'-S [*]<n>' sets both height and width scale factor to <n> directly or\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
284 " relative to the certain input format's default aspect/scale factors.\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
285 "\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
286 "'-S <W>:<H>[*<n>]' scales width by W*n and height H*n.\n" |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
287 " If <n> is not specified, it defaults to 1.\n"; |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
288 |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
289 case 42: |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
290 return |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
291 "Palette remapping (-R)\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
292 "----------------------\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
293 "Indexed palette color remapping can be performed via the '-R' option in\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
294 "several different ways:\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
295 "\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
296 " 1) '-R auto'\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
297 " will remap input image to a destination palette specified with the\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
298 " '-p' option (which may be a supported palette file, another paletted\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
299 " image file, or one of the internal gfxconv palettes, see '-p help')\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
300 "\n" |
2498
2e38e1512a22
Fix/clarify an explanation in '-R' option help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2497
diff
changeset
|
301 " Example: '-R auto+remove -p pepto' would remap the input image to the\n" |
2e38e1512a22
Fix/clarify an explanation in '-R' option help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2497
diff
changeset
|
302 " internal Pepto's C64 palette, removing any unused palette entries.\n" |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
303 "\n" |
2510
e1a71d9eaede
Some improvements/fixes to -R option help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2505
diff
changeset
|
304 " 2) '-R <#RRGGBBaa|index>:<index>[,<(#RRGGBBaa|index):<index>[,...]]'\n" |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
305 " can be used to specify single RGB(A) color quadruplets/triplets or\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
306 " palette indices to be remapped to destination palette indices. Any\n" |
2510
e1a71d9eaede
Some improvements/fixes to -R option help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2505
diff
changeset
|
307 " unspecified indices will be automatically mapped. Specifying alpha\n" |
e1a71d9eaede
Some improvements/fixes to -R option help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2505
diff
changeset
|
308 " channel is optional, and will require +alpha flag/modifier to be\n" |
e1a71d9eaede
Some improvements/fixes to -R option help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2505
diff
changeset
|
309 " enabled for comparisions to take alpha channel into account.\n" |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
310 "\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
311 " Example: '-R #000000:0,#ffffff:1' would map black and white to indices 0 and 1.\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
312 "\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
313 " 3) '-R @<filename>'\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
314 " can be used to specify a mapping file, which is a text file with one\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
315 " remap definition per line in same format as above. All empty lines and\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
316 " lines starting with a semicolor (;) will be ignored as comments. Also\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
317 " any extra whitespace separating items will be ignored as well.\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
318 "\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
319 "Optional modifier flags can be specified as well:\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
320 "\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
321 " +remove Remove all unused colors from the resulting palette.\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
322 "\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
323 " +alpha Enable alpha value matching in color comparisions.\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
324 " NOTE! This may result in unexpected behaviour.\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
325 "\n" |
2503
7b55c7b6a300
Clarify the help for -R sub-option "max=".
Matti Hamalainen <ccr@tnsp.org>
parents:
2502
diff
changeset
|
326 " +max=<f> Set the maximum color distance/delta acceptable for\n" |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
327 " matching colors. Default is -1, meaning closest possible\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
328 " that can be found even if the match is poor. Any value \n" |
2503
7b55c7b6a300
Clarify the help for -R sub-option "max=".
Matti Hamalainen <ccr@tnsp.org>
parents:
2502
diff
changeset
|
329 " above or equal to 0 will be considered strict limit, see\n" |
7b55c7b6a300
Clarify the help for -R sub-option "max=".
Matti Hamalainen <ccr@tnsp.org>
parents:
2502
diff
changeset
|
330 " the 'nomatch' modifier below.\n" |
7b55c7b6a300
Clarify the help for -R sub-option "max=".
Matti Hamalainen <ccr@tnsp.org>
parents:
2502
diff
changeset
|
331 " Range: -1, 0 .. 1.0\n" |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
332 "\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
333 " +nomatch=<n>\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
334 " If no acceptable match is found (see +max modifier)\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
335 " then use this (<n>) color index. This may have unexpected\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
336 " results with +remove modifier. The default value of 'n'\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
337 " is -1, which will result in error if no match is found.\n" |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
338 ""; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
339 |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
340 default: |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
341 return NULL; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
342 } |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
343 } |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
344 |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
345 |
2447 | 346 // |
347 // Replace filename extension based on format pattern. | |
348 // Usage: res = dm_strdup_fext(orig_filename, "foo_%s.cmp"); | |
349 // | |
2079
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
350 char *dm_strdup_fext(const char *filename, const char *fmt) |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
351 { |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
352 char *result, *tmp, *fext; |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
353 |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
354 if (filename == NULL || |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
355 (tmp = dm_strdup(filename)) == NULL) |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
356 return NULL; |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
357 |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
358 if ((fext = strrchr(tmp, '.')) != NULL) |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
359 { |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
360 char *fpath = strrchr(tmp, DM_DIR_SEPARATOR); |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
361 if (fpath == NULL || (fpath != NULL && fext > fpath)) |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
362 *fext = 0; |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
363 } |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
364 |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
365 result = dm_strdup_printf(fmt, tmp); |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
366 |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
367 dmFree(tmp); |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
368 |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
369 return result; |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
370 } |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
371 |
9b6027d51f76
Move dm_strdup_fext() and dm_basefilename() to gfxconv, as they are only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
2077
diff
changeset
|
372 |
1866
734234e7ca95
Add a comment about the imperfection of ANSI color output.
Matti Hamalainen <ccr@tnsp.org>
parents:
1865
diff
changeset
|
373 // |
734234e7ca95
Add a comment about the imperfection of ANSI color output.
Matti Hamalainen <ccr@tnsp.org>
parents:
1865
diff
changeset
|
374 // Return a "matching" ANSI colour code for given C64 palette index. |
734234e7ca95
Add a comment about the imperfection of ANSI color output.
Matti Hamalainen <ccr@tnsp.org>
parents:
1865
diff
changeset
|
375 // As the standard 16 ANSI colours are not exact match and some C64 |
734234e7ca95
Add a comment about the imperfection of ANSI color output.
Matti Hamalainen <ccr@tnsp.org>
parents:
1865
diff
changeset
|
376 // colours cant be represented, this is an imperfect conversion. |
734234e7ca95
Add a comment about the imperfection of ANSI color output.
Matti Hamalainen <ccr@tnsp.org>
parents:
1865
diff
changeset
|
377 // |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
378 const char *dmC64GetANSIFromC64Color(const int col) |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
379 { |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
380 switch (col) |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
381 { |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
382 case 0: return "0;30"; // Black |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
383 case 1: return "0;1;37"; // White |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
384 case 2: return "0;31"; // Red |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
385 case 3: return "0;36"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
386 case 4: return "0;35"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
387 case 5: return "0;32"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
388 case 6: return "0;34"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
389 case 7: return "0;1;33"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
390 case 8: return "0;33"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
391 case 9: return "0;31"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
392 case 10: return "0;1;31"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
393 case 11: return "0;1;30"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
394 case 12: return "0;1;30"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
395 case 13: return "0;1;32"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
396 case 14: return "0;1;34"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
397 case 15: return "0;37"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
398 |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
399 default: return "0"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
400 } |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
401 } |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
402 |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
403 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
404 BOOL dmGetConvFormat(const int type, const int format, DMConvFormat *pfmt) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
405 { |
1546 | 406 for (int i = 0; i < nconvFormatList; i++) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
407 { |
1546 | 408 const DMConvFormat *fmt = &convFormatList[i]; |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
409 if (fmt->type == type && |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
410 fmt->format == format) |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
411 { |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
412 memcpy(pfmt, fmt, sizeof(DMConvFormat)); |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
413 return TRUE; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
414 } |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
415 } |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
416 |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
417 for (int i = 0; i < nconvFormatList; i++) |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
418 { |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
419 const DMConvFormat *fmt = &convFormatList[i]; |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
420 if (fmt->type == type && type == FFMT_BITMAP) |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
421 { |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
422 const DMConvFormat *fmt = &convFormatList[i]; |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
423 const DMC64ImageFormat *cfmt = &dmC64ImageFormats[format]; |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
424 memcpy(pfmt, fmt, sizeof(DMConvFormat)); |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
425 pfmt->fext = cfmt->name; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
426 return TRUE; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
427 } |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
428 } |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
429 |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
430 return FALSE; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
431 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
432 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
433 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
434 BOOL dmGetC64FormatByExt(const char *fext, int *type, int *format) |
819
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
435 { |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
436 if (fext == NULL) |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
437 return FALSE; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
438 |
1569 | 439 for (int i = 0; i < ndmC64ImageFormats; i++) |
819
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
440 { |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
441 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
442 if (fmt->fext != NULL && |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
443 strcasecmp(fext, fmt->fext) == 0) |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
444 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
445 *type = FFMT_BITMAP; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
446 *format = i; |
819
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
447 return TRUE; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
448 } |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
449 } |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
450 |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
451 return FALSE; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
452 } |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
453 |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
454 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
455 BOOL dmGetFormatByExt(const char *fext, int *type, int *format) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
456 { |
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
|
457 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
|
458 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
|
459 |
1569 | 460 for (int i = 0; i < nconvFormatList; i++) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
461 { |
1546 | 462 const 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
|
463 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
|
464 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
|
465 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
466 *type = fmt->type; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
467 *format = fmt->format; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
468 return TRUE; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
469 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
470 } |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
471 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
472 return FALSE; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
473 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
474 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
475 |
2454
375da267d994
Un-staticize functions in the main program.
Matti Hamalainen <ccr@tnsp.org>
parents:
2453
diff
changeset
|
476 BOOL dmParseMapOptionMapItem(const char *popt, DMMapValue *value, const unsigned int nmax, const char *msg) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
477 { |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
478 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
|
479 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
480 if (opt == NULL) |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
481 goto out; |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
482 |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
483 if ((end = split = strchr(opt, ':')) == NULL) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
484 { |
2389
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
485 dmErrorMsg("Invalid %s value '%s', expected <(#|%%)RRGGBB|[$|0x]index>:<[$|0x]index>.\n", |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
486 msg, opt); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
487 goto out; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
488 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
489 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
490 // Trim whitespace |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
491 *end = 0; |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
492 for (end--; end > opt && *end && isspace(*end); end--) |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
493 *end = 0; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
494 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
495 // 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
|
496 if (*opt == '#' || *opt == '%') |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
497 { |
867 | 498 unsigned int colR, colG, colB, colA; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
499 |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
500 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
|
501 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
|
502 { |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
503 value->alpha = TRUE; |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
504 value->color.a = colA; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
505 } |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
506 else |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
507 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
|
508 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
|
509 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
510 dmErrorMsg("Invalid %s value '%s', expected a hex triplet, got '%s'.\n", msg, popt, opt + 1); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
511 goto out; |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
512 } |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
513 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
514 value->color.r = colR; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
515 value->color.g = colG; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
516 value->color.b = colB; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
517 value->triplet = TRUE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
518 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
519 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
520 { |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
521 if (!dmGetIntVal(opt, &value->from, NULL)) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
522 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
523 dmErrorMsg("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
524 goto out; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
525 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
526 value->triplet = FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
527 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
528 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
529 // Trim whitespace |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
530 split++; |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
531 while (*split && isspace(*split)) split++; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
532 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
533 // Parse destination value |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
534 if (!dmGetIntVal(split, &value->to, NULL)) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
535 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
536 dmErrorMsg("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
537 goto out; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
538 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
539 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
540 if (!value->triplet && value->from > 255) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
541 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
542 dmErrorMsg("Invalid %s map source color index value %d, must be [0..255].\n", msg, value->from); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
543 goto out; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
544 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
545 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
546 if (value->to > nmax) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
547 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
548 dmErrorMsg("Invalid %s map destination color index value %d, must be [0..%d].\n", msg, value->to, nmax); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
549 goto out; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
550 } |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
551 |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
552 dmFree(opt); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
553 return TRUE; |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
554 |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
555 out: |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
556 dmFree(opt); |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
557 return FALSE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
558 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
559 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
560 |
2454
375da267d994
Un-staticize functions in the main program.
Matti Hamalainen <ccr@tnsp.org>
parents:
2453
diff
changeset
|
561 BOOL dmParseMapOptionItem(char *opt, char *end, void *pvalue, const int index, const int nmax, const BOOL requireIndex, const char *msg) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
562 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
563 // Trim whitespace |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
564 if (end != NULL) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
565 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
566 *end = 0; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
567 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
|
568 *end = 0; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
569 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
570 while (*opt && isspace(*opt)) opt++; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
571 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
572 // Parse item based on mode |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
573 if (requireIndex) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
574 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
575 DMMapValue *value = (DMMapValue *) pvalue; |
475
c0dedfef3edf
Fix option parsing of mappings.
Matti Hamalainen <ccr@tnsp.org>
parents:
474
diff
changeset
|
576 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
|
577 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
578 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
579 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
580 { |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
581 unsigned int *value = (unsigned int *) pvalue; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
582 char *split = strchr(opt, ':'); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
583 if (split != NULL) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
584 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
585 dmErrorMsg("Unexpected ':' in indexed %s '%s'.\n", msg, opt); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
586 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
587 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
588 |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
589 if (!dmGetIntVal(opt, &value[index], NULL)) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
590 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
591 dmErrorMsg("Invalid %s value '%s', could not parse.\n", msg, opt); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
592 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
593 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
594 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
595 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
596 return TRUE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
597 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
598 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
599 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
600 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
|
601 { |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
602 char *start = opt; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
603 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
604 *nvalues = 0; |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
605 while (*start && *nvalues < nmax) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
606 { |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
607 char *end = strchr(start, ','); |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
608 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
609 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
|
610 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
611 |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
612 (*nvalues)++; |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
613 |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
614 if (!end) |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
615 break; |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
616 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
617 start = end + 1; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
618 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
619 |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
620 return TRUE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
621 } |
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 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
624 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
|
625 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
626 FILE *fp; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
627 char line[512]; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
628 int res = DMERR_OK; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
629 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
630 if ((fp = fopen(filename, "r")) == NULL) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
631 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
632 res = dmGetErrno(); |
2389
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
633 return dmError(res, "Could not open color remap file '%s' for reading: %s.\n", |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
634 filename, dmErrorStr(res)); |
473
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 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
637 while (fgets(line, sizeof(line), fp)) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
638 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
639 char *start = line; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
640 line[sizeof(line) - 1] = 0; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
641 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
642 while (*start && isspace(*start)) start++; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
643 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
644 if (*start != 0 && *start != ';') |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
645 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
646 if (!dmParseMapOptionMapItem(line, &values[*nvalue], nmax, "mapping file")) |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
647 goto out; |
2448
cd5805f392a9
Remove useless else and block.
Matti Hamalainen <ccr@tnsp.org>
parents:
2447
diff
changeset
|
648 |
cd5805f392a9
Remove useless else and block.
Matti Hamalainen <ccr@tnsp.org>
parents:
2447
diff
changeset
|
649 (*nvalue)++; |
cd5805f392a9
Remove useless else and block.
Matti Hamalainen <ccr@tnsp.org>
parents:
2447
diff
changeset
|
650 if (*nvalue >= nmax) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
651 { |
2448
cd5805f392a9
Remove useless else and block.
Matti Hamalainen <ccr@tnsp.org>
parents:
2447
diff
changeset
|
652 dmErrorMsg("Too many mapping pairs in '%s', maximum is %d.\n", |
cd5805f392a9
Remove useless else and block.
Matti Hamalainen <ccr@tnsp.org>
parents:
2447
diff
changeset
|
653 filename, nmax); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
654 goto out; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
655 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
656 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
657 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
658 |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
659 out: |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
660 fclose(fp); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
661 return res; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
662 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
663 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
664 |
1867
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
665 BOOL dmParseFormatOption(const char *msg1, const char *msg2, char *optArg, int *format, int *subFormat) |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
666 { |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
667 char *flags = strchr(optArg, ':'); |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
668 if (flags != NULL) |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
669 *flags++ = 0; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
670 |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
671 if (!dmGetFormatByExt(optArg, format, subFormat) && |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
672 !dmGetC64FormatByExt(optArg, format, subFormat)) |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
673 { |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
674 dmErrorMsg("Invalid %s format '%s', see -F / --formats for format list.\n", |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
675 msg1, optArg); |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
676 return FALSE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
677 } |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
678 |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
679 if (flags != NULL) |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
680 { |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
681 switch (*format) |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
682 { |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
683 case FFMT_SPRITE: |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
684 case FFMT_CHAR: |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
685 if (strcasecmp(flags, "mc") == 0) |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
686 optInMulticolor = TRUE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
687 else |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
688 if (strcasecmp(flags, "sc") == 0) |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
689 optInMulticolor = FALSE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
690 else |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
691 { |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
692 dmErrorMsg("Invalid %s format flags for sprite/char '%s', should be 'mc' or 'sc'.\n", |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
693 msg1, flags); |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
694 return FALSE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
695 } |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
696 break; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
697 |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
698 default: |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
699 dmErrorMsg("%s format '%s' does not support any flags ('%s').\n", |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
700 msg2, optArg, flags); |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
701 return FALSE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
702 } |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
703 } |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
704 |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
705 return TRUE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
706 } |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
707 |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
708 |
2491
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
709 char *dmParseValWithSep(char **arg, char *last, BOOL (*isok)(const int ch), const char *sep) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
710 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
711 char *ptr = *arg, *end, *start; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
712 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
713 // Skip any whitespace at start |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
714 while (*ptr != 0 && isspace(*ptr)) |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
715 ptr++; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
716 |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
717 start = ptr; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
718 |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
719 // Find next not-xdigit/separator |
2491
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
720 while (*ptr != 0 && (isok == NULL || isok(*ptr)) && |
2485
fce2ed3f681f
Change dmParseIntValWithSep() separator spec from char to char *, to specify
Matti Hamalainen <ccr@tnsp.org>
parents:
2484
diff
changeset
|
721 strchr(sep, *ptr) == NULL) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
722 ptr++; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
723 |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
724 end = ptr; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
725 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
726 // Skip whitespace again |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
727 while (*ptr != 0 && isspace(*ptr)) |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
728 ptr++; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
729 |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
730 // Return last character in "last" |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
731 *last = *ptr; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
732 |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
733 // Set end to NUL |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
734 *end = 0; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
735 |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
736 // And if last character is not NUL, move ptr |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
737 if (*last != 0) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
738 ptr++; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
739 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
740 *arg = ptr; |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
741 |
2491
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
742 return start; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
743 } |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
744 |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
745 |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
746 BOOL dmParseIntValTok(const int ch) |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
747 { |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
748 return isxdigit(ch) || ch == 'x' || ch == '$'; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
749 } |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
750 |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
751 |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
752 BOOL dmParseIntValWithSep(char **arg, unsigned int *value, char *last, const char *sep) |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
753 { |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
754 return dmGetIntVal(dmParseValWithSep(arg, last, dmParseIntValTok, sep), value, NULL); |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
755 } |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
756 |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
757 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
758 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
|
759 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
760 unsigned int tmpUInt; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
761 char *tmpStr; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
762 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
763 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
|
764 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
765 case 0: |
2515
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
766 optShowHelp = 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
|
767 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
768 |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
769 case 3: |
2515
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
770 optShowHelp = 2; |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
771 break; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
772 |
2410
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
773 case 1: |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
774 dmPrintLicense(stdout); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
775 exit(0); |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
776 break; |
bc05bcfc4598
Add a C file with the generic BSD license text and a function for
Matti Hamalainen <ccr@tnsp.org>
parents:
2408
diff
changeset
|
777 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
778 case 2: |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
779 dmVerbosity++; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
780 break; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
781 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
782 case 10: |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
783 optOutFilename = optArg; |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
784 break; |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
785 |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
786 case 12: |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
787 if (!dmGetIntVal(optArg, &optInSkip, &optInSkipNeg)) |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
788 { |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
789 dmErrorMsg("Invalid skip value argument '%s'.\n", optArg); |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
790 return FALSE; |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
791 } |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
792 break; |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
793 |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
794 case 14: |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
795 { |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
796 DMConvFormat fmt; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
797 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
798 if (!dmParseFormatOption("input", "Input", optArg, &optInType, &optForcedInSubFormat)) |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
799 return FALSE; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
800 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
801 dmGetConvFormat(optInType, optForcedInSubFormat, &fmt); |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
802 if ((fmt.flags & DM_FMT_RD) == 0) |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
803 { |
1870
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
804 dmErrorMsg("Invalid input format '%s', does not support reading.\n", |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
805 fmt.name); |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
806 return FALSE; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
807 } |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
808 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
809 break; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
810 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
811 case 16: |
1870
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
812 { |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
813 DMConvFormat fmt; |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
814 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
815 if (!dmParseFormatOption("output", "Output", optArg, &optOutType, &optOutFormat)) |
1870
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
816 return FALSE; |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
817 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
818 dmGetConvFormat(optOutType, optOutFormat, &fmt); |
1870
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
819 if ((fmt.flags & DM_FMT_WR) == 0) |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
820 { |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
821 dmErrorMsg("Invalid output format '%s', does not support writing.\n", |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
822 fmt.name); |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
823 return FALSE; |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
824 } |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
825 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
826 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
827 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
828 case 18: |
2515
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
829 optShowHelp = 3; |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
830 break; |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
831 |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
832 case 20: |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
833 optSequential = TRUE; |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
834 break; |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
835 |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
836 case 22: |
2495
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
837 if (strcasecmp(optArg, "help") == 0) |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
838 { |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
839 fprintf(stdout, "\n%s\n", argGetHelpTopic(optN)); |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
840 exit(0); |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
841 } |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
842 else |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
843 { |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
844 int ncolors; |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
845 if (!dmParseMapOptionString(optArg, optColorMap, |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
846 &ncolors, D64_NCOLORS, FALSE, "color index option")) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
847 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
|
848 |
2030 | 849 dmMsg(1, "Set color index mapping: "); |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
850 for (int 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
|
851 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
852 dmPrint(1, "[%d:%d]%s", |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
853 index, optColorMap[index], |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
854 (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
|
855 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
856 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
|
857 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
858 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
859 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
860 case 24: |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
861 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
862 tmpUInt < 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
|
863 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
864 dmErrorMsg("Invalid count value argument '%s' [1 .. MAXINT]\n", |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
865 optArg); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
866 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
|
867 } |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
868 optItemCount = tmpUInt; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
869 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
870 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
871 case 26: |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
872 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
873 tmpUInt < 1 || tmpUInt > 512) |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
874 { |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
875 dmErrorMsg("Invalid planed width value '%s' [1 .. 512]\n", |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
876 optArg); |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
877 return FALSE; |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
878 } |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
879 optPlanedWidth = tmpUInt; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
880 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
881 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
882 case 28: |
2495
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
883 if (strcasecmp(optArg, "help") == 0) |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
884 { |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
885 fprintf(stdout, "\n%s\n", argGetHelpTopic(optN)); |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
886 exit(0); |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
887 } |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
888 else |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
889 { |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
890 BOOL error = FALSE; |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
891 unsigned int tmpUInt2; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
892 char *tmpStr = dm_strdup(optArg), |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
893 *tmpOpt = tmpStr, sep; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
894 |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
895 // Check for "relative scale mode specifier |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
896 if (*tmpOpt == '*') |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
897 { |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
898 tmpOpt++; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
899 optScaleMode = SCALE_RELATIVE; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
900 } |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
901 else |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
902 optScaleMode = SCALE_SET; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
903 |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
904 // Parse the values |
2485
fce2ed3f681f
Change dmParseIntValWithSep() separator spec from char to char *, to specify
Matti Hamalainen <ccr@tnsp.org>
parents:
2484
diff
changeset
|
905 if (dmParseIntValWithSep(&tmpOpt, &tmpUInt, &sep, ":")) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
906 { |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
907 if (sep == ':' && |
2485
fce2ed3f681f
Change dmParseIntValWithSep() separator spec from char to char *, to specify
Matti Hamalainen <ccr@tnsp.org>
parents:
2484
diff
changeset
|
908 dmParseIntValWithSep(&tmpOpt, &tmpUInt2, &sep, "*")) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
909 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
910 optSpec.scaleX = tmpUInt; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
911 optSpec.scaleY = tmpUInt2; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
912 |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
913 if (sep == '*' && |
2496
6a6ed3eeded5
Fix parsing of some arguments to -S option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2495
diff
changeset
|
914 dmParseIntValWithSep(&tmpOpt, &tmpUInt, &sep, "")) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
915 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
916 optSpec.scaleX *= tmpUInt; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
917 optSpec.scaleY *= tmpUInt; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
918 } |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
919 error = (sep != 0); |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
920 } |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
921 else |
1890
ee95059b4c18
Oops, fix a blunder left in the refactored scale option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1889
diff
changeset
|
922 if (sep == 0) |
ee95059b4c18
Oops, fix a blunder left in the refactored scale option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1889
diff
changeset
|
923 { |
ee95059b4c18
Oops, fix a blunder left in the refactored scale option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1889
diff
changeset
|
924 optSpec.scaleX = optSpec.scaleY = tmpUInt; |
ee95059b4c18
Oops, fix a blunder left in the refactored scale option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1889
diff
changeset
|
925 } |
ee95059b4c18
Oops, fix a blunder left in the refactored scale option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1889
diff
changeset
|
926 else |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
927 error = TRUE; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
928 } |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
929 else |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
930 error = TRUE; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
931 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
932 dmFree(tmpStr); |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
933 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
934 if (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
|
935 { |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
936 dmErrorMsg( |
2496
6a6ed3eeded5
Fix parsing of some arguments to -S option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2495
diff
changeset
|
937 "Invalid scale option value '%s', should be [*]<n> or or <w>:<h>[*<n>].\n", |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
938 optArg); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
939 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
|
940 } |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
941 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
942 if (optSpec.scaleX < 1 || optSpec.scaleX > 50) |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
943 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
944 dmErrorMsg("Invalid X scale value %d.\n", optSpec.scaleX); |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
945 return FALSE; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
946 } |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
947 if (optSpec.scaleY < 1 || optSpec.scaleY > 50) |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
948 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
949 dmErrorMsg("Invalid Y scale value %d.\n", optSpec.scaleY); |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
950 return FALSE; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
951 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
952 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
953 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
954 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
955 case 30: |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
956 optUsePalette = 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
|
957 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
958 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
959 case 32: |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
960 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
961 tmpUInt < 1 || tmpUInt > 8) |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
962 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
963 dmErrorMsg("Invalid number of bitplanes value '%s' [1 .. 8]\n", |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
964 optArg); |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
965 return FALSE; |
1288 | 966 } |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
967 optSpec.nplanes = tmpUInt; |
1288 | 968 break; |
969 | |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
970 case 34: |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
971 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
972 tmpUInt < 1 || tmpUInt > 32) |
1288 | 973 { |
2144
0bb1d0ad178f
Fix bpp option description.
Matti Hamalainen <ccr@tnsp.org>
parents:
2143
diff
changeset
|
974 dmErrorMsg("Invalid number of bits per plane value '%s' [1 .. 32]\n", |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
975 optArg); |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
976 return FALSE; |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
977 } |
2099
dac89484f143
Fix nplanes and bpp in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2097
diff
changeset
|
978 optSpec.bpp = tmpUInt; |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
979 break; |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
980 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
981 case 36: |
1291 | 982 optSpec.planar = TRUE; |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
983 break; |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
984 |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
985 case 38: |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
986 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
987 tmpUInt > FCMP_BEST) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
988 { |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
989 dmErrorMsg("Invalid compression setting '%s' [%d .. %d]\n", |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
990 optArg, FCMP_NONE, FCMP_BEST); |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
991 return FALSE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
992 } |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
993 optSpec.compression = tmpUInt; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
994 break; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
995 |
2413 | 996 case 40: |
2488
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
997 if (strcasecmp(optArg, "auto") == 0) |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
998 { |
2488
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
999 optCropMode = CROP_AUTO; |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1000 } |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1001 else |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1002 { |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1003 unsigned int tx0, ty0, tx1, ty1; |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1004 char sep, modeSep = 0, *tmpTok, *tmpStr; |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1005 BOOL ok; |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1006 if ((tmpTok = tmpStr = dm_strdup(optArg)) == NULL) |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1007 { |
2488
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1008 dmErrorMsg("Could not allocate memory for temporary string.\n"); |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1009 return FALSE; |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1010 } |
2488
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1011 |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1012 // Check for 'x0:y0-x1:y1' pattern |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1013 ok = dmParseIntValWithSep(&tmpTok, &tx0, &sep, ":") && |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1014 sep == ':' && |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1015 dmParseIntValWithSep(&tmpTok, &ty0, &modeSep, ":-") && |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1016 (sep == ':' || sep == '-') && |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1017 dmParseIntValWithSep(&tmpTok, &tx1, &sep, ":") && |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1018 sep == ':' && |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1019 dmParseIntValWithSep(&tmpTok, &ty1, &sep, ""); |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1020 |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1021 dmFree(tmpStr); |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1022 |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1023 if (ok) |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1024 { |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1025 optCropMode = CROP_SIZE; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1026 optCropX0 = tx0; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1027 optCropY0 = ty0; |
2488
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1028 |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1029 if (modeSep == '-') |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1030 { |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1031 DM_SWAP_IF(unsigned int, tx0, tx1); |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1032 DM_SWAP_IF(unsigned int, ty0, ty1); |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1033 |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1034 optCropW = tx1 - tx0; |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1035 optCropH = ty1 - ty0; |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1036 |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1037 dmMsg(1, "Crop coordinates %d, %d - %d, %d [dim %d, %d]\n", |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1038 tx0, ty0, tx1, ty1, optCropW, optCropH); |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1039 } |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1040 else |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1041 { |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1042 optCropW = tx1; |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1043 optCropH = ty1; |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1044 |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1045 dmMsg(1, "Crop coordinates %d, %d - %d, %d [dim %d, %d]\n", |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1046 tx0, ty0, tx0 + tx1, ty0 + ty1, optCropW, optCropH); |
87c8be2bc8ba
Rework some option parsing to be more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
2487
diff
changeset
|
1047 } |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1048 } |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1049 else |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1050 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1051 dmErrorMsg("Invalid crop mode / argument '%s'.\n", optArg); |
854
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1052 return FALSE; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1053 } |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1054 } |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1055 break; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
1056 |
2413 | 1057 case 42: |
2495
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
1058 if (strcasecmp(optArg, "help") == 0) |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
1059 { |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
1060 fprintf(stdout, "\n%s\n", argGetHelpTopic(optN)); |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
1061 exit(0); |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
1062 } |
88c68a03c493
Add 'help' support to -m, -S and -R options.
Matti Hamalainen <ccr@tnsp.org>
parents:
2494
diff
changeset
|
1063 |
2492
1bd7387984ed
Add few comments to the -R sub-option parsing and remove dead code.
Matti Hamalainen <ccr@tnsp.org>
parents:
2491
diff
changeset
|
1064 // Check if any flags/sub-options are specified |
2491
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1065 if ((tmpStr = strchr(optArg, '+')) != NULL) |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1066 { |
2491
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1067 *tmpStr++ = 0; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1068 do |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1069 { |
2492
1bd7387984ed
Add few comments to the -R sub-option parsing and remove dead code.
Matti Hamalainen <ccr@tnsp.org>
parents:
2491
diff
changeset
|
1070 // Parse one sub-option |
1bd7387984ed
Add few comments to the -R sub-option parsing and remove dead code.
Matti Hamalainen <ccr@tnsp.org>
parents:
2491
diff
changeset
|
1071 char sep, *topt = dmParseValWithSep(&tmpStr, &sep, NULL, "+"); |
1bd7387984ed
Add few comments to the -R sub-option parsing and remove dead code.
Matti Hamalainen <ccr@tnsp.org>
parents:
2491
diff
changeset
|
1072 |
1bd7387984ed
Add few comments to the -R sub-option parsing and remove dead code.
Matti Hamalainen <ccr@tnsp.org>
parents:
2491
diff
changeset
|
1073 // Check what option we have |
2491
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1074 if (strcasecmp(topt, "remove") == 0) |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1075 optRemapRemove = TRUE; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1076 else |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1077 if (strcasecmp(topt, "alpha") == 0) |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1078 optRemapMatchAlpha = TRUE; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1079 else |
2494
fcaf2db0cd05
Remove dm_str(n)casecmp() functions, in favour of standard libc ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
2493
diff
changeset
|
1080 if (strncasecmp(topt, "max=", 4) == 0) |
2491
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1081 { |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1082 char *start = topt + 4, *end; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1083 optRemapMaxDist = strtof(start, &end); |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1084 |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1085 if (end == start) |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1086 { |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1087 dmErrorMsg("Invalid or missing value parameter for -R option flag: '%s'.\n", |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1088 topt); |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1089 return FALSE; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1090 } |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1091 } |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1092 else |
2494
fcaf2db0cd05
Remove dm_str(n)casecmp() functions, in favour of standard libc ones.
Matti Hamalainen <ccr@tnsp.org>
parents:
2493
diff
changeset
|
1093 if (strncasecmp(topt, "nomatch=", 8) == 0) |
2491
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1094 { |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1095 char *start = topt + 8, *end; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1096 optRemapNoMatchColor = strtol(start, &end, 10); |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1097 |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1098 if (end == start) |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1099 { |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1100 dmErrorMsg("Invalid or missing value parameter for -R option flag: '%s'.\n", |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1101 topt); |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1102 return FALSE; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1103 } |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1104 |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1105 if (optRemapNoMatchColor < -1 || optRemapNoMatchColor > 255) |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1106 { |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1107 dmErrorMsg("Invalid remap no-match color value %d. Should be [-1 .. 255].\n", |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1108 optRemapNoMatchColor); |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1109 return FALSE; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1110 } |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1111 } |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1112 else |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1113 { |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1114 dmErrorMsg("Unknown -R option flag '%s'.\n", topt); |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1115 return FALSE; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1116 } |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1117 } while (*tmpStr != 0); |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1118 } |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1119 |
2492
1bd7387984ed
Add few comments to the -R sub-option parsing and remove dead code.
Matti Hamalainen <ccr@tnsp.org>
parents:
2491
diff
changeset
|
1120 // Check which remap mode is being requested |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1121 if (strcasecmp(optArg, "auto") == 0) |
2022
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
1122 { |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1123 if (optRemapMode != REMAP_NONE && optRemapMode != REMAP_AUTO) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1124 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1125 dmErrorMsg("Remap mode already set to something else than 'auto'. You can only have one remapping mode.\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1126 return FALSE; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1127 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1128 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1129 optRemapMode = REMAP_AUTO; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1130 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1131 else |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1132 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1133 if (optRemapMode != REMAP_NONE && optRemapMode != REMAP_MAPPED) |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1134 { |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1135 dmErrorMsg("Remap mode already set to something else than 'mapped'. You can only have one remapping mode.\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1136 return FALSE; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1137 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1138 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1139 if (optArg[0] == '@') |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1140 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1141 if (optArg[1] != 0) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1142 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1143 int res; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1144 if ((res = dmParseColorRemapFile(optArg + 1, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1145 optRemapTable, &optNRemapTable, DM_MAX_COLORS)) != DMERR_OK) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1146 return FALSE; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1147 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1148 else |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1149 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1150 dmErrorMsg("No remap filename given.\n"); |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1151 return FALSE; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1152 } |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1153 } |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1154 else |
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1155 { |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1156 if (!dmParseMapOptionString(optArg, optRemapTable, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1157 &optNRemapTable, DM_MAX_COLORS, TRUE, "color remap option")) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1158 return FALSE; |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1159 } |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1160 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1161 optRemapMode = REMAP_MAPPED; |
2022
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
1162 } |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1163 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1164 if (optRemapMatchAlpha) |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1165 { |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1166 dmErrorMsg("WARNING: Palette alpha matching may have unexpected results.\n"); |
2408
60e119262c67
Option index re-ordering cleanup work.
Matti Hamalainen <ccr@tnsp.org>
parents:
2402
diff
changeset
|
1167 } |
2022
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
1168 break; |
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2021
diff
changeset
|
1169 |
2413 | 1170 case 44: |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
1171 optCharROMFilename = optArg; |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
1172 break; |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
1173 |
2413 | 1174 case 46: |
2214 | 1175 return argHandleC64PaletteOption(optArg, &optC64Palette, &optPaletteFile); |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
1176 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1177 default: |
2183
e3f0eaf23f4f
Change the error message for unimplemented option argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
2182
diff
changeset
|
1178 dmErrorMsg("Unimplemented option argument '%s'.\n", currArg); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1179 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
|
1180 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1181 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1182 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
|
1183 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1184 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1185 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1186 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
|
1187 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1188 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
|
1189 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
|
1190 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1191 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1192 dmErrorMsg("Source filename already specified, extraneous argument '%s'.\n", |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1193 currArg); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1194 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
|
1195 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1196 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1197 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
|
1198 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1199 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1200 |
2359
de570106b6cc
Add argument to dmPrintByte() for reversing the bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
2295
diff
changeset
|
1201 void dmPrintByte(FILE *out, const Uint8 byte, const int format, const BOOL multicolor, const BOOL dir) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1202 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1203 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
|
1204 { |
2359
de570106b6cc
Add argument to dmPrintByte() for reversing the bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
2295
diff
changeset
|
1205 for (int i = 0; i < DM_ASC_NBITS; i += 2) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1206 { |
2359
de570106b6cc
Add argument to dmPrintByte() for reversing the bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
2295
diff
changeset
|
1207 int k = dir ? i : (DM_ASC_NBITS - i - 1); |
de570106b6cc
Add argument to dmPrintByte() for reversing the bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
2295
diff
changeset
|
1208 Uint8 val = (byte & (3ULL << k)) >> k; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1209 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
|
1210 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
|
1211 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1212 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
|
1213 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
|
1214 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
|
1215 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1216 case FFMT_ANSI: |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1217 fprintf(out, "\x1b[%sm##\x1b[0m", |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1218 dmC64GetANSIFromC64Color(optColorMap[val])); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1219 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1220 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1221 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1222 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1223 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1224 { |
2359
de570106b6cc
Add argument to dmPrintByte() for reversing the bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
2295
diff
changeset
|
1225 for (int i = 0; i < DM_ASC_NBITS; 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
|
1226 { |
2359
de570106b6cc
Add argument to dmPrintByte() for reversing the bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
2295
diff
changeset
|
1227 int k = dir ? i : (DM_ASC_NBITS - i - 1); |
de570106b6cc
Add argument to dmPrintByte() for reversing the bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
2295
diff
changeset
|
1228 Uint8 val = (byte & (1ULL << k)) >> k; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1229 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
|
1230 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1231 case FFMT_ASCII: |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1232 fputc(val ? '#' : '.', out); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1233 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1234 case FFMT_ANSI: |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1235 fprintf(out, "\x1b[%sm#\x1b[0m", |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1236 dmC64GetANSIFromC64Color(optColorMap[val])); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1237 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1238 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1239 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1240 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1241 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1242 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1243 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1244 void dmDumpCharASCII(FILE *outFile, const Uint8 *buf, const size_t offs, const int fmt, const BOOL multicolor) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1245 { |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1246 for (size_t yc = 0; yc < D64_CHR_HEIGHT_UT; yc++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1247 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1248 fprintf(outFile, "%04" DM_PRIx_SIZE_T " : ", offs + yc); |
2359
de570106b6cc
Add argument to dmPrintByte() for reversing the bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
2295
diff
changeset
|
1249 dmPrintByte(outFile, buf[yc], fmt, multicolor, 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
|
1250 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
|
1251 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1252 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1253 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1254 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1255 void dmDumpSpriteASCII(FILE *outFile, const Uint8 *buf, const size_t offs, const int fmt, BOOL multicolor) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1256 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1257 size_t bufOffs, xc, yc; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1258 |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1259 for (bufOffs = yc = 0; yc < D64_SPR_HEIGHT_UT; yc++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1260 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1261 fprintf(outFile, "%04" DM_PRIx_SIZE_T " ", offs + bufOffs); |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1262 for (xc = 0; xc < D64_SPR_WIDTH_UT; xc++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1263 { |
2359
de570106b6cc
Add argument to dmPrintByte() for reversing the bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
2295
diff
changeset
|
1264 dmPrintByte(outFile, buf[bufOffs], fmt, multicolor, 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
|
1265 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
|
1266 bufOffs++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1267 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1268 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
|
1269 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1270 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1271 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1272 |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1273 // XXX TODO: we need to evaluate the color vector itself, not just the distance |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1274 float dmGetColorDist(const DMColor *c1, const DMColor *c2, const BOOL alpha) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1275 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1276 const float |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1277 dr = (c1->r - c2->r) / 255.0, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1278 dg = (c1->g - c2->g) / 255.0, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1279 db = (c1->b - c2->b) / 255.0; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1280 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1281 if (alpha) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1282 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1283 const float da = (c1->a - c2->a) / 255.0; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1284 return (dr * dr + dg * dg + db * db + da * da) / 4.0; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1285 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1286 else |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1287 return (dr * dr + dg * dg + db * db) / 3.0; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1288 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1289 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1290 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1291 int dmScanUsedColors(const DMImage *src, const BOOL warn, BOOL *used, int *nused) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1292 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1293 BOOL warned = FALSE; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1294 *nused = 0; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1295 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1296 if (src == NULL || used == NULL || nused == NULL) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1297 return DMERR_NULLPTR; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1298 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1299 if (src->pal == NULL || src->pixfmt != DM_PIXFMT_PALETTE) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1300 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1301 return dmError(DMERR_INVALID_DATA, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1302 "Source image is not paletted.\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1303 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1304 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1305 for (int index = 0; index < src->pal->ncolors; index++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1306 used[index] = FALSE; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1307 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1308 for (int yc = 0; yc < src->height; yc++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1309 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1310 const Uint8 *dp = src->data + src->pitch * yc; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1311 for (int xc = 0; xc < src->width; xc++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1312 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1313 Uint8 col = dp[xc]; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1314 if (col < src->pal->ncolors) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1315 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1316 if (!used[col]) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1317 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1318 used[col] = TRUE; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1319 (*nused)++; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1320 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1321 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1322 else |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1323 if (warn && !warned) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1324 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1325 dmErrorMsg("Image contains color indices that are out of bounds of the palette.\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1326 warned = TRUE; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1327 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1328 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1329 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1330 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1331 return DMERR_OK; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1332 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1333 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1334 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1335 int dmDoRemapImageColors(DMImage **pdst, const DMImage *src, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1336 const int *mapping, const DMPalette *dpal) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1337 { |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1338 DMImage *dst = NULL; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1339 int res = DMERR_OK; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1340 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1341 if (pdst == NULL || src == NULL || mapping == NULL) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1342 return DMERR_NULLPTR; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1343 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1344 // Allocate target image |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1345 if ((dst = *pdst = dmImageAlloc(src->width, src->height, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1346 src->pixfmt, -1)) == NULL) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1347 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1348 res = dmError(DMERR_MALLOC, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1349 "Could not allocate image for re-mapped data.\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1350 goto out; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1351 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1352 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1353 for (int yc = 0; yc < src->height; yc++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1354 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1355 Uint8 *sp = src->data + src->pitch * yc; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1356 Uint8 *dp = dst->data + dst->pitch * yc; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1357 for (int xc = 0; xc < src->width; xc++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1358 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1359 dp[xc] = mapping[sp[xc]]; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1360 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1361 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1362 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1363 if ((res = dmPaletteCopy(&dst->pal, dpal)) != DMERR_OK) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1364 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1365 dmErrorMsg("Error installing remapped palette to destination image: %s\n", |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1366 dmErrorStr(res)); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1367 goto out; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1368 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1369 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1370 out: |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1371 return res; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1372 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1373 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1374 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1375 int dmRemapImageColors(DMImage **pdst, const DMImage *src, |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1376 const DMPalette *dpal, |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1377 const float maxDist, const int noMatchColor, |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1378 const BOOL alpha, const BOOL removeUnused) |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1379 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1380 DMPalette *tpal = NULL; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1381 const DMPalette *ppal; |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1382 BOOL *used = NULL; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1383 int *mapping = NULL, *mapped = NULL; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1384 int res = DMERR_OK; |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1385 BOOL fail = FALSE; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1386 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1387 if (pdst == NULL || src == NULL || dpal == NULL) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1388 return DMERR_NULLPTR; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1389 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1390 if (src->pal == NULL || src->pixfmt != DM_PIXFMT_PALETTE) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1391 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1392 res = dmError(DMERR_INVALID_DATA, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1393 "Source image is not paletted.\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1394 goto out; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1395 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1396 |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1397 dmMsg(1, "Remapping image from %d to %d colors @ maxDist=", |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1398 src->pal->ncolors, |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1399 dpal->ncolors); |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1400 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1401 if (maxDist < 0) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1402 dmPrint(1, "auto"); |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1403 else |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1404 dmPrint(1, "%1.3f", maxDist); |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1405 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1406 dmPrint(1, ", %s, ", |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1407 alpha ? "match alpha" : "ignore alpha"); |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1408 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1409 if (noMatchColor < 0) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1410 dmPrint(1, "fail on 'no match'\n"); |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1411 else |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1412 dmPrint(1, "use color #%d if no match\n", noMatchColor); |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1413 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1414 // Allocate remapping tables |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1415 if ((mapped = dmMalloc0(src->pal->ncolors * sizeof(*mapped))) == NULL || |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1416 (used = dmMalloc0(src->pal->ncolors * sizeof(*used))) == NULL || |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1417 (mapping = dmMalloc(src->pal->ncolors * sizeof(*mapping))) == NULL) |
2449
ff639208aae6
Reorder few NULL checks to be earlier.
Matti Hamalainen <ccr@tnsp.org>
parents:
2448
diff
changeset
|
1418 { |
ff639208aae6
Reorder few NULL checks to be earlier.
Matti Hamalainen <ccr@tnsp.org>
parents:
2448
diff
changeset
|
1419 res = dmError(DMERR_MALLOC, |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1420 "Could not allocate memory for color remap tables.\n"); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
1421 goto out; |
2449
ff639208aae6
Reorder few NULL checks to be earlier.
Matti Hamalainen <ccr@tnsp.org>
parents:
2448
diff
changeset
|
1422 } |
ff639208aae6
Reorder few NULL checks to be earlier.
Matti Hamalainen <ccr@tnsp.org>
parents:
2448
diff
changeset
|
1423 |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1424 for (int index = 0; index < src->pal->ncolors; index++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1425 mapping[index] = -1; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1426 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1427 // Populate remap table |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1428 for (int sc = 0; sc < src->pal->ncolors; sc++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1429 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1430 // Check if we can find a match in destination palette dpal |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1431 float closestDist = 1000000, dist = 0; |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1432 int closestDC = -1; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1433 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1434 for (int dc = 0; dc < dpal->ncolors; dc++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1435 { |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1436 dist = dmGetColorDist(&src->pal->colors[sc], &dpal->colors[dc], alpha); |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1437 if (dist < closestDist) |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1438 { |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1439 closestDist = dist; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1440 closestDC = dc; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1441 } |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1442 } |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1443 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1444 // Did we find a close-enough match? |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1445 if (maxDist >= 0 && closestDist > maxDist) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1446 { |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1447 // No, either error out or use noMatchColor color index |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1448 if (noMatchColor < 0) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1449 { |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1450 DMColor *dcol = &dpal->colors[closestDC]; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1451 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1452 dmPrint(0, |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1453 "No match for source color #%d. Closest: #%d (%02x %02x %02x) [dist=%1.3f > %1.3f]\n", |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1454 sc, closestDC, dcol->r, dcol->g, dcol->b, |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1455 closestDist, maxDist); |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1456 fail = TRUE; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1457 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1458 else |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1459 { |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1460 closestDC = noMatchColor; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1461 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1462 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1463 else |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1464 { |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1465 DMColor *scol = &src->pal->colors[sc], |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1466 *dcol = &dpal->colors[closestDC]; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1467 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1468 dmPrint(3, "Palette match #%d (%02x %02x %02x) -> #%d (%02x %02x %02x) [dist=%1.3f]\n", |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1469 sc, scol->r, scol->g, scol->b, |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1470 closestDC, dcol->r, dcol->g, dcol->b, |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1471 closestDist); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1472 } |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1473 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1474 mapping[sc] = closestDC; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1475 } |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1476 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1477 if (fail) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1478 { |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1479 res = DMERR_INVALID_DATA; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1480 goto out; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1481 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1482 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1483 // Remove unused colors if requested |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1484 if (removeUnused) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1485 { |
2491
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1486 int nused; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1487 |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1488 if (noMatchColor >= 0) |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1489 { |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1490 dmErrorMsg("WARNING! Removing unused colors with 'no-match' color index set may have unintended results.\n"); |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1491 } |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1492 |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1493 // Get the actually used colors |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1494 if ((res = dmScanUsedColors(src, TRUE, used, &nused)) != DMERR_OK) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1495 goto out; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1496 |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1497 dmMsg(2, "Found %d used color indices.\n", nused); |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1498 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1499 // Remove duplicates from the mapped colour indices |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1500 for (int index = 0; index < src->pal->ncolors; index++) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1501 { |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1502 for (int n = 0; n < src->pal->ncolors; n++) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1503 if (n != index && |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1504 mapping[index] == mapping[n] && |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1505 used[n] && used[index]) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1506 { |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1507 used[n] = FALSE; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1508 } |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1509 } |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1510 |
2491
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1511 if (noMatchColor >= 0) |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1512 used[noMatchColor] = TRUE; |
ed2f56abda22
Implement parsing of -R option suboptions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2488
diff
changeset
|
1513 |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1514 // Re-count number of actually used indices |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1515 nused = 0; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1516 for (int index = 0; index < src->pal->ncolors; index++) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1517 if (used[index]) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1518 nused++; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1519 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1520 dmMsg(2, "After mapped dupe removal, %d color indices used.\n", nused); |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1521 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1522 if ((res = dmPaletteAlloc(&tpal, nused, -1)) != DMERR_OK) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1523 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1524 dmErrorMsg("Could not allocate memory for remap palette.\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1525 goto out; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1526 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1527 |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1528 // Copy colors from dpal to tpal, also mapping the reordered indices |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1529 nused = 0; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1530 for (int index = 0; index < src->pal->ncolors; index++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1531 if (used[index]) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1532 { |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1533 // Copy the color to tpal |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1534 memcpy(&tpal->colors[nused], &dpal->colors[mapping[index]], sizeof(DMColor)); |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1535 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1536 // Save current mapping to mapped[] |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1537 mapped[nused] = mapping[index]; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1538 |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1539 // Reorder the mapping |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1540 mapping[index] = nused; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1541 nused++; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1542 } |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1543 else |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1544 { |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1545 // "Unused" color, find matching mapping from mapped[] |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1546 for (int n = 0; n < nused; n++) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1547 if (mapping[index] == mapped[n]) |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1548 { |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1549 mapping[index] = n; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1550 break; |
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
1551 } |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1552 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1553 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1554 ppal = tpal; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1555 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1556 else |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1557 ppal = dpal; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1558 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1559 // Perform image data remapping |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1560 res = dmDoRemapImageColors(pdst, src, mapping, ppal); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1561 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1562 out: |
2484
79e3f824a2d0
Oops, use dmPaletteFree() instead of dmFree().
Matti Hamalainen <ccr@tnsp.org>
parents:
2483
diff
changeset
|
1563 dmPaletteFree(tpal); |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1564 dmFree(mapping); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1565 dmFree(mapped); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1566 dmFree(used); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1567 return res; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1568 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1569 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1570 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1571 int dmMapImageColors(DMImage **pdst, const DMImage *src, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1572 const DMMapValue *mapTable, const int nmapTable, |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1573 const float maxDist, const int noMatchColor, |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1574 const BOOL alpha, const BOOL removeUnused) |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1575 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1576 DMPalette *tpal = NULL; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1577 BOOL *mapped = NULL, *used = NULL; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1578 int *mapping = NULL; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1579 int nused, res = DMERR_OK; |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1580 BOOL fail = FALSE; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1581 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1582 if (pdst == NULL || src == NULL || mapTable == NULL) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1583 return DMERR_NULLPTR; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1584 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1585 if (src->pal == NULL || src->pixfmt != DM_PIXFMT_PALETTE) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1586 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1587 res = dmError(DMERR_INVALID_DATA, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1588 "Source image is not paletted.\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1589 goto out; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1590 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1591 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1592 // Allocate remapping tables |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1593 if ((mapped = dmMalloc(src->pal->ncolors * sizeof(*mapped))) == NULL || |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1594 (used = dmMalloc(src->pal->ncolors * sizeof(*used))) == NULL || |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1595 (mapping = dmMalloc(src->pal->ncolors * sizeof(*mapping))) == NULL) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1596 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1597 res = dmError(DMERR_MALLOC, |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1598 "Could not allocate memory for color remap tables.\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1599 goto out; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1600 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1601 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1602 for (int index = 0; index < src->pal->ncolors; index++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1603 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1604 mapping[index] = -1; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1605 mapped[index] = FALSE; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1606 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1607 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1608 if ((res = dmPaletteAlloc(&tpal, src->pal->ncolors, -1)) != DMERR_OK) |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1609 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1610 dmErrorMsg("Could not allocate memory for remap palette.\n"); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
1611 goto out; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1612 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1613 |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1614 dmMsg(1, "Remapping %d input image of %d colors, %s, ", |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1615 optNRemapTable, src->pal->ncolors, |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1616 alpha ? "match alpha" : "ignore alpha"); |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1617 |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1618 if (noMatchColor < 0) |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1619 dmPrint(1, "fail on 'no match'\n"); |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1620 else |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1621 dmPrint(1, "use color #%d if no match\n", noMatchColor); |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1622 |
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
|
1623 // Match and mark mapped colors |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1624 for (int index = 0; index < nmapTable; index++) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1625 { |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1626 const DMMapValue *map = &mapTable[index]; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1627 if (map->triplet) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1628 { |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1629 float closestDist = 1000000, dist = 0; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1630 int closestDC = -1; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1631 |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1632 for (int n = 0; n < src->pal->ncolors; n++) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1633 { |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1634 dist = dmGetColorDist(&src->pal->colors[n], &map->color, map->alpha && alpha); |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1635 if (dist < closestDist) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1636 { |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1637 closestDist = dist; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1638 closestDC = n; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1639 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1640 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1641 |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1642 // Did we find a close-enough match? |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1643 if (maxDist >= 0 && closestDist > maxDist) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1644 { |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1645 // No, either error out or use noMatchColor color index |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1646 if (noMatchColor < 0) |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1647 { |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1648 DMColor *dcol = &src->pal->colors[closestDC]; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1649 |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1650 dmMsg(3, "No RGBA match found for map index %d, #%02x%02x%02x%02x. Closest: #%d (#%02x%02x%02x%02x) [dist=%1.3f > %1.3f]\n", |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1651 index, map->color.r, map->color.g, map->color.b, map->color.a, |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1652 closestDC, dcol->r, dcol->g, dcol->b, dcol->a, closestDist, maxDist); |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1653 |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1654 fail = TRUE; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1655 } |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1656 else |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1657 { |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1658 DMColor *dcol = &src->pal->colors[noMatchColor]; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1659 closestDC = noMatchColor; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1660 |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1661 dmMsg(3, "RGBA noMatch #%02x%02x%02x%02x: #%d -> #%d #%02x%02x%02x%02x [dist=%1.3f]\n", |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1662 map->color.r, map->color.g, map->color.b, map->color.a, |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1663 map->to, |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1664 closestDC, dcol->r, dcol->g, dcol->b, dcol->a, closestDist); |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1665 |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1666 mapping[closestDC] = map->to; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1667 mapped[map->to] = TRUE; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1668 } |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1669 } |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1670 else |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1671 { |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1672 DMColor *dcol = &src->pal->colors[closestDC]; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1673 |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1674 dmMsg(3, "RGBA match #%02x%02x%02x%02x: #%d -> #%d #%02x%02x%02x%02x [dist=%1.3f]\n", |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1675 map->color.r, map->color.g, map->color.b, map->color.a, |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1676 map->to, |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1677 closestDC, dcol->r, dcol->g, dcol->b, dcol->a, closestDist); |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1678 |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1679 mapping[closestDC] = map->to; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1680 mapped[map->to] = TRUE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1681 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1682 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1683 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1684 { |
482 | 1685 dmMsg(3, "Map index: %d -> %d\n", |
1686 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
|
1687 |
482 | 1688 mapping[map->from] = map->to; |
1689 mapped[map->to] = TRUE; | |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1690 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1691 } |
482 | 1692 |
2493
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1693 if (fail) |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1694 { |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1695 res = DMERR_INVALID_DATA; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1696 goto out; |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1697 } |
ec036e88a0c2
More improvements to palette remapping etc.
Matti Hamalainen <ccr@tnsp.org>
parents:
2492
diff
changeset
|
1698 |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1699 // Fill the unmapped colors |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1700 if (removeUnused) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1701 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1702 dmMsg(2, "Scanning for used colors.\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1703 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1704 if ((res = dmScanUsedColors(src, TRUE, used, &nused)) != DMERR_OK) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1705 goto out; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1706 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1707 dmMsg(2, "Removing unused colors: %d -> %d.\n", |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1708 src->pal->ncolors, nused); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1709 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1710 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1711 for (int index = 0; index < src->pal->ncolors; index++) |
1807
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1712 if (mapping[index] < 0 && |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1713 (!removeUnused || used[index])) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1714 { |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1715 for (int n = 0; n < src->pal->ncolors; n++) |
1807
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1716 if (!mapped[n]) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1717 { |
1807
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1718 mapping[index] = n; |
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1719 mapped[n] = TRUE; |
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1720 break; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1721 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1722 } |
482 | 1723 |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1724 // Copy mapped palette entries |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1725 for (int index = 0; index < src->pal->ncolors; index++) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1726 if (mapping[index] >= 0) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1727 { |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1728 memcpy(&tpal->colors[mapping[index]], &src->pal->colors[index], sizeof(DMColor)); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1729 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1730 |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1731 // Perform image data remapping |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1732 res = dmDoRemapImageColors(pdst, src, mapping, tpal); |
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
|
1733 |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
1734 out: |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1735 dmPaletteFree(tpal); |
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
|
1736 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
|
1737 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
|
1738 dmFree(used); |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1739 return res; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1740 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1741 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1742 |
2226
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1743 int dmDumpC64Block(const char *fprefix, const char *fext, const DMC64MemBlock *blk, const int index) |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1744 { |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1745 int res = DMERR_OK; |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1746 if (blk != NULL && blk->data != NULL) |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1747 { |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1748 char *filename = dm_strdup_printf("%s_%s_%d.bin", fprefix, fext, index); |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1749 if (filename == NULL) |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1750 return DMERR_MALLOC; |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1751 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1752 res = dmWriteDataFile(NULL, filename, blk->data, blk->size); |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1753 dmFree(filename); |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1754 } |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1755 return res; |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1756 } |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1757 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1758 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1759 int dmDumpC64Bitmap(const char *fprefix, const DMC64Image *img) |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1760 { |
2230 | 1761 int res = DMERR_OK; |
2226
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1762 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1763 for (int i = 0; i < img->nblocks; i++) |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1764 { |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1765 res = dmDumpC64Block(fprefix, "bitmap", &img->bitmap[i], i); |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1766 res = dmDumpC64Block(fprefix, "color", &img->color[i], i); |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1767 res = dmDumpC64Block(fprefix, "screen", &img->screen[i], i); |
2532
f3be70c19ce9
Implement dumping of character/font memory block for -f dump output.
Matti Hamalainen <ccr@tnsp.org>
parents:
2516
diff
changeset
|
1768 res = dmDumpC64Block(fprefix, "chardata", &img->charData[i], i); |
2533
78ece6187a7c
Make sure we won't access DMC64Image::extraData[] indices out of bounds when
Matti Hamalainen <ccr@tnsp.org>
parents:
2532
diff
changeset
|
1769 |
78ece6187a7c
Make sure we won't access DMC64Image::extraData[] indices out of bounds when
Matti Hamalainen <ccr@tnsp.org>
parents:
2532
diff
changeset
|
1770 if ((size_t) i < sizeof(img->extraData) / sizeof(img->extraData[0])) |
78ece6187a7c
Make sure we won't access DMC64Image::extraData[] indices out of bounds when
Matti Hamalainen <ccr@tnsp.org>
parents:
2532
diff
changeset
|
1771 res = dmDumpC64Block(fprefix, "extradata", &img->extraData[i], i); |
2226
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1772 } |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1773 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1774 return res; |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1775 } |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1776 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1777 |
1550 | 1778 int dmConvertC64Bitmap(DMC64Image **pdst, const DMC64Image *src, |
1779 const DMC64ImageFormat *dstFmt, const DMC64ImageFormat *srcFmt) | |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1780 { |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1781 DMC64Image *dst; |
1891 | 1782 DMC64MemBlock *srcBlk = NULL, *dstBlk = NULL; |
1783 const char *blkname = NULL; | |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1784 |
1550 | 1785 if (pdst == NULL || dstFmt == NULL || src == NULL || srcFmt == NULL) |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1786 return DMERR_NULLPTR; |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1787 |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1788 // Allocate the destination image |
1550 | 1789 if ((dst = *pdst = dmC64ImageAlloc(dstFmt)) == NULL) |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1790 return DMERR_MALLOC; |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1791 |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1792 // Copy rest of the structure .. |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1793 dst->d020 = src->d020; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1794 dst->bgcolor = src->bgcolor; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1795 dst->d022 = src->d022; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1796 dst->d023 = src->d023; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1797 dst->d024 = src->d024; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1798 |
2369
2dfb448a7ff5
Copy certain DMC64Image::extraInfo fields in dmConvertC64Bitmap() to the destination image.
Matti Hamalainen <ccr@tnsp.org>
parents:
2360
diff
changeset
|
1799 // And some extraInfo fields .. |
2dfb448a7ff5
Copy certain DMC64Image::extraInfo fields in dmConvertC64Bitmap() to the destination image.
Matti Hamalainen <ccr@tnsp.org>
parents:
2360
diff
changeset
|
1800 dst->extraInfo[D64_EI_CHAR_CASE] = src->extraInfo[D64_EI_CHAR_CASE]; |
2dfb448a7ff5
Copy certain DMC64Image::extraInfo fields in dmConvertC64Bitmap() to the destination image.
Matti Hamalainen <ccr@tnsp.org>
parents:
2360
diff
changeset
|
1801 dst->extraInfo[D64_EI_CHAR_CUSTOM] = src->extraInfo[D64_EI_CHAR_CUSTOM]; |
2dfb448a7ff5
Copy certain DMC64Image::extraInfo fields in dmConvertC64Bitmap() to the destination image.
Matti Hamalainen <ccr@tnsp.org>
parents:
2360
diff
changeset
|
1802 |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1803 // Try to do some simple fixups |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
1804 if ((dst->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == D64_FMT_MC && |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
1805 (src->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == D64_FMT_HIRES) |
2124
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1806 { |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1807 dmC64MemBlockCopy(&dst->screen[0], &src->screen[0]); |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1808 } |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1809 else |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
1810 if ((dst->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == D64_FMT_HIRES && |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
1811 (src->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) == D64_FMT_MC) |
2124
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1812 { |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1813 // XXX TODO: Handle FLI mc->hires differently? |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1814 } |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1815 |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
1816 if ((dst->extraInfo[D64_EI_MODE] & D64_FMT_FLI) && |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
1817 (src->extraInfo[D64_EI_MODE] & D64_FMT_FLI) == 0) |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1818 { |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1819 dmMsg(1, "Upconverting multicolor to FLI.\n"); |
2237 | 1820 for (int i = 0; i < dst->nblocks; i++) |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1821 { |
1929
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1822 if (dst->color[i].data == NULL) |
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1823 dmC64MemBlockCopy(&dst->color[i], &src->color[0]); |
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1824 |
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1825 if (dst->screen[i].data == NULL) |
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1826 dmC64MemBlockCopy(&dst->screen[i], &src->screen[0]); |
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1827 |
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1828 if (dst->bitmap[i].data == NULL) |
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1829 dmC64MemBlockCopy(&dst->bitmap[i], &src->bitmap[0]); |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1830 } |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1831 } |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1832 else |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
1833 if ((src->extraInfo[D64_EI_MODE] & D64_FMT_FLI) && |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
1834 (dst->extraInfo[D64_EI_MODE] & D64_FMT_FLI) == 0) |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1835 { |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1836 dmMsg(1, "Downconverting FLI to multicolor.\n"); |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1837 } |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1838 |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1839 // Do per opcode copies |
2389
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1840 for (int opn = 0; opn < D64_MAX_ENCDEC_OPS; opn++) |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1841 { |
2389
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1842 const DMC64EncDecOp *op = fmtGetEncDecOp(dstFmt, opn); |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1843 size_t size; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1844 |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1845 if (op->type == DO_LAST) |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1846 break; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1847 |
1933
c5a46cb4cce5
Change DMC64ImageFormat parameter of dmC64GetSubjectSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1931
diff
changeset
|
1848 size = dmC64GetOpSubjectSize(op, dstFmt->format); |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1849 switch (op->type) |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1850 { |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1851 case DO_COPY: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1852 case DO_SET_MEM: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1853 case DO_SET_MEM_HI: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1854 case DO_SET_MEM_LO: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1855 case DO_SET_OP: |
2108
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2103
diff
changeset
|
1856 srcBlk = (DMC64MemBlock *) dmC64GetOpMemBlock(src, op->subject, op->bank); |
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2103
diff
changeset
|
1857 dstBlk = (DMC64MemBlock *) dmC64GetOpMemBlock(dst, op->subject, op->bank); |
1852
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1843
diff
changeset
|
1858 blkname = dmC64GetOpSubjectName(op->subject); |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1859 |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1860 // Skip if we did previous fixups/upconverts |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1861 if (dstBlk != NULL && dstBlk->data != NULL) |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1862 break; |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1863 |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1864 if (srcBlk != NULL && srcBlk->data != NULL && srcBlk->size >= size) |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1865 { |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1866 // The block exists in source and is of sufficient size, so copy it |
2389
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1867 dmMsg(3, "Copying whole block '%s' " |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1868 "op #%d, offs=%d ($%04x), bank=%d, size=%" DM_PRIu_SIZE_T " ($%04" DM_PRIx_SIZE_T ")\n", |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1869 blkname, opn, op->offs, op->offs, op->bank, size, size); |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1870 |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1871 dmC64MemBlockCopy(dstBlk, srcBlk); |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1872 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1873 else |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1874 switch (op->subject) |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1875 { |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1876 case DS_COLOR_RAM: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1877 case DS_SCREEN_RAM: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1878 case DS_BITMAP_RAM: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1879 case DS_CHAR_DATA: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1880 case DS_EXTRA_DATA: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1881 if ((dmC64MemBlockAlloc(dstBlk, size)) != DMERR_OK) |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1882 { |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1883 return dmError(DMERR_MALLOC, |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1884 "Could not allocate '%s' block! " |
2389
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1885 "op #%d, offs=%d ($%04x), bank=%d, size=%" DM_PRIu_SIZE_T " ($%04" DM_PRIx_SIZE_T ")\n", |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1886 blkname, opn, op->offs, op->offs, op->bank, size, size); |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1887 } |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1888 if (srcBlk == NULL || srcBlk->data == NULL) |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1889 { |
2389
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1890 dmMsg(3, "Creating whole block '%s' " |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1891 "op #%d, offs=%d ($%04x), bank=%d, size=%" DM_PRIu_SIZE_T " ($%04" DM_PRIx_SIZE_T ")\n", |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1892 blkname, opn, op->offs, op->offs, op->bank, size, size); |
1842
a3fc0cab1a60
Improve C64 bitmap conversion messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1836
diff
changeset
|
1893 } |
a3fc0cab1a60
Improve C64 bitmap conversion messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1836
diff
changeset
|
1894 else |
a3fc0cab1a60
Improve C64 bitmap conversion messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1836
diff
changeset
|
1895 { |
2389
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1896 dmMsg(3, "Creating block '%s' from partial data " |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1897 "op #%d, offs=%d ($%04x), bank=%d, size=%" DM_PRIu_SIZE_T " ($%04" DM_PRIx_SIZE_T ")\n", |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1898 blkname, opn, op->offs, op->offs, op->bank, size, size); |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1899 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1900 switch (op->type) |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1901 { |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1902 case DO_COPY: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1903 // If some data exists, copy it. Rest is zero. |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1904 // Otherwise just set to zero. |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1905 if (srcBlk != NULL && srcBlk->data != NULL) |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1906 memcpy(dstBlk->data, srcBlk->data, srcBlk->size); |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1907 break; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1908 |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1909 case DO_SET_MEM: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1910 // Leave allocate data to zero. |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1911 break; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1912 |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1913 case DO_SET_OP: |
2414
69a5af2eb1ea
Remove useless dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents:
2413
diff
changeset
|
1914 memset(dstBlk->data, op->offs, size); |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1915 break; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1916 |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1917 default: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1918 return dmError(DMERR_INTERNAL, |
2389
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1919 "Unhandled op type #%d in " |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1920 "op #%d, offs=%d ($%04x), bank=%d, size=%" DM_PRIu_SIZE_T " ($%04" DM_PRIx_SIZE_T ")\n", |
647671a9a0b8
More printf() format specifier size_t -related fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2387
diff
changeset
|
1921 op->type, opn, op->offs, op->offs, op->bank, size, size); |
1823
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1922 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1923 break; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1924 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1925 break; |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1926 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1927 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1928 |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1929 return DMERR_OK; |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1930 } |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1931 |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1932 |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1933 int dmWriteBitmap(const char *filename, const DMC64Image *image, const DMC64ImageFormat *fmt) |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1934 { |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1935 int res = DMERR_OK; |
1481 | 1936 DMGrowBuf buf; |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1937 |
1694
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1692
diff
changeset
|
1938 dmGrowBufInit(&buf); |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1692
diff
changeset
|
1939 |
1481 | 1940 // Encode to target format |
1941 dmMsg(1, "Encoding C64 bitmap data to format '%s'\n", fmt->name); | |
1470
499835ba215c
Use dmC64EncodeBMP() in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1465
diff
changeset
|
1942 if ((res = dmC64EncodeBMP(&buf, image, fmt)) != DMERR_OK) |
1585 | 1943 { |
1944 dmErrorMsg("Error encoding bitmap data: %s\n", dmErrorStr(res)); | |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
1945 goto out; |
1585 | 1946 } |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1947 |
1481 | 1948 // And output the file |
1696
cf0fddd4bf52
When writing a C64 bitmap output, inform the user about the output file size.
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
1949 dmMsg(1, "Writing output file '%s', %" DM_PRIu_SIZE_T " bytes.\n", |
cf0fddd4bf52
When writing a C64 bitmap output, inform the user about the output file size.
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
1950 filename, buf.len); |
cf0fddd4bf52
When writing a C64 bitmap output, inform the user about the output file size.
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
1951 |
1550 | 1952 res = dmWriteDataFile(NULL, filename, buf.data, buf.len); |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1953 |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
1954 out: |
1465
88845f95e791
Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1464
diff
changeset
|
1955 dmGrowBufFree(&buf); |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1956 return res; |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1957 } |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1958 |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1959 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1960 int dmWriteIFFMasterRAWHeaderFile( |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1961 const char *hdrFilename, const char *dataFilename, |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1962 const char *prefix, const DMImage *img, |
2156
e6ec7fad9ce2
Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
2155
diff
changeset
|
1963 const DMImageWriteSpec *spec) |
1303 | 1964 { |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1965 DMResource *fp; |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1966 int res; |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1967 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1968 if ((res = dmf_open_stdio(hdrFilename, "wb", &fp)) != DMERR_OK) |
1303 | 1969 { |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1970 return dmError(res, |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1971 "Could not open file '%s' for writing: %s\n", |
2460
2723cf62d039
Improve few error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
2459
diff
changeset
|
1972 hdrFilename, dmErrorStr(res)); |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1973 } |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1974 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
1975 res = dmWriteIFFMasterRAWHeader(fp, dataFilename, prefix, img, spec); |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1976 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1977 dmf_close(fp); |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1978 return res; |
1303 | 1979 } |
1980 | |
1981 | |
2447 | 1982 int dmWriteImage(const char *filename, DMImage *pimage, |
2456
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
1983 DMImageWriteSpec *spec, const DMImageFormat *fmt) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1984 { |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1985 int res = DMERR_OK; |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1986 DMImage *image = pimage; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
1987 BOOL allocated = FALSE; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
1988 |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1989 // Check if writing is even supported |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1990 if (fmt->write == NULL || (fmt->flags & DM_FMT_WR) == 0) |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1991 { |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1992 return dmError(DMERR_NOT_SUPPORTED, |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1993 "Writing of '%s' format is not supported.\n", |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1994 fmt->name); |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1995 } |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1996 |
2456
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
1997 dmMsg(1, "Outputting '%s' image %d x %d -> %d x %d [%d x %d]\n", |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
1998 fmt->name, |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
1999 pimage->width, pimage->height, |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2000 pimage->width * spec->scaleX, pimage->height * spec->scaleY, |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2001 spec->scaleX, spec->scaleY); |
435 | 2002 |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2003 if (image->pixfmt == DM_PIXFMT_PALETTE) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
2004 { |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2005 switch (optRemapMode) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2006 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2007 case REMAP_NONE: |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2008 if (optPaletteData != NULL) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2009 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2010 DMPalette *tpal; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2011 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2012 dmMsg(1, "Replacing image palette %d colors with %d colors.\n", |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2013 image->pal->ncolors, optPaletteData->ncolors); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2014 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2015 if ((res = dmPaletteCopy(&tpal, optPaletteData)) != DMERR_OK) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2016 return res; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2017 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2018 if (image->pal->ncolors != optPaletteData->ncolors) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2019 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2020 dmMsg(1, "Trying to resize to %d colors.\n", |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2021 image->pal->ncolors); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2022 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2023 if ((res = dmPaletteResize(&tpal, image->pal->ncolors)) != DMERR_OK) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2024 return res; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2025 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2026 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2027 dmPaletteFree(image->pal); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2028 image->pal = tpal; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2029 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2030 break; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2031 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2032 case REMAP_MAPPED: |
2500
5621befda8d6
Output a warning if REMAP_MAPPED is used together with palette replacement
Matti Hamalainen <ccr@tnsp.org>
parents:
2499
diff
changeset
|
2033 if (optPaletteData != NULL) |
5621befda8d6
Output a warning if REMAP_MAPPED is used together with palette replacement
Matti Hamalainen <ccr@tnsp.org>
parents:
2499
diff
changeset
|
2034 { |
5621befda8d6
Output a warning if REMAP_MAPPED is used together with palette replacement
Matti Hamalainen <ccr@tnsp.org>
parents:
2499
diff
changeset
|
2035 dmErrorMsg( |
5621befda8d6
Output a warning if REMAP_MAPPED is used together with palette replacement
Matti Hamalainen <ccr@tnsp.org>
parents:
2499
diff
changeset
|
2036 "WARNING: Color remapping requested, but palette replacement (-p) set. This will have no effect.\n"); |
5621befda8d6
Output a warning if REMAP_MAPPED is used together with palette replacement
Matti Hamalainen <ccr@tnsp.org>
parents:
2499
diff
changeset
|
2037 } |
5621befda8d6
Output a warning if REMAP_MAPPED is used together with palette replacement
Matti Hamalainen <ccr@tnsp.org>
parents:
2499
diff
changeset
|
2038 |
2497
ea5929b04a26
Oooops, forgot to commit these changes to color remapping stuff. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents:
2496
diff
changeset
|
2039 if ((res = dmMapImageColors( |
ea5929b04a26
Oooops, forgot to commit these changes to color remapping stuff. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents:
2496
diff
changeset
|
2040 &image, pimage, optRemapTable, optNRemapTable, |
ea5929b04a26
Oooops, forgot to commit these changes to color remapping stuff. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents:
2496
diff
changeset
|
2041 optRemapMaxDist, optRemapNoMatchColor, |
ea5929b04a26
Oooops, forgot to commit these changes to color remapping stuff. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents:
2496
diff
changeset
|
2042 optRemapMatchAlpha, optRemapRemove)) != DMERR_OK) |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2043 goto out; |
2497
ea5929b04a26
Oooops, forgot to commit these changes to color remapping stuff. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents:
2496
diff
changeset
|
2044 |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2045 allocated = TRUE; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2046 break; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2047 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2048 case REMAP_AUTO: |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2049 if (optPaletteData == NULL) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2050 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2051 dmErrorMsg( |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2052 "Color auto-remapping requested, but target palette not set? (-p option)\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2053 goto out; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2054 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2055 |
2497
ea5929b04a26
Oooops, forgot to commit these changes to color remapping stuff. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents:
2496
diff
changeset
|
2056 if ((res = dmRemapImageColors( |
ea5929b04a26
Oooops, forgot to commit these changes to color remapping stuff. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents:
2496
diff
changeset
|
2057 &image, pimage, optPaletteData, |
2487
14a4f8d78fe6
More work on image palette remapping functionality.
Matti Hamalainen <ccr@tnsp.org>
parents:
2485
diff
changeset
|
2058 optRemapMaxDist, optRemapNoMatchColor, |
2497
ea5929b04a26
Oooops, forgot to commit these changes to color remapping stuff. 100L.
Matti Hamalainen <ccr@tnsp.org>
parents:
2496
diff
changeset
|
2059 optRemapMatchAlpha, optRemapRemove)) != DMERR_OK) |
2481
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2060 goto out; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2061 |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2062 allocated = TRUE; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2063 break; |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2064 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2065 } |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2066 else |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2067 if (optRemapMode != REMAP_NONE) |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2068 { |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2069 dmErrorMsg("Color remapping requested, but image is not paletted?\n"); |
f3d9cdb0a295
Some work towards more flexible palette remapping.
Matti Hamalainen <ccr@tnsp.org>
parents:
2468
diff
changeset
|
2070 goto out; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
2071 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
2072 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
2073 // Determine number of planes, if paletted |
2142
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
2074 if (spec->nplanes == 0) |
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
2075 { |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
2076 if (image->pixfmt == DM_PIXFMT_PALETTE && |
2142
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
2077 image->pal != NULL) |
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
2078 spec->nplanes = dmGetNPlanesFromNColors(image->pal->ncolors); |
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
2079 else |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
2080 if (image->pixfmt == DM_PIXFMT_GRAYSCALE) |
2142
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
2081 spec->nplanes = image->bpp; |
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
2082 } |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
2083 |
2100
81fb21dd3265
Add dmGetNPlanesFromNColors() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
2099
diff
changeset
|
2084 if (spec->nplanes <= 0) |
2099
dac89484f143
Fix nplanes and bpp in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2097
diff
changeset
|
2085 spec->nplanes = 4; |
dac89484f143
Fix nplanes and bpp in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2097
diff
changeset
|
2086 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
2087 spec->fmtid = fmt->fmtid; |
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
2088 |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2089 // Do some format-specific adjustments and other things |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2090 switch (fmt->fmtid) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2091 { |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
2092 case DM_IMGFMT_PNG: |
2155
28b7a842181f
Make PNG/PPM output a bit more sane with -P option and grayscale data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2144
diff
changeset
|
2093 if (optUsePalette) |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
2094 spec->pixfmt = (image->pixfmt == DM_PIXFMT_GRAYSCALE) ? DM_PIXFMT_GRAYSCALE : DM_PIXFMT_PALETTE; |
2155
28b7a842181f
Make PNG/PPM output a bit more sane with -P option and grayscale data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2144
diff
changeset
|
2095 else |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
2096 spec->pixfmt = DM_PIXFMT_RGBA; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
2097 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
|
2098 |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
2099 case DM_IMGFMT_PPM: |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
2100 if (optUsePalette && image->pixfmt == DM_PIXFMT_GRAYSCALE) |
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
2101 spec->pixfmt = DM_PIXFMT_GRAYSCALE; |
2155
28b7a842181f
Make PNG/PPM output a bit more sane with -P option and grayscale data.
Matti Hamalainen <ccr@tnsp.org>
parents:
2144
diff
changeset
|
2102 else |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
2103 spec->pixfmt = DM_PIXFMT_RGB; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
2104 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
|
2105 |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
2106 case DM_IMGFMT_RAW: |
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
2107 case DM_IMGFMT_ARAW: |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2108 { |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2109 char *prefix = NULL, *hdrFilename = NULL; |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2110 if ((hdrFilename = dm_strdup_fext(filename, "%s.inc")) == NULL || |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2111 (prefix = dm_strdup_fext(filename, "img_%s")) == NULL) |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
2112 { |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2113 res = dmError(DMERR_MALLOC, |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2114 "Could not allocate memory for filename strings? :O\n"); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2115 goto out; |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
2116 } |
820 | 2117 |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2118 // Replace any non-alphanumerics in palette ID |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2119 for (int i = 0; prefix[i]; i++) |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2120 prefix[i] = isalnum(prefix[i]) ? tolower(prefix[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
|
2121 |
2456
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2122 dmMsg(2, "%d bitplanes, %s planes output.\n", |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2123 spec->nplanes, |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2124 spec->planar ? "planar/interleaved" : "non-interleaved"); |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2125 dmMsg(2, "%s datafile '%s', ID prefix '%s'.\n", |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2126 fmt->fmtid == DM_IMGFMT_ARAW ? "ARAW" : "RAW", |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2127 hdrFilename, prefix); |
1891 | 2128 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2129 res = dmWriteIFFMasterRAWHeaderFile( |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
2130 hdrFilename, filename, prefix, image, spec); |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2131 |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2132 dmFree(prefix); |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2133 dmFree(hdrFilename); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2134 } |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
2135 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
|
2136 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
2137 default: |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
2138 spec->pixfmt = optUsePalette ? DM_PIXFMT_PALETTE : DM_PIXFMT_RGB; |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1893
diff
changeset
|
2139 break; |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2140 } |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2141 |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2142 // If no error has occured thus far, write the image |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2143 if (res == DMERR_OK) |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2144 { |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2145 DMResource *fp; |
2456
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2146 char *str; |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2147 switch (spec->pixfmt) |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2148 { |
2456
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2149 case DM_PIXFMT_PALETTE : str = "indexed/paletted"; break; |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2150 case DM_PIXFMT_RGB : str = "24bit RGB"; break; |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2151 case DM_PIXFMT_RGBA : str = "32bit RGBA"; break; |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2152 case DM_PIXFMT_GRAYSCALE : str = "grayscale"; break; |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2153 default : str = "???"; break; |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2154 } |
2456
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2155 dmMsg(1, "Using %s output.\n", str); |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2156 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2157 if ((res = dmf_open_stdio(filename, "wb", &fp)) != DMERR_OK) |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2158 { |
2460
2723cf62d039
Improve few error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
2459
diff
changeset
|
2159 dmErrorMsg("Could not open file '%s' for writing: %s\n", |
2723cf62d039
Improve few error messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
2459
diff
changeset
|
2160 filename, dmErrorStr(res)); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2161 goto out; |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2162 } |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2163 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2164 res = fmt->write(fp, image, spec); |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2165 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
2166 dmf_close(fp); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2167 } |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
2168 |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2169 out: |
1360
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
2170 if (allocated) |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
2171 dmImageFree(image); |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
2172 |
fcaf04cb0830
Make image palette remapping use a destination image instead of doing remapping on the source image.
Matti Hamalainen <ccr@tnsp.org>
parents:
1340
diff
changeset
|
2173 return res; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2174 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2175 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2176 |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2177 int dmWritePalette(const char *filename, const DMPalette *palette, const DMPaletteFormat *fmt) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2178 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2179 DMResource *fp = NULL; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2180 int res; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2181 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2182 // Check if writing is even supported |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2183 if (fmt->write == NULL || (fmt->flags & DM_FMT_WR) == 0) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2184 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2185 return dmError(DMERR_NOT_SUPPORTED, |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2186 "Writing of '%s' format is not supported.\n", |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2187 fmt->name); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2188 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2189 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2190 dmMsg(1, "Outputting '%s' format palette of %d entries.\n", |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2191 fmt->name, palette->ncolors); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2192 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2193 if ((res = dmf_open_stdio(filename, "wb", &fp)) != DMERR_OK) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2194 { |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2195 dmErrorMsg("Could not open file '%s' for writing: %s\n", |
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2196 filename, dmErrorStr(res)); |
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2197 goto out; |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2198 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2199 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2200 res = fmt->write(fp, palette); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2201 |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2202 out: |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2203 dmf_close(fp); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2204 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2205 return res; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2206 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2207 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2208 |
2454
375da267d994
Un-staticize functions in the main program.
Matti Hamalainen <ccr@tnsp.org>
parents:
2453
diff
changeset
|
2209 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
|
2210 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2211 Uint8 byte = 0; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2212 int xc; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2213 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2214 if (multicolor) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2215 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2216 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
|
2217 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2218 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
|
2219 byte |= pixel << (6 - (xc * 2)); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2220 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2221 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2222 else |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2223 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2224 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
|
2225 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2226 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
|
2227 byte |= pixel << (7 - xc); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2228 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2229 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2230 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2231 return byte; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2232 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2233 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2234 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2235 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
|
2236 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
|
2237 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2238 int yc; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2239 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2240 if (xoffs < 0 || yoffs < 0 || |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2241 xoffs + D64_CHR_WIDTH_PX > image->width || |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2242 yoffs + D64_CHR_HEIGHT_PX > image->height) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2243 return FALSE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2244 |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2245 for (yc = 0; yc < D64_CHR_HEIGHT_UT; yc++) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2246 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2247 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
|
2248 buf[yc] = dmConvertByte(sp, multicolor); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2249 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2250 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2251 return TRUE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2252 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2253 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2254 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2255 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
|
2256 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
|
2257 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2258 int yc, xc; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2259 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2260 if (xoffs < 0 || yoffs < 0 || |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2261 xoffs + D64_SPR_WIDTH_PX > image->width || |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2262 yoffs + D64_SPR_HEIGHT_PX > image->height) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2263 return FALSE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2264 |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2265 for (yc = 0; yc < D64_SPR_HEIGHT_UT; yc++) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2266 { |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2267 for (xc = 0; xc < D64_SPR_WIDTH_PX / D64_SPR_WIDTH_UT; xc++) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2268 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2269 const Uint8 *sp = image->data + ((yc + yoffs) * image->pitch) + (xc * 8) + xoffs; |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2270 buf[(yc * D64_SPR_WIDTH_UT) + xc] = dmConvertByte(sp, multicolor); |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2271 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2272 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2273 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2274 return TRUE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2275 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2276 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2277 |
1928 | 2278 int dmWriteSpritesAndChars(const char *filename, DMImage *image, int outFormat, const BOOL multicolor) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2279 { |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
2280 int ret = DMERR_OK; |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
2281 int outBlockW, outBlockH, bx, by; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2282 FILE *outFile = NULL; |
2256 | 2283 Uint8 *tmpBuf = NULL; |
907 | 2284 size_t outBufSize; |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
2285 char *outType; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2286 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2287 switch (outFormat) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2288 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2289 case FFMT_CHAR: |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2290 outBufSize = D64_CHR_SIZE; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2291 outBlockW = image->width / D64_CHR_WIDTH_PX; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2292 outBlockH = image->height / D64_CHR_HEIGHT_PX; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2293 outType = "char"; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2294 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2295 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2296 case FFMT_SPRITE: |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2297 outBufSize = D64_SPR_SIZE; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2298 outBlockW = image->width / D64_SPR_WIDTH_PX; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2299 outBlockH = image->height / D64_SPR_HEIGHT_PX; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2300 outType = "sprite"; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2301 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2302 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2303 default: |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2304 ret = dmError(DMERR_INVALID_ARGS, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2305 "Invalid output format %d, internal error.\n", outFormat); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2306 goto out; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2307 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2308 |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
2309 if (outBlockW < 1 || outBlockH < 1) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2310 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2311 ret = dmError(DMERR_INVALID_ARGS, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2312 "Source image dimensions too small for conversion, block dimensions %d x %d.\n", |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2313 outBlockW, outBlockH); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2314 goto out; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2315 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2316 |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
2317 if ((outFile = fopen(filename, "wb")) == NULL) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2318 { |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
2319 ret = dmGetErrno(); |
2387
68efae89c034
Clean up some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
2320 dmErrorMsg("Could not open '%s' for writing: %s.\n", |
68efae89c034
Clean up some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
2321 filename, dmErrorStr(ret)); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2322 goto out; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2323 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2324 |
2256 | 2325 if ((tmpBuf = dmMalloc(outBufSize)) == NULL) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2326 { |
2384
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2371
diff
changeset
|
2327 dmErrorMsg("Could not allocate %" DM_PRIu_SIZE_T |
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2371
diff
changeset
|
2328 " bytes for conversion buffer.\n", |
907 | 2329 outBufSize); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2330 goto out; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2331 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2332 |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
2333 dmMsg(1, "Writing %d x %d = %d blocks of %s data...\n", |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
2334 outBlockW, outBlockH, outBlockW * outBlockH, outType); |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
2335 |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2336 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
|
2337 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
|
2338 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2339 switch (outFormat) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2340 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2341 case FFMT_CHAR: |
2256 | 2342 if (!dmConvertImage2Char(tmpBuf, image, |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2343 bx * D64_CHR_WIDTH_PX, by * D64_CHR_HEIGHT_PX, |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2344 multicolor)) |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
2345 { |
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
2346 ret = DMERR_DATA_ERROR; |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2347 goto out; |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
2348 } |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2349 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2350 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2351 case FFMT_SPRITE: |
2256 | 2352 if (!dmConvertImage2Sprite(tmpBuf, image, |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2353 bx * D64_SPR_WIDTH_PX, by * D64_SPR_HEIGHT_PX, |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2354 multicolor)) |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
2355 { |
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
2356 ret = DMERR_DATA_ERROR; |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2357 goto out; |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
2358 } |
910 | 2359 break; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2360 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2361 |
2256 | 2362 if (!dm_fwrite_str(outFile, tmpBuf, outBufSize)) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2363 { |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
2364 ret = dmGetErrno(); |
2387
68efae89c034
Clean up some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
2365 dmError(ret, "Error writing data block %d,%d to '%s': %s.\n", |
68efae89c034
Clean up some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
2366 bx, by, filename, dmErrorStr(ret)); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2367 goto out; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2368 } |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
2369 } |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
2370 |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2371 out: |
2292 | 2372 // Cleanup |
828 | 2373 if (outFile != NULL) |
2374 fclose(outFile); | |
2256 | 2375 |
2376 dmFree(tmpBuf); | |
2377 | |
910 | 2378 return ret; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2379 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2380 |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
2381 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2382 int dmDumpSpritesAndChars(const Uint8 *dataBuf, const size_t dataSize, const size_t realOffs) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2383 { |
1524
532c3ceaec1a
Fix uninitilized variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1522
diff
changeset
|
2384 int ret = DMERR_OK, itemCount, outWidth, outWidthPX, outHeight; |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2385 size_t offs, outSize; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2386 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2387 switch (optInType) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2388 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2389 case FFMT_CHAR: |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2390 outSize = D64_CHR_SIZE; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2391 outWidth = D64_CHR_WIDTH_UT; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2392 outWidthPX = D64_CHR_WIDTH_PX; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2393 outHeight = D64_CHR_HEIGHT_UT; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2394 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2395 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2396 case FFMT_SPRITE: |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2397 outSize = D64_SPR_SIZE; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2398 outWidth = D64_SPR_WIDTH_UT; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2399 outWidthPX = D64_SPR_WIDTH_PX; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2400 outHeight = D64_SPR_HEIGHT_UT; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2401 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2402 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2403 default: |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2404 return dmError(DMERR_INTERNAL, |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2405 "Invalid input format %d, internal error.\n", optInType); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2406 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2407 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2408 offs = 0; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2409 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
|
2410 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2411 if (optOutType == FFMT_ANSI || optOutType == 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
|
2412 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2413 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
|
2414 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
|
2415 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2416 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
|
2417 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
|
2418 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2419 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
|
2420 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2421 ret = dmGetErrno(); |
2387
68efae89c034
Clean up some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
2422 dmError(ret, "Error opening output file '%s': %s.\n", |
1525
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
2423 optOutFilename, dmErrorStr(ret)); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2424 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2425 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2426 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2427 while (offs + outSize < dataSize && !error && (optItemCount < 0 || itemCount < optItemCount)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2428 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2429 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
|
2430 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2431 switch (optInType) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2432 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2433 case FFMT_CHAR: |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2434 dmDumpCharASCII(outFile, dataBuf + offs, realOffs + offs, optOutType, optInMulticolor); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2435 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2436 case FFMT_SPRITE: |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2437 dmDumpSpriteASCII(outFile, dataBuf + offs, realOffs + offs, optOutType, optInMulticolor); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2438 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2439 } |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2440 offs += outSize; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2441 itemCount++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2442 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2443 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2444 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
|
2445 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2446 else |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2447 if (optOutType == 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
|
2448 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2449 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
|
2450 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
|
2451 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
|
2452 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2453 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
|
2454 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2455 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
|
2456 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2457 dmErrorMsg("Sequential image output requires filename template.\n"); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2458 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2459 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2460 |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
2461 outImage = dmImageAlloc(outWidthPX, outHeight, DM_PIXFMT_PALETTE, -1); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2462 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
|
2463 optItemCount, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2464 outImage->width, outImage->height, |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2465 outImage->width * optSpec.scaleX, |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2466 outImage->height * optSpec.scaleY); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2467 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2468 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2469 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2470 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
|
2471 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
|
2472 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2473 dmErrorMsg("Single-image output requires count to be set (-n).\n"); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2474 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2475 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
2476 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2477 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
|
2478 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
|
2479 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
|
2480 outIHeight++; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
2481 |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
2482 outImage = dmImageAlloc(outWidthPX * outIWidth, outIHeight * outHeight, DM_PIXFMT_PALETTE, -1); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2483 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2484 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2485 if ((err = dmC64SetImagePalette(outImage, &optC64Spec, FALSE)) != DMERR_OK) |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
2486 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
2487 dmErrorMsg("Could not allocate C64 palette for output image: %d\n", err); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2488 goto out; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
2489 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
2490 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2491 while (offs + outSize < dataSize && (optItemCount < 0 || itemCount < optItemCount)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2492 { |
827 | 2493 if ((err = dmC64ConvertCSDataToImage(outImage, outX * outWidthPX, outY * outHeight, |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
2494 dataBuf + offs, outWidth, outHeight, optInMulticolor, optColorMap)) != 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
|
2495 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2496 dmErrorMsg("Internal error in conversion of raw data to bitmap: %d.\n", err); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2497 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2498 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2499 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2500 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
|
2501 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2502 outFilename = dm_strdup_printf("%s%04d.%s", |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2503 optOutFilename, |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2504 itemCount, |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2505 convFormatList[optOutType].fext); |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2506 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2507 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
|
2508 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2509 dmErrorMsg("Could not allocate memory for filename template?\n"); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2510 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2511 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
2512 |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2513 ret = dmWriteImage(outFilename, outImage, &optSpec, |
2456
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2514 &dmImageFormatList[optOutFormat]); |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2515 |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2516 if (ret != DMERR_OK) |
799 | 2517 { |
1525
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
2518 dmErrorMsg("Error writing output image '%s': %s.\n", |
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
2519 outFilename, dmErrorStr(ret)); |
799 | 2520 } |
2521 | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2522 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
|
2523 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2524 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2525 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2526 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
|
2527 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2528 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
|
2529 outY++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2530 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2531 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
2532 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2533 offs += outSize; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2534 itemCount++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2535 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2536 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2537 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
|
2538 { |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2539 ret = dmWriteImage(optOutFilename, outImage, &optSpec, |
2456
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2540 &dmImageFormatList[optOutFormat]); |
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
2541 |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2542 if (ret != DMERR_OK) |
799 | 2543 { |
1525
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
2544 dmError(ret, "Error writing output image '%s': %s.\n", |
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
2545 optOutFilename, dmErrorStr(ret)); |
799 | 2546 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2547 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
2548 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2549 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
|
2550 } |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
2551 else |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2552 if (optOutType == FFMT_BITMAP) |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
2553 { |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
2554 if (optSequential) |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
2555 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2556 ret = dmError(DMERR_INVALID_ARGS, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2557 "Sequential output not supported for spr/char -> bitmap conversion.\n"); |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2558 goto out; |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
2559 } |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
2560 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2561 |
2459
567b4543f73b
Rename labels more unformly.
Matti Hamalainen <ccr@tnsp.org>
parents:
2456
diff
changeset
|
2562 out: |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2563 return ret; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2564 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2565 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2566 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2567 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
|
2568 { |
933 | 2569 FILE *inFile = NULL; |
1440 | 2570 const DMC64ImageFormat *inC64Fmt = NULL; |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2571 DMConvFormat inFormat, outFormat; |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
2572 DMC64Image *inC64Image = NULL, *outC64Image = NULL; |
2052
aa8df4f1b785
Fix minor memory leaks in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2030
diff
changeset
|
2573 DMImage *inImage = NULL, *outImage = NULL; |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2574 Uint8 *dataBuf = NULL, *dataBufOrig = NULL; |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2575 size_t dataSize, dataSizeOrig, dataRealOffs; |
2097 | 2576 int i, n, 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
|
2577 |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
2578 // Default color mapping |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
2579 for (i = 0; i < D64_NCOLORS; i++) |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
2580 optColorMap[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
|
2581 |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2582 // Initialize c64 image conversion spec |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2583 memset(&optC64Spec, 0, sizeof(optC64Spec)); |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2584 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2585 // Initialize list of additional conversion formats |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
2586 if ((res = dmLib64GFXInit()) != DMERR_OK) |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
2587 { |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
2588 dmErrorMsg("Could not initialize lib64gfx: %s\n", |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
2589 dmErrorStr(res)); |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
2590 goto exit; |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
2591 } |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
2592 |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2593 nconvFormatList = ndmImageFormatList + ndmPaletteFormatList + nbaseFormatList; |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2594 convFormatList = dmCalloc(nconvFormatList, sizeof(DMConvFormat)); |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2595 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2596 for (n = i = 0; i < ndmImageFormatList; i++) |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2597 { |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2598 const DMImageFormat *sfmt = &dmImageFormatList[i]; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2599 DMConvFormat *dfmt = &convFormatList[n++]; |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2600 dfmt->name = sfmt->name; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2601 dfmt->fext = sfmt->fext; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2602 dfmt->flags = sfmt->flags; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2603 dfmt->type = FFMT_IMAGE; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2604 dfmt->format = sfmt->fmtid; |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2605 } |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2606 |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2607 for (i = 0; i < ndmPaletteFormatList; i++) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2608 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2609 const DMPaletteFormat *sfmt = &dmPaletteFormatList[i]; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2610 DMConvFormat *dfmt = &convFormatList[n++]; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2611 dfmt->name = sfmt->name; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2612 dfmt->fext = sfmt->fext; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2613 dfmt->flags = sfmt->flags; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2614 dfmt->type = FFMT_PALETTE; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2615 dfmt->format = sfmt->fmtid; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2616 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2617 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2618 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2619 for (i = 0; i < nbaseFormatList; i++) |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2620 memcpy(&convFormatList[n++], &baseFormatList[i], sizeof(DMConvFormat)); |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2621 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2622 // Initialize and parse commandline |
2499 | 2623 dmInitProg("gfxconv", "Simple graphics converter", "0.95", 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
|
2624 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2625 if (!dmArgsProcess(argc, argv, optList, optListN, |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
854
diff
changeset
|
2626 argHandleOpt, argHandleFile, OPTH_BAILOUT)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2627 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
|
2628 |
2515
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2629 switch (optShowHelp) |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2630 { |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2631 case 1: |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2632 argShowHelp(); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2633 exit(0); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2634 break; |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2635 |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2636 case 2: |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2637 argShowHelp(); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2638 argShowFormats(); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2639 argShowC64Formats(stdout, TRUE, TRUE); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2640 argShowC64PaletteHelp(stdout); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2641 |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2642 for (int n = 0; n < optListN; n++) |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2643 { |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2644 const char *str = argGetHelpTopic(optList[n].id); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2645 if (str != NULL) |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2646 fprintf(stdout, "\n%s\n", str); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2647 } |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2648 exit(0); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2649 break; |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2650 |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2651 case 3: |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2652 argShowFormats(); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2653 argShowC64Formats(stdout, TRUE, dmVerbosity > 0); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2654 exit(0); |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2655 break; |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2656 } |
a40de347fcb0
Make c64 formats listing (optionally) more verbose. Handle --help a bit
Matti Hamalainen <ccr@tnsp.org>
parents:
2510
diff
changeset
|
2657 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2658 // Determine input format, if not specified |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2659 if (optInType == 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
|
2660 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2661 char *dext = strrchr(optInFilename, '.'); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2662 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
|
2663 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2664 if (dmGetFormatByExt(dext + 1, &optInType, &optInFormat) || |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2665 dmGetC64FormatByExt(dext + 1, &optInType, &optInFormat)) |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2666 { |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2667 dmMsg(3, "Guessed input type as %s\n", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2668 formatTypeList[optInType]); |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2669 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2670 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2671 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2672 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2673 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
|
2674 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2675 if (optInType == 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
|
2676 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2677 dmErrorMsg("Standard input cannot be used without specifying input format.\n"); |
2504
f90a97aef546
Mention --longhelp in the message if no arguments are given.
Matti Hamalainen <ccr@tnsp.org>
parents:
2503
diff
changeset
|
2678 dmErrorMsg("Perhaps you should try --help or --longhelp\n"); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2679 goto exit; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2680 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2681 inFile = stdin; |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2682 optInFilename = "stdin"; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2683 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2684 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2685 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
|
2686 { |
2097 | 2687 res = dmGetErrno(); |
2387
68efae89c034
Clean up some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
2688 dmErrorMsg("Error opening input file '%s': %s\n", |
68efae89c034
Clean up some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
2689 optInFilename, dmErrorStr(res)); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2690 goto exit; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2691 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2692 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2693 // Determine output format, if not specified |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2694 if (optOutType == FFMT_AUTO && optOutFilename != NULL) |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2695 { |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2696 char *dext = strrchr(optOutFilename, '.'); |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2697 if (dext) |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2698 { |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2699 if (dmGetFormatByExt(dext + 1, &optOutType, &optOutFormat) || |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2700 dmGetC64FormatByExt(dext + 1, &optOutType, &optOutFormat)) |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2701 { |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2702 dmMsg(3, "Guessed output type as %s\n", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2703 formatTypeList[optOutType]); |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2704 } |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2705 } |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2706 } |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2707 else |
1911
794cbb938a58
Do not force output type to FFMT_ASCII if format is set on commandline.
Matti Hamalainen <ccr@tnsp.org>
parents:
1910
diff
changeset
|
2708 if (optOutType == FFMT_AUTO) |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2709 optOutType = FFMT_ASCII; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2710 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2711 // Read the input .. |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2712 dmMsg(1, "Reading input from '%s'.\n", optInFilename); |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2713 |
2097 | 2714 if ((res = dmReadDataFile(inFile, NULL, &dataBufOrig, &dataSizeOrig)) != DMERR_OK) |
2715 { | |
2716 dmErrorMsg("Could not read input: %s.\n", dmErrorStr(res)); | |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2717 goto exit; |
2097 | 2718 } |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2719 |
1664
9181d9148654
Fix a minor memory leak and file descriptor leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1640
diff
changeset
|
2720 fclose(inFile); |
9181d9148654
Fix a minor memory leak and file descriptor leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1640
diff
changeset
|
2721 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2722 // Check and compute the input skip |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2723 if (optInSkip > dataSizeOrig) |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2724 { |
2010
09d548b08150
Improve input skip option messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
2006
diff
changeset
|
2725 dmErrorMsg("Input skip value %d (0x%x) is larger than input size %" DM_PRIu_SIZE_T ".\n", |
09d548b08150
Improve input skip option messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
2006
diff
changeset
|
2726 optInSkip, optInSkip, dataSizeOrig); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2727 goto exit; |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2728 } |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2729 |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2730 if (optInSkipNeg) |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2731 { |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2732 dataBuf = dataBufOrig + dataSizeOrig - optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2733 dataSize = optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2734 dataRealOffs = dataSizeOrig - optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2735 |
2384
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2371
diff
changeset
|
2736 dmMsg(1, "Input skip -%d (-0x%x). " |
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2371
diff
changeset
|
2737 "Offset %" DM_PRIu_SIZE_T " (0x%" DM_PRIx_SIZE_T "), " |
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2371
diff
changeset
|
2738 "size %" DM_PRIu_SIZE_T " (0x%" DM_PRIx_SIZE_T ").\n", |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2739 optInSkip, optInSkip, |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2740 dataRealOffs, dataRealOffs, |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2741 dataSize, dataSize); |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2742 |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2743 } |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2744 else |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2745 { |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2746 dataBuf = dataBufOrig + optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2747 dataSize = dataSizeOrig - optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2748 dataRealOffs = optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2749 |
2384
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2371
diff
changeset
|
2750 dmMsg(1, "Input skip %d (0x%x), " |
36edd316184a
Fix some format strings to use proper PRI*_SIZE_T where necessary.
Matti Hamalainen <ccr@tnsp.org>
parents:
2371
diff
changeset
|
2751 "size %" DM_PRIu_SIZE_T " (0x%" DM_PRIx_SIZE_T ").\n", |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2752 optInSkip, optInSkip, |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2753 dataSize, dataSize); |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2754 } |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2755 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2756 // Check for forced input format here |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2757 if (optForcedInSubFormat >= 0) |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2758 optInFormat = optForcedInSubFormat; |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2759 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2760 // Perform probing, if required |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2761 if (optInType == FFMT_AUTO || optInType == 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
|
2762 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2763 // Probe for format |
516 | 2764 const DMC64ImageFormat *forced = NULL; |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1696
diff
changeset
|
2765 DMGrowBuf tbuf; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2766 |
1867
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
2767 if (optForcedInSubFormat >= 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
|
2768 { |
1867
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
2769 forced = &dmC64ImageFormats[optForcedInSubFormat]; |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2770 dmMsg(0, "Forced '%s' format image, type %d, %s\n", |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
2771 forced->name, forced->format->mode, 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
|
2772 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2773 |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
2774 res = dmC64DecodeBMP(&inC64Image, |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
2775 dmGrowBufConstCreateFrom(&tbuf, dataBuf, dataSize), |
2516
5fcc9f7b8ad8
Change dmC64DecodeBMP() probeOffs and dataOffs to ssize_t, and use default
Matti Hamalainen <ccr@tnsp.org>
parents:
2515
diff
changeset
|
2776 -1, -1, &inC64Fmt, forced); |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
2777 |
1630
00e0d345e7f1
Improve autoprobing error handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1629
diff
changeset
|
2778 if (forced == NULL && inC64Fmt != NULL && 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
|
2779 { |
1522
0d1cf72fb732
Clarify the "probed" messages of gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1514
diff
changeset
|
2780 dmMsg(1, "Probed '%s' format image, type %d, %s\n", |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
2781 inC64Fmt->name, inC64Fmt->format->mode, inC64Fmt->fext); |
1630
00e0d345e7f1
Improve autoprobing error handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1629
diff
changeset
|
2782 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2783 optInType = FFMT_BITMAP; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2784 } |
897 | 2785 else |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2786 if (res != DMERR_OK && (forced != NULL || optInType == FFMT_BITMAP)) |
897 | 2787 { |
1464
73e00bf7531c
Improve one error message by showing the error code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1457
diff
changeset
|
2788 dmErrorMsg("Could not decode input image: %s.\n", dmErrorStr(res)); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2789 goto exit; |
897 | 2790 } |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2791 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2792 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2793 if (optInType == FFMT_AUTO || optInType == FFMT_IMAGE) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2794 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2795 const DMImageFormat *ifmt = NULL; |
435 | 2796 int index; |
465 | 2797 dmMsg(4, "Trying to probe image formats.\n"); |
2450
dc92cf744ad9
Check that the image format detected by dmImageProbeGeneric() has read() function defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
2449
diff
changeset
|
2798 if (dmImageProbeGeneric(dataBuf, dataSize, &ifmt, &index) > 0 && |
dc92cf744ad9
Check that the image format detected by dmImageProbeGeneric() has read() function defined.
Matti Hamalainen <ccr@tnsp.org>
parents:
2449
diff
changeset
|
2799 ifmt->read != NULL) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2800 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2801 optInType = FFMT_IMAGE; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2802 optInFormat = index; |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2803 dmMsg(1, "Probed '%s' format image.\n", ifmt->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
|
2804 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2805 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2806 |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2807 if (optInType == FFMT_AUTO || optInType == FFMT_PALETTE) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2808 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2809 const DMPaletteFormat *pfmt = NULL; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2810 int index; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2811 dmMsg(4, "Trying to probe palette formats.\n"); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2812 if (dmPaletteProbeGeneric(dataBuf, dataSize, &pfmt, &index) > 0 && |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2813 pfmt->read != NULL) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2814 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2815 optInType = FFMT_PALETTE; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2816 optInFormat = index; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2817 dmMsg(1, "Probed '%s' format palette.\n", pfmt->name); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2818 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2819 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2820 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2821 if (optInType == 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
|
2822 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2823 dmErrorMsg("No input format specified, and could not be determined automatically.\n"); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2824 goto exit; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2825 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2826 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2827 if (dmGetConvFormat(optInType, optInFormat, &inFormat) && |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2828 dmGetConvFormat(optOutType, optOutFormat, &outFormat)) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2829 { |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2830 dmMsg(1, "Attempting conversion %s (%s) -> %s (%s)\n", |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2831 inFormat.name, inFormat.fext, |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2832 outFormat.name, outFormat.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
|
2833 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2834 |
2447 | 2835 // Check if we need to scale the output |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2836 if (optScaleMode != SCALE_SET) |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2837 { |
2464 | 2838 // Default to 1:1 scalefactors |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2839 int scaleX = 1, scaleY = 1; |
2464 | 2840 |
2841 // For C64 formats, use the aspect ratios from them | |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2842 if (inC64Fmt != NULL) |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2843 { |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2844 scaleX = inC64Fmt->format->aspectX; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2845 scaleY = inC64Fmt->format->aspectY; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2846 } |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2847 |
2464 | 2848 // Then, depending on the scaling mode, apply scale |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2849 switch (optScaleMode) |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2850 { |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2851 case SCALE_AUTO: |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2852 optSpec.scaleX = scaleX; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2853 optSpec.scaleY = scaleY; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2854 break; |
2070 | 2855 |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2856 case SCALE_RELATIVE: |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2857 optSpec.scaleX *= scaleX; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2858 optSpec.scaleY *= scaleY; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2859 break; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2860 } |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2861 } |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2862 |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2863 // Handle palette stuff that is generic for different operation modes |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2864 if (optPaletteFile != NULL && |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2865 (res = dmHandleExternalPalette(optPaletteFile, &optPaletteData)) != DMERR_OK) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2866 goto exit; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2867 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2868 switch (optInType) |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2869 { |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2870 case FFMT_SPRITE: |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2871 case FFMT_CHAR: |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2872 case FFMT_BITMAP: |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2873 if (optPaletteData == NULL) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2874 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2875 // No palette file specified, use internal palette |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2876 if (optC64Palette == NULL) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2877 optC64Palette = &dmC64DefaultPalettes[0]; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2878 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2879 dmMsg(1, "Using internal palette '%s' (%s).\n", |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2880 optC64Palette->name, optC64Palette->desc); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2881 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2882 if ((res = dmC64PaletteFromC64Palette(&optPaletteData, optC64Palette, FALSE)) != DMERR_OK) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2883 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2884 dmErrorMsg("Could not set up palette: %s.\n", |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2885 dmErrorStr(res)); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2886 goto exit; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2887 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2888 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2889 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2890 if (optPaletteData->ncolors < D64_NCOLORS) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2891 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2892 dmErrorMsg("Palette does not have enough colors (%d < %d)\n", |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2893 optPaletteData->ncolors, D64_NCOLORS); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2894 goto exit; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2895 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2896 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2897 if (optPaletteData->ncolors > D64_NCOLORS) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2898 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2899 dmMsg(1, "Palette has %d colors, using only first %d.\n", |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2900 optPaletteData->ncolors, D64_NCOLORS); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2901 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2902 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2903 optC64Spec.pal = optPaletteData; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2904 break; |
2468
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2905 |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2906 default: |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2907 if (optC64Palette != NULL) |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2908 { |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2909 dmMsg(1, "Using internal palette '%s' (%s).\n", |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2910 optC64Palette->name, optC64Palette->desc); |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2911 |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2912 if ((res = dmC64PaletteFromC64Palette(&optPaletteData, optC64Palette, FALSE)) != DMERR_OK) |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2913 { |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2914 dmErrorMsg("Could not set up palette: %s.\n", |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2915 dmErrorStr(res)); |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2916 goto exit; |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2917 } |
16c57206cef7
Enable the use of internal (C64) palettes for generally specifying a palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2467
diff
changeset
|
2918 } |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2919 } |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2920 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2921 switch (optInType) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2922 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2923 case FFMT_SPRITE: |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2924 case FFMT_CHAR: |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2925 dmDumpSpritesAndChars(dataBuf, dataSize, dataRealOffs); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2926 break; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
2927 |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2928 case FFMT_PALETTE: |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2929 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2930 const DMPaletteFormat *pfmt = &dmPaletteFormatList[optInFormat]; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2931 DMResource *fp; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2932 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2933 if (optOutFilename == NULL) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2934 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2935 dmErrorMsg("Output filename not set, required for palette formats.\n"); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2936 goto exit; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2937 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2938 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2939 // Read palette file |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2940 if ((res = dmf_open_memio(NULL, optInFilename, dataBuf, dataSize, &fp)) != DMERR_OK) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2941 { |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2942 dmErrorMsg("Could not create MemIO handle for input.\n"); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2943 goto exit; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2944 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2945 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2946 // Read input |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2947 if (pfmt->read != NULL) |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2948 res = pfmt->read(fp, &optPaletteData); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2949 else |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2950 dmErrorMsg("Unsupported input palette format.\n"); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2951 |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2952 dmf_close(fp); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2953 |
2483
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2954 if (res != DMERR_OK) |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2955 { |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2956 dmErrorMsg("Palette could not be read.\n"); |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2957 goto exit; |
2483
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2958 } |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2959 } |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2960 |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2961 if (optPaletteData == NULL) |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2962 goto exit; |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2963 |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2964 switch (optOutType) |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2965 { |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2966 case FFMT_PALETTE: |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2967 res = dmWritePalette(optOutFilename, optPaletteData, &dmPaletteFormatList[optOutFormat]); |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2968 break; |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2969 |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2970 case FFMT_IMAGE: |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2971 // Allocate image |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2972 if ((inImage = dmImageAlloc(16, 16, DM_PIXFMT_PALETTE, |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2973 dmGetNPlanesFromNColors(optPaletteData->ncolors))) == NULL) |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2974 { |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2975 res = dmError(DMERR_MALLOC, |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2976 "Could not allocate memory for image.\n"); |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2977 goto exit; |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2978 } |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2979 |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2980 if ((res = dmPaletteCopy(&inImage->pal, optPaletteData)) != DMERR_OK) |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2981 { |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2982 dmErrorMsg("Could not allocate image palette: %s\n", |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2983 dmErrorStr(res)); |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2984 goto exit; |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2985 } |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2986 |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2987 res = dmWriteImage(optOutFilename, inImage, &optSpec, |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2988 &dmImageFormatList[optOutFormat]); |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2989 break; |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2990 |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2991 default: |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2992 dmErrorMsg("Unsupported output format for palette conversion.\n"); |
2d60e112255e
Add support for converting palette to another palette format, or to a supported image format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2481
diff
changeset
|
2993 break; |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2994 } |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2995 break; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
2996 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2997 case FFMT_BITMAP: |
2097 | 2998 if (optOutFilename == 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
|
2999 { |
2097 | 3000 dmErrorMsg("Output filename not set, required for bitmap formats.\n"); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3001 goto exit; |
2097 | 3002 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3003 |
2097 | 3004 switch (optOutType) |
3005 { | |
3006 case FFMT_IMAGE: | |
3007 case FFMT_CHAR: | |
3008 case FFMT_SPRITE: | |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3009 // Set character data if required |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2256
diff
changeset
|
3010 if ((inC64Image->extraInfo[D64_EI_MODE] & D64_FMT_CHAR) && |
2126
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
3011 inC64Image->charData[0].data == NULL) |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3012 { |
2126
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
3013 // Check character ROM filename |
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
3014 if (optCharROMFilename == NULL) |
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
3015 optCharROMFilename = DM_DEF_CHARGEN; |
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
3016 |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3017 // Attempt to read character ROM |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3018 dmMsg(1, "Using character ROM file '%s'.\n", |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3019 optCharROMFilename); |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3020 |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3021 if ((res = dmReadDataFile(NULL, optCharROMFilename, |
2126
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
3022 &inC64Image->charData[0].data, |
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
3023 &inC64Image->charData[0].size)) != DMERR_OK) |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3024 { |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3025 dmErrorMsg("Could not read character ROM from '%s'.\n", |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3026 optCharROMFilename); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3027 goto exit; |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3028 } |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3029 } |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3030 |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
3031 // Convert the image |
2223
5477e792def3
Remove useless DMC64ImageFormat parameter from some conversion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2217
diff
changeset
|
3032 res = dmC64ConvertBMP2Image(&outImage, inC64Image, &optC64Spec); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3033 |
2097 | 3034 if (res != DMERR_OK || outImage == NULL) |
3035 { | |
2387
68efae89c034
Clean up some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
3036 dmErrorMsg("Error in bitmap to image conversion: %s.\n", |
2295
046056326041
Show error code message when bitmap image conversion fails.
Matti Hamalainen <ccr@tnsp.org>
parents:
2292
diff
changeset
|
3037 dmErrorStr(res)); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3038 goto exit; |
2097 | 3039 } |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3040 |
2097 | 3041 switch (optOutType) |
3042 { | |
3043 case FFMT_IMAGE: | |
3044 res = dmWriteImage(optOutFilename, outImage, &optSpec, | |
2456
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
3045 &dmImageFormatList[optOutFormat]); |
2097 | 3046 break; |
1874 | 3047 |
2097 | 3048 case FFMT_CHAR: |
3049 case FFMT_SPRITE: | |
3050 res = dmWriteSpritesAndChars(optOutFilename, outImage, | |
3051 optOutType, optInMulticolor); | |
3052 break; | |
3053 } | |
3054 break; | |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3055 |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
3056 case FFMT_PALETTE: |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
3057 res = dmWritePalette(optOutFilename, optPaletteData, &dmPaletteFormatList[optOutFormat]); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
3058 break; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
3059 |
2226
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
3060 case FFMT_DUMP: |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
3061 dmDumpC64Bitmap(optOutFilename, inC64Image); |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
3062 break; |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
3063 |
2097 | 3064 case FFMT_BITMAP: |
3065 if ((res = dmConvertC64Bitmap(&outC64Image, inC64Image, | |
3066 &dmC64ImageFormats[optOutFormat], inC64Fmt)) != DMERR_OK) | |
3067 { | |
3068 dmErrorMsg("Error in bitmap format conversion.\n"); | |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3069 goto exit; |
2097 | 3070 } |
3071 if (dmVerbosity >= 2) | |
3072 { | |
3073 dmPrint(0, "INPUT:\n"); dmC64ImageDump(stderr, inC64Image, inC64Fmt, " "); | |
3074 dmPrint(0, "OUTPUT:\n"); dmC64ImageDump(stderr, outC64Image, &dmC64ImageFormats[optOutFormat], " "); | |
3075 } | |
3076 res = dmWriteBitmap(optOutFilename, outC64Image, &dmC64ImageFormats[optOutFormat]); | |
3077 break; | |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
3078 |
2097 | 3079 default: |
3080 dmErrorMsg("Unsupported output format for bitmap conversion.\n"); | |
3081 break; | |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3082 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3083 break; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3084 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3085 case FFMT_IMAGE: |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3086 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
3087 const DMImageFormat *ifmt = &dmImageFormatList[optInFormat]; |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
3088 DMResource *fp; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3089 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3090 if (optOutFilename == NULL) |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3091 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
3092 dmErrorMsg("Output filename not set, required for image formats.\n"); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3093 goto exit; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3094 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3095 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
3096 if ((res = dmf_open_memio(NULL, optInFilename, dataBuf, dataSize, &fp)) != DMERR_OK) |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
3097 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
3098 dmErrorMsg("Could not create MemIO handle for input.\n"); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3099 goto exit; |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
3100 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
3101 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3102 // Read input |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
3103 if (ifmt->read != NULL) |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
3104 res = ifmt->read(fp, &inImage); |
441
2a4de5fe4003
Improve loading of input images to use the list provided by libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
435
diff
changeset
|
3105 else |
1874 | 3106 dmErrorMsg("Unsupported input image format for image conversion.\n"); |
409
b529b7e8ff83
Various improvements and cruft cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
3107 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
3108 dmf_close(fp); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
3109 |
1440 | 3110 if (res != DMERR_OK || inImage == NULL) |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3111 goto exit; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
3112 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
3113 switch (optOutType) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3114 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3115 case FFMT_IMAGE: |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
3116 res = dmWriteImage(optOutFilename, inImage, &optSpec, |
2456
f5f8001490ae
Remove the unused "BOOL info" argument from dmWriteImage().
Matti Hamalainen <ccr@tnsp.org>
parents:
2455
diff
changeset
|
3117 &dmImageFormatList[optOutFormat]); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3118 break; |
417 | 3119 |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
3120 case FFMT_PALETTE: |
2461
1ef7cdb8a5c1
Check that the source image has a palette when doing image -> palette conversion/extraction.
Matti Hamalainen <ccr@tnsp.org>
parents:
2460
diff
changeset
|
3121 if (inImage->pal == NULL || inImage->pixfmt != DM_PIXFMT_PALETTE) |
1ef7cdb8a5c1
Check that the source image has a palette when doing image -> palette conversion/extraction.
Matti Hamalainen <ccr@tnsp.org>
parents:
2460
diff
changeset
|
3122 { |
1ef7cdb8a5c1
Check that the source image has a palette when doing image -> palette conversion/extraction.
Matti Hamalainen <ccr@tnsp.org>
parents:
2460
diff
changeset
|
3123 dmErrorMsg("Source image is not a paletted format or has no palette.\n"); |
1ef7cdb8a5c1
Check that the source image has a palette when doing image -> palette conversion/extraction.
Matti Hamalainen <ccr@tnsp.org>
parents:
2460
diff
changeset
|
3124 goto exit; |
1ef7cdb8a5c1
Check that the source image has a palette when doing image -> palette conversion/extraction.
Matti Hamalainen <ccr@tnsp.org>
parents:
2460
diff
changeset
|
3125 } |
2453
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
3126 res = dmWritePalette(optOutFilename, inImage->pal, &dmPaletteFormatList[optOutFormat]); |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
3127 break; |
11151bc8d056
Implement functionality for converting the supported palette formats to
Matti Hamalainen <ccr@tnsp.org>
parents:
2452
diff
changeset
|
3128 |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
3129 case FFMT_CHAR: |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
3130 case FFMT_SPRITE: |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3131 res = dmWriteSpritesAndChars(optOutFilename, inImage, |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3132 optOutType, optInMulticolor); |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3133 break; |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3134 |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3135 case FFMT_BITMAP: |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3136 { |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3137 DMC64Image *tmpC64Image = NULL; |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3138 res = dmC64ConvertImage2BMP(&tmpC64Image, inImage, |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
3139 &dmC64ImageFormats[optOutFormat], &optC64Spec); |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3140 |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3141 if (res != DMERR_OK || tmpC64Image == NULL) |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3142 { |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3143 dmC64ImageFree(tmpC64Image); |
2387
68efae89c034
Clean up some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
3144 dmErrorMsg("Error in image to bitmap conversion: %s.\n", |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3145 dmErrorStr(res)); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3146 goto exit; |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3147 } |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3148 |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3149 if ((res = dmConvertC64Bitmap(&outC64Image, tmpC64Image, |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3150 &dmC64ImageFormats[optOutFormat], &dmC64ImageFormats[optOutFormat])) != DMERR_OK) |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3151 { |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3152 dmC64ImageFree(tmpC64Image); |
2387
68efae89c034
Clean up some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2384
diff
changeset
|
3153 dmErrorMsg("Error in bitmap format conversion: %s.\n", |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3154 dmErrorStr(res)); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3155 goto exit; |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3156 } |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3157 |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3158 res = dmWriteBitmap(optOutFilename, outC64Image, &dmC64ImageFormats[optOutFormat]); |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3159 dmC64ImageFree(tmpC64Image); |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
3160 } |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
3161 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
3162 |
417 | 3163 default: |
1874 | 3164 dmErrorMsg("Unsupported output format for image conversion.\n"); |
417 | 3165 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
|
3166 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3167 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3168 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3169 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3170 |
2451
2e2a6c344371
Move conversion final write error checking to a more generic location.
Matti Hamalainen <ccr@tnsp.org>
parents:
2450
diff
changeset
|
3171 if (res != DMERR_OK) |
2e2a6c344371
Move conversion final write error checking to a more generic location.
Matti Hamalainen <ccr@tnsp.org>
parents:
2450
diff
changeset
|
3172 { |
2e2a6c344371
Move conversion final write error checking to a more generic location.
Matti Hamalainen <ccr@tnsp.org>
parents:
2450
diff
changeset
|
3173 dmErrorMsg("Error writing output data: %s\n", |
2e2a6c344371
Move conversion final write error checking to a more generic location.
Matti Hamalainen <ccr@tnsp.org>
parents:
2450
diff
changeset
|
3174 dmErrorStr(res)); |
2e2a6c344371
Move conversion final write error checking to a more generic location.
Matti Hamalainen <ccr@tnsp.org>
parents:
2450
diff
changeset
|
3175 } |
2e2a6c344371
Move conversion final write error checking to a more generic location.
Matti Hamalainen <ccr@tnsp.org>
parents:
2450
diff
changeset
|
3176 |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3177 exit: |
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
3178 // Cleanup |
1664
9181d9148654
Fix a minor memory leak and file descriptor leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1640
diff
changeset
|
3179 dmFree(convFormatList); |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
3180 dmFree(dataBufOrig); |
2466
213ce6d400dc
Free the allocated extra palette, if any.
Matti Hamalainen <ccr@tnsp.org>
parents:
2464
diff
changeset
|
3181 dmPaletteFree(optPaletteData); |
1440 | 3182 dmC64ImageFree(inC64Image); |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
3183 dmC64ImageFree(outC64Image); |
2052
aa8df4f1b785
Fix minor memory leaks in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2030
diff
changeset
|
3184 dmImageFree(inImage); |
aa8df4f1b785
Fix minor memory leaks in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2030
diff
changeset
|
3185 dmImageFree(outImage); |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
3186 dmLib64GFXClose(); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
3187 |
933 | 3188 return 0; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3189 } |