Mercurial > hg > dmlib
annotate tools/lib64gfx.c @ 2303:dcf1016f3d27
Implement new (horizontal raw element) pattern storage mode for JSSMOD. Bump
JSSMOD format version.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 08 Jul 2019 10:06:18 +0300 |
parents | 48b48251610a |
children | cd266022e4a8 |
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 * Functions for reading and converting various restricted |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * C64/etc and/or indexed/paletted 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
|
4 * Programmed and designed by Matti 'ccr' Hamalainen |
2120 | 5 * (C) Copyright 2012-2019 Tecnic Software productions (TNSP) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 * |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 * 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
|
8 */ |
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 "lib64gfx.h" |
435 | 10 |
514 | 11 #define BUF_SIZE_INITIAL (16*1024) |
12 #define BUF_SIZE_GROW (4*1024) | |
13 | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
14 |
2175
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
15 // |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
16 // Some "default" C64 palettes |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
17 // |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
18 DMC64Palette dmC64DefaultPalettes[] = |
1731
474055f25ab0
Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
19 { |
2175
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
20 { |
2203
b259312ddb59
Add description field to DMC64Palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2201
diff
changeset
|
21 "pepto", |
b259312ddb59
Add description field to DMC64Palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2201
diff
changeset
|
22 "Pepto's classic (default)", |
2175
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
23 { |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
24 { 0x00, 0x00, 0x00, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
25 { 0xFF, 0xFF, 0xFF, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
26 { 0x68, 0x37, 0x2B, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
27 { 0x70, 0xA4, 0xB2, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
28 { 0x6F, 0x3D, 0x86, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
29 { 0x58, 0x8D, 0x43, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
30 { 0x35, 0x28, 0x79, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
31 { 0xB8, 0xC7, 0x6F, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
32 { 0x6F, 0x4F, 0x25, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
33 { 0x43, 0x39, 0x00, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
34 { 0x9A, 0x67, 0x59, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
35 { 0x44, 0x44, 0x44, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
36 { 0x6C, 0x6C, 0x6C, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
37 { 0x9A, 0xD2, 0x84, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
38 { 0x6C, 0x5E, 0xB5, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
39 { 0x95, 0x95, 0x95, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
40 }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
41 }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
42 { |
2203
b259312ddb59
Add description field to DMC64Palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2201
diff
changeset
|
43 "colodore", |
2175
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
44 "Colodore", |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
45 { |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
46 { 0x00, 0x00, 0x00, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
47 { 0xff, 0xff, 0xff, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
48 { 0x96, 0x28, 0x2e, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
49 { 0x5b, 0xd6, 0xce, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
50 { 0x9f, 0x2d, 0xad, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
51 { 0x41, 0xb9, 0x36, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
52 { 0x27, 0x24, 0xc4, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
53 { 0xef, 0xf3, 0x47, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
54 { 0x9f, 0x48, 0x15, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
55 { 0x5e, 0x35, 0x00, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
56 { 0xda, 0x5f, 0x66, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
57 { 0x47, 0x47, 0x47, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
58 { 0x78, 0x78, 0x78, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
59 { 0x91, 0xff, 0x84, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
60 { 0x68, 0x64, 0xff, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
61 { 0xae, 0xae, 0xae, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
62 }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
63 }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
64 { |
2203
b259312ddb59
Add description field to DMC64Palette.
Matti Hamalainen <ccr@tnsp.org>
parents:
2201
diff
changeset
|
65 "vice3", |
2175
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
66 "VICE 3.3", |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
67 { |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
68 { 0x00, 0x00, 0x00, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
69 { 0xfd, 0xfe, 0xfc, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
70 { 0xbe, 0x1a, 0x24, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
71 { 0x30, 0xe6, 0xc6, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
72 { 0xb4, 0x1a, 0xe2, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
73 { 0x1f, 0xd2, 0x1e, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
74 { 0x21, 0x1b, 0xae, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
75 { 0xdf, 0xf6, 0x0a, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
76 { 0xb8, 0x41, 0x04, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
77 { 0x6a, 0x33, 0x04, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
78 { 0xfe, 0x4a, 0x57, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
79 { 0x42, 0x45, 0x40, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
80 { 0x70, 0x74, 0x6f, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
81 { 0x59, 0xfe, 0x59, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
82 { 0x5f, 0x53, 0xfe, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
83 { 0xa4, 0xa7, 0xa2, 0xff }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
84 }, |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
85 }, |
1731
474055f25ab0
Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
86 }; |
474055f25ab0
Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
87 |
2175
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
88 const int ndmC64DefaultPalettes = sizeof(dmC64DefaultPalettes) / sizeof(dmC64DefaultPalettes[0]); |
58fab91830d5
Change default C64 palette system a bit, add two more palettes. These are
Matti Hamalainen <ccr@tnsp.org>
parents:
2172
diff
changeset
|
89 |
1731
474055f25ab0
Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
90 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
91 int dmC64PaletteFromC64Colors(DMPalette **ppal, const DMColor *colors, const BOOL mixed) |
1457
dcff9ac95d3f
Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1456
diff
changeset
|
92 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2061
diff
changeset
|
93 int res; |
2131
781b1d63109a
Free previously allocated palette in the image palette allocation functions if it
Matti Hamalainen <ccr@tnsp.org>
parents:
2128
diff
changeset
|
94 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
95 if (ppal == NULL || colors == NULL) |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
96 return DMERR_NULLPTR; |
2201
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
97 |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
98 // Allocate and create new |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
99 if (mixed) |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
100 { |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
101 // Mixed 256 color palette |
2206
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
102 if ((res = dmPaletteAlloc(ppal, D64_NCOLORS * D64_NCOLORS, -1)) != DMERR_OK) |
2201
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
103 return res; |
2131
781b1d63109a
Free previously allocated palette in the image palette allocation functions if it
Matti Hamalainen <ccr@tnsp.org>
parents:
2128
diff
changeset
|
104 |
2201
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
105 for (int n1 = 0, n = 0; n1 < D64_NCOLORS; n1++) |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
106 { |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
107 const DMColor *col1 = &colors[n1]; |
2201
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
108 for (int n2 = 0; n2 < D64_NCOLORS; n2++) |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
109 { |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
110 const DMColor *col2 = &colors[n2]; |
2206
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
111 (*ppal)->colors[n].r = (col1->r + col2->r) / 2; |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
112 (*ppal)->colors[n].g = (col1->g + col2->g) / 2; |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
113 (*ppal)->colors[n].b = (col1->b + col2->b) / 2; |
2201
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
114 n++; |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
115 } |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
116 } |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
117 } |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
118 else |
1732
07111a60cd4e
Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents:
1731
diff
changeset
|
119 { |
2201
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
120 // Standard palette, just copy it |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
121 if ((res = dmPaletteAlloc(ppal, D64_NCOLORS, 255)) != DMERR_OK) |
2201
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
122 return res; |
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
123 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
124 memcpy((*ppal)->colors, colors, D64_NCOLORS * sizeof(DMColor)); |
1732
07111a60cd4e
Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents:
1731
diff
changeset
|
125 } |
07111a60cd4e
Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents:
1731
diff
changeset
|
126 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2061
diff
changeset
|
127 return DMERR_OK; |
1732
07111a60cd4e
Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents:
1731
diff
changeset
|
128 } |
07111a60cd4e
Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents:
1731
diff
changeset
|
129 |
07111a60cd4e
Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents:
1731
diff
changeset
|
130 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
131 int dmC64PaletteFromC64Palette(DMPalette **ppal, const DMC64Palette *cpal, const BOOL mixed) |
2206
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
132 { |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
133 if (ppal == NULL || cpal == NULL) |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
134 return DMERR_NULLPTR; |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
135 |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
136 return dmC64PaletteFromC64Colors(ppal, cpal->colors, mixed); |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
137 } |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
138 |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
139 |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
140 int dmC64SetImagePalette(DMImage *img, const DMC64ImageConvSpec *spec, const BOOL mixed) |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
141 { |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
142 if (img == NULL || spec == NULL) |
2206
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
143 return DMERR_NULLPTR; |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
144 |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
145 // Free previous palette |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
146 if (!img->constpal) |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
147 dmPaletteFree(img->pal); |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
148 |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
149 img->constpal = FALSE; |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
150 |
2208
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
151 // If specific palette is wanted, use it |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
152 if (spec->pal != NULL) |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
153 { |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
154 if (spec->pal->ncolors > D64_NCOLORS) |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
155 return dmPaletteCopy(&img->pal, spec->pal); |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
156 else |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
157 if (spec->pal->ncolors == D64_NCOLORS) |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
158 return dmC64PaletteFromC64Colors(&img->pal, spec->pal->colors, mixed); |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
159 } |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
160 |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
161 // Else, use the c64 palette specified |
90ec1ec89c56
Revamp the palette handling in lib64gfx somewhat, add helper functions to
Matti Hamalainen <ccr@tnsp.org>
parents:
2206
diff
changeset
|
162 return dmC64PaletteFromC64Palette(&img->pal, spec->cpal, mixed); |
2206
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
163 } |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
164 |
7694b5c8edc1
Add dmC64PaletteFromC64Palette(), used by dmC64SetImagePalette().
Matti Hamalainen <ccr@tnsp.org>
parents:
2204
diff
changeset
|
165 |
1780
5ea4713e9e0f
Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1775
diff
changeset
|
166 BOOL dmCompareAddr16(const DMGrowBuf *buf, const size_t offs, const Uint16 addr) |
1381 | 167 { |
1780
5ea4713e9e0f
Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1775
diff
changeset
|
168 return |
5ea4713e9e0f
Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1775
diff
changeset
|
169 offs + 1 < buf->len && |
1923
42cd527a01b9
Remove mostly unused DM_GET_ADDR_{LO,HI} macros.
Matti Hamalainen <ccr@tnsp.org>
parents:
1922
diff
changeset
|
170 buf->data[offs ] == (addr & 0xff) && |
42cd527a01b9
Remove mostly unused DM_GET_ADDR_{LO,HI} macros.
Matti Hamalainen <ccr@tnsp.org>
parents:
1922
diff
changeset
|
171 buf->data[offs + 1] == ((addr >> 8) & 0xff); |
1381 | 172 } |
173 | |
174 | |
2179
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
175 int dmC64ImageGetNumBlocks(const DMC64ImageFormat *fmt) |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
176 { |
2179
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
177 int nblocks = 0; |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
178 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) |
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
179 { |
1591
3cc7b2aadda3
Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1588
diff
changeset
|
180 const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
181 if (op->type == DO_LAST) |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
182 break; |
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
183 |
2179
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
184 if (op->bank > nblocks) |
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
185 nblocks = op->bank; |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
186 } |
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
187 |
2179
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
188 return nblocks + 1; |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
189 } |
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
190 |
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
191 |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
192 int dmC64MemBlockAlloc(DMC64MemBlock *blk, const size_t size) |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
193 { |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
194 if ((blk->data = dmMalloc0(size)) == NULL) |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
195 return DMERR_MALLOC; |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
196 |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
197 blk->size = size; |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
198 return DMERR_OK; |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
199 } |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
200 |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
201 |
1846
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
202 int dmC64MemBlockReAlloc(DMC64MemBlock *blk, const size_t size) |
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
203 { |
1851
cfc7046fb176
Reallocate buffer only if the new size is larger in dmC64MemBlockReAlloc().
Matti Hamalainen <ccr@tnsp.org>
parents:
1846
diff
changeset
|
204 // Reallocate only if new size is larger |
cfc7046fb176
Reallocate buffer only if the new size is larger in dmC64MemBlockReAlloc().
Matti Hamalainen <ccr@tnsp.org>
parents:
1846
diff
changeset
|
205 if (size <= blk->size) |
cfc7046fb176
Reallocate buffer only if the new size is larger in dmC64MemBlockReAlloc().
Matti Hamalainen <ccr@tnsp.org>
parents:
1846
diff
changeset
|
206 return DMERR_OK; |
cfc7046fb176
Reallocate buffer only if the new size is larger in dmC64MemBlockReAlloc().
Matti Hamalainen <ccr@tnsp.org>
parents:
1846
diff
changeset
|
207 |
1846
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
208 if ((blk->data = dmRealloc(blk->data, size)) == NULL) |
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
209 return DMERR_MALLOC; |
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
210 |
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
211 dmMemset(blk->data + blk->size, 0, size - blk->size); |
1851
cfc7046fb176
Reallocate buffer only if the new size is larger in dmC64MemBlockReAlloc().
Matti Hamalainen <ccr@tnsp.org>
parents:
1846
diff
changeset
|
212 |
1846
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
213 blk->size = size; |
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
214 return DMERR_OK; |
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
215 } |
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
216 |
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
217 |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
218 int dmC64MemBlockCopy(DMC64MemBlock *dst, const DMC64MemBlock *src) |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
219 { |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
220 if (src->data != NULL && src->size > 0) |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
221 { |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
222 dst->size = src->size; |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
223 if ((dst->data = dmMalloc(src->size)) == NULL) |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
224 return DMERR_MALLOC; |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
225 |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
226 memcpy(dst->data, src->data, src->size); |
1824
adf9f05c26e1
Improve error handling of dmC64MemBlockCopy().
Matti Hamalainen <ccr@tnsp.org>
parents:
1822
diff
changeset
|
227 return DMERR_OK; |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
228 } |
1824
adf9f05c26e1
Improve error handling of dmC64MemBlockCopy().
Matti Hamalainen <ccr@tnsp.org>
parents:
1822
diff
changeset
|
229 else |
adf9f05c26e1
Improve error handling of dmC64MemBlockCopy().
Matti Hamalainen <ccr@tnsp.org>
parents:
1822
diff
changeset
|
230 return DMERR_INVALID_DATA; |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
231 } |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
232 |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
233 |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
234 void dmC64MemBlockFree(DMC64MemBlock *blk) |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
235 { |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
236 if (blk != NULL) |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
237 { |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
238 dmFreeR(&blk->data); |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
239 blk->size = 0; |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
240 } |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
241 } |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
242 |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
243 |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
244 static void dmC64SetupImageData(DMC64Image *img, const DMC64ImageFormat *fmt) |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
245 { |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
246 img->fmt = fmt->format; |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
247 img->nblocks = dmC64ImageGetNumBlocks(fmt); |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
248 |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
249 memset(img->extraInfo, 0, sizeof(img->extraInfo)); |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
250 img->extraInfo[D64_EI_MODE] = fmt->format->mode; |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
251 } |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
252 |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
253 |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
254 DMC64Image *dmC64ImageAlloc(const DMC64ImageFormat *fmt) |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
255 { |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
256 DMC64Image *img = dmMalloc0(sizeof(DMC64Image)); |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
257 |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
258 if (img == NULL) |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
259 return NULL; |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
260 |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
261 // Initialize image information |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
262 dmC64SetupImageData(img, fmt); |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
263 |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
264 // Allocate banks |
2179
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
265 if ((img->color = dmCalloc(img->nblocks, sizeof(DMC64MemBlock))) == NULL || |
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
266 (img->bitmap = dmCalloc(img->nblocks, sizeof(DMC64MemBlock))) == NULL || |
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
267 (img->screen = dmCalloc(img->nblocks, sizeof(DMC64MemBlock))) == NULL || |
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
268 (img->charData = dmCalloc(img->nblocks, sizeof(DMC64MemBlock))) == NULL) |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
269 goto err; |
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
270 |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
271 return img; |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
272 |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
273 err: |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
274 dmC64ImageFree(img); |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
275 return NULL; |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
276 } |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
277 |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
278 |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
279 void dmC64ImageFree(DMC64Image *img) |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
280 { |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
281 if (img != NULL) |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
282 { |
1462
9cb6dd1046bf
Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents:
1461
diff
changeset
|
283 // Free the allocated areas |
2179
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
284 for (int i = 0; i < img->nblocks; i++) |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
285 { |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
286 dmC64MemBlockFree(&img->color[i]); |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
287 dmC64MemBlockFree(&img->bitmap[i]); |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
288 dmC64MemBlockFree(&img->screen[i]); |
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
289 dmC64MemBlockFree(&img->charData[i]); |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
290 } |
1373
fc5ee5b4b0e9
Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1372
diff
changeset
|
291 |
1462
9cb6dd1046bf
Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents:
1461
diff
changeset
|
292 // Free the pointers to the areas |
9cb6dd1046bf
Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents:
1461
diff
changeset
|
293 dmFree(img->color); |
9cb6dd1046bf
Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents:
1461
diff
changeset
|
294 dmFree(img->bitmap); |
9cb6dd1046bf
Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents:
1461
diff
changeset
|
295 dmFree(img->screen); |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
296 dmFree(img->charData); |
1462
9cb6dd1046bf
Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents:
1461
diff
changeset
|
297 |
9cb6dd1046bf
Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents:
1461
diff
changeset
|
298 // Extra data .. |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2122
diff
changeset
|
299 for (int i = 0; i < D64_MAX_EXTRA_DATA; i++) |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
300 dmC64MemBlockFree(&img->extraData[i]); |
1373
fc5ee5b4b0e9
Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1372
diff
changeset
|
301 |
1167 | 302 dmMemset(img, 0, sizeof(DMC64Image)); |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
303 dmFree(img); |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
304 } |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
305 } |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
306 |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
307 |
827 | 308 int dmC64ConvertCSDataToImage(DMImage *img, |
410
e4b2f689aff6
Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
309 int xoffs, int yoffs, const Uint8 *buf, |
915 | 310 int width, int height, BOOL multicolor, |
311 int *colors) | |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
312 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
313 int yc, widthpx = width * 8; |
410
e4b2f689aff6
Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
314 Uint8 *dp; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
315 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
316 if (img == NULL) |
517
e2a76bb59888
Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
317 return DMERR_NULLPTR; |
e2a76bb59888
Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
318 |
e2a76bb59888
Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
319 if (xoffs < 0 || yoffs < 0 || |
e2a76bb59888
Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
320 xoffs > img->width - widthpx || |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
321 yoffs > img->height - height) |
517
e2a76bb59888
Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
322 return DMERR_INVALID_ARGS; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
323 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
324 dp = img->data + (yoffs * img->pitch) + xoffs; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
325 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
326 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
|
327 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 for (yc = 0; yc < height; yc++) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 const int offs = yc * width; |
410
e4b2f689aff6
Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
331 Uint8 *d = dp; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
332 |
1875 | 333 for (int xc = 0; xc < widthpx / 2; 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
|
334 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
335 const int b = buf[offs + (xc / 4)]; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
336 const int v = 6 - ((xc * 2) & 6); |
410
e4b2f689aff6
Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
337 const Uint8 c = colors[(b >> v) & 3]; |
925 | 338 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
339 *d++ = c; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
340 *d++ = c; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
341 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
342 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
343 dp += img->pitch; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 else |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 for (yc = 0; yc < height; yc++) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
349 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
350 const int offs = yc * width; |
410
e4b2f689aff6
Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
351 Uint8 *d = dp; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
352 |
1875 | 353 for (int xc = 0; xc < widthpx; 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
|
354 { |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
355 const int b = buf[offs + (xc / 8)]; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
356 const int v = 7 - (xc & 7); |
410
e4b2f689aff6
Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
357 const Uint8 c = colors[(b >> v) & 1]; |
925 | 358 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
359 *d++ = c; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
360 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
361 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
362 dp += img->pitch; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
363 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
364 } |
925 | 365 |
517
e2a76bb59888
Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents:
516
diff
changeset
|
366 return DMERR_OK; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
367 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
370 void dmGenericRLEAnalyze(const DMGrowBuf *buf, DMCompParams *cfg) |
1503
c7b9ef56319b
Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents:
1501
diff
changeset
|
371 { |
1542
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
372 #define DM_STAT_MAX 256 |
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
373 size_t *stats; |
1503
c7b9ef56319b
Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents:
1501
diff
changeset
|
374 |
1542
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
375 // Allocate statistics counts buffer |
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
376 if ((stats = dmMalloc0(DM_STAT_MAX * sizeof(size_t))) == NULL) |
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
377 return; |
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
378 |
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
379 // Get statistics on the data |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
380 for (size_t offs = 0; offs < buf->len; offs++) |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
381 stats[buf->data[offs]]++; |
1542
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
382 |
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
383 // According to compression type .. |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
384 switch (cfg->type) |
1542
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
385 { |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
386 case DM_COMP_RLE_MARKER: |
1542
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
387 { |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
388 size_t selected = 0, |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
389 smallest = buf->len; |
1542
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
390 |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
391 // Find least used byte value |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
392 for (size_t n = 0; n < DM_STAT_MAX; n++) |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
393 { |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
394 if (stats[n] < smallest) |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
395 { |
1821
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
396 switch (cfg->flags & DM_RLE_RUNS_MASK) |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
397 { |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
398 case DM_RLE_BYTE_RUNS | DM_RLE_WORD_RUNS: |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
399 cfg->rleMarkerW = selected; |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
400 cfg->rleMarkerB = selected = n; |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
401 break; |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
402 |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
403 case DM_RLE_BYTE_RUNS: |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
404 cfg->rleMarkerB = selected = n; |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
405 break; |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
406 |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
407 case DM_RLE_WORD_RUNS: |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
408 cfg->rleMarkerW = selected = n; |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
409 break; |
ee2383d1a21e
Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents:
1820
diff
changeset
|
410 } |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
411 smallest = stats[n]; |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
412 } |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
413 } |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
414 } |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
415 break; |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
416 |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
417 case DM_COMP_RLE_MASK: |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
418 cfg->rleMarkerMask = 0xC0; |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
419 cfg->rleMarkerBits = 0xC0; |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
420 cfg->rleCountMask = 0x3f; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
421 break; |
1542
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
422 } |
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
423 |
69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents:
1537
diff
changeset
|
424 dmFree(stats); |
1503
c7b9ef56319b
Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents:
1501
diff
changeset
|
425 } |
c7b9ef56319b
Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents:
1501
diff
changeset
|
426 |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
427 |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
428 //#define RLE_DEBUG |
1503
c7b9ef56319b
Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents:
1501
diff
changeset
|
429 |
1713
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
430 void dmSetupRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg) |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
431 { |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
432 if (src != NULL && (cfg->flags & DM_RLE_BACKWARDS_INPUT)) |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
433 { |
1831
ce1a734b016f
Change the logic of how DMGrowBuf works in "backwards" growing mode. Adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
1828
diff
changeset
|
434 src->offs = src->len; |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
435 src->backwards = TRUE; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
436 } |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
437 |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
438 if (dst != NULL && (cfg->flags & DM_RLE_BACKWARDS_OUTPUT)) |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
439 { |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
440 dst->backwards = TRUE; |
1831
ce1a734b016f
Change the logic of how DMGrowBuf works in "backwards" growing mode. Adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
1828
diff
changeset
|
441 dst->offs = dst->size; |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
442 } |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
443 |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
444 #ifdef RLE_DEBUG |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
445 fprintf(stderr, "dmSetupRLEBuffers:\n"); |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
446 if (src != NULL) |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
447 fprintf(stderr, " src.len=%" DM_PRIx_SIZE_T ", src.size=%" DM_PRIx_SIZE_T ", src.offs=%" DM_PRIx_SIZE_T "\n", src->len, src->size, src->offs); |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
448 if (dst != NULL) |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
449 fprintf(stderr, " dst.len=%" DM_PRIx_SIZE_T ", dst.size=%" DM_PRIx_SIZE_T ", dst.offs=%" DM_PRIx_SIZE_T "\n", dst->len, dst->size, dst->offs); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
450 fprintf(stderr, "------------------\n"); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
451 #endif |
1718
bed88d17f28c
Fix a commit blunder here ..
Matti Hamalainen <ccr@tnsp.org>
parents:
1717
diff
changeset
|
452 } |
bed88d17f28c
Fix a commit blunder here ..
Matti Hamalainen <ccr@tnsp.org>
parents:
1717
diff
changeset
|
453 |
bed88d17f28c
Fix a commit blunder here ..
Matti Hamalainen <ccr@tnsp.org>
parents:
1717
diff
changeset
|
454 |
1713
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
455 void dmFinishRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg) |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
456 { |
1741
6f1313c761aa
Actually fix the warnings .. sigh.
Matti Hamalainen <ccr@tnsp.org>
parents:
1740
diff
changeset
|
457 (void) src; |
6f1313c761aa
Actually fix the warnings .. sigh.
Matti Hamalainen <ccr@tnsp.org>
parents:
1740
diff
changeset
|
458 |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
459 #ifdef RLE_DEBUG |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
460 fprintf(stderr, "------------------\n"); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
461 fprintf(stderr, "dmFinishRLEBuffers:\n"); |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
462 if (src != NULL) |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
463 fprintf(stderr, " src.len=%" DM_PRIx_SIZE_T ", src.size=%" DM_PRIx_SIZE_T ", src.offs=%" DM_PRIx_SIZE_T "\n", src->len, src->size, src->offs); |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
464 if (dst != NULL) |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
465 fprintf(stderr, " dst.len=%" DM_PRIx_SIZE_T ", dst.size=%" DM_PRIx_SIZE_T ", dst.offs=%" DM_PRIx_SIZE_T "\n", dst->len, dst->size, dst->offs); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
466 #endif |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
467 |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
468 if (dst != NULL) |
1720
77a4d8fab5cc
Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1718
diff
changeset
|
469 { |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
470 if (cfg->flags & DM_RLE_BACKWARDS_OUTPUT) |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
471 { |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
472 memmove(dst->data, dst->data + dst->offs, dst->len); |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
473 dst->offs = 0; |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
474 } |
1720
77a4d8fab5cc
Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1718
diff
changeset
|
475 |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
476 switch (cfg->flags & DM_OUT_CROP_MASK) |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
477 { |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
478 case DM_OUT_CROP_END: |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
479 if (cfg->cropOutLen < dst->len) |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
480 { |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
481 memmove(dst->data, dst->data + dst->len - cfg->cropOutLen, cfg->cropOutLen); |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
482 dst->len = cfg->cropOutLen; |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
483 } |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
484 break; |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
485 |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
486 case DM_OUT_CROP_START: |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
487 if (cfg->cropOutLen <= dst->len) |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
488 dst->len = cfg->cropOutLen; |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
489 break; |
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
490 } |
1720
77a4d8fab5cc
Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1718
diff
changeset
|
491 } |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
492 |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
493 #ifdef RLE_DEBUG |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
494 fprintf(stderr, "ADJUSTED:\n"); |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
495 if (src != NULL) |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
496 fprintf(stderr, " src.len=%" DM_PRIx_SIZE_T ", src.size=%" DM_PRIx_SIZE_T ", src.offs=%" DM_PRIx_SIZE_T "\n", src->len, src->size, src->offs); |
2140
b8491ee3cf24
Allow NULL buffer argument(s) for dmSetupRLEBuffers() and dmFinishRLEBuffers().
Matti Hamalainen <ccr@tnsp.org>
parents:
2132
diff
changeset
|
497 if (dst != NULL) |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
498 fprintf(stderr, " dst.len=%" DM_PRIx_SIZE_T ", dst.size=%" DM_PRIx_SIZE_T ", dst.offs=%" DM_PRIx_SIZE_T "\n", dst->len, dst->size, dst->offs); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
499 #endif |
1713
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
500 } |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
501 |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
502 |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
503 int dmGenericRLEOutputRun(DMGrowBuf *dst, const DMCompParams *cfg, const Uint8 data, const unsigned int count) |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
504 { |
1944 | 505 for (unsigned int scount = count; scount; scount--) |
1713
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
506 { |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
507 if (!dmGrowBufPutU8(dst, data)) |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
508 { |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
509 return dmError(DMERR_MALLOC, |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
510 "%s: RLE: Could not output RLE run %d x 0x%02x @ " |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
511 "offs=0x%" DM_PRIx_SIZE_T ", size=0x%" DM_PRIx_SIZE_T ".\n", |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
512 cfg->func, count, data, dst->offs, dst->size); |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
513 } |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
514 } |
0a9110b4d036
Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1710
diff
changeset
|
515 return DMERR_OK; |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
516 } |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
517 |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
518 |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
519 int dmDecodeGenericRLE(DMGrowBuf *dst, const DMGrowBuf *psrc, const DMCompParams *cfg) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
520 { |
1463
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
521 int res; |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
522 Uint8 tmp1, tmp2, tmp3, data; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
523 DMGrowBuf src; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
524 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
525 // As we need to modify the offs, etc. but not the data, |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
526 // we will just make a shallow copy of the DMGrowBuf struct |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
527 dmGrowBufConstCopy(&src, psrc); |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
528 dmSetupRLEBuffers(dst, &src, cfg); |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
529 |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
530 while (dmGrowBufGetU8(&src, &data)) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
531 { |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
532 unsigned int count = 1; |
1463
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
533 |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
534 if (cfg->type == DM_COMP_RLE_MARKER) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
535 { |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
536 // A simple marker byte RLE variant: [Marker] [count] [data] |
1744
e40227e994e2
Fix unitialized data accesses.
Matti Hamalainen <ccr@tnsp.org>
parents:
1741
diff
changeset
|
537 if ((cfg->flags & DM_RLE_BYTE_RUNS) && data == cfg->rleMarkerB) |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
538 { |
1750
b9f3c1796fba
More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
539 if (!dmGrowBufGetU8(&src, &tmp1)) |
1463
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
540 { |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
541 #ifdef RLE_DEBUG |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
542 fprintf(stderr, " marker=$%02x\n", cfg->rleMarkerB); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
543 fprintf(stderr, " src.len=%" DM_PRIx_SIZE_T ", src.size=%" DM_PRIx_SIZE_T ", src.offs=%" DM_PRIx_SIZE_T "\n", src.len, src.size, src.offs); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
544 fprintf(stderr, " dst.len=%" DM_PRIx_SIZE_T ", dst.size=%" DM_PRIx_SIZE_T ", dst.offs=%" DM_PRIx_SIZE_T "\n", dst->len, dst->size, dst->offs); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
545 #endif |
1727
8eb5ff34864a
Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1726
diff
changeset
|
546 res = dmError(DMERR_INVALID_DATA, |
1750
b9f3c1796fba
More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
547 "%s: RLE: Invalid data/out of data for byte length run sequence (1).\n", |
b9f3c1796fba
More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
548 cfg->func); |
b9f3c1796fba
More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
549 goto out; |
b9f3c1796fba
More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
550 } |
b9f3c1796fba
More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
551 if (!dmGrowBufGetU8(&src, &tmp2)) |
b9f3c1796fba
More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
552 { |
2061
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
553 #ifdef RLE_DEBUG |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
554 fprintf(stderr, " marker=$%02x, data=$%02x\n", cfg->rleMarkerB, tmp1); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
555 fprintf(stderr, " src.len=%" DM_PRIx_SIZE_T ", src.size=%" DM_PRIx_SIZE_T ", src.offs=%" DM_PRIx_SIZE_T "\n", src.len, src.size, src.offs); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
556 fprintf(stderr, " dst.len=%" DM_PRIx_SIZE_T ", dst.size=%" DM_PRIx_SIZE_T ", dst.offs=%" DM_PRIx_SIZE_T "\n", dst->len, dst->size, dst->offs); |
221a95caa91e
Add some #ifdef'd out RLE (de)compression debug prints.
Matti Hamalainen <ccr@tnsp.org>
parents:
1984
diff
changeset
|
557 #endif |
1750
b9f3c1796fba
More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
558 res = dmError(DMERR_INVALID_DATA, |
b9f3c1796fba
More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
559 "%s: RLE: Invalid data/out of data for byte length run sequence (2).\n", |
1727
8eb5ff34864a
Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1726
diff
changeset
|
560 cfg->func); |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
561 goto out; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
562 } |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
563 switch (cfg->flags & DM_RLE_ORDER_MASK) |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
564 { |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
565 case DM_RLE_ORDER_1: |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
566 count = tmp1; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
567 data = tmp2; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
568 break; |
1573
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
569 |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
570 case DM_RLE_ORDER_2: |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
571 data = tmp1; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
572 count = tmp2; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
573 break; |
1463
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
574 } |
1783
1ce808599129
Add DM_RLE_ZERO_COUNT_MAX flag for RLE decoder which makes it interpret run
Matti Hamalainen <ccr@tnsp.org>
parents:
1780
diff
changeset
|
575 |
1ce808599129
Add DM_RLE_ZERO_COUNT_MAX flag for RLE decoder which makes it interpret run
Matti Hamalainen <ccr@tnsp.org>
parents:
1780
diff
changeset
|
576 if (count == 0 && (cfg->flags & DM_RLE_ZERO_COUNT_MAX)) |
1ce808599129
Add DM_RLE_ZERO_COUNT_MAX flag for RLE decoder which makes it interpret run
Matti Hamalainen <ccr@tnsp.org>
parents:
1780
diff
changeset
|
577 count = 256; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
578 } |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
579 else |
1744
e40227e994e2
Fix unitialized data accesses.
Matti Hamalainen <ccr@tnsp.org>
parents:
1741
diff
changeset
|
580 if ((cfg->flags & DM_RLE_WORD_RUNS) && data == cfg->rleMarkerW) |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
581 { |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
582 if (!dmGrowBufGetU8(&src, &tmp1) || |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
583 !dmGrowBufGetU8(&src, &tmp2) || |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
584 !dmGrowBufGetU8(&src, &tmp3)) |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
585 { |
1727
8eb5ff34864a
Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1726
diff
changeset
|
586 res = dmError(DMERR_INVALID_DATA, |
8eb5ff34864a
Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1726
diff
changeset
|
587 "%s: RLE: Invalid data/out of data for word length run sequence.\n", |
8eb5ff34864a
Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1726
diff
changeset
|
588 cfg->func); |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
589 goto out; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
590 } |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
591 switch (cfg->flags & DM_RLE_ORDER_MASK) |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
592 { |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
593 case DM_RLE_ORDER_1: |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
594 count = (tmp2 << 8) | tmp1; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
595 data = tmp3; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
596 break; |
1463
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
597 |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
598 case DM_RLE_ORDER_2: |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
599 data = tmp1; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
600 count = (tmp3 << 8) | tmp2; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
601 break; |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
602 } |
1783
1ce808599129
Add DM_RLE_ZERO_COUNT_MAX flag for RLE decoder which makes it interpret run
Matti Hamalainen <ccr@tnsp.org>
parents:
1780
diff
changeset
|
603 |
1ce808599129
Add DM_RLE_ZERO_COUNT_MAX flag for RLE decoder which makes it interpret run
Matti Hamalainen <ccr@tnsp.org>
parents:
1780
diff
changeset
|
604 if (count == 0 && (cfg->flags & DM_RLE_ZERO_COUNT_MAX)) |
1ce808599129
Add DM_RLE_ZERO_COUNT_MAX flag for RLE decoder which makes it interpret run
Matti Hamalainen <ccr@tnsp.org>
parents:
1780
diff
changeset
|
605 count = 65536; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
606 } |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
607 } |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
608 else |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
609 if (cfg->type == DM_COMP_RLE_MASK) |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
610 { |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
611 // Mask marker RLE: usually high bit(s) of byte mark RLE sequence |
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
612 // and the lower bits contain the count: [Mask + count] [data] |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
613 if ((data & cfg->rleMarkerMask) == cfg->rleMarkerBits) |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
614 { |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
615 if (!dmGrowBufGetU8(&src, &tmp1)) |
1463
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
616 { |
1727
8eb5ff34864a
Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1726
diff
changeset
|
617 res = dmError(DMERR_INVALID_DATA, |
8eb5ff34864a
Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1726
diff
changeset
|
618 "%s: RLE: Invalid data/out of data for byte length mask/run sequence.\n", |
8eb5ff34864a
Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1726
diff
changeset
|
619 cfg->func); |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
620 goto out; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
621 } |
1466
bc75be0546fc
More work on RLE decoder/encoder changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1465
diff
changeset
|
622 |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
623 count = data & cfg->rleCountMask; |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
624 data = tmp1; |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
625 } |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
626 } |
1463
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
627 |
1715
c0c6fd8b288a
Use dmGenericRLEOutputRun().
Matti Hamalainen <ccr@tnsp.org>
parents:
1713
diff
changeset
|
628 if ((res = dmGenericRLEOutputRun(dst, cfg, data, count)) != DMERR_OK) |
c0c6fd8b288a
Use dmGenericRLEOutputRun().
Matti Hamalainen <ccr@tnsp.org>
parents:
1713
diff
changeset
|
629 goto out; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
630 } |
523
d0c0c6baeb57
Split the RLE decoding from DrazPaint/Lace and Amica paint decoders to a
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
631 |
1717
7de37c01dbd4
Use dmFinishRLEBuffers() in dmDecodeGenericRLE()
Matti Hamalainen <ccr@tnsp.org>
parents:
1716
diff
changeset
|
632 dmFinishRLEBuffers(dst, &src, cfg); |
1463
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
633 res = DMERR_OK; |
523
d0c0c6baeb57
Split the RLE decoding from DrazPaint/Lace and Amica paint decoders to a
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
634 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
635 out: |
1463
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
636 return res; |
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
637 } |
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
638 |
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
639 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
640 int dmDecodeGenericRLEAlloc(DMGrowBuf *dst, const DMGrowBuf *src, const DMCompParams *cfg) |
1463
bde6a66bc2f6
Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents:
1462
diff
changeset
|
641 { |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
642 int res; |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
643 if ((res = dmGrowBufAlloc(dst, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
644 return res; |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
645 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
646 return dmDecodeGenericRLE(dst, src, cfg); |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
647 } |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
648 |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
649 |
1820
bea67833b9fa
Oops, need to deconstify the "count" argument of dmEncodeGenericRLESequence() as we now modify it inside.
Matti Hamalainen <ccr@tnsp.org>
parents:
1818
diff
changeset
|
650 int dmEncodeGenericRLESequence(DMGrowBuf *dst, const Uint8 data, unsigned int count, const DMCompParams *cfg) |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
651 { |
1496 | 652 BOOL copyOnly = FALSE; |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
653 int res; |
1505
3265175b24d2
Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
1503
diff
changeset
|
654 |
3265175b24d2
Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
1503
diff
changeset
|
655 switch (cfg->type) |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
656 { |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
657 case DM_COMP_RLE_MARKER: |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
658 if ((cfg->flags & DM_RLE_WORD_RUNS) && |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
659 (count >= cfg->rleMinCountW || data == cfg->rleMarkerW)) |
1496 | 660 { |
1818
7bafe5f0998d
Implement DM_RLE_ZERO_COUNT_MAX support in the generic RLE compressor.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
661 if (count == 65536 && (cfg->flags & DM_RLE_ZERO_COUNT_MAX)) |
7bafe5f0998d
Implement DM_RLE_ZERO_COUNT_MAX support in the generic RLE compressor.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
662 count = 0; |
7bafe5f0998d
Implement DM_RLE_ZERO_COUNT_MAX support in the generic RLE compressor.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
663 |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
664 if (!dmGrowBufPutU8(dst, cfg->rleMarkerW)) |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
665 goto err; |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
666 |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
667 switch (cfg->flags & DM_RLE_ORDER_MASK) |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
668 { |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
669 case DM_RLE_ORDER_1: |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
670 if (!dmGrowBufPutU16LE(dst, count) || |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
671 !dmGrowBufPutU8(dst, data)) |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
672 goto err; |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
673 break; |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
674 |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
675 case DM_RLE_ORDER_2: |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
676 if (!dmGrowBufPutU8(dst, data) || |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
677 !dmGrowBufPutU16LE(dst, count)) |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
678 goto err; |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
679 break; |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
680 } |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
681 } |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
682 else |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
683 if ((cfg->flags & DM_RLE_BYTE_RUNS) && |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
684 (count >= cfg->rleMinCountB || data == cfg->rleMarkerB)) |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
685 { |
1818
7bafe5f0998d
Implement DM_RLE_ZERO_COUNT_MAX support in the generic RLE compressor.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
686 if (count == 256 && (cfg->flags & DM_RLE_ZERO_COUNT_MAX)) |
7bafe5f0998d
Implement DM_RLE_ZERO_COUNT_MAX support in the generic RLE compressor.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
687 count = 0; |
7bafe5f0998d
Implement DM_RLE_ZERO_COUNT_MAX support in the generic RLE compressor.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
688 |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
689 if (!dmGrowBufPutU8(dst, cfg->rleMarkerB)) |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
690 goto err; |
1573
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
691 |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
692 switch (cfg->flags & DM_RLE_ORDER_MASK) |
1573
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
693 { |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
694 case DM_RLE_ORDER_1: |
1573
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
695 if (!dmGrowBufPutU8(dst, count) || |
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
696 !dmGrowBufPutU8(dst, data)) |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
697 goto err; |
1573
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
698 break; |
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
699 |
1650
9233da9de92c
Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents:
1647
diff
changeset
|
700 case DM_RLE_ORDER_2: |
1573
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
701 if (!dmGrowBufPutU8(dst, data) || |
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
702 !dmGrowBufPutU8(dst, count)) |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
703 goto err; |
1573
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
704 break; |
86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1548
diff
changeset
|
705 } |
1496 | 706 } |
707 else | |
708 copyOnly = TRUE; | |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
709 break; |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
710 |
1505
3265175b24d2
Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents:
1503
diff
changeset
|
711 case DM_COMP_RLE_MASK: |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
712 if (count >= cfg->rleMinCountB || (data & cfg->rleMarkerMask) == cfg->rleMarkerBits) |
1496 | 713 { |
714 // Mask marker RLE: usually high bit(s) of byte mark RLE sequence | |
715 // and the lower bits contain the count: [Mask + count] [data] | |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
716 if (!dmGrowBufPutU8(dst, cfg->rleMarkerBits | count) || |
1496 | 717 !dmGrowBufPutU8(dst, data)) |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
718 goto err; |
1496 | 719 } |
720 else | |
721 copyOnly = TRUE; | |
722 break; | |
723 } | |
724 | |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
725 if (copyOnly && (res = dmGenericRLEOutputRun(dst, cfg, data, count)) != DMERR_OK) |
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
726 return res; |
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
727 |
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
728 return DMERR_OK; |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
729 |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
730 err: |
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
731 return dmError(DMERR_MALLOC, |
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
732 "%s: RLE: Could not output RLE sequence %d x 0x%02x.\n", |
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
733 cfg->func, count, data); |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
734 } |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
735 |
1466
bc75be0546fc
More work on RLE decoder/encoder changes.
Matti Hamalainen <ccr@tnsp.org>
parents:
1465
diff
changeset
|
736 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
737 int dmEncodeGenericRLE(DMGrowBuf *dst, const DMGrowBuf *psrc, const DMCompParams *cfg) |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
738 { |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
739 DMGrowBuf src; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
740 unsigned int count = 0; |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
741 int prev = -1, res = DMERR_OK; |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
742 Uint8 data; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
743 |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
744 // As we need to modify the offs, etc. but not the data, |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
745 // we will just make a shallow copy of the DMGrowBuf struct |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
746 dmGrowBufConstCopy(&src, psrc); |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
747 dmSetupRLEBuffers(dst, &src, cfg); |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
748 |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
749 while (dmGrowBufGetU8(&src, &data)) |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
750 { |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
751 // If new data byte is different, or we exceed the rleMaxCount |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
752 // for the active runs mode(s) .. then encode the run. |
1833
19d4f76e003d
Improve RLE compression by checking for "first byte" condition in the compressor.
Matti Hamalainen <ccr@tnsp.org>
parents:
1831
diff
changeset
|
753 if ((data != prev && prev != -1) || |
1660
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
754 ((cfg->flags & DM_RLE_WORD_RUNS) && count >= cfg->rleMaxCountW) || |
7555c8803529
More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1650
diff
changeset
|
755 (((cfg->flags & DM_RLE_RUNS_MASK) == DM_RLE_BYTE_RUNS) && count >= cfg->rleMaxCountB)) |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
756 { |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
757 if ((res = dmEncodeGenericRLESequence(dst, prev, count, cfg)) != DMERR_OK) |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
758 goto err; |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
759 |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
760 count = 1; |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
761 } |
1496 | 762 else |
763 count++; | |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
764 |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
765 prev = data; |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
766 } |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
767 |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
768 // If there is anything left in the output queue .. |
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
769 if ((res = dmEncodeGenericRLESequence(dst, prev, count, cfg)) != DMERR_OK) |
1518
24b8b452925e
Improve error handling of RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1513
diff
changeset
|
770 goto err; |
24b8b452925e
Improve error handling of RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1513
diff
changeset
|
771 |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
772 dmFinishRLEBuffers(dst, &src, cfg); |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
773 |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
774 err: |
1716
9731b0bdec64
Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1715
diff
changeset
|
775 return res; |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
776 } |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
777 |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
778 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
779 int dmEncodeGenericRLEAlloc(DMGrowBuf *dst, const DMGrowBuf *src, const DMCompParams *cfg) |
1478
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
780 { |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
781 int res; |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
782 if ((res = dmGrowBufAlloc(dst, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
783 return res; |
d883b4c1cf48
More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1476
diff
changeset
|
784 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
785 return dmEncodeGenericRLE(dst, src, cfg); |
523
d0c0c6baeb57
Split the RLE decoding from DrazPaint/Lace and Amica paint decoders to a
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
786 } |
d0c0c6baeb57
Split the RLE decoding from DrazPaint/Lace and Amica paint decoders to a
Matti Hamalainen <ccr@tnsp.org>
parents:
519
diff
changeset
|
787 |
519 | 788 |
1537
776aa43b2c57
Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
1534
diff
changeset
|
789 int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img) |
510
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
790 { |
2196
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
791 if (op->flags == 0) |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
792 { |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
793 return dmError(DMERR_INTERNAL, |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
794 "Invalid operation flags value %d in generic encode/decode operator %d @ #%d.\n", |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
795 op->flags, op->type, i); |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
796 } |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
797 |
1373
fc5ee5b4b0e9
Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1372
diff
changeset
|
798 switch (op->type) |
510
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
799 { |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
800 case DO_COPY: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
801 case DO_SET_MEM: |
1726
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
802 case DO_SET_MEM_HI: |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
803 case DO_SET_MEM_LO: |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
804 case DO_SET_OP: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
805 switch (op->subject) |
1373
fc5ee5b4b0e9
Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1372
diff
changeset
|
806 { |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
807 case DS_COLOR_RAM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
808 case DS_BITMAP_RAM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
809 case DS_SCREEN_RAM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
810 case DS_CHAR_DATA: |
2179
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
811 if (op->bank < 0 || op->bank > img->nblocks) |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
812 { |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
813 return dmError(DMERR_INTERNAL, |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
814 "Invalid bank %d / %d definition in generic encode/decode operator %d @ #%d.\n", |
2179
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
815 op->bank, img->nblocks, op->type, i); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
816 } |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
817 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
818 |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
819 case DS_EXTRA_DATA: |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2122
diff
changeset
|
820 if (op->bank < 0 || op->bank >= D64_MAX_EXTRA_DATA) |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
821 { |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
822 return dmError(DMERR_INTERNAL, |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
823 "Invalid bank %d definition in generic encode/decode operator %d @ #%d.\n", |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
824 op->bank, op->type, i); |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
825 } |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
826 break; |
1373
fc5ee5b4b0e9
Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1372
diff
changeset
|
827 } |
fc5ee5b4b0e9
Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1372
diff
changeset
|
828 break; |
fc5ee5b4b0e9
Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1372
diff
changeset
|
829 |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
830 // Just list the allowed ops here |
1922
3c6f638ce402
Remove the useless distinction of DO_ENC_FUNC and DO_DEC_FUNC, as the
Matti Hamalainen <ccr@tnsp.org>
parents:
1919
diff
changeset
|
831 case DO_FUNC: |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
832 case DO_CHAR_CFG: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
833 case DO_LAST: |
1373
fc5ee5b4b0e9
Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1372
diff
changeset
|
834 break; |
510
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
835 |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
836 default: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
837 return dmError(DMERR_INTERNAL, |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
838 "Invalid op type %d in generic encode/decode operator @ #%d.\n", |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
839 op->type, i); |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
840 break; |
510
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
841 } |
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
842 |
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
843 return DMERR_OK; |
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
844 } |
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
845 |
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
846 |
1933
c5a46cb4cce5
Change DMC64ImageFormat parameter of dmC64GetSubjectSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1931
diff
changeset
|
847 size_t dmC64GetSubjectSize(const int subject, const DMC64ImageCommonFormat *fmt) |
927
db495f421242
Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents:
925
diff
changeset
|
848 { |
1916
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
849 switch (subject) |
927
db495f421242
Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents:
925
diff
changeset
|
850 { |
1725
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
851 case DS_SCREEN_RAM: |
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
852 case DS_COLOR_RAM: |
1933
c5a46cb4cce5
Change DMC64ImageFormat parameter of dmC64GetSubjectSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1931
diff
changeset
|
853 return fmt->chHeight * fmt->chWidth; |
1725
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
854 |
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
855 case DS_BITMAP_RAM: |
1933
c5a46cb4cce5
Change DMC64ImageFormat parameter of dmC64GetSubjectSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1931
diff
changeset
|
856 return fmt->chHeight * fmt->chWidth * 8; |
927
db495f421242
Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents:
925
diff
changeset
|
857 |
1725
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
858 case DS_CHAR_DATA: |
2125
56d4dc81774b
Rename various C64_* constants to D64_*.
Matti Hamalainen <ccr@tnsp.org>
parents:
2122
diff
changeset
|
859 return D64_MAX_CHARS * D64_CHR_SIZE; |
927
db495f421242
Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents:
925
diff
changeset
|
860 |
1725
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
861 case DS_D020: |
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
862 case DS_BGCOL: |
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
863 case DS_D021: |
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
864 case DS_D022: |
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
865 case DS_D023: |
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
866 case DS_D024: |
1916
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
867 return 1; |
1725
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
868 |
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
869 default: |
40a5ba0b3838
Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents:
1722
diff
changeset
|
870 // Default to size of 0 |
1916
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
871 return 0; |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
872 } |
1916
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
873 } |
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
874 |
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
875 |
1933
c5a46cb4cce5
Change DMC64ImageFormat parameter of dmC64GetSubjectSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1931
diff
changeset
|
876 size_t dmC64GetOpSubjectSize(const DMC64EncDecOp *op, const DMC64ImageCommonFormat *fmt) |
1916
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
877 { |
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
878 size_t size = dmC64GetSubjectSize(op->subject, fmt); |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
879 |
1632
2a1866fd546e
Use C64 encdec operator specified size for the element if it is larger than the default size.
Matti Hamalainen <ccr@tnsp.org>
parents:
1631
diff
changeset
|
880 // If the operator specified size is larger, use it. |
1916
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
881 if (op->size > size) |
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
882 size = op->size; |
1632
2a1866fd546e
Use C64 encdec operator specified size for the element if it is larger than the default size.
Matti Hamalainen <ccr@tnsp.org>
parents:
1631
diff
changeset
|
883 |
1916
34ba8e2d2dd7
Split dmC64GetOpSize() to dmC64GetSubjectSize() and dmC64GetOpSubjectSize().
Matti Hamalainen <ccr@tnsp.org>
parents:
1875
diff
changeset
|
884 return size; |
927
db495f421242
Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents:
925
diff
changeset
|
885 } |
db495f421242
Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents:
925
diff
changeset
|
886 |
db495f421242
Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents:
925
diff
changeset
|
887 |
1852
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
888 const char *dmC64GetOpSubjectName(const int subject) |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
889 { |
1852
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
890 static const char *subjectNames[DS_LAST] = |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
891 { |
1852
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
892 "Color RAM", |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
893 "Bitmap RAM", |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
894 "Screen RAM", |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
895 "Extra data", |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
896 "Character data", |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
897 |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
898 "d020 / border", |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
899 "d021 / background", |
1852
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
900 "d022", |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
901 "d023", |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
902 "d024", |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
903 }; |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
904 if (subject >= 0 && subject < DS_LAST) |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
905 return subjectNames[subject]; |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
906 else |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
907 return NULL; |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
908 } |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
909 |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
910 |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
911 const char *dmC64GetOpType(const int type) |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
912 { |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
913 static const char *typeNames[DO_LAST] = |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
914 { |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
915 "COPY", |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
916 "SET_MEM", |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
917 "SET_OP", |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
918 "SET_MEM_HI", |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
919 "SET_MEM_LO", |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
920 |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
921 "FUNC", |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
922 "CHAR_CFG", |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
923 }; |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
924 if (type >= 0 && type < DO_LAST) |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
925 return typeNames[type]; |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
926 else |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
927 return "ERROR"; |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
928 } |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
929 |
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
930 |
2108
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
931 const DMC64MemBlock * dmC64GetOpMemBlock(const DMC64Image *img, const int subject, const int bank) |
1852
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
932 { |
2179
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
933 if (bank >= 0 && bank < img->nblocks) |
1852
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
934 { |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
935 switch (subject) |
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
936 { |
2108
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
937 case DS_COLOR_RAM : return &img->color[bank]; |
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
938 case DS_SCREEN_RAM : return &img->screen[bank]; |
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
939 case DS_BITMAP_RAM : return &img->bitmap[bank]; |
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
940 case DS_CHAR_DATA : return &img->charData[bank]; |
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
941 case DS_EXTRA_DATA : return &img->extraData[bank]; |
1852
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
942 } |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
943 } |
2108
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
944 |
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
945 return NULL; |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
946 } |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
947 |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
948 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
949 int dmC64DecodeGenericBMP(DMC64Image *img, const DMGrowBuf *buf, const DMC64ImageFormat *fmt) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
950 { |
1460 | 951 int res = DMERR_OK; |
952 | |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
953 if (buf == NULL || buf->data == NULL || img == NULL || fmt == NULL) |
513 | 954 return DMERR_NULLPTR; |
955 | |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
956 dmC64SetupImageData(img, fmt); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
957 |
518 | 958 // Perform decoding |
1365
60d7240e1a63
Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents:
1364
diff
changeset
|
959 for (int i = 0; i < D64_MAX_ENCDEC_OPS; 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
|
960 { |
1591
3cc7b2aadda3
Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1588
diff
changeset
|
961 const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i); |
410
e4b2f689aff6
Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents:
407
diff
changeset
|
962 const Uint8 *src; |
1600
e28e67358ff6
Fix some uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1597
diff
changeset
|
963 DMC64MemBlock *blk = NULL; |
1853
2081bb4a998a
Improve error messaging in generic c64 image encode/decode.
Matti Hamalainen <ccr@tnsp.org>
parents:
1852
diff
changeset
|
964 const char *subjname = dmC64GetOpSubjectName(op->subject); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
965 size_t size; |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
966 Uint8 value; |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
967 |
1365
60d7240e1a63
Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents:
1364
diff
changeset
|
968 // Check for last operator |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
969 if (op->type == DO_LAST) |
1365
60d7240e1a63
Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents:
1364
diff
changeset
|
970 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
|
971 |
811 | 972 // Check operation validity |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
973 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK) |
510
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
974 return res; |
925 | 975 |
2196
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
976 // Check flags |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
977 if ((op->flags & DF_DECODE) == 0) |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
978 continue; |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
979 |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
980 // Is the operation inside the bounds? |
1933
c5a46cb4cce5
Change DMC64ImageFormat parameter of dmC64GetSubjectSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1931
diff
changeset
|
981 size = dmC64GetOpSubjectSize(op, fmt->format); |
1858
1816211341a0
Only check operator size for DO_COPY operators against source size.
Matti Hamalainen <ccr@tnsp.org>
parents:
1853
diff
changeset
|
982 if (op->type == DO_COPY && op->offs + size > buf->len + 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
|
983 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
984 return dmError(DMERR_INVALID_DATA, |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
985 "Decode SRC out of bounds, op #%d type=%s, subj=%s, offs=%d ($%04x), " |
510
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
986 "bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
987 i, dmC64GetOpType(op->type), subjname, op->offs, op->offs, op->bank, |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
988 size, size, buf->len, buf->len); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
989 } |
811 | 990 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
991 src = buf->data + op->offs; |
811 | 992 |
993 // Perform operation | |
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 switch (op->type) |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
995 { |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
996 case DO_COPY: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
997 case DO_SET_MEM: |
1726
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
998 case DO_SET_MEM_HI: |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
999 case DO_SET_MEM_LO: |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1000 case DO_SET_OP: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1001 switch (op->subject) |
1373
fc5ee5b4b0e9
Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1372
diff
changeset
|
1002 { |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1003 case DS_COLOR_RAM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1004 case DS_SCREEN_RAM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1005 case DS_BITMAP_RAM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1006 case DS_CHAR_DATA: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1007 case DS_EXTRA_DATA: |
2108
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
1008 // XXX BZZZT .. a nasty cast here |
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
1009 blk = (DMC64MemBlock *) dmC64GetOpMemBlock(img, op->subject, op->bank); |
1852
219417325036
Split dmC64GetOpMemBlockAndName() into dmC64GetOpMemBlock() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1851
diff
changeset
|
1010 |
1846
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
1011 if ((dmC64MemBlockReAlloc(blk, op->offs2 + size)) != DMERR_OK) |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1012 { |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1013 return dmError(DMERR_MALLOC, |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1014 "Could not allocate '%s' block! " |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1015 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1853
2081bb4a998a
Improve error messaging in generic c64 image encode/decode.
Matti Hamalainen <ccr@tnsp.org>
parents:
1852
diff
changeset
|
1016 subjname, i, op->offs, op->offs, op->bank, op->offs2 + size, op->offs2 + size, buf->len, buf->len); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1017 } |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1018 switch (op->type) |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1019 { |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1020 case DO_COPY: |
1846
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
1021 memcpy(blk->data + op->offs2, src, size); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1022 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1023 |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1024 case DO_SET_MEM: |
1846
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
1025 dmMemset(blk->data + op->offs2, *src, size); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1026 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1027 |
1925
cf0457f93b37
Add support for DO_SET_MEM_LO and DO_SET_MEM_HI for blocks in dmC64DecodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents:
1924
diff
changeset
|
1028 case DO_SET_MEM_HI: |
cf0457f93b37
Add support for DO_SET_MEM_LO and DO_SET_MEM_HI for blocks in dmC64DecodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents:
1924
diff
changeset
|
1029 dmMemset(blk->data + op->offs2, (*src >> 4) & 0x0f, size); |
cf0457f93b37
Add support for DO_SET_MEM_LO and DO_SET_MEM_HI for blocks in dmC64DecodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents:
1924
diff
changeset
|
1030 break; |
cf0457f93b37
Add support for DO_SET_MEM_LO and DO_SET_MEM_HI for blocks in dmC64DecodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents:
1924
diff
changeset
|
1031 |
cf0457f93b37
Add support for DO_SET_MEM_LO and DO_SET_MEM_HI for blocks in dmC64DecodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents:
1924
diff
changeset
|
1032 case DO_SET_MEM_LO: |
cf0457f93b37
Add support for DO_SET_MEM_LO and DO_SET_MEM_HI for blocks in dmC64DecodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents:
1924
diff
changeset
|
1033 dmMemset(blk->data + op->offs2, *src & 0x0f, size); |
cf0457f93b37
Add support for DO_SET_MEM_LO and DO_SET_MEM_HI for blocks in dmC64DecodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents:
1924
diff
changeset
|
1034 break; |
cf0457f93b37
Add support for DO_SET_MEM_LO and DO_SET_MEM_HI for blocks in dmC64DecodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents:
1924
diff
changeset
|
1035 |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1036 case DO_SET_OP: |
1846
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
1037 dmMemset(blk->data + op->offs2, op->offs, size); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1038 break; |
1727
8eb5ff34864a
Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1726
diff
changeset
|
1039 |
1721
c9a6f1dae756
Add one default case error handler.
Matti Hamalainen <ccr@tnsp.org>
parents:
1720
diff
changeset
|
1040 default: |
c9a6f1dae756
Add one default case error handler.
Matti Hamalainen <ccr@tnsp.org>
parents:
1720
diff
changeset
|
1041 return dmError(DMERR_INTERNAL, |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
1042 "Unhandled op type %s in " |
1721
c9a6f1dae756
Add one default case error handler.
Matti Hamalainen <ccr@tnsp.org>
parents:
1720
diff
changeset
|
1043 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
1044 dmC64GetOpType(op->type), i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1045 } |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1046 break; |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1047 |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1048 case DS_D020: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1049 case DS_BGCOL: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1050 case DS_D021: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1051 case DS_D022: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1052 case DS_D023: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1053 case DS_D024: |
2238
5db6e0b63b35
Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents:
2224
diff
changeset
|
1054 case DS_EXTRA_INFO: |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1055 switch (op->type) |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1056 { |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1057 case DO_COPY: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1058 case DO_SET_MEM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1059 value = *src; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1060 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1061 |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1062 case DO_SET_OP: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1063 value = op->offs; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1064 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1065 |
1726
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1066 case DO_SET_MEM_HI: |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1067 value = (*src >> 4) & 0x0f; |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1068 break; |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1069 |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1070 case DO_SET_MEM_LO: |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1071 value = *src & 0x0f; |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1072 break; |
1924
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1073 |
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1074 default: |
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1075 return dmError(DMERR_INTERNAL, |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
1076 "Unhandled op type %s in " |
1924
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1077 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
1078 dmC64GetOpType(op->type), i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1079 } |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1080 switch (op->subject) |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1081 { |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1082 case DS_D020: img->d020 = value; break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1083 case DS_BGCOL: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1084 case DS_D021: img->bgcolor = value; break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1085 case DS_D022: img->d022 = value; break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1086 case DS_D023: img->d023 = value; break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1087 case DS_D024: img->d024 = value; break; |
2238
5db6e0b63b35
Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents:
2224
diff
changeset
|
1088 case DS_EXTRA_INFO: img->extraInfo[op->offs2] = value; break; |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1089 } |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1090 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1091 |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1092 default: |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
1093 return dmError(DMERR_INTERNAL, |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1094 "Unhandled subject %d in " |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
1095 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1096 op->subject, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1097 } |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1098 break; |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1099 |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1100 case DO_CHAR_CFG: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1101 switch (op->subject) |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1102 { |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1103 case D64_CHCFG_SCREEN: |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1104 break; |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1105 |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1106 case D64_CHCFG_LINEAR: |
2179
8d53da5bf067
Rename DMC64Image::nbanks to nblocks, which reflects better what it does.
Matti Hamalainen <ccr@tnsp.org>
parents:
2175
diff
changeset
|
1107 for (int bank = 0; bank < img->nblocks; bank++) |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1108 { |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1109 for (int offs = 0; offs < fmt->format->chHeight * fmt->format->chWidth; offs++) |
1588
ca087c0cc9c4
Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents:
1586
diff
changeset
|
1110 img->screen[bank].data[offs] = offs & 0xff; |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1111 } |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1112 break; |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1113 |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1114 default: |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
1115 return dmError(DMERR_INTERNAL, |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1116 "Unhandled DO_CHAR_CFG mode %d in ", |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
1117 "op #%d, bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1118 op->subject, i, op->bank, size, size, buf->len, buf->len); |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1119 } |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1120 break; |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1121 |
1922
3c6f638ce402
Remove the useless distinction of DO_ENC_FUNC and DO_DEC_FUNC, as the
Matti Hamalainen <ccr@tnsp.org>
parents:
1919
diff
changeset
|
1122 case DO_FUNC: |
3c6f638ce402
Remove the useless distinction of DO_ENC_FUNC and DO_DEC_FUNC, as the
Matti Hamalainen <ccr@tnsp.org>
parents:
1919
diff
changeset
|
1123 if (op->decFunction != NULL && |
2114
27cf33c3a646
Return actual error code from enc and dec functions instead of just BOOL.
Matti Hamalainen <ccr@tnsp.org>
parents:
2113
diff
changeset
|
1124 (res = op->decFunction(op, img, buf, fmt->format)) != 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
|
1125 { |
2114
27cf33c3a646
Return actual error code from enc and dec functions instead of just BOOL.
Matti Hamalainen <ccr@tnsp.org>
parents:
2113
diff
changeset
|
1126 return dmError(res, |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
1127 "Decode op custom function failed: op #%d, " |
510
43ea59887c69
Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents:
508
diff
changeset
|
1128 "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1129 i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1130 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1131 break; |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1132 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1133 } |
916 | 1134 |
1647
948d6fda722d
Add sanity check for interlaced formats: check that the interlace type flags are set.
Matti Hamalainen <ccr@tnsp.org>
parents:
1645
diff
changeset
|
1135 // Sanity check certain things .. |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1136 if ((img->extraInfo[D64_EI_MODE] & D64_FMT_ILACE) && |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1137 img->extraInfo[D64_EI_ILACE_TYPE] == D64_ILACE_NONE) |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1138 { |
1647
948d6fda722d
Add sanity check for interlaced formats: check that the interlace type flags are set.
Matti Hamalainen <ccr@tnsp.org>
parents:
1645
diff
changeset
|
1139 return dmError(DMERR_INTERNAL, |
948d6fda722d
Add sanity check for interlaced formats: check that the interlace type flags are set.
Matti Hamalainen <ccr@tnsp.org>
parents:
1645
diff
changeset
|
1140 "Format '%s' (%s) has interlace flag set, but interlace type is not set.\n", |
948d6fda722d
Add sanity check for interlaced formats: check that the interlace type flags are set.
Matti Hamalainen <ccr@tnsp.org>
parents:
1645
diff
changeset
|
1141 fmt->name, fmt->fext); |
948d6fda722d
Add sanity check for interlaced formats: check that the interlace type flags are set.
Matti Hamalainen <ccr@tnsp.org>
parents:
1645
diff
changeset
|
1142 } |
948d6fda722d
Add sanity check for interlaced formats: check that the interlace type flags are set.
Matti Hamalainen <ccr@tnsp.org>
parents:
1645
diff
changeset
|
1143 |
508
1ed5025c2538
Return DMLIB error values instead of arbitrary 0/negatives.
Matti Hamalainen <ccr@tnsp.org>
parents:
507
diff
changeset
|
1144 return DMERR_OK; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1145 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1146 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1147 |
1499
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1148 int dmC64EncodeGenericBMP(const BOOL allocate, DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt) |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1149 { |
1365
60d7240e1a63
Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents:
1364
diff
changeset
|
1150 int res = DMERR_OK; |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1151 |
1469
0046b4e1b35f
Various fixes in bmp encoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1467
diff
changeset
|
1152 if (img == NULL || fmt == NULL) |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1153 return DMERR_NULLPTR; |
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1154 |
1499
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1155 // Allocate the output buffer if requested |
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1156 if (allocate && (res = dmGrowBufAlloc(buf, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1157 { |
1472
b9d3577d8290
Improve error handling and checking.
Matti Hamalainen <ccr@tnsp.org>
parents:
1471
diff
changeset
|
1158 dmError(res, |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
1159 "Could not allocate %d bytes of memory for C64 image encoding buffer.\n", |
1465
88845f95e791
Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1463
diff
changeset
|
1160 fmt->size); |
1447 | 1161 goto err; |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1162 } |
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1163 |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1672
diff
changeset
|
1164 if (buf->backwards) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1672
diff
changeset
|
1165 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1672
diff
changeset
|
1166 dmError(DMERR_INVALID_DATA, |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1672
diff
changeset
|
1167 "Buffer specified for dmC64EncodeGenericBMP() is in backwards mode, which is not supported.\n"); |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1672
diff
changeset
|
1168 goto err; |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1672
diff
changeset
|
1169 } |
1506
4fd4e7a00db4
Fix handling of predefined DMGrowBuffer in dmC64EncodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents:
1505
diff
changeset
|
1170 |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1171 // Perform encoding |
1365
60d7240e1a63
Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents:
1364
diff
changeset
|
1172 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++) |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1173 { |
1591
3cc7b2aadda3
Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1588
diff
changeset
|
1174 const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i); |
1364 | 1175 size_t size, chksize; |
1600
e28e67358ff6
Fix some uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents:
1597
diff
changeset
|
1176 const DMC64MemBlock *blk = NULL; |
1853
2081bb4a998a
Improve error messaging in generic c64 image encode/decode.
Matti Hamalainen <ccr@tnsp.org>
parents:
1852
diff
changeset
|
1177 const char *subjname = dmC64GetOpSubjectName(op->subject); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1178 Uint8 value; |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1179 |
1365
60d7240e1a63
Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents:
1364
diff
changeset
|
1180 // Check for last operator |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1181 if (op->type == DO_LAST) |
1365
60d7240e1a63
Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents:
1364
diff
changeset
|
1182 break; |
60d7240e1a63
Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents:
1364
diff
changeset
|
1183 |
811 | 1184 // Check operation validity |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
1185 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK) |
1447 | 1186 goto err; |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1187 |
2196
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
1188 // Check flags |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
1189 if ((op->flags & DF_ENCODE) == 0) |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
1190 continue; |
28871f500e84
Add new "flags" field to DMC64EncDecOp, defined by DF_* that can be used to
Matti Hamalainen <ccr@tnsp.org>
parents:
2194
diff
changeset
|
1191 |
811 | 1192 // Do we need to reallocate some more space? |
1933
c5a46cb4cce5
Change DMC64ImageFormat parameter of dmC64GetSubjectSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
1931
diff
changeset
|
1193 size = dmC64GetOpSubjectSize(op, fmt->format); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1672
diff
changeset
|
1194 chksize = buf->offs + op->offs + size; |
1465
88845f95e791
Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1463
diff
changeset
|
1195 if (!dmGrowBufCheckGrow(buf, chksize)) |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1196 { |
1465
88845f95e791
Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1463
diff
changeset
|
1197 res = dmError(DMERR_MALLOC, |
88845f95e791
Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1463
diff
changeset
|
1198 "Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n", |
88845f95e791
Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1463
diff
changeset
|
1199 chksize); |
88845f95e791
Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents:
1463
diff
changeset
|
1200 goto err; |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1201 } |
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1202 |
811 | 1203 // Perform operation |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1672
diff
changeset
|
1204 Uint8 *dst = buf->data + buf->offs + op->offs; |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1205 switch (op->type) |
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1206 { |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1207 case DO_COPY: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1208 case DO_SET_MEM: |
1926
f4fa11ecdc6f
Add some operators case handlers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1925
diff
changeset
|
1209 case DO_SET_MEM_HI: |
f4fa11ecdc6f
Add some operators case handlers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1925
diff
changeset
|
1210 case DO_SET_MEM_LO: |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1211 case DO_SET_OP: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1212 switch (op->subject) |
1373
fc5ee5b4b0e9
Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents:
1372
diff
changeset
|
1213 { |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1214 case DS_COLOR_RAM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1215 case DS_SCREEN_RAM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1216 case DS_BITMAP_RAM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1217 case DS_CHAR_DATA: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1218 case DS_EXTRA_DATA: |
2108
5f8f170f8774
Change dmC64GetOpMemBlock() function API.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
1219 blk = dmC64GetOpMemBlock(img, op->subject, op->bank); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1220 switch (op->type) |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1221 { |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1222 case DO_COPY: |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1223 if (blk->data == NULL) |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1224 { |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1225 res = dmError(DMERR_NULLPTR, |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1226 "'%s' block is NULL in " |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1227 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1853
2081bb4a998a
Improve error messaging in generic c64 image encode/decode.
Matti Hamalainen <ccr@tnsp.org>
parents:
1852
diff
changeset
|
1228 subjname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1229 goto err; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1230 } |
1846
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
1231 if (op->offs2 + size > blk->size) |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1232 { |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1233 res = dmError(DMERR_INTERNAL, |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1234 "'%s' size mismatch %d <> %d in " |
1846
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
1235 "op #%d, offs=%d ($%04x), bank=%d, offs2=%d ($%02x), size=%d ($%04x)\n", |
1853
2081bb4a998a
Improve error messaging in generic c64 image encode/decode.
Matti Hamalainen <ccr@tnsp.org>
parents:
1852
diff
changeset
|
1236 subjname, op->offs2 + size, blk->size, i, op->offs, op->offs, op->bank, op->offs2, op->offs2, size, size); |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1237 goto err; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1238 } |
1846
88cef7758303
Implement data block offset in certain DMC64EncDecOps. This allows us to
Matti Hamalainen <ccr@tnsp.org>
parents:
1833
diff
changeset
|
1239 memcpy(dst, blk->data + op->offs2, size); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1240 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1241 |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1242 case DO_SET_MEM: |
1926
f4fa11ecdc6f
Add some operators case handlers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1925
diff
changeset
|
1243 case DO_SET_MEM_HI: |
f4fa11ecdc6f
Add some operators case handlers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1925
diff
changeset
|
1244 case DO_SET_MEM_LO: |
f4fa11ecdc6f
Add some operators case handlers.
Matti Hamalainen <ccr@tnsp.org>
parents:
1925
diff
changeset
|
1245 case DO_SET_OP: |
1918
ba88ff5e85ea
Fix a silly bug in the generic c64 bitmap encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1917
diff
changeset
|
1246 // This operation makes no sense in encoding, so do nothing |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1247 break; |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1248 |
1924
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1249 default: |
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1250 return dmError(DMERR_INTERNAL, |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
1251 "Unhandled op type %s in " |
1924
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1252 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
1253 dmC64GetOpType(op->type), i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1254 } |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1255 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1256 |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1257 case DS_D020: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1258 case DS_BGCOL: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1259 case DS_D021: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1260 case DS_D022: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1261 case DS_D023: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1262 case DS_D024: |
2238
5db6e0b63b35
Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents:
2224
diff
changeset
|
1263 case DS_EXTRA_INFO: |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1264 switch (op->subject) |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1265 { |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1266 case DS_D020: value = img->d020; break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1267 case DS_BGCOL: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1268 case DS_D021: value = img->bgcolor; break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1269 case DS_D022: value = img->d022; break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1270 case DS_D023: value = img->d023; break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1271 case DS_D024: value = img->d024; break; |
2238
5db6e0b63b35
Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents:
2224
diff
changeset
|
1272 case DS_EXTRA_INFO: value = img->extraInfo[op->offs2]; break; |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1273 } |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1274 switch (op->type) |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1275 { |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1276 case DO_COPY: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1277 case DO_SET_MEM: |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1278 *dst = value; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1279 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1280 |
1726
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1281 case DO_SET_MEM_HI: |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1282 *dst |= (value & 0x0f) << 4; |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1283 break; |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1284 |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1285 case DO_SET_MEM_LO: |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1286 *dst |= value & 0x0f; |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1287 break; |
f9128665a47e
Implement operator types DO_SET_MEM_HI and DO_SET_MEM_LO. Not used yet.
Matti Hamalainen <ccr@tnsp.org>
parents:
1725
diff
changeset
|
1288 |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1289 case DO_SET_OP: |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1290 // Do nothing in this case |
2238
5db6e0b63b35
Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents:
2224
diff
changeset
|
1291 // XXX TODO: what about DS_EXTRA_INFO? |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1292 break; |
1924
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1293 |
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1294 default: |
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1295 return dmError(DMERR_INTERNAL, |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
1296 "Unhandled op type %s in " |
1924
1c5ea4fa8788
Add some default-case error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1923
diff
changeset
|
1297 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
2171
a39bf85308e5
Add helper function dmC64GetOpType() and use it to display operator type
Matti Hamalainen <ccr@tnsp.org>
parents:
2157
diff
changeset
|
1298 dmC64GetOpType(op->type), i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1299 } |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1300 break; |
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1301 |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1302 default: |
1668
1741717b1ae5
Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents:
1660
diff
changeset
|
1303 return dmError(DMERR_INTERNAL, |
1853
2081bb4a998a
Improve error messaging in generic c64 image encode/decode.
Matti Hamalainen <ccr@tnsp.org>
parents:
1852
diff
changeset
|
1304 "Unhandled subject '%s' in " |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
1305 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1853
2081bb4a998a
Improve error messaging in generic c64 image encode/decode.
Matti Hamalainen <ccr@tnsp.org>
parents:
1852
diff
changeset
|
1306 subjname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1307 } |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1308 break; |
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1309 |
1922
3c6f638ce402
Remove the useless distinction of DO_ENC_FUNC and DO_DEC_FUNC, as the
Matti Hamalainen <ccr@tnsp.org>
parents:
1919
diff
changeset
|
1310 case DO_FUNC: |
3c6f638ce402
Remove the useless distinction of DO_ENC_FUNC and DO_DEC_FUNC, as the
Matti Hamalainen <ccr@tnsp.org>
parents:
1919
diff
changeset
|
1311 if (op->encFunction != NULL && |
2114
27cf33c3a646
Return actual error code from enc and dec functions instead of just BOOL.
Matti Hamalainen <ccr@tnsp.org>
parents:
2113
diff
changeset
|
1312 (res = op->encFunction(op, buf, img, fmt->format)) != DMERR_OK) |
904
d3cd9f2a8ef1
Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents:
903
diff
changeset
|
1313 { |
2114
27cf33c3a646
Return actual error code from enc and dec functions instead of just BOOL.
Matti Hamalainen <ccr@tnsp.org>
parents:
2113
diff
changeset
|
1314 dmErrorMsg( |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
946
diff
changeset
|
1315 "Encode op custom function failed: op #%d, " |
904
d3cd9f2a8ef1
Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents:
903
diff
changeset
|
1316 "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n", |
1486
bc13af8954d7
Add DMC64ImageFormat to C64 bitmap format encoding/decoding ops function parameters.
Matti Hamalainen <ccr@tnsp.org>
parents:
1485
diff
changeset
|
1317 i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len); |
bc13af8954d7
Add DMC64ImageFormat to C64 bitmap format encoding/decoding ops function parameters.
Matti Hamalainen <ccr@tnsp.org>
parents:
1485
diff
changeset
|
1318 goto err; |
904
d3cd9f2a8ef1
Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents:
903
diff
changeset
|
1319 } |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1320 break; |
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1321 } |
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1322 } |
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1323 |
1448
50402c225ef4
Do not insert load address to the buffer beginning in dmC64EncodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents:
1447
diff
changeset
|
1324 res = DMERR_OK; |
535
ab8d9696225c
Add helper macros and use them to set the loading address while encoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
534
diff
changeset
|
1325 |
1447 | 1326 err: |
532
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1327 return res; |
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1328 } |
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1329 |
128a50feff07
Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents:
531
diff
changeset
|
1330 |
2132
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1331 static int fmtGetGenericSCPixel(Uint8 *col, const DMC64Image *img, |
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1332 const int rasterX, const int rasterY) |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1333 { |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1334 DM_C64_GENERIC_SC_PIXEL_DEFS(img) |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1335 |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1336 return dmC64GetGenericSCPixel( |
2132
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1337 col, img, |
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1338 bmoffs, scroffs, |
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1339 vshift, 0, 0); |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1340 } |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1341 |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1342 |
2132
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1343 static int fmtGetGenericMCPixel(Uint8 *col, const DMC64Image *img, |
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1344 const int rasterX, const int rasterY) |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1345 { |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1346 DM_C64_GENERIC_MC_PIXEL_DEFS(img) |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1347 |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1348 return dmC64GetGenericMCPixel( |
2132
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1349 col, img, |
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1350 bmoffs, scroffs, |
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1351 vshift, 0, |
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1352 0, 0, img->bgcolor); |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1353 } |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1354 |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1355 |
2172
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1356 static int fmtGetGenericCharPixel(Uint8 *col, |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1357 const DMC64Image *img, const int rasterX, const int rasterY) |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1358 { |
2132
6528a1398e8e
Add char map helper functions and use them.
Matti Hamalainen <ccr@tnsp.org>
parents:
2131
diff
changeset
|
1359 DM_C64_GENERIC_CHAR_PIXEL(img) |
2172
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1360 int chr = img->screen[0].data[scroffs]; |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1361 |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1362 if (!img->extraInfo[D64_EI_CHAR_CUSTOM] && |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1363 img->extraInfo[D64_EI_CHAR_CASE]) |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1364 chr += 256; // lower case, so add 256 to char ROM offset |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1365 |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1366 switch (img->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) |
2172
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1367 { |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1368 case D64_FMT_HIRES: |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1369 return dmC64GetGenericCharSCPixel( |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1370 col, img, |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1371 scroffs, rasterX, |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1372 0, (chr * D64_CHR_SIZE) + (rasterY & 7), chr, |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1373 0, img->bgcolor); |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1374 |
2172
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1375 case D64_FMT_MC: |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1376 return dmC64GetGenericCharMCPixel( |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1377 col, img, |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1378 scroffs, rasterX, |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1379 0, (chr * D64_CHR_SIZE) + (rasterY & 7), chr, |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1380 0, img->bgcolor, img->d022, img->d023); |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1381 |
2172
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1382 case D64_FMT_ECM: |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1383 return dmC64GetGenericCharECMPixel( |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1384 col, img, |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1385 scroffs, rasterX, |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1386 0, ((chr & 0x3f) * D64_CHR_SIZE) + (rasterY & 7), chr, |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1387 0, img->bgcolor, img->d022, img->d023, img->d024); |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1388 |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1389 default: |
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1390 return dmError(DMERR_INVALID_DATA, |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1391 "Invalid character map image mode=0x%x.\n", |
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1392 img->extraInfo[D64_EI_MODE]); |
2172
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1393 } |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1394 } |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1395 |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1396 |
530
5b37a2e427b7
Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents:
529
diff
changeset
|
1397 // Convert a generic "C64" format bitmap in DMC64Image struct to |
5b37a2e427b7
Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents:
529
diff
changeset
|
1398 // a indexed/paletted bitmap image. |
2223
5477e792def3
Remove useless DMC64ImageFormat parameter from some conversion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2208
diff
changeset
|
1399 int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageConvSpec *spec) |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1400 { |
1375
f5368c13a872
Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents:
1373
diff
changeset
|
1401 DMC64GetPixelFunc getPixel; |
530
5b37a2e427b7
Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents:
529
diff
changeset
|
1402 |
556
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1403 // Sanity check arguments |
2223
5477e792def3
Remove useless DMC64ImageFormat parameter from some conversion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2208
diff
changeset
|
1404 if (dst == NULL || src == NULL || spec == NULL) |
556
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1405 return DMERR_NULLPTR; |
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1406 |
1947
8896d5676f1b
Architectural change: remove some duplicated variables from DMC64Image
Matti Hamalainen <ccr@tnsp.org>
parents:
1944
diff
changeset
|
1407 if (dst->width != src->fmt->width || dst->height != src->fmt->height) |
1460 | 1408 { |
1409 return dmError(DMERR_INVALID_DATA, | |
1410 "Invalid src vs. dst width/height %d x %d <-> %d x %d\n", | |
1947
8896d5676f1b
Architectural change: remove some duplicated variables from DMC64Image
Matti Hamalainen <ccr@tnsp.org>
parents:
1944
diff
changeset
|
1411 src->fmt->width, src->fmt->height, dst->width, dst->height); |
1460 | 1412 } |
556
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1413 |
1167 | 1414 dmMemset(dst->data, 0, dst->size); |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
1415 |
1375
f5368c13a872
Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents:
1373
diff
changeset
|
1416 // Check pixel getter function |
1947
8896d5676f1b
Architectural change: remove some duplicated variables from DMC64Image
Matti Hamalainen <ccr@tnsp.org>
parents:
1944
diff
changeset
|
1417 if (src->fmt->getPixel != NULL) |
8896d5676f1b
Architectural change: remove some duplicated variables from DMC64Image
Matti Hamalainen <ccr@tnsp.org>
parents:
1944
diff
changeset
|
1418 getPixel = src->fmt->getPixel; |
1375
f5368c13a872
Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents:
1373
diff
changeset
|
1419 else |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1420 if (src->extraInfo[D64_EI_MODE] & D64_FMT_CHAR) |
2172
de88333acc44
Move the PETSCII getpixel function to lib64gfx.c and remove the
Matti Hamalainen <ccr@tnsp.org>
parents:
2171
diff
changeset
|
1421 getPixel = fmtGetGenericCharPixel; |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1422 else |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1423 switch (src->extraInfo[D64_EI_MODE] & D64_FMT_MODE_MASK) |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1424 { |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1425 case D64_FMT_MC : getPixel = fmtGetGenericMCPixel; break; |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1426 case D64_FMT_HIRES : getPixel = fmtGetGenericSCPixel; break; |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1427 default: |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1428 return dmError(DMERR_INVALID_DATA, |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1429 "Invalid bitmap image type/fmt=0x%x.\n", |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1430 src->extraInfo[D64_EI_MODE]); |
2118
05a6e00b09d0
Change D64_FMT_* MASK constants and how they are used.
Matti Hamalainen <ccr@tnsp.org>
parents:
2117
diff
changeset
|
1431 } |
1375
f5368c13a872
Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents:
1373
diff
changeset
|
1432 |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
1433 // Perform conversion |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1434 for (int yc = 0; yc < dst->height; yc++) |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1435 { |
1919 | 1436 Uint8 *dp = dst->data + (yc * dst->pitch); |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1437 for (int xc = 0; xc < dst->width; xc++, dp++) |
917
df3a74f230d9
Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
916
diff
changeset
|
1438 { |
2128
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1439 int res; |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1440 if ((res = getPixel(dp, src, xc, yc)) != DMERR_OK) |
a8f5295ab2e7
Validate format index values better in dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents:
2125
diff
changeset
|
1441 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
|
1442 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1443 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1444 |
508
1ed5025c2538
Return DMLIB error values instead of arbitrary 0/negatives.
Matti Hamalainen <ccr@tnsp.org>
parents:
507
diff
changeset
|
1445 return DMERR_OK; |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1446 } |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1447 |
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1448 |
2223
5477e792def3
Remove useless DMC64ImageFormat parameter from some conversion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2208
diff
changeset
|
1449 int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageConvSpec *spec) |
556
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1450 { |
2224
a36c81c3df85
Make color interlace type generate a mixed palette instead of using special
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1451 DMImage *dst; |
a36c81c3df85
Make color interlace type generate a mixed palette instead of using special
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1452 BOOL mixed; |
940
ff18d2511843
Remove the doubleMC madness completely. Should be replaced with x/y aspect
Matti Hamalainen <ccr@tnsp.org>
parents:
939
diff
changeset
|
1453 int res; |
556
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1454 |
2223
5477e792def3
Remove useless DMC64ImageFormat parameter from some conversion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2208
diff
changeset
|
1455 if (pdst == NULL || src == NULL || spec == NULL) |
556
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1456 return DMERR_NULLPTR; |
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1457 |
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1458 // Allocate image structure |
1947
8896d5676f1b
Architectural change: remove some duplicated variables from DMC64Image
Matti Hamalainen <ccr@tnsp.org>
parents:
1944
diff
changeset
|
1459 if ((*pdst = dst = dmImageAlloc( |
2157
9a9493809b3a
Rename DM_COLFMT_* constants to DM_PIXFMT_* and the 'format' field of DMImage
Matti Hamalainen <ccr@tnsp.org>
parents:
2147
diff
changeset
|
1460 src->fmt->width, src->fmt->height, DM_PIXFMT_PALETTE, -1)) == NULL) |
556
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1461 return DMERR_MALLOC; |
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1462 |
2201
9f3fb4004c20
Improvements to the lib64gfx palette handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2200
diff
changeset
|
1463 // Set palette information |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1464 mixed = (src->extraInfo[D64_EI_MODE] & D64_FMT_ILACE) && |
2238
5db6e0b63b35
Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents:
2224
diff
changeset
|
1465 src->extraInfo[D64_EI_ILACE_TYPE] == D64_ILACE_COLOR; |
5db6e0b63b35
Change again how the interlace type information is stored. Now store it in
Matti Hamalainen <ccr@tnsp.org>
parents:
2224
diff
changeset
|
1466 |
2224
a36c81c3df85
Make color interlace type generate a mixed palette instead of using special
Matti Hamalainen <ccr@tnsp.org>
parents:
2223
diff
changeset
|
1467 if ((res = dmC64SetImagePalette(dst, spec, mixed)) != DMERR_OK) |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2061
diff
changeset
|
1468 return res; |
556
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1469 |
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1470 // Convert |
2223
5477e792def3
Remove useless DMC64ImageFormat parameter from some conversion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2208
diff
changeset
|
1471 if (src->fmt->convertFrom != NULL) |
5477e792def3
Remove useless DMC64ImageFormat parameter from some conversion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2208
diff
changeset
|
1472 res = src->fmt->convertFrom(dst, src, spec); |
556
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1473 else |
2223
5477e792def3
Remove useless DMC64ImageFormat parameter from some conversion functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
2208
diff
changeset
|
1474 res = dmC64ConvertGenericBMP2Image(dst, src, spec); |
556
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1475 |
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1476 return res; |
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1477 } |
44d1e0d4acf3
Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents:
548
diff
changeset
|
1478 |
407
59244a7ae37f
Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1479 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1480 int dmC64DecodeBMP(DMC64Image **img, const DMGrowBuf *buf, |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1481 const size_t probeOffs, const size_t loadOffs, |
516 | 1482 const DMC64ImageFormat **fmt, const DMC64ImageFormat *forced) |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1483 { |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1484 DMGrowBuf tmp; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1485 |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1486 if (img == NULL || buf == NULL) |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
1487 return DMERR_NULLPTR; |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
1488 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1489 // Check for forced format |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1490 if (forced != NULL) |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1491 *fmt = forced; |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1492 else |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1493 { |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1494 // Nope, perform a generic probe |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1495 if (probeOffs >= buf->len) |
1460 | 1496 return DMERR_OUT_OF_DATA; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1497 |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
1498 dmGrowBufConstCopyOffs(&tmp, buf, probeOffs); |
1780
5ea4713e9e0f
Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1775
diff
changeset
|
1499 if (dmC64ProbeBMP(&tmp, fmt) == DM_PROBE_SCORE_FALSE) |
1460 | 1500 return DMERR_NOT_SUPPORTED; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1501 } |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1502 |
1710
1f0fac3af8e3
Use buf->len instead of tmp.len, as it might not be initialized.
Matti Hamalainen <ccr@tnsp.org>
parents:
1707
diff
changeset
|
1503 if (loadOffs >= buf->len) |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
1504 return DMERR_INVALID_ARGS; |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
1505 |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
1506 if (*fmt == NULL) |
1548
20cd589366d7
Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1542
diff
changeset
|
1507 return DMERR_NOT_SUPPORTED; |
20cd589366d7
Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1542
diff
changeset
|
1508 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1509 // Format supports only reading? |
1548
20cd589366d7
Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1542
diff
changeset
|
1510 if (((*fmt)->flags & DM_FMT_RD) == 0) |
20cd589366d7
Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1542
diff
changeset
|
1511 return DMERR_NOT_SUPPORTED; |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
1512 |
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
1513 // Allocate memory |
1378
c465860e44ed
Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents:
1377
diff
changeset
|
1514 if ((*img = dmC64ImageAlloc(*fmt)) == NULL) |
931
2270d7f3af77
Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents:
927
diff
changeset
|
1515 return DMERR_MALLOC; |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1516 |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
1517 dmGrowBufConstCopyOffs(&tmp, buf, loadOffs); |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1518 |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1519 // Decode the bitmap to memory layout |
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1520 if ((*fmt)->decode != NULL) |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1521 return (*fmt)->decode(*img, &tmp, *fmt); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1522 else |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
1523 return dmC64DecodeGenericBMP(*img, &tmp, *fmt); |
419
936bc27a79d6
Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents:
410
diff
changeset
|
1524 } |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1525 |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1526 |
2109
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1527 int dmC64MemBlockAllocSubj(DMC64Image *img, const int subject, const int bank) |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1528 { |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1529 const char *subjname = dmC64GetOpSubjectName(subject); |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1530 size_t size = dmC64GetSubjectSize(subject, img->fmt); |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1531 DMC64MemBlock *blk = (DMC64MemBlock *) dmC64GetOpMemBlock(img, subject, bank); |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1532 int res; |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1533 |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1534 if ((res = dmC64MemBlockAlloc(blk, size)) != DMERR_OK) |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1535 { |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1536 return dmError(res, |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1537 "Could not allocate '%s' block with size %d bytes.\n", |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1538 subjname, size); |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1539 } |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1540 |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1541 return DMERR_OK; |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1542 } |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1543 |
510ea816d1ff
Add helper function dmC64MemBlockAllocSubj().
Matti Hamalainen <ccr@tnsp.org>
parents:
2108
diff
changeset
|
1544 |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1545 // Convert a generic bitmap image to DMC64Image |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1927
diff
changeset
|
1546 int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1927
diff
changeset
|
1547 const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec) |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1548 { |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1927
diff
changeset
|
1549 if (dst == NULL || src == NULL || fmt == NULL || spec == NULL) |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1550 return DMERR_NULLPTR; |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1551 |
1949
f8e2728c1b7f
Return DMERR_NOT_SUPPORTED from dmC64ConvertGenericImage2BMP() as it does
Matti Hamalainen <ccr@tnsp.org>
parents:
1947
diff
changeset
|
1552 return DMERR_NOT_SUPPORTED; |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1553 } |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1554 |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1555 |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1927
diff
changeset
|
1556 int dmC64ConvertImage2BMP(DMC64Image **pdst, const DMImage *src, |
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1927
diff
changeset
|
1557 const DMC64ImageFormat *fmt, const DMC64ImageConvSpec *spec) |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1558 { |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1559 int res; |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1560 DMC64Image *dst; |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1561 |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1562 if (pdst == NULL || src == NULL) |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1563 return DMERR_NULLPTR; |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1564 |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1565 // Allocate the basic C64 bitmap image structure |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1566 if ((*pdst = dst = dmC64ImageAlloc(fmt)) == NULL) |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1567 return DMERR_MALLOC; |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1568 |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1569 // Convert |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1570 if (fmt->format->convertTo != NULL) |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1927
diff
changeset
|
1571 res = fmt->format->convertTo(dst, src, fmt, spec); |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1572 else |
1931
410679d2fe8a
"Enable" the image->c64 bitmap conversion path in gfxconv. It does not work
Matti Hamalainen <ccr@tnsp.org>
parents:
1927
diff
changeset
|
1573 res = dmC64ConvertGenericImage2BMP(dst, src, fmt, spec); |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1574 |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1575 return res; |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1576 } |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1577 |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1578 |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1579 int dmC64EncodeBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt) |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1580 { |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1581 int res; |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1582 |
1580
72f809e6eb3c
Add NULL check for growbuf pointer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1573
diff
changeset
|
1583 if (buf == NULL || img == NULL || fmt == NULL) |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1584 return DMERR_NULLPTR; |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1585 |
1548
20cd589366d7
Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1542
diff
changeset
|
1586 if ((fmt->flags & DM_FMT_WR) == 0) |
20cd589366d7
Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1542
diff
changeset
|
1587 return DMERR_NOT_SUPPORTED; |
20cd589366d7
Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1542
diff
changeset
|
1588 |
1499
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1589 // Allocate a buffer |
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1590 if ((res = dmGrowBufAlloc(buf, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK) |
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1591 goto err; |
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1592 |
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1593 // Add the loading address |
1828
6e1dd79c6bce
Use dmGrowBufPutU16LE() instead of two dmGrowBufPutU8() to push the loading
Matti Hamalainen <ccr@tnsp.org>
parents:
1827
diff
changeset
|
1594 if (!dmGrowBufPutU16LE(buf, fmt->addr)) |
1499
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1595 goto err; |
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1596 |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1597 // Attempt to encode the image to a buffer |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1598 if (fmt->encode != NULL) |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1599 res = fmt->encode(buf, img, fmt); |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1600 else |
1499
32640e1934d5
Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1498
diff
changeset
|
1601 res = dmC64EncodeGenericBMP(FALSE, buf, img, fmt); |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1602 |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1603 if (res != DMERR_OK) |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1604 goto err; |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1605 |
1797
5204fab92c9e
If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
1606 // Finally, if the format has a set size and our buffer is smaller |
5204fab92c9e
If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
1607 // than that size, we grow the buffer to match (with zeroed data). |
5204fab92c9e
If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
1608 // This accounts for format variants that are otherwise identical. |
5204fab92c9e
If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
1609 if (fmt->size > 0 && buf->len < fmt->size && |
5204fab92c9e
If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
1610 !dmGrowBufCheckGrow(buf, fmt->size)) |
5204fab92c9e
If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
1611 { |
5204fab92c9e
If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
1612 res = DMERR_MALLOC; |
5204fab92c9e
If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
1613 goto err; |
5204fab92c9e
If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
1614 } |
5204fab92c9e
If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents:
1790
diff
changeset
|
1615 |
1469
0046b4e1b35f
Various fixes in bmp encoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1467
diff
changeset
|
1616 return DMERR_OK; |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1617 |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1618 err: |
1799 | 1619 // In error case, free the buffer |
1467
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1620 dmGrowBufFree(buf); |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1621 return res; |
32203356c652
Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
1466
diff
changeset
|
1622 } |
1774
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1623 |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1624 |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1625 // Perform probing of the given data buffer, trying to determine |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1626 // if it contains a supported "C64" image format. Returns the |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1627 // "probe score", see libgfx.h for list of values. If a match |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1628 // is found, pointer to format description is set to *pfmt. |
1780
5ea4713e9e0f
Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1775
diff
changeset
|
1629 int dmC64ProbeBMP(const DMGrowBuf *buf, const DMC64ImageFormat **pfmt) |
1774
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1630 { |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1631 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1632 |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1633 for (int i = 0; i < ndmC64ImageFormats; i++) |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1634 { |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1635 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1636 int score = DM_PROBE_SCORE_FALSE; |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1637 if (fmt->probe == NULL && fmt->size > 0 && fmt->addr > 0) |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1638 { |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1639 // Generic probe just checks matching size and load address |
1780
5ea4713e9e0f
Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1775
diff
changeset
|
1640 if (buf->len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr)) |
1774
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1641 score = DM_PROBE_SCORE_GOOD; |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1642 } |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1643 else |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1644 if (fmt->probe != NULL) |
1780
5ea4713e9e0f
Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1775
diff
changeset
|
1645 score = fmt->probe(buf, fmt); |
1774
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1646 |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1647 if (score > scoreMax) |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1648 { |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1649 scoreMax = score; |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1650 scoreIndex = i; |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1651 } |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1652 } |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1653 |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1654 if (scoreIndex >= 0) |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1655 { |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1656 *pfmt = &dmC64ImageFormats[scoreIndex]; |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1657 return scoreMax; |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1658 } |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1659 else |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1660 return DM_PROBE_SCORE_FALSE; |
88354355b8e1
Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents:
1764
diff
changeset
|
1661 } |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1662 |
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1663 |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1664 BOOL dmLib64GFXInitialized = FALSE; |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1665 DMC64ImageFormat **dmC64ImageFormatsSorted = NULL; |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1666 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1667 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1668 int dmC64ImageFormatCompare(const void *va, const void *vb) |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1669 { |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1670 const DMC64ImageFormat |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1671 *fmta = *(DMC64ImageFormat **) va, |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1672 *fmtb = *(DMC64ImageFormat **) vb; |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1673 |
2265
48b48251610a
Refactor how the image "mode/type" is handled. It is still not perfect for
Matti Hamalainen <ccr@tnsp.org>
parents:
2238
diff
changeset
|
1674 int res = fmta->format->mode - fmtb->format->mode; |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1675 if (res == 0) |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1676 return strcmp(fmta->name, fmtb->name); |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1677 else |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1678 return res; |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1679 } |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1680 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1681 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1682 int dmLib64GFXInit(void) |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1683 { |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1684 // Safety check |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1685 if (dmLib64GFXInitialized) |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1686 dmLib64GFXClose(); |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1687 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1688 dmLib64GFXInitialized = TRUE; |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1689 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1690 if ((dmC64ImageFormatsSorted = dmCalloc(ndmC64ImageFormats, sizeof(dmC64ImageFormatsSorted[0]))) == NULL) |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1691 return DMERR_MALLOC; |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1692 |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1693 for (int i = 0; i < ndmC64ImageFormats; i++) |
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1694 { |
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1695 DMC64ImageFormat *fmt = &dmC64ImageFormats[i]; |
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1696 if (fmt->format == NULL) |
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1697 fmt->format = &fmt->formatDef; |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1698 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1699 dmC64ImageFormatsSorted[i] = fmt; |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1700 } |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1701 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1702 qsort(dmC64ImageFormatsSorted, ndmC64ImageFormats, |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1703 sizeof(DMC64ImageFormat *), dmC64ImageFormatCompare); |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1704 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1705 return DMERR_OK; |
1775
4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents:
1774
diff
changeset
|
1706 } |
2200
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1707 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1708 |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1709 void dmLib64GFXClose(void) |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1710 { |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1711 dmFreeR(&dmC64ImageFormatsSorted); |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1712 dmLib64GFXInitialized = FALSE; |
dcd26cdc395e
Replace dmC64InitializeFormats() with dmLib64GFXInit() and dmLib64GFXClose().
Matti Hamalainen <ccr@tnsp.org>
parents:
2196
diff
changeset
|
1713 } |