Mercurial > hg > dmlib
annotate tools/gfxconv.c @ 2236:57ccd949093f
Show the default chargen/character ROM file path in help.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 15 Jun 2019 06:19:34 +0300 |
parents | ba5141771d9a |
children | 26f1bae40fb6 |
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 |
2120 | 4 * (C) Copyright 2012-2019 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, |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
37 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
38 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
|
39 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
40 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
41 |
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
|
42 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
|
43 { |
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 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
|
45 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
|
46 }; |
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 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
49 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
|
50 { |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
51 "AUTO", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
52 "ASCII text", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
53 "ANSI text", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
54 "C64 bitmap image", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
55 "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
|
56 "C64 sprite data", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
57 "Image", |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
58 }; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
59 |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
60 |
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
|
61 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
|
62 { |
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
|
63 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
|
64 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
|
65 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
|
66 }; |
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 |
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 |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
69 enum |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
70 { |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
71 SCALE_SET, |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
72 SCALE_RELATIVE, |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
73 SCALE_AUTO, |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
74 }; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
75 |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
76 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
77 typedef struct |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
78 { |
1340 | 79 char *name; // Descriptive name of the format |
80 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
|
81 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
|
82 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
|
83 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
|
84 char *help; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
85 } DMConvFormat; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
86 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
87 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
88 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
|
89 { |
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
|
90 { "ASCII text" , "asc" , DM_FMT_WR , FFMT_ASCII , 0 , NULL }, |
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
|
91 { "ANSI colored text" , "ansi" , DM_FMT_WR , FFMT_ANSI , 0 , NULL }, |
2159
3b89ad9355f2
Show string 'bitmap' instead of NULL for c64 bitmap sources.
Matti Hamalainen <ccr@tnsp.org>
parents:
2158
diff
changeset
|
92 { "C64 bitmap image" , "bitmap", DM_FMT_RDWR , FFMT_BITMAP , -1 , NULL }, |
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
|
93 { "C64 character/font data" , "chr" , DM_FMT_RDWR , FFMT_CHAR , 0 , " (chr:mc/chr:sc for multi/singlecolor)" }, |
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
|
94 { "C64 sprite data" , "spr" , DM_FMT_RDWR , FFMT_SPRITE , 0 , " (spr:mc/spr:sc for multi/singlecolor)" }, |
2226
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
95 { "C64 bitmap image dump" , "dump" , DM_FMT_WR , FFMT_DUMP , 0 , 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
|
96 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
97 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
98 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
|
99 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
100 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
101 static DMConvFormat *convFormatList = NULL; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
102 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
|
103 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
104 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
105 typedef struct |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
106 { |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
107 BOOL triplet, alpha; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
108 DMColor color; |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
109 unsigned int from, to; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
110 } DMMapValue; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
111 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
112 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
113 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
114 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
|
115 *optOutFilename = NULL; |
837 | 116 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
117 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
|
118 optOutType = FFMT_AUTO, |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
119 optInFormat = -1, |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
120 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
|
121 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
|
122 optPlanedWidth = 1, |
1867
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
123 optForcedInSubFormat = -1; |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
124 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
|
125 BOOL optInSkipNeg = FALSE; |
838
f2ac9877263e
Bitmap format specifying option changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
837
diff
changeset
|
126 |
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
|
127 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
|
128 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
|
129 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
|
130 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
131 BOOL optInMulticolor = FALSE, |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
132 optSequential = FALSE, |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
133 optRemapColors = FALSE, |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
134 optRemapRemove = FALSE, |
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
135 optUsePalette = FALSE; |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
136 int optNRemapTable = 0, |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
137 optScaleMode = SCALE_AUTO; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
138 DMMapValue optRemapTable[DM_MAX_COLORS]; |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
139 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
|
140 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
|
141 DMC64Palette *optC64Palette = NULL; |
2214 | 142 char *optPaletteFile = NULL; |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
143 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
144 |
2156
e6ec7fad9ce2
Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
2155
diff
changeset
|
145 DMImageWriteSpec optSpec = |
435 | 146 { |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
147 .scaleX = 1, |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
148 .scaleY = 1, |
2099
dac89484f143
Fix nplanes and bpp in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2097
diff
changeset
|
149 .nplanes = 0, |
1288 | 150 .bpp = 8, |
1291 | 151 .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
|
152 .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
|
153 .compression = FCMP_BEST, |
435 | 154 }; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
155 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
156 DMC64ImageConvSpec optC64Spec; |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
157 |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
158 |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
854
diff
changeset
|
159 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
|
160 { |
983 | 161 { 0, '?', "help", "Show this help", OPT_NONE }, |
162 { 15, 'v', "verbose", "Increase verbosity", OPT_NONE }, | |
163 { 3, 'o', "output", "Output filename", OPT_ARGREQ }, | |
2006
9f7e9a393771
Document the negative input skip in -s option help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2005
diff
changeset
|
164 { 4, 's', "skip", "Skip N bytes in input from start (negative value will be offset from input end)", OPT_ARGREQ }, |
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
|
165 { 1, 'i', "informat", "Set input format (see --formats)", OPT_ARGREQ }, |
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
|
166 { 5, 'f', "format", "Set output format (see --formats)", OPT_ARGREQ }, |
1640
e9a43ee46f71
Add '-F' short option alias for '--formats'.
Matti Hamalainen <ccr@tnsp.org>
parents:
1638
diff
changeset
|
167 { 17, 'F', "formats", "List supported input/output formats", OPT_NONE }, |
983 | 168 { 8, 'q', "sequential", "Output sequential files (image output only)", OPT_NONE }, |
2029
5ecd51009072
Rename '-c' colorindex map short option to '-m'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2022
diff
changeset
|
169 { 6, 'm', "colormap", "Set color index mapping (see below for information)", OPT_ARGREQ }, |
983 | 170 { 7, 'n', "numitems", "How many 'items' to output (default: all)", OPT_ARGREQ }, |
171 { 11, 'w', "width", "Item width (number of items per row, min 1)", OPT_ARGREQ }, | |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
172 { 9, 'S', "scale", "Scale output image by specified value(s) (see below)", OPT_ARGREQ }, |
987
5af2097ab284
Cleanup gfxconv option help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
983
diff
changeset
|
173 { 12, 'P', "paletted", "Use indexed/paletted output IF possible.", OPT_NONE }, |
1291 | 174 { 13, 'N', "nplanes", "# of bitplanes (some output formats)", OPT_ARGREQ }, |
2144
0bb1d0ad178f
Fix bpp option description.
Matti Hamalainen <ccr@tnsp.org>
parents:
2143
diff
changeset
|
175 { 18, 'B', "bpp", "Bits per plane (some output formats)", OPT_ARGREQ }, |
1293
1dce9e5f4a2f
Oops, two options were overlapping, fixed.
Matti Hamalainen <ccr@tnsp.org>
parents:
1291
diff
changeset
|
176 { 14, 'I', "interleave", "Interleaved/planar output (some output formats)", OPT_NONE }, |
2059
5b7f5505267c
Improve gfxconv --help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2058
diff
changeset
|
177 { 20, 'C', "compress", "Use compression -C <0-9>, 0 = disable, default is 9", OPT_ARGREQ }, |
983 | 178 { 16, 'R', "remap", "Remap output image colors (-R <(#RRGGBB|index):index>[,<..>][+remove] | -R @map.txt[+remove])", OPT_ARGREQ }, |
2137
903effcd616b
Use only long option for char ROM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2126
diff
changeset
|
179 { 21, 0, "char-rom", "Set character ROM file to be used.", OPT_ARGREQ }, |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
180 { 22, 'p', "palette" , "Set C64 palette to be used (see list with -p help).", 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
|
181 }; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
182 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
183 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
|
184 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
185 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
186 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
|
187 { |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
188 printf( |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
189 "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
|
190 " frmt | RW | Description\n" |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
191 "------+----+-------------------------------------------------------\n" |
432
b583a682f12d
Improve listing of input/output formats in --help.
Matti Hamalainen <ccr@tnsp.org>
parents:
431
diff
changeset
|
192 ); |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
193 |
1532 | 194 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
|
195 { |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
196 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
|
197 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
|
198 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
|
199 (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
|
200 (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
|
201 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
|
202 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
|
203 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
204 |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
205 printf( |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
206 "\n" |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
207 "(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
|
208 "\n" |
1604 | 209 "Available C64 bitmap formats (-f <frmt>):\n" |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
210 " frmt | RW | Type | Description\n" |
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
211 "------+----+-----------------+-------------------------------------\n" |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
212 ); |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
213 |
1532 | 214 for (int i = 0; i < ndmC64ImageFormats; 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
|
215 { |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
216 const DMC64ImageFormat *fmt = dmC64ImageFormatsSorted[i]; |
530
5b37a2e427b7
Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
217 char buf[64]; |
1759
027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
218 printf("%-6s| %c%c | %-15s | %s%s\n", |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
219 fmt->fext, |
1545
3b613fcbf3ff
Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents:
1543
diff
changeset
|
220 (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
|
221 (fmt->flags & DM_FMT_WR) ? 'W' : ' ', |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1759
diff
changeset
|
222 dmC64GetImageTypeString(buf, sizeof(buf), fmt->format->type, FALSE), |
1759
027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
223 fmt->name, |
027fb7313d85
Add a format flag for marking formats that have broken/incomplete support and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
224 fmt->flags & DM_FMT_BROKEN ? " [BROKEN]" : ""); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
225 } |
1667
7f74073813c6
Display number of supported C64 image formats in --formats list of 64vw and gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1664
diff
changeset
|
226 printf("%d formats supported.\n", ndmC64ImageFormats); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
227 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
228 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
229 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
230 void argShowHelp() |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
231 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
232 dmPrintBanner(stdout, dmProgName, "[options] <input file>"); |
860
daebbf28953d
The argument handling API in dmargs* was synced with th-libs.
Matti Hamalainen <ccr@tnsp.org>
parents:
854
diff
changeset
|
233 dmArgsPrintHelp(stdout, optList, optListN, 0); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
234 |
2236
57ccd949093f
Show the default chargen/character ROM file path in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2230
diff
changeset
|
235 fprintf(stdout, |
837 | 236 "\n" |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
237 "Output image scaling (-S)\n" |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
238 "-------------------------\n" |
2062
f11fad2dc3b5
Improve scale factor option '-S' help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2059
diff
changeset
|
239 "Scaling option '-S <n>', '-S <x>:<y>', '-S <x>:<y>*<n>' can be used to set\n" |
f11fad2dc3b5
Improve scale factor option '-S' help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2059
diff
changeset
|
240 "the direct or relative scale integer factor(s). '-S <n>' sets both height\n" |
f11fad2dc3b5
Improve scale factor option '-S' help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2059
diff
changeset
|
241 "and width scale factor to <n>. '-S <x>:<y>*<n>' scales width by X*n and\n" |
f11fad2dc3b5
Improve scale factor option '-S' help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2059
diff
changeset
|
242 "height Y*n. Certain input formats set their default aspect/scale factors.\n" |
f11fad2dc3b5
Improve scale factor option '-S' help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2059
diff
changeset
|
243 "By prepending -S parameters with asterisk ('*') you can scale relative to\n" |
f11fad2dc3b5
Improve scale factor option '-S' help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2059
diff
changeset
|
244 "those values. (e.g. '-S *2' for example.) NOTE! Only integer scale factors\n" |
f11fad2dc3b5
Improve scale factor option '-S' help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2059
diff
changeset
|
245 "can be used at the moment.\n" |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
246 "\n" |
1914 | 247 "Palette remapping (-R)\n" |
248 "----------------------\n" | |
249 "Indexed palette color remapping can be performed via the -R option, either\n" | |
818
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
250 "specifying single colors or filename of file containing remap definitions.\n" |
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
251 "Colors to be remapped can be specified either by their palette index or by\n" |
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
252 "their RGB values as a hex triplet (#rrggbb). Example of a remap definition:\n" |
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
253 "-R #000000:0,#ffffff:1 would remap black and white to indices 0 and 1.\n" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
254 "\n" |
1330 | 255 "Remap file can be specified as \"-R @filename\", and it is a text file with\n" |
256 "one remap definition per line in same format as above. All empty lines and\n" | |
257 "lines starting with a semicolor (;) will be ignored as comments. Any extra\n" | |
258 "whitespace separating items will be ignored as well.\n" | |
818
a6452b575c63
Add some online documentation.
Matti Hamalainen <ccr@tnsp.org>
parents:
814
diff
changeset
|
259 "\n" |
821
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
260 "Optional +remove can be specified (-R <...>+remove), which will remove all\n" |
2077
838ed06b3927
Make a note about '-R +remove' in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2070
diff
changeset
|
261 "unused colors from the palette. This is not always desirable, for example\n" |
838ed06b3927
Make a note about '-R +remove' in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2070
diff
changeset
|
262 "when converting multiple images to same palette. You can also specify the\n" |
838ed06b3927
Make a note about '-R +remove' in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2070
diff
changeset
|
263 "+remove option by itself to remove all unused colors: -R +remove\n" |
821
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
264 "\n" |
2029
5ecd51009072
Rename '-c' colorindex map short option to '-m'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2022
diff
changeset
|
265 "Color index mapping (-m)\n" |
5ecd51009072
Rename '-c' colorindex map short option to '-m'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2022
diff
changeset
|
266 "------------------------\n" |
2217
80cc4ac6d876
Improve colormap (-m) option help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2216
diff
changeset
|
267 "Color index map definitions are used for sprite/char data input (and ANSI\n" |
80cc4ac6d876
Improve colormap (-m) option help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2216
diff
changeset
|
268 "output), to set what colors of the C64 palette are used for each single\n" |
80cc4ac6d876
Improve colormap (-m) option help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2216
diff
changeset
|
269 "color/multi color bit-combination.\n" |
80cc4ac6d876
Improve colormap (-m) option help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2216
diff
changeset
|
270 "For example, if the input is multi color sprite or char, you can define\n" |
80cc4ac6d876
Improve colormap (-m) option help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2216
diff
changeset
|
271 "colors like: -m 0,8,3,15 .. for hires/single color: -m 0,1\n" |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
272 "The numbers are palette indexes, and the order is for bit(pair)-values\n" |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
273 "00, 01, 10, 11 (multi color) and 0, 1 (single color). NOTICE! 255 is the\n" |
2217
80cc4ac6d876
Improve colormap (-m) option help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2216
diff
changeset
|
274 "special transparency color index; -m 255,2 would use transparency for\n" |
80cc4ac6d876
Improve colormap (-m) option help a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2216
diff
changeset
|
275 "'0' bits and and C64 color 2 for '1' bits.\n" |
837 | 276 "\n" |
2236
57ccd949093f
Show the default chargen/character ROM file path in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2230
diff
changeset
|
277 "Default character ROM file for this build is:\n" |
57ccd949093f
Show the default chargen/character ROM file path in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2230
diff
changeset
|
278 "%s\n", |
57ccd949093f
Show the default chargen/character ROM file path in help.
Matti Hamalainen <ccr@tnsp.org>
parents:
2230
diff
changeset
|
279 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
|
280 ); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
281 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
282 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
283 |
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
|
284 /* Replace filename extension based on format pattern. |
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
|
285 * Usage: res = dm_strdup_fext(orig_filename, "foo_%s.cmp"); |
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
|
286 */ |
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
|
287 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
|
288 { |
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
|
289 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
|
290 |
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
|
291 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
|
292 (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
|
293 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
|
294 |
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
|
295 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
|
296 { |
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
|
297 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
|
298 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
|
299 *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
|
300 } |
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
|
301 |
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
|
302 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
|
303 |
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
|
304 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
|
305 |
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
|
306 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
|
307 } |
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
|
308 |
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
|
309 |
1866
734234e7ca95
Add a comment about the imperfection of ANSI color output.
Matti Hamalainen <ccr@tnsp.org>
parents:
1865
diff
changeset
|
310 // |
734234e7ca95
Add a comment about the imperfection of ANSI color output.
Matti Hamalainen <ccr@tnsp.org>
parents:
1865
diff
changeset
|
311 // 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
|
312 // 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
|
313 // 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
|
314 // |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
315 const char *dmC64GetANSIFromC64Color(const int col) |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
316 { |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
317 switch (col) |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
318 { |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
319 case 0: return "0;30"; // Black |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
320 case 1: return "0;1;37"; // White |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
321 case 2: return "0;31"; // Red |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
322 case 3: return "0;36"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
323 case 4: return "0;35"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
324 case 5: return "0;32"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
325 case 6: return "0;34"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
326 case 7: return "0;1;33"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
327 case 8: return "0;33"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
328 case 9: return "0;31"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
329 case 10: return "0;1;31"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
330 case 11: return "0;1;30"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
331 case 12: return "0;1;30"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
332 case 13: return "0;1;32"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
333 case 14: return "0;1;34"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
334 case 15: return "0;37"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
335 |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
336 default: return "0"; |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
337 } |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
338 } |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
339 |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
340 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
341 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
|
342 { |
1546 | 343 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
|
344 { |
1546 | 345 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
|
346 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
|
347 fmt->format == format) |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
348 { |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
349 memcpy(pfmt, fmt, sizeof(DMConvFormat)); |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
350 return TRUE; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
351 } |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
352 } |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
353 |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
354 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
|
355 { |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
356 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
|
357 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
|
358 { |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
359 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
|
360 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
|
361 memcpy(pfmt, fmt, sizeof(DMConvFormat)); |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
362 pfmt->fext = cfmt->name; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
363 return TRUE; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
364 } |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
365 } |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
366 |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
367 return FALSE; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
368 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
369 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
370 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
371 BOOL dmGetC64FormatByExt(const char *fext, int *type, int *format) |
819
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
372 { |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
373 if (fext == NULL) |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
374 return FALSE; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
375 |
1569 | 376 for (int i = 0; i < ndmC64ImageFormats; i++) |
819
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
377 { |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
378 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
379 if (fmt->fext != NULL && |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
380 strcasecmp(fext, fmt->fext) == 0) |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
381 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
382 *type = FFMT_BITMAP; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
383 *format = i; |
819
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
384 return TRUE; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
385 } |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
386 } |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
387 |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
388 return FALSE; |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
389 } |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
390 |
0177d4a66d48
Split dmGetFormatByExt() to dmGetC64FormatByExt().
Matti Hamalainen <ccr@tnsp.org>
parents:
818
diff
changeset
|
391 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
392 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
|
393 { |
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
|
394 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
|
395 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
|
396 |
1569 | 397 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
|
398 { |
1546 | 399 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
|
400 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
|
401 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
|
402 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
403 *type = fmt->type; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
404 *format = fmt->format; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
405 return TRUE; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
406 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
407 } |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
408 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
409 return FALSE; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
410 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
411 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
412 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
413 static BOOL dmParseMapOptionMapItem(const char *popt, DMMapValue *value, const unsigned int nmax, const char *msg) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
414 { |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
415 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
|
416 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
417 if (opt == NULL) |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
418 goto error; |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
419 |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
420 if ((end = split = strchr(opt, ':')) == NULL) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
421 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
422 dmErrorMsg("Invalid %s value '%s', expected <(#|%)RRGGBB|[$|0x]index>:<[$|0x]index>.\n", msg, opt); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
423 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
424 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
425 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
426 // Trim whitespace |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
427 *end = 0; |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
428 for (end--; end > opt && *end && isspace(*end); end--) |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
429 *end = 0; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
430 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
431 // 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
|
432 if (*opt == '#' || *opt == '%') |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
433 { |
867 | 434 unsigned int colR, colG, colB, colA; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
435 |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
436 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
|
437 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
|
438 { |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
439 value->alpha = TRUE; |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
440 value->color.a = colA; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
441 } |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
442 else |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
443 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
|
444 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
|
445 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
446 dmErrorMsg("Invalid %s value '%s', expected a hex triplet, got '%s'.\n", msg, popt, opt + 1); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
447 goto error; |
474
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
448 } |
95d1facfdb77
Improve color matching, make it possible to ignore alpha values.
Matti Hamalainen <ccr@tnsp.org>
parents:
473
diff
changeset
|
449 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
450 value->color.r = colR; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
451 value->color.g = colG; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
452 value->color.b = colB; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
453 value->triplet = TRUE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
454 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
455 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
456 { |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
457 if (!dmGetIntVal(opt, &value->from, NULL)) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
458 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
459 dmErrorMsg("Invalid %s value '%s', could not parse source value '%s'.\n", msg, popt, opt); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
460 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
461 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
462 value->triplet = FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
463 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
464 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
465 // Trim whitespace |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
466 split++; |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
467 while (*split && isspace(*split)) split++; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
468 |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
469 // Parse destination value |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
470 if (!dmGetIntVal(split, &value->to, NULL)) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
471 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
472 dmErrorMsg("Invalid %s value '%s', could not parse destination value '%s'.\n", msg, popt, split); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
473 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
474 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
475 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
476 if (!value->triplet && value->from > 255) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
477 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
478 dmErrorMsg("Invalid %s map source color index value %d, must be [0..255].\n", msg, value->from); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
479 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
480 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
481 |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
482 if (value->to > nmax) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
483 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
484 dmErrorMsg("Invalid %s map destination color index value %d, must be [0..%d].\n", msg, value->to, nmax); |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
485 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
486 } |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
487 |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
488 dmFree(opt); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
489 return TRUE; |
481
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
490 |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
491 error: |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
492 dmFree(opt); |
c3f0fca5b596
Improve remapping option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
480
diff
changeset
|
493 return FALSE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
494 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
495 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
496 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
497 static BOOL dmParseMapOptionItem(char *opt, char *end, void *pvalue, const int index, const int nmax, const BOOL requireIndex, const char *msg) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
498 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
499 // Trim whitespace |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
500 if (end != NULL) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
501 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
502 *end = 0; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
503 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
|
504 *end = 0; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
505 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
506 while (*opt && isspace(*opt)) opt++; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
507 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
508 // Parse item based on mode |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
509 if (requireIndex) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
510 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
511 DMMapValue *value = (DMMapValue *) pvalue; |
475
c0dedfef3edf
Fix option parsing of mappings.
Matti Hamalainen <ccr@tnsp.org>
parents:
474
diff
changeset
|
512 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
|
513 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
514 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
515 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
516 { |
871
fc272f5f2d15
Make value type of dmGetIntVal() unsigned.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
517 unsigned int *value = (unsigned int *) pvalue; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
518 char *split = strchr(opt, ':'); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
519 if (split != NULL) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
520 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
521 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
|
522 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
523 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
524 |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
525 if (!dmGetIntVal(opt, &value[index], NULL)) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
526 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
527 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
|
528 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
529 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
530 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
531 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
532 return TRUE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
533 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
534 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
535 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
536 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
|
537 { |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
538 char *start = opt; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
539 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
540 *nvalues = 0; |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
541 while (*start && *nvalues < nmax) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
542 { |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
543 char *end = strchr(start, ','); |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
544 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
545 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
|
546 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
547 |
853
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
548 (*nvalues)++; |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
549 |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
550 if (!end) |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
551 break; |
b2140d41785a
Cleanup some parsing logic.
Matti Hamalainen <ccr@tnsp.org>
parents:
838
diff
changeset
|
552 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
553 start = end + 1; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
554 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
555 |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
556 return TRUE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
557 } |
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 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
|
561 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
562 FILE *fp; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
563 char line[512]; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
564 int res = DMERR_OK; |
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 if ((fp = fopen(filename, "r")) == NULL) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
567 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
568 res = dmGetErrno(); |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
569 dmError(res, "Could not open color remap file '%s' for reading, %d: %s\n", |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
570 res, dmErrorStr(res)); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
571 return res; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
572 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
573 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
574 while (fgets(line, sizeof(line), fp)) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
575 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
576 char *start = line; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
577 line[sizeof(line) - 1] = 0; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
578 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
579 while (*start && isspace(*start)) start++; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
580 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
581 if (*start != 0 && *start != ';') |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
582 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
583 if (!dmParseMapOptionMapItem(line, &values[*nvalue], nmax, "mapping file")) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
584 goto error; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
585 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
586 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
587 (*nvalue)++; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
588 if (*nvalue >= nmax) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
589 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
590 dmErrorMsg("Too many mapping pairs in '%s', maximum is %d.\n", |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
591 filename, nmax); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
592 goto error; |
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 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
595 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
596 } |
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 error: |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
599 fclose(fp); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
600 return res; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
601 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
602 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
603 |
1867
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
604 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
|
605 { |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
606 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
|
607 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
|
608 *flags++ = 0; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
609 |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
610 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
|
611 !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
|
612 { |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
613 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
|
614 msg1, optArg); |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
615 return FALSE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
616 } |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
617 |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
618 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
|
619 { |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
620 switch (*format) |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
621 { |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
622 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
|
623 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
|
624 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
|
625 optInMulticolor = TRUE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
626 else |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
627 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
|
628 optInMulticolor = FALSE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
629 else |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
630 { |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
631 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
|
632 msg1, flags); |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
633 return FALSE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
634 } |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
635 break; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
636 |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
637 default: |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
638 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
|
639 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
|
640 return FALSE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
641 } |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
642 } |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
643 |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
644 return TRUE; |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
645 } |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
646 |
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
647 |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
648 BOOL dmParseIntValWithSep(char **arg, unsigned int *value, char *last, const char sep) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
649 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
650 char *ptr = *arg, *end, *start; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
651 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
652 // Skip any whitespace at start |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
653 while (*ptr != 0 && isspace(*ptr)) |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
654 ptr++; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
655 |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
656 start = ptr; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
657 |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
658 // Find next not-xdigit/separator |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
659 while (*ptr != 0 && |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
660 (isxdigit(*ptr) || *ptr == 'x' || *ptr == '$') && |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
661 *ptr != sep) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
662 ptr++; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
663 |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
664 end = ptr; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
665 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
666 // Skip whitespace again |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
667 while (*ptr != 0 && isspace(*ptr)) |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
668 ptr++; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
669 |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
670 // Return last character in "last" |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
671 *last = *ptr; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
672 |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
673 // Set end to NUL |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
674 *end = 0; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
675 |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
676 // And if last character is not NUL, move ptr |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
677 if (*last != 0) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
678 ptr++; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
679 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
680 *arg = ptr; |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
681 |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
682 return dmGetIntVal(start, value, NULL); |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
683 } |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
684 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
685 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
686 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
|
687 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
688 unsigned int tmpUInt; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
689 char *tmpStr; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
690 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
691 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
|
692 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
693 case 0: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
694 argShowHelp(); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
695 exit(0); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
696 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
697 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
698 case 17: |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
699 argShowFormats(); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
700 exit(0); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
701 break; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
702 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
703 case 15: |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
704 dmVerbosity++; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
705 break; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
706 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
707 case 1: |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
708 { |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
709 DMConvFormat fmt; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
710 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
711 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
|
712 return FALSE; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
713 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
714 dmGetConvFormat(optInType, optForcedInSubFormat, &fmt); |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
715 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
|
716 { |
1870
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
717 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
|
718 fmt.name); |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
719 return FALSE; |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
720 } |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
721 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
722 break; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
723 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
724 case 3: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
725 optOutFilename = optArg; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
726 break; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
727 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
728 case 4: |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
729 if (!dmGetIntVal(optArg, &optInSkip, &optInSkipNeg)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
730 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
731 dmErrorMsg("Invalid skip value argument '%s'.\n", optArg); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
732 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
|
733 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
734 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
735 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
736 case 5: |
1870
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
737 { |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
738 DMConvFormat fmt; |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
739 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
740 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
|
741 return FALSE; |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
742 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
743 dmGetConvFormat(optOutType, optOutFormat, &fmt); |
1870
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
744 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
|
745 { |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
746 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
|
747 fmt.name); |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
748 return FALSE; |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
749 } |
1e8f60ce21d1
Add check for writability in output format option -f
Matti Hamalainen <ccr@tnsp.org>
parents:
1869
diff
changeset
|
750 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
751 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
752 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
753 case 6: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
754 { |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
755 int index, ncolors; |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
756 if (!dmParseMapOptionString(optArg, optColorMap, |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
757 &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
|
758 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
|
759 |
2030 | 760 dmMsg(1, "Set color index mapping: "); |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
761 for (index = 0; index < ncolors; index++) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
762 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
763 dmPrint(1, "[%d:%d]%s", |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
764 index, optColorMap[index], |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
765 (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
|
766 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
767 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
|
768 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
769 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
770 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
771 case 7: |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
772 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
773 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
|
774 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
775 dmErrorMsg("Invalid count value argument '%s' [1 .. MAXINT]\n", |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
776 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
|
777 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
|
778 } |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
779 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
|
780 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
781 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
782 case 8: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
783 optSequential = TRUE; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
784 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
785 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
786 case 9: |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
787 { |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
788 BOOL error = FALSE; |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
789 unsigned int tmpUInt2; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
790 char *tmpStr = dm_strdup(optArg), |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
791 *tmpOpt = tmpStr, sep; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
792 |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
793 // 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
|
794 if (*tmpOpt == '*') |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
795 { |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
796 tmpOpt++; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
797 optScaleMode = SCALE_RELATIVE; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
798 } |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
799 else |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
800 optScaleMode = SCALE_SET; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
801 |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
802 // Parse the values |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
803 if (dmParseIntValWithSep(&tmpOpt, &tmpUInt, &sep, ':')) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
804 { |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
805 if (sep == ':' && |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
806 dmParseIntValWithSep(&tmpOpt, &tmpUInt2, &sep, '*')) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
807 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
808 optSpec.scaleX = tmpUInt; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
809 optSpec.scaleY = tmpUInt2; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
810 |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
811 if (sep == '*' && |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
812 dmParseIntValWithSep(&tmpOpt, &tmpUInt, &sep, 0)) |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
813 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
814 optSpec.scaleX *= tmpUInt; |
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
815 optSpec.scaleY *= tmpUInt; |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
816 } |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
817 error = (sep != 0); |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
818 } |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
819 else |
1890
ee95059b4c18
Oops, fix a blunder left in the refactored scale option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1889
diff
changeset
|
820 if (sep == 0) |
ee95059b4c18
Oops, fix a blunder left in the refactored scale option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1889
diff
changeset
|
821 { |
ee95059b4c18
Oops, fix a blunder left in the refactored scale option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1889
diff
changeset
|
822 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
|
823 } |
ee95059b4c18
Oops, fix a blunder left in the refactored scale option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1889
diff
changeset
|
824 else |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
825 error = TRUE; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
826 } |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
827 else |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
828 error = TRUE; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
829 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
830 dmFree(tmpStr); |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
831 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
832 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
|
833 { |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
834 dmErrorMsg( |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
835 "Invalid scale option value '%s', should be <n>, <w>:<h> or <w>:<h>*<n>.\n", |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
836 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
|
837 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
|
838 } |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
839 |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
840 if (optSpec.scaleX < 1 || optSpec.scaleX > 50) |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
841 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
842 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
|
843 return FALSE; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
844 } |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
845 if (optSpec.scaleY < 1 || optSpec.scaleY > 50) |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
846 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
847 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
|
848 return FALSE; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
849 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
850 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
851 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
852 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
853 case 11: |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
854 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
855 tmpUInt < 1 || tmpUInt > 512) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
856 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
857 dmErrorMsg("Invalid planed width value '%s' [1 .. 512]\n", |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
858 optArg); |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
859 return FALSE; |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
860 } |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
861 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
|
862 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
863 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
864 case 12: |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
865 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
|
866 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
867 |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
868 case 13: |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
869 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
870 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
|
871 { |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
872 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
|
873 optArg); |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
874 return FALSE; |
1288 | 875 } |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
876 optSpec.nplanes = tmpUInt; |
1288 | 877 break; |
878 | |
879 case 18: | |
2004
161e731eb152
Improve dmGetIntVal() to accept an optional negative value boolean flag
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
880 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
1889
ac9784afae27
Improve option argument parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1888
diff
changeset
|
881 tmpUInt < 1 || tmpUInt > 32) |
1288 | 882 { |
2144
0bb1d0ad178f
Fix bpp option description.
Matti Hamalainen <ccr@tnsp.org>
parents:
2143
diff
changeset
|
883 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
|
884 optArg); |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
885 return FALSE; |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
886 } |
2099
dac89484f143
Fix nplanes and bpp in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2097
diff
changeset
|
887 optSpec.bpp = tmpUInt; |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
888 break; |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
889 |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
890 case 14: |
1291 | 891 optSpec.planar = TRUE; |
415
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
892 break; |
d94f4bcb4be3
IFFMaster RAW output works now, at least to some extent.
Matti Hamalainen <ccr@tnsp.org>
parents:
409
diff
changeset
|
893 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
894 case 16: |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
895 if ((tmpStr = dm_strrcasecmp(optArg, "+remove")) != NULL) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
896 { |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
897 optRemapRemove = TRUE; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
898 *tmpStr = 0; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
899 } |
821
8ec16cca0eef
Change -R remap option syntax slightly and document it.
Matti Hamalainen <ccr@tnsp.org>
parents:
820
diff
changeset
|
900 |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
901 if (optArg[0] == '@') |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
902 { |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
903 if (optArg[1] != 0) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
904 { |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
905 int res; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
906 if ((res = dmParseColorRemapFile(optArg + 1, |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
907 optRemapTable, &optNRemapTable, DM_MAX_COLORS)) != DMERR_OK) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
908 return FALSE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
909 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
910 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
911 { |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
912 dmErrorMsg("No remap filename given.\n"); |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
913 return FALSE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
914 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
915 } |
1888
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
916 else |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
917 { |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
918 if (!dmParseMapOptionString(optArg, optRemapTable, |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
919 &optNRemapTable, DM_MAX_COLORS, TRUE, "color remap option")) |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
920 return FALSE; |
b97f273a9d54
Improve some gfxconv commanline option parsing.
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
921 } |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
922 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
923 optRemapColors = TRUE; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
924 break; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
925 |
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
|
926 case 19: |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
927 { |
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
|
928 int tx0, ty0, tx1, ty1; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
929 if (strcasecmp(optArg, "auto") == 0) |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
930 { |
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
|
931 optCropMode = CROP_AUTO; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
932 } |
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
|
933 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
|
934 if (sscanf(optArg, "%d:%d-%d:%d", &tx0, &ty0, &tx1, &ty1) == 4) |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
935 { |
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
|
936 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
|
937 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
|
938 optCropY0 = ty0; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
939 optCropW = tx1 - tx0 + 1; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
940 optCropH = ty1 - ty0 + 1; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
941 } |
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
|
942 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
|
943 if (sscanf(optArg, "%d:%d:%d:%d", &tx0, &ty0, &tx1, &ty1) == 4) |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
944 { |
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
|
945 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
|
946 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
|
947 optCropY0 = ty0; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
948 optCropW = tx1; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
949 optCropH = ty1; |
ca5b4696be21
Add some code for parsing crop mode option, but the logic itself is not yet
Matti Hamalainen <ccr@tnsp.org>
parents:
853
diff
changeset
|
950 } |
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
|
951 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
|
952 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
953 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
|
954 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
|
955 } |
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
|
956 } |
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
|
957 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
|
958 |
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
|
959 case 20: |
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
|
960 if (!dmGetIntVal(optArg, &tmpUInt, NULL) || |
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
|
961 tmpUInt > FCMP_BEST) |
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
|
962 { |
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
|
963 dmErrorMsg("Invalid compression setting '%s' [%d .. %d]\n", |
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
|
964 optArg, FCMP_NONE, FCMP_BEST); |
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
|
965 return FALSE; |
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
|
966 } |
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
|
967 optSpec.compression = tmpUInt; |
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
|
968 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
|
969 |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
970 case 21: |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
971 optCharROMFilename = optArg; |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
972 break; |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
973 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
974 case 22: |
2214 | 975 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
|
976 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
977 default: |
2183
e3f0eaf23f4f
Change the error message for unimplemented option argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
2182
diff
changeset
|
978 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
|
979 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
|
980 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
981 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
982 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
|
983 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
984 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
985 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
986 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
|
987 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
988 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
|
989 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
|
990 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
991 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
992 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
|
993 currArg); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
994 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
|
995 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
996 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
997 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
|
998 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
999 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1000 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1001 void dmPrintByte(FILE *out, int byte, int format, BOOL multicolor) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1002 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1003 int i; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1004 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1005 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
|
1006 { |
837 | 1007 for (i = DM_ASC_NBITS; i; i -= 2) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1008 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1009 int val = (byte & (3ULL << (i - 2))) >> (i - 2); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1010 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
|
1011 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
|
1012 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1013 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
|
1014 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
|
1015 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
|
1016 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1017 case FFMT_ANSI: |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1018 fprintf(out, "\x1b[%sm##\x1b[0m", |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1019 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
|
1020 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1021 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1022 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1023 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1024 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1025 { |
837 | 1026 for (i = DM_ASC_NBITS; i; i--) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1027 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1028 int val = (byte & (1ULL << (i - 1))) >> (i - 1); |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1029 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
|
1030 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1031 case FFMT_ASCII: |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1032 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
|
1033 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1034 case FFMT_ANSI: |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1035 fprintf(out, "\x1b[%sm#\x1b[0m", |
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1036 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
|
1037 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1038 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1039 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1040 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1041 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1042 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1043 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1044 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
|
1045 { |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1046 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
|
1047 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1048 fprintf(outFile, "%04" DM_PRIx_SIZE_T " : ", offs + yc); |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1049 dmPrintByte(outFile, buf[yc], fmt, 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
|
1050 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
|
1051 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1052 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1053 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1054 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1055 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
|
1056 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1057 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
|
1058 |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1059 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
|
1060 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1061 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
|
1062 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
|
1063 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1064 dmPrintByte(outFile, buf[bufOffs], fmt, 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
|
1065 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
|
1066 bufOffs++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1067 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1068 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
|
1069 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1070 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1071 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1072 |
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
|
1073 int dmRemapImageColors(DMImage **pdst, const DMImage *src) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1074 { |
2143 | 1075 DMPalette *tmpPal = NULL; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1076 int *mapping = dmMalloc(src->pal->ncolors * sizeof(int)); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1077 BOOL *mapped = dmMalloc(src->pal->ncolors * sizeof(BOOL)); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1078 BOOL *used = dmMalloc(src->pal->ncolors * sizeof(BOOL)); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1079 int n, index, xc, yc, ncolors, res = DMERR_OK; |
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
|
1080 DMImage *dst; |
482 | 1081 |
2143 | 1082 if ((res = dmPaletteAlloc(&tmpPal, 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
|
1083 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1084 dmErrorMsg("Could not allocate memory for remap palette.\n"); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1085 goto error; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1086 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1087 |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
1088 if ((dst = *pdst = dmImageAlloc(src->width, src->height, src->pixfmt, src->bpp)) == 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
|
1089 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1090 res = dmError(DMERR_MALLOC, |
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
|
1091 "Could not allocate memory for remapped image.\n"); |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1092 goto error; |
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
|
1093 } |
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
|
1094 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1095 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1096 if (mapping == NULL || mapped == NULL || used == NULL) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1097 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1098 res = dmError(DMERR_MALLOC, |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1099 "Could not allocate memory for reused palette.\n"); |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1100 goto error; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1101 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1102 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1103 dmMsg(1, "Remapping %d output image colors of %d colors.\n", |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1104 optNRemapTable, src->pal->ncolors); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1105 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1106 for (index = 0; index < src->pal->ncolors; index++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1107 { |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1108 mapping[index] = -1; |
482 | 1109 mapped[index] = used[index] = FALSE; |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1110 } |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1111 |
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
|
1112 // Find used colors |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1113 dmMsg(2, "Scanning image for used colors...\n"); |
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
|
1114 for (ncolors = yc = 0; yc < src->height; yc++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1115 { |
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
|
1116 const Uint8 *dp = src->data + src->pitch * yc; |
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
|
1117 for (xc = 0; xc < src->width; xc++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1118 { |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1119 Uint8 col = dp[xc]; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1120 if (col < src->pal->ncolors && !used[col]) |
482 | 1121 { |
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
|
1122 used[col] = TRUE; |
482 | 1123 ncolors++; |
1124 } | |
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
|
1125 } |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1126 } |
482 | 1127 dmMsg(2, "Found %d used colors, creating remap-table.\n", ncolors); |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1128 |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1129 // Match and mark mapped colors |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1130 for (index = 0; index < optNRemapTable; index++) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1131 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1132 DMMapValue *map = &optRemapTable[index]; |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1133 if (map->triplet) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1134 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1135 BOOL found = FALSE; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1136 for (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
|
1137 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1138 if (dmCompareColor(&(src->pal->colors[n]), &(map->color), map->alpha)) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1139 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1140 dmMsg(3, "RGBA match #%02x%02x%02x%02x: %d -> %d\n", |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1141 map->color.r, map->color.g, map->color.b, map->color.a, |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1142 n, |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1143 map->to); |
482 | 1144 |
1145 mapping[n] = map->to; | |
1146 mapped[map->to] = TRUE; | |
1147 found = TRUE; | |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1148 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1149 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1150 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1151 if (!found) |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1152 { |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1153 dmMsg(3, "No RGBA match found for map index %d, #%02x%02x%02x%02x\n", |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1154 index, |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1155 map->color.r, map->color.g, map->color.b, map->color.a); |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1156 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1157 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1158 else |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1159 { |
482 | 1160 dmMsg(3, "Map index: %d -> %d\n", |
1161 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
|
1162 |
482 | 1163 mapping[map->from] = map->to; |
1164 mapped[map->to] = TRUE; | |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1165 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1166 } |
482 | 1167 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1168 // Fill in the rest |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1169 if (optRemapRemove) |
1807
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1170 dmMsg(2, "Removing unused colors.\n"); |
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1171 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1172 for (index = 0; index < src->pal->ncolors; index++) |
1807
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1173 if (mapping[index] < 0 && |
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1174 (!optRemapRemove || (optRemapRemove && used[index]))) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1175 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1176 for (n = 0; n < src->pal->ncolors; n++) |
1807
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1177 if (!mapped[n]) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1178 { |
1807
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1179 mapping[index] = n; |
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1180 mapped[n] = TRUE; |
d53bdee5ffa5
Remove slight bit of code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1801
diff
changeset
|
1181 break; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1182 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1183 } |
482 | 1184 |
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
|
1185 // Calculate final number of palette colors |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1186 ncolors = 0; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1187 for (index = 0; index < src->pal->ncolors; index++) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1188 { |
482 | 1189 if (mapping[index] + 1 > ncolors) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1190 ncolors = mapping[index] + 1; |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1191 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1192 |
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
|
1193 // Copy palette entries |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1194 for (index = 0; index < src->pal->ncolors; index++) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1195 { |
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1196 if (mapping[index] >= 0) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1197 { |
2143 | 1198 memcpy(&tmpPal->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
|
1199 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1200 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1201 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1202 // Remap image |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1203 dmMsg(1, "Remapping image to %d colors...\n", ncolors); |
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
|
1204 for (yc = 0; yc < src->height; yc++) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1205 { |
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
|
1206 Uint8 *sp = src->data + src->pitch * yc; |
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
|
1207 Uint8 *dp = dst->data + dst->pitch * yc; |
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
|
1208 for (xc = 0; xc < src->width; xc++) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1209 { |
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
|
1210 Uint8 col = sp[xc]; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1211 if (col < src->pal->ncolors && |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1212 mapping[col] >= 0 && |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1213 mapping[col] < src->pal->ncolors) |
479
b768bfb0b364
Improve color remapping, add option for removing unused colors from the final output palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
478
diff
changeset
|
1214 dp[xc] = mapping[col]; |
478
7c7a57590236
Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents:
477
diff
changeset
|
1215 else |
7c7a57590236
Calculate number of remapped colors.
Matti Hamalainen <ccr@tnsp.org>
parents:
477
diff
changeset
|
1216 dp[xc] = 0; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1217 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1218 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1219 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1220 // Set new palette, free memory |
2143 | 1221 if ((res = dmPaletteCopy(&dst->pal, tmpPal)) != 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
|
1222 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1223 res = dmError(DMERR_MALLOC, |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1224 "Could not allocate memory for final remapped palette.\n"); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1225 goto error; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1226 } |
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
|
1227 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1228 error: |
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
|
1229 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
|
1230 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
|
1231 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
|
1232 return res; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1233 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1234 |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1235 |
2226
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1236 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
|
1237 { |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1238 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
|
1239 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
|
1240 { |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1241 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
|
1242 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
|
1243 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
|
1244 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1245 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
|
1246 dmFree(filename); |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1247 } |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1248 return res; |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1249 } |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1250 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1251 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1252 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
|
1253 { |
2230 | 1254 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
|
1255 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1256 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
|
1257 { |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1258 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
|
1259 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
|
1260 res = dmDumpC64Block(fprefix, "screen", &img->screen[i], i); |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1261 res = dmDumpC64Block(fprefix, "extradata", &img->extraData[i], i); |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1262 } |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1263 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1264 return res; |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1265 } |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1266 |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1267 |
1550 | 1268 int dmConvertC64Bitmap(DMC64Image **pdst, const DMC64Image *src, |
1269 const DMC64ImageFormat *dstFmt, const DMC64ImageFormat *srcFmt) | |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1270 { |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1271 DMC64Image *dst; |
1891 | 1272 DMC64MemBlock *srcBlk = NULL, *dstBlk = NULL; |
1273 const char *blkname = NULL; | |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1274 |
1550 | 1275 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
|
1276 return DMERR_NULLPTR; |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1277 |
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
|
1278 // Allocate the destination image |
1550 | 1279 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
|
1280 return DMERR_MALLOC; |
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1281 |
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
|
1282 // 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
|
1283 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
|
1284 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
|
1285 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
|
1286 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
|
1287 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
|
1288 |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1289 // Try to do some simple fixups |
2181
560ba06a99eb
Oops, forgot these from previous commit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2160
diff
changeset
|
1290 if ((dst->fmt->type & D64_FMT_MODE_MASK) == D64_FMT_MC && |
560ba06a99eb
Oops, forgot these from previous commit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2160
diff
changeset
|
1291 (src->fmt->type & D64_FMT_MODE_MASK) == D64_FMT_HIRES) |
2124
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1292 { |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1293 dmC64MemBlockCopy(&dst->screen[0], &src->screen[0]); |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1294 } |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1295 else |
2181
560ba06a99eb
Oops, forgot these from previous commit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2160
diff
changeset
|
1296 if ((dst->fmt->type & D64_FMT_MODE_MASK) == D64_FMT_HIRES && |
560ba06a99eb
Oops, forgot these from previous commit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2160
diff
changeset
|
1297 (src->fmt->type & D64_FMT_MODE_MASK) == D64_FMT_MC) |
2124
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1298 { |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1299 // XXX TODO: Handle FLI mc->hires differently? |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1300 } |
a17b37872d8e
Simplistic conversion fixups.
Matti Hamalainen <ccr@tnsp.org>
parents:
2123
diff
changeset
|
1301 |
1947
8896d5676f1b
Architectural change: remove some duplicated variables from DMC64Image
Matti Hamalainen <ccr@tnsp.org>
parents:
1933
diff
changeset
|
1302 if ((dst->fmt->type & D64_FMT_FLI) && (src->fmt->type & 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
|
1303 { |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1304 dmMsg(1, "Upconverting multicolor to FLI.\n"); |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1305 for (int i = 0; i < dst->nbanks; i++) |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1306 { |
1929
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1307 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
|
1308 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
|
1309 |
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1310 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
|
1311 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
|
1312 |
b49814dd8469
Only copy memory blocks that do not already exist in destination.
Matti Hamalainen <ccr@tnsp.org>
parents:
1928
diff
changeset
|
1313 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
|
1314 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
|
1315 } |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1316 } |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1317 else |
1947
8896d5676f1b
Architectural change: remove some duplicated variables from DMC64Image
Matti Hamalainen <ccr@tnsp.org>
parents:
1933
diff
changeset
|
1318 if ((src->fmt->type & D64_FMT_FLI) && (dst->fmt->type & 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
|
1319 { |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1320 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
|
1321 } |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1322 |
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
|
1323 // Do per opcode copies |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1324 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) |
1493
d987a4933e1c
Some dabbling work on basic C64 bitmap conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1490
diff
changeset
|
1325 { |
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
|
1326 const DMC64EncDecOp *op = fmtGetEncDecOp(dstFmt, i); |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1327 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
|
1328 |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1329 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
|
1330 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
|
1331 |
1933
c5a46cb4cce5
Change DMC64ImageFormat parameter of dmC64GetSubjectSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1931
diff
changeset
|
1332 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
|
1333 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
|
1334 { |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1335 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
|
1336 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
|
1337 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
|
1338 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
|
1339 case DO_SET_OP: |
2108
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2103
diff
changeset
|
1340 srcBlk = (DMC64MemBlock *) dmC64GetOpMemBlock(src, op->subject, op->bank); |
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2103
diff
changeset
|
1341 dstBlk = (DMC64MemBlock *) dmC64GetOpMemBlock(dst, op->subject, op->bank); |
1852
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1843
diff
changeset
|
1342 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
|
1343 |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1344 // 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
|
1345 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
|
1346 break; |
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1347 |
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
|
1348 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
|
1349 { |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1350 // The block exists in source and is of sufficient size, so copy it |
1842
a3fc0cab1a60
Improve C64 bitmap conversion messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1836
diff
changeset
|
1351 dmMsg(3, "Copying whole block '%s' op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x)\n", |
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
|
1352 blkname, i, 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
|
1353 |
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
|
1354 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
|
1355 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1356 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
|
1357 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
|
1358 { |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1359 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
|
1360 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
|
1361 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
|
1362 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
|
1363 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
|
1364 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
|
1365 { |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1366 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
|
1367 "Could not allocate '%s' block! " |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1368 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x)\n", |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1369 blkname, i, op->offs, op->offs, op->bank, 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
|
1370 } |
1829
5639142e0b87
Change the order and logic of how we do upconversion fixups in dmConvertC64Bitmap().
Matti Hamalainen <ccr@tnsp.org>
parents:
1823
diff
changeset
|
1371 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
|
1372 { |
1842
a3fc0cab1a60
Improve C64 bitmap conversion messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1836
diff
changeset
|
1373 dmMsg(3, "Creating whole block '%s' op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x)\n", |
a3fc0cab1a60
Improve C64 bitmap conversion messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1836
diff
changeset
|
1374 blkname, i, op->offs, op->offs, op->bank, size, size); |
a3fc0cab1a60
Improve C64 bitmap conversion messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1836
diff
changeset
|
1375 } |
a3fc0cab1a60
Improve C64 bitmap conversion messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1836
diff
changeset
|
1376 else |
a3fc0cab1a60
Improve C64 bitmap conversion messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1836
diff
changeset
|
1377 { |
a3fc0cab1a60
Improve C64 bitmap conversion messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1836
diff
changeset
|
1378 dmMsg(3, "Creating block '%s' from partial data op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x)\n", |
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
|
1379 blkname, i, op->offs, op->offs, op->bank, 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
|
1380 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1381 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
|
1382 { |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1383 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
|
1384 // 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
|
1385 // 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
|
1386 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
|
1387 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
|
1388 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
|
1389 |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1390 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
|
1391 // 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
|
1392 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
|
1393 |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1394 case DO_SET_OP: |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1395 dmMemset(dstBlk->data, op->offs, 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
|
1396 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
|
1397 |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1398 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
|
1399 return dmError(DMERR_INTERNAL, |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1400 "Unhandled op type %d in " |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1401 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1402 op->type, i, op->offs, op->offs, op->bank, 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
|
1403 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1404 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
|
1405 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1406 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
|
1407 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1408 } |
02f604264bc4
Improve C64 image format up/down conversion. Might actually work for some formats now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1811
diff
changeset
|
1409 |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1410 return DMERR_OK; |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1411 } |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1412 |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1413 |
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1414 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
|
1415 { |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1416 int res = DMERR_OK; |
1481 | 1417 DMGrowBuf buf; |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1418 |
1694
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1692
diff
changeset
|
1419 dmGrowBufInit(&buf); |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1692
diff
changeset
|
1420 |
1481 | 1421 // Encode to target format |
1422 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
|
1423 if ((res = dmC64EncodeBMP(&buf, image, fmt)) != DMERR_OK) |
1585 | 1424 { |
1425 dmErrorMsg("Error encoding bitmap data: %s\n", dmErrorStr(res)); | |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1426 goto error; |
1585 | 1427 } |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1428 |
1481 | 1429 // 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
|
1430 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
|
1431 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
|
1432 |
1550 | 1433 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
|
1434 |
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1435 error: |
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
|
1436 dmGrowBufFree(&buf); |
550
12854cbd6fab
Initial support for bitmap -> bitmap conversion in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
547
diff
changeset
|
1437 return res; |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1438 } |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1439 |
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1440 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1441 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
|
1442 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
|
1443 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
|
1444 const DMImageWriteSpec *spec) |
1303 | 1445 { |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1446 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
|
1447 int res; |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1448 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1449 if ((res = dmf_open_stdio(hdrFilename, "wb", &fp)) != DMERR_OK) |
1303 | 1450 { |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1451 return dmError(res, |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1452 "RAW: Could not open file '%s' for writing.\n", |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1453 hdrFilename); |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1454 } |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1455 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
1456 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
|
1457 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1458 dmf_close(fp); |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1459 return res; |
1303 | 1460 } |
1461 | |
1462 | |
2156
e6ec7fad9ce2
Rename DMImageConvSpec to DMImageWriteSpec to better reflec the struct's purpose.
Matti Hamalainen <ccr@tnsp.org>
parents:
2155
diff
changeset
|
1463 int dmWriteImage(const char *filename, DMImage *pimage, DMImageWriteSpec *spec, const DMImageFormat *fmt, BOOL info) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1464 { |
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
|
1465 int res = DMERR_OK; |
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
|
1466 |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1467 // 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
|
1468 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
|
1469 { |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1470 return dmError(DMERR_NOT_SUPPORTED, |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1471 "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
|
1472 fmt->name); |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1473 } |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1474 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1475 if (info) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1476 { |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1477 dmMsg(1, "Outputting '%s' image %d x %d -> %d x %d [%d x %d]\n", |
1893
334501b6cce5
Use format name instead of file extension in a message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1891
diff
changeset
|
1478 fmt->name, |
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
|
1479 pimage->width, pimage->height, |
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
|
1480 pimage->width * spec->scaleX, pimage->height * spec->scaleY, |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
897
diff
changeset
|
1481 spec->scaleX, spec->scaleY); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1482 } |
435 | 1483 |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1484 // Perform color remapping |
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
|
1485 DMImage *image = pimage; |
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
|
1486 BOOL allocated = FALSE; |
2182
52985e4bc9ce
Wrong struct pointer variable used .. but actually the same pointer, so no harm done. Fixed anyway.
Matti Hamalainen <ccr@tnsp.org>
parents:
2181
diff
changeset
|
1487 if (optRemapColors && image->pixfmt == DM_PIXFMT_PALETTE) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1488 { |
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
|
1489 if ((res = dmRemapImageColors(&image, pimage)) != DMERR_OK) |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1490 return res; |
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
|
1491 |
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
|
1492 allocated = TRUE; |
473
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1493 } |
73bfe73553eb
Implement palette remapping option for image outputs.
Matti Hamalainen <ccr@tnsp.org>
parents:
471
diff
changeset
|
1494 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
1495 // 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
|
1496 if (spec->nplanes == 0) |
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
1497 { |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
1498 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
|
1499 image->pal != NULL) |
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
1500 spec->nplanes = dmGetNPlanesFromNColors(image->pal->ncolors); |
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
1501 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
|
1502 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
|
1503 spec->nplanes = image->bpp; |
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
1504 } |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
1505 |
2100
81fb21dd3265
Add dmGetNPlanesFromNColors() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
2099
diff
changeset
|
1506 if (spec->nplanes <= 0) |
2099
dac89484f143
Fix nplanes and bpp in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2097
diff
changeset
|
1507 spec->nplanes = 4; |
dac89484f143
Fix nplanes and bpp in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2097
diff
changeset
|
1508 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
1509 spec->fmtid = fmt->fmtid; |
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
1510 |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1511 // 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
|
1512 switch (fmt->fmtid) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1513 { |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
1514 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
|
1515 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
|
1516 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
|
1517 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
|
1518 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
|
1519 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
|
1520 |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
1521 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
|
1522 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
|
1523 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
|
1524 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
|
1525 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
|
1526 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
|
1527 |
1543
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
1528 case DM_IMGFMT_RAW: |
416d7b3ba3b2
Rename libgfx IMGFMT_* constants to DM_IMGFMT_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
1529 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
|
1530 { |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1531 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
|
1532 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
|
1533 (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
|
1534 { |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1535 res = dmError(DMERR_MALLOC, |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1536 "Could not allocate memory for filename strings? :O\n"); |
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
|
1537 goto err; |
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
|
1538 } |
820 | 1539 |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1540 // 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
|
1541 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
|
1542 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
|
1543 |
1291 | 1544 if (info) |
1545 { | |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1546 dmMsg(2, "%d bitplanes, %s planes output.\n", |
1291 | 1547 spec->nplanes, |
1548 spec->planar ? "planar/interleaved" : "non-interleaved"); | |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1549 dmMsg(2, "%s datafile '%s', ID prefix '%s'.\n", |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1550 fmt->fmtid == DM_IMGFMT_ARAW ? "ARAW" : "RAW", |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1551 hdrFilename, prefix); |
1291 | 1552 } |
1891 | 1553 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1554 res = dmWriteIFFMasterRAWHeaderFile( |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
1555 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
|
1556 |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1557 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
|
1558 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
|
1559 } |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1560 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
|
1561 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2062
diff
changeset
|
1562 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
|
1563 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
|
1564 break; |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1565 } |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1566 |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1567 // 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
|
1568 if (res == DMERR_OK) |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1569 { |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1570 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
|
1571 |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1572 if (info) |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1573 { |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1574 char *str; |
2158
e363dc852383
Oops, display the real intended output pixfmt.
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
1575 switch (spec->pixfmt) |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1576 { |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
1577 case DM_PIXFMT_PALETTE : str = "indexed/paletted"; break; |
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
1578 case DM_PIXFMT_RGB : str = "24bit RGB"; break; |
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
1579 case DM_PIXFMT_RGBA : str = "32bit RGBA"; break; |
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
1580 case DM_PIXFMT_GRAYSCALE : str = "grayscale"; break; |
2142
894781b7310a
Possibly fix RAW output when clipping nplanes/bpp.
Matti Hamalainen <ccr@tnsp.org>
parents:
2137
diff
changeset
|
1581 default : str = "???"; break; |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1582 } |
2160
0b9315070001
Lower verbosity threshold the "Using ... output" when converting to image.
Matti Hamalainen <ccr@tnsp.org>
parents:
2159
diff
changeset
|
1583 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
|
1584 } |
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1585 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1586 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
|
1587 { |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1588 dmErrorMsg("Could not open file '%s' for writing.\n", |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1589 filename); |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1590 goto err; |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1591 } |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1592 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1593 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
|
1594 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1874
diff
changeset
|
1595 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
|
1596 } |
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
|
1597 |
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
|
1598 err: |
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
|
1599 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
|
1600 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
|
1601 |
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
|
1602 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
|
1603 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1604 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1605 |
547
ca5ad51c6479
Make dmConvertByte() static.
Matti Hamalainen <ccr@tnsp.org>
parents:
546
diff
changeset
|
1606 static Uint8 dmConvertByte(const Uint8 *sp, const BOOL multicolor) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1607 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1608 Uint8 byte = 0; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1609 int xc; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1610 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1611 if (multicolor) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1612 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1613 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
|
1614 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1615 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
|
1616 byte |= pixel << (6 - (xc * 2)); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1617 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1618 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1619 else |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1620 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1621 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
|
1622 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1623 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
|
1624 byte |= pixel << (7 - xc); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1625 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1626 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1627 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1628 return byte; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1629 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1630 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1631 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1632 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
|
1633 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
|
1634 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1635 int yc; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1636 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1637 if (xoffs < 0 || yoffs < 0 || |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1638 xoffs + D64_CHR_WIDTH_PX > image->width || |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1639 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
|
1640 return FALSE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1641 |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1642 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
|
1643 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1644 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
|
1645 buf[yc] = dmConvertByte(sp, multicolor); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1646 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1647 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1648 return TRUE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1649 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1650 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1651 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1652 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
|
1653 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
|
1654 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1655 int yc, xc; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1656 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1657 if (xoffs < 0 || yoffs < 0 || |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1658 xoffs + D64_SPR_WIDTH_PX > image->width || |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1659 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
|
1660 return FALSE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1661 |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1662 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
|
1663 { |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1664 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
|
1665 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1666 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
|
1667 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
|
1668 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1669 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1670 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1671 return TRUE; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1672 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1673 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1674 |
1928 | 1675 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
|
1676 { |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1677 int ret = DMERR_OK; |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1678 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
|
1679 FILE *outFile = NULL; |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1680 Uint8 *buf = NULL; |
907 | 1681 size_t outBufSize; |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1682 char *outType; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1683 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1684 switch (outFormat) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1685 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1686 case FFMT_CHAR: |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1687 outBufSize = D64_CHR_SIZE; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1688 outBlockW = image->width / D64_CHR_WIDTH_PX; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1689 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
|
1690 outType = "char"; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1691 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1692 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1693 case FFMT_SPRITE: |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1694 outBufSize = D64_SPR_SIZE; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1695 outBlockW = image->width / D64_SPR_WIDTH_PX; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1696 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
|
1697 outType = "sprite"; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1698 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1699 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1700 default: |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1701 ret = dmError(DMERR_INVALID_ARGS, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1702 "Invalid output format %d, internal error.\n", outFormat); |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1703 goto error; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1704 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1705 |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1706 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
|
1707 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1708 ret = dmError(DMERR_INVALID_ARGS, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1709 "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
|
1710 outBlockW, outBlockH); |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1711 goto error; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1712 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1713 |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1714 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
|
1715 { |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1716 ret = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1717 dmErrorMsg("Could not open '%s' for writing, %d: %s.\n", |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1718 filename, ret, dmErrorStr(ret)); |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1719 goto error; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1720 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1721 |
907 | 1722 if ((buf = dmMalloc(outBufSize)) == NULL) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1723 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1724 dmErrorMsg("Could not allocate %d bytes for conversion buffer.\n", |
907 | 1725 outBufSize); |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1726 goto error; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1727 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1728 |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1729 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
|
1730 outBlockW, outBlockH, outBlockW * outBlockH, outType); |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1731 |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1732 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
|
1733 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
|
1734 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1735 switch (outFormat) |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1736 { |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1737 case FFMT_CHAR: |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1738 if (!dmConvertImage2Char(buf, image, |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1739 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
|
1740 multicolor)) |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1741 { |
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1742 ret = DMERR_DATA_ERROR; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1743 goto error; |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1744 } |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1745 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1746 |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1747 case FFMT_SPRITE: |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1748 if (!dmConvertImage2Sprite(buf, image, |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1749 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
|
1750 multicolor)) |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1751 { |
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1752 ret = DMERR_DATA_ERROR; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1753 goto error; |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1754 } |
910 | 1755 break; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1756 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1757 |
907 | 1758 if (!dm_fwrite_str(outFile, buf, outBufSize)) |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1759 { |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1760 ret = dmGetErrno(); |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1761 dmError(ret, "Error writing data block %d,%d to '%s', %d: %s\n", |
909
be5d276f8a6c
Some work on error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
907
diff
changeset
|
1762 bx, by, filename, ret, dmErrorStr(ret)); |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1763 goto error; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1764 } |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1765 } |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1766 |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1767 fclose(outFile); |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1768 dmFree(buf); |
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1769 return 0; |
828 | 1770 |
1771 error: | |
1772 if (outFile != NULL) | |
1773 fclose(outFile); | |
829
97700378ecd8
Oops, accidentally committed unfinished code :S
Matti Hamalainen <ccr@tnsp.org>
parents:
828
diff
changeset
|
1774 dmFree(buf); |
910 | 1775 return ret; |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1776 } |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
1777 |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
1778 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1779 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
|
1780 { |
1524
532c3ceaec1a
Fix uninitilized variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1522
diff
changeset
|
1781 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
|
1782 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
|
1783 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
1784 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
|
1785 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1786 case FFMT_CHAR: |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1787 outSize = D64_CHR_SIZE; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1788 outWidth = D64_CHR_WIDTH_UT; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1789 outWidthPX = D64_CHR_WIDTH_PX; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1790 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
|
1791 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1792 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1793 case FFMT_SPRITE: |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1794 outSize = D64_SPR_SIZE; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1795 outWidth = D64_SPR_WIDTH_UT; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1796 outWidthPX = D64_SPR_WIDTH_PX; |
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1797 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
|
1798 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1799 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1800 default: |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1801 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
|
1802 "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
|
1803 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1804 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1805 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
|
1806 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
|
1807 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
1808 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
|
1809 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1810 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
|
1811 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
|
1812 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1813 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
|
1814 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
|
1815 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1816 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
|
1817 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1818 ret = dmGetErrno(); |
1525
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1819 dmError(ret, "Error opening output file '%s': %s\n", |
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1820 optOutFilename, dmErrorStr(ret)); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1821 goto error; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1822 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1823 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1824 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
|
1825 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1826 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
|
1827 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
1828 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
|
1829 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1830 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
|
1831 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
|
1832 break; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
1833 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
|
1834 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
|
1835 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1836 } |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1837 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
|
1838 itemCount++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1839 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1840 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1841 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
|
1842 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1843 else |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
1844 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
|
1845 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1846 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
|
1847 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
|
1848 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
|
1849 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1850 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
|
1851 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1852 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
|
1853 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1854 dmErrorMsg("Sequential image output requires filename template.\n"); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1855 goto error; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1856 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1857 |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
1858 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
|
1859 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
|
1860 optItemCount, |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1861 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
|
1862 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
|
1863 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
|
1864 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1865 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1866 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1867 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
|
1868 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
|
1869 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1870 dmErrorMsg("Single-image output requires count to be set (-n).\n"); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1871 goto error; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1872 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1873 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1874 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
|
1875 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
|
1876 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
|
1877 outIHeight++; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1878 |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2156
diff
changeset
|
1879 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
|
1880 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1881 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
1882 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
|
1883 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1884 dmErrorMsg("Could not allocate C64 palette for output image: %d\n", err); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1885 goto error; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1886 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1887 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1888 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
|
1889 { |
827 | 1890 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
|
1891 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
|
1892 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1893 dmErrorMsg("Internal error in conversion of raw data to bitmap: %d.\n", err); |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2079
diff
changeset
|
1894 goto error; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1895 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1896 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1897 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
|
1898 { |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1899 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
|
1900 optOutFilename, |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1901 itemCount, |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
1902 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
|
1903 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1904 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
|
1905 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
1906 dmErrorMsg("Could not allocate memory for filename template?\n"); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1907 goto error; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1908 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1909 |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1910 ret = dmWriteImage(outFilename, outImage, &optSpec, |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
1911 &dmImageFormatList[optOutFormat], TRUE); |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1912 if (ret != DMERR_OK) |
799 | 1913 { |
1525
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1914 dmErrorMsg("Error writing output image '%s': %s.\n", |
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1915 outFilename, dmErrorStr(ret)); |
799 | 1916 } |
1917 | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1918 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
|
1919 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1920 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1921 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1922 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
|
1923 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1924 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
|
1925 outY++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1926 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1927 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1928 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
1929 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
|
1930 itemCount++; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1931 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1932 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1933 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
|
1934 { |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
1935 ret = dmWriteImage(optOutFilename, outImage, &optSpec, |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
1936 &dmImageFormatList[optOutFormat], TRUE); |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1937 if (ret != DMERR_OK) |
799 | 1938 { |
1525
9602f7ea1e7e
Improve some error messages in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1524
diff
changeset
|
1939 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
|
1940 optOutFilename, dmErrorStr(ret)); |
799 | 1941 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1942 } |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
1943 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1944 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
|
1945 } |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1946 else |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
1947 if (optOutType == FFMT_BITMAP) |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1948 { |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1949 if (optSequential) |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1950 { |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1951 ret = dmError(DMERR_INVALID_ARGS, |
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1952 "Sequential output not supported for spr/char -> bitmap conversion.\n"); |
607
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1953 goto error; |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1954 } |
360b1ad83ed9
Rename things; Fix build by combining the conflicting rules.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
1955 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1956 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1957 error: |
972
6d5edc6af2ad
Error handling cleanups/fixes.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1958 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
|
1959 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1960 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1961 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1962 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
|
1963 { |
933 | 1964 FILE *inFile = NULL; |
1440 | 1965 const DMC64ImageFormat *inC64Fmt = NULL; |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
1966 DMConvFormat inFormat, outFormat; |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
1967 DMC64Image *inC64Image = NULL, *outC64Image = NULL; |
2052
aa8df4f1b785
Fix minor memory leaks in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2030
diff
changeset
|
1968 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
|
1969 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
|
1970 size_t dataSize, dataSizeOrig, dataRealOffs; |
2097 | 1971 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
|
1972 |
1865
3e830bcb001a
Improve color map and ANSI output support.
Matti Hamalainen <ccr@tnsp.org>
parents:
1864
diff
changeset
|
1973 // Default color mapping |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2124
diff
changeset
|
1974 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
|
1975 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
|
1976 |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
1977 // 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
|
1978 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
|
1979 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1980 // Initialize list of additional conversion formats |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
1981 if ((res = dmLib64GFXInit()) != DMERR_OK) |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
1982 { |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
1983 dmErrorMsg("Could not initialize lib64gfx: %s\n", |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
1984 dmErrorStr(res)); |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
1985 goto exit; |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
1986 } |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
1987 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1988 nconvFormatList = ndmImageFormatList + nbaseFormatList; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1989 convFormatList = dmCalloc(nconvFormatList, sizeof(DMConvFormat)); |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1990 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1991 for (n = i = 0; i < ndmImageFormatList; i++) |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1992 { |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1993 const DMImageFormat *sfmt = &dmImageFormatList[i]; |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1994 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
|
1995 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
|
1996 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
|
1997 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
|
1998 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
|
1999 dfmt->format = sfmt->fmtid; |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2000 } |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2001 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2002 for (i = 0; i < nbaseFormatList; i++) |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2003 memcpy(&convFormatList[n++], &baseFormatList[i], sizeof(DMConvFormat)); |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2004 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2005 // Initialize and parse commandline |
1910 | 2006 dmInitProg("gfxconv", "Simple graphics converter", "0.94", 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
|
2007 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2008 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
|
2009 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
|
2010 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
|
2011 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2012 // 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
|
2013 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
|
2014 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2015 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
|
2016 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
|
2017 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2018 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
|
2019 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
|
2020 { |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2021 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
|
2022 formatTypeList[optInType]); |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2023 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2024 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2025 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2026 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2027 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
|
2028 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2029 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
|
2030 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2031 dmErrorMsg("Standard input cannot be used without specifying input format.\n"); |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2032 dmErrorMsg("Perhaps you should try using --help\n"); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2033 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
|
2034 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2035 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
|
2036 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
|
2037 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2038 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2039 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
|
2040 { |
2097 | 2041 res = dmGetErrno(); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2042 dmErrorMsg("Error opening input file '%s', %d: %s\n", |
488 | 2043 optInFilename, res, dmErrorStr(res)); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2044 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
|
2045 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2046 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2047 // 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
|
2048 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
|
2049 { |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2050 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
|
2051 if (dext) |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2052 { |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2053 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
|
2054 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
|
2055 { |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2056 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
|
2057 formatTypeList[optOutType]); |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2058 } |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2059 } |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2060 } |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2061 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
|
2062 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
|
2063 optOutType = FFMT_ASCII; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2064 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2065 // 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
|
2066 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
|
2067 |
2097 | 2068 if ((res = dmReadDataFile(inFile, NULL, &dataBufOrig, &dataSizeOrig)) != DMERR_OK) |
2069 { | |
2070 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
|
2071 goto exit; |
2097 | 2072 } |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2073 |
1664
9181d9148654
Fix a minor memory leak and file descriptor leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1640
diff
changeset
|
2074 fclose(inFile); |
9181d9148654
Fix a minor memory leak and file descriptor leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1640
diff
changeset
|
2075 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2076 // 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
|
2077 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
|
2078 { |
2010
09d548b08150
Improve input skip option messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
2006
diff
changeset
|
2079 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
|
2080 optInSkip, optInSkip, dataSizeOrig); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2081 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
|
2082 } |
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2083 |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2084 if (optInSkipNeg) |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2085 { |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2086 dataBuf = dataBufOrig + dataSizeOrig - optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2087 dataSize = optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2088 dataRealOffs = dataSizeOrig - optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2089 |
2010
09d548b08150
Improve input skip option messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
2006
diff
changeset
|
2090 dmMsg(1, "Input skip -%d (-0x%x). Offset %d (0x%x), size %d (0x%x).\n", |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2091 optInSkip, optInSkip, |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2092 dataRealOffs, dataRealOffs, |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2093 dataSize, dataSize); |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2094 |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2095 } |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2096 else |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2097 { |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2098 dataBuf = dataBufOrig + optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2099 dataSize = dataSizeOrig - optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2100 dataRealOffs = optInSkip; |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2101 |
2010
09d548b08150
Improve input skip option messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
2006
diff
changeset
|
2102 dmMsg(1, "Input skip %d (0x%x), size %d (0x%x).\n", |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2103 optInSkip, optInSkip, |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2104 dataSize, dataSize); |
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2105 } |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2106 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2107 // 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
|
2108 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
|
2109 optInFormat = optForcedInSubFormat; |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2110 |
1479
c4755b73b93c
Improve how input skipping is done. This, however, currently breaks skipping for
Matti Hamalainen <ccr@tnsp.org>
parents:
1470
diff
changeset
|
2111 // 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
|
2112 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
|
2113 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2114 // Probe for format |
516 | 2115 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
|
2116 DMGrowBuf tbuf; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2117 |
1867
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
2118 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
|
2119 { |
1867
15cbf17a8ea6
Make output format -f option symmetric with the -i input format option.
Matti Hamalainen <ccr@tnsp.org>
parents:
1866
diff
changeset
|
2120 forced = &dmC64ImageFormats[optForcedInSubFormat]; |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2121 dmMsg(0, "Forced '%s' format image, type %d, %s\n", |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1759
diff
changeset
|
2122 forced->name, forced->format->type, forced->fext); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2123 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2124 |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
2125 res = dmC64DecodeBMP(&inC64Image, |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
2126 dmGrowBufConstCreateFrom(&tbuf, dataBuf, dataSize), |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
2127 0, 2, &inC64Fmt, forced); |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
2128 |
1630
00e0d345e7f1
Improve autoprobing error handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1629
diff
changeset
|
2129 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
|
2130 { |
1522
0d1cf72fb732
Clarify the "probed" messages of gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1514
diff
changeset
|
2131 dmMsg(1, "Probed '%s' format image, type %d, %s\n", |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1759
diff
changeset
|
2132 inC64Fmt->name, inC64Fmt->format->type, inC64Fmt->fext); |
1630
00e0d345e7f1
Improve autoprobing error handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1629
diff
changeset
|
2133 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2134 optInType = FFMT_BITMAP; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2135 } |
897 | 2136 else |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2137 if (res != DMERR_OK && (forced != NULL || optInType == FFMT_BITMAP)) |
897 | 2138 { |
1464
73e00bf7531c
Improve one error message by showing the error code.
Matti Hamalainen <ccr@tnsp.org>
parents:
1457
diff
changeset
|
2139 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
|
2140 goto exit; |
897 | 2141 } |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2142 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2143 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2144 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
|
2145 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2146 const DMImageFormat *ifmt = NULL; |
435 | 2147 int index; |
465 | 2148 dmMsg(4, "Trying to probe image formats.\n"); |
1708
55db8d6dffa5
Do not apply input skip offset here anymore, it's handled more generally elsewhere.
Matti Hamalainen <ccr@tnsp.org>
parents:
1707
diff
changeset
|
2149 if (dmImageProbeGeneric(dataBuf, dataSize, &ifmt, &index) > 0) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2150 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2151 optInType = FFMT_IMAGE; |
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2152 optInFormat = index; |
1869
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2153 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
|
2154 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2155 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2156 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2157 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
|
2158 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2159 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
|
2160 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
|
2161 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2162 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2163 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
|
2164 dmGetConvFormat(optOutType, optOutFormat, &outFormat)) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2165 { |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2166 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
|
2167 inFormat.name, inFormat.fext, |
1067df067f28
Improve input/output format probe/forcing and related messages.
Matti Hamalainen <ccr@tnsp.org>
parents:
1867
diff
changeset
|
2168 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
|
2169 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2170 |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2171 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
|
2172 { |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2173 int scaleX = 1, scaleY = 1; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2174 if (inC64Fmt != NULL) |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2175 { |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2176 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
|
2177 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
|
2178 } |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2179 |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2180 switch (optScaleMode) |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2181 { |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2182 case SCALE_AUTO: |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2183 optSpec.scaleX = scaleX; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2184 optSpec.scaleY = scaleY; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2185 break; |
2070 | 2186 |
2058
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2187 case SCALE_RELATIVE: |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2188 optSpec.scaleX *= scaleX; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2189 optSpec.scaleY *= scaleY; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2190 break; |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2191 } |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2192 } |
020f2151949a
Implement support for the c64 format aspect rations and automatic scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2052
diff
changeset
|
2193 |
2214 | 2194 if (optPaletteFile != NULL) |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2195 { |
2214 | 2196 if ((res = dmHandleExternalPalette(optPaletteFile, &optC64Spec.pal)) != DMERR_OK) |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2197 goto exit; |
2215
69e868af764c
Check for minimum number of colors in a external palette file.
Matti Hamalainen <ccr@tnsp.org>
parents:
2214
diff
changeset
|
2198 |
2216
2fa3458b364d
Oops, 10L in previous commit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2215
diff
changeset
|
2199 if (optC64Spec.pal->ncolors < D64_NCOLORS) |
2215
69e868af764c
Check for minimum number of colors in a external palette file.
Matti Hamalainen <ccr@tnsp.org>
parents:
2214
diff
changeset
|
2200 { |
69e868af764c
Check for minimum number of colors in a external palette file.
Matti Hamalainen <ccr@tnsp.org>
parents:
2214
diff
changeset
|
2201 dmErrorMsg("Palette does not have enough colors (%d < %d)\n", |
2216
2fa3458b364d
Oops, 10L in previous commit.
Matti Hamalainen <ccr@tnsp.org>
parents:
2215
diff
changeset
|
2202 optC64Spec.pal->ncolors, D64_NCOLORS); |
2215
69e868af764c
Check for minimum number of colors in a external palette file.
Matti Hamalainen <ccr@tnsp.org>
parents:
2214
diff
changeset
|
2203 goto exit; |
69e868af764c
Check for minimum number of colors in a external palette file.
Matti Hamalainen <ccr@tnsp.org>
parents:
2214
diff
changeset
|
2204 } |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2205 } |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2206 else |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2207 { |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2208 // No palette file specified, use internal palette |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2209 if (optC64Palette == NULL) |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2210 optC64Palette = &dmC64DefaultPalettes[0]; |
2226
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
2211 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2212 dmMsg(1, "Using internal palette '%s' (%s).\n", |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2213 optC64Palette->name, optC64Palette->desc); |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2214 |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2215 optC64Spec.cpal = optC64Palette; |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2216 |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2217 if ((res = dmC64PaletteFromC64Palette(&optC64Spec.pal, optC64Palette, FALSE)) != DMERR_OK) |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2218 { |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2219 dmErrorMsg("Could not setup palette: %s\n", |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2220 dmErrorStr(res)); |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2221 goto exit; |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2222 } |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2223 } |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
2224 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2225 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
|
2226 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2227 case FFMT_SPRITE: |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2228 case FFMT_CHAR: |
2005
2ff214f811b4
Implement negative input data skip values for gfxconv -s option.
Matti Hamalainen <ccr@tnsp.org>
parents:
2004
diff
changeset
|
2229 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
|
2230 break; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
2231 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2232 case FFMT_BITMAP: |
2097 | 2233 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
|
2234 { |
2097 | 2235 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
|
2236 goto exit; |
2097 | 2237 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2238 |
2097 | 2239 switch (optOutType) |
2240 { | |
2241 case FFMT_IMAGE: | |
2242 case FFMT_CHAR: | |
2243 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
|
2244 // Set character data if required |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
2245 if ((inC64Fmt->format->type & D64_FMT_CHAR) && |
2126
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
2246 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
|
2247 { |
2126
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
2248 // Check character ROM filename |
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
2249 if (optCharROMFilename == NULL) |
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
2250 optCharROMFilename = DM_DEF_CHARGEN; |
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
2251 |
2123
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
2252 // 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
|
2253 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
|
2254 optCharROMFilename); |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
2255 |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
2256 if ((res = dmReadDataFile(NULL, optCharROMFilename, |
2126
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
2257 &inC64Image->charData[0].data, |
cffadb745484
Fix character ROM data handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
2258 &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
|
2259 { |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
2260 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
|
2261 optCharROMFilename); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2262 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
|
2263 } |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
2264 } |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
2265 |
47ddbedf5b56
Add initial support to 64vw and gfxconv for viewing and converting character
Matti Hamalainen <ccr@tnsp.org>
parents:
2120
diff
changeset
|
2266 // Convert the image |
2223
5477e792def3
Remove useless DMC64ImageFormat parameter from some conversion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2217
diff
changeset
|
2267 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
|
2268 |
2097 | 2269 if (res != DMERR_OK || outImage == NULL) |
2270 { | |
2271 dmErrorMsg("Error in bitmap to image conversion.\n"); | |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2272 goto exit; |
2097 | 2273 } |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2274 |
2097 | 2275 switch (optOutType) |
2276 { | |
2277 case FFMT_IMAGE: | |
2278 res = dmWriteImage(optOutFilename, outImage, &optSpec, | |
2279 &dmImageFormatList[optOutFormat], TRUE); | |
2280 break; | |
1874 | 2281 |
2097 | 2282 case FFMT_CHAR: |
2283 case FFMT_SPRITE: | |
2284 res = dmWriteSpritesAndChars(optOutFilename, outImage, | |
2285 optOutType, optInMulticolor); | |
2286 break; | |
2287 } | |
2288 break; | |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2289 |
2226
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
2290 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
|
2291 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
|
2292 break; |
6037ba60730a
Add output format for "dumping" c64 bitmap image structs data into separate
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
2293 |
2097 | 2294 case FFMT_BITMAP: |
2295 if ((res = dmConvertC64Bitmap(&outC64Image, inC64Image, | |
2296 &dmC64ImageFormats[optOutFormat], inC64Fmt)) != DMERR_OK) | |
2297 { | |
2298 dmErrorMsg("Error in bitmap format conversion.\n"); | |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2299 goto exit; |
2097 | 2300 } |
2301 if (dmVerbosity >= 2) | |
2302 { | |
2303 dmPrint(0, "INPUT:\n"); dmC64ImageDump(stderr, inC64Image, inC64Fmt, " "); | |
2304 dmPrint(0, "OUTPUT:\n"); dmC64ImageDump(stderr, outC64Image, &dmC64ImageFormats[optOutFormat], " "); | |
2305 } | |
2306 res = dmWriteBitmap(optOutFilename, outC64Image, &dmC64ImageFormats[optOutFormat]); | |
2307 break; | |
534
fbfdc9e4fe2b
Begin preparations for improved bitmap conversion support. Breaks lib64gfx API.
Matti Hamalainen <ccr@tnsp.org>
parents:
530
diff
changeset
|
2308 |
2097 | 2309 default: |
2310 dmErrorMsg("Unsupported output format for bitmap conversion.\n"); | |
2311 break; | |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2312 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2313 break; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2314 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2315 case FFMT_IMAGE: |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2316 { |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2317 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
|
2318 DMResource *fp; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2319 |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2320 if (optOutFilename == NULL) |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2321 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2322 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
|
2323 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
|
2324 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2325 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
2326 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
|
2327 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
2328 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
|
2329 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
|
2330 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
2331 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2332 // 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
|
2333 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
|
2334 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
|
2335 else |
1874 | 2336 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
|
2337 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1604
diff
changeset
|
2338 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
|
2339 |
1440 | 2340 if (res != DMERR_OK || inImage == NULL) |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2341 goto exit; |
1235
5b8245e5f785
Remove trailing whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
1167
diff
changeset
|
2342 |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2343 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
|
2344 { |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2345 case FFMT_IMAGE: |
1811
4f141426eb31
Clean up the image format output stuff in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
1807
diff
changeset
|
2346 res = dmWriteImage(optOutFilename, inImage, &optSpec, |
1909
a323ca23f449
Rename several variables to lessen the confusion about input/output "format"
Matti Hamalainen <ccr@tnsp.org>
parents:
1897
diff
changeset
|
2347 &dmImageFormatList[optOutFormat], 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
|
2348 break; |
417 | 2349 |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2350 case FFMT_CHAR: |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2351 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
|
2352 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
|
2353 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
|
2354 break; |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2355 |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2356 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
|
2357 { |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2358 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
|
2359 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
|
2360 &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
|
2361 |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2362 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
|
2363 { |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2364 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
|
2365 dmErrorMsg("Error in image to bitmap conversion: %s\n", |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2366 dmErrorStr(res)); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2367 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
|
2368 } |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2369 |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2370 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
|
2371 &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
|
2372 { |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2373 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
|
2374 dmErrorMsg("Error in bitmap format conversion: %s\n", |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2375 dmErrorStr(res)); |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2376 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
|
2377 } |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2378 |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1929
diff
changeset
|
2379 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
|
2380 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
|
2381 } |
489
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2382 break; |
fca3c240ccac
Implement simplistic image input to char/sprite splitter conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
488
diff
changeset
|
2383 |
417 | 2384 default: |
1874 | 2385 dmErrorMsg("Unsupported output format for image conversion.\n"); |
417 | 2386 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
|
2387 } |
806 | 2388 |
2389 if (res != DMERR_OK) | |
2390 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
940
diff
changeset
|
2391 dmErrorMsg("Error writing output (%s), probably unsupported output format for bitmap/image conversion.\n", |
806 | 2392 dmErrorStr(res)); |
2393 } | |
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 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2395 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2396 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2397 |
2198
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2398 exit: |
c26a51ea70be
Replace label 'error' with 'exit'.
Matti Hamalainen <ccr@tnsp.org>
parents:
2183
diff
changeset
|
2399 // Cleanup |
1664
9181d9148654
Fix a minor memory leak and file descriptor leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1640
diff
changeset
|
2400 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
|
2401 dmFree(dataBufOrig); |
1440 | 2402 dmC64ImageFree(inC64Image); |
1490
665a0b917d22
Begin restructuring how C64 bitmaps are converted.
Matti Hamalainen <ccr@tnsp.org>
parents:
1481
diff
changeset
|
2403 dmC64ImageFree(outC64Image); |
2052
aa8df4f1b785
Fix minor memory leaks in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2030
diff
changeset
|
2404 dmImageFree(inImage); |
aa8df4f1b785
Fix minor memory leaks in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2030
diff
changeset
|
2405 dmImageFree(outImage); |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2198
diff
changeset
|
2406 dmLib64GFXClose(); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
417
diff
changeset
|
2407 |
933 | 2408 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
|
2409 } |