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