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