annotate tools/lib64gfx.c @ 1824:adf9f05c26e1

Improve error handling of dmC64MemBlockCopy().
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 22 Jun 2018 12:22:33 +0300
parents 9bec535956fd
children d6fbbf7ddba1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
1456
42fb39da7dde Bump copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents: 1448
diff changeset
5 * (C) Copyright 2012-2018 Tecnic Software productions (TNSP)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 433
diff changeset
10
514
c9b9f912acfb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
11 #define BUF_SIZE_INITIAL (16*1024)
c9b9f912acfb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
12 #define BUF_SIZE_GROW (4*1024)
c9b9f912acfb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
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
1731
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
15 // Based on Pepto's palette, stolen from VICE
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
16 DMColor dmDefaultC64Palette[C64_NCOLORS] =
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
17 {
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
18 { 0x00, 0x00, 0x00, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
19 { 0xFF, 0xFF, 0xFF, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
20 { 0x68, 0x37, 0x2B, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
21 { 0x70, 0xA4, 0xB2, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
22 { 0x6F, 0x3D, 0x86, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
23 { 0x58, 0x8D, 0x43, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
24 { 0x35, 0x28, 0x79, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
25 { 0xB8, 0xC7, 0x6F, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
26 { 0x6F, 0x4F, 0x25, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
27 { 0x43, 0x39, 0x00, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
28 { 0x9A, 0x67, 0x59, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
29 { 0x44, 0x44, 0x44, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
30 { 0x6C, 0x6C, 0x6C, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
31 { 0x9A, 0xD2, 0x84, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
32 { 0x6C, 0x5E, 0xB5, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
33 { 0x95, 0x95, 0x95, 0xff },
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
34 };
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
35
474055f25ab0 Move dmDefaultC64Palette back to lib64gfx.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1730
diff changeset
36
1644
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
37 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng)
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
38 {
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
39 snprintf(buf, len,
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
40 "%s%s%s%s",
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
41 (type & D64_FMT_MC) ? (lng ? "MultiColor " : "MC ") : "HiRes ",
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
42 (type & D64_FMT_ILACE) ? (lng ? "Interlaced " : "ILace ") : "",
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
43 (type & D64_FMT_FLI) ? "FLI " : "",
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
44 (type & D64_FMT_CHAR) ? "CHAR" : ""
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
45 );
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
46
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
47 return buf;
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
48 }
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
49
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1632
diff changeset
50
1822
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
51 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt, const char *indent)
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
52 {
1728
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
53 char typeStr[64], typeStr2[64];
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
54
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
55 dmC64GetImageTypeString(typeStr, sizeof(typeStr), fmt->format->type, TRUE);
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
56
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
57 if (fmt != NULL)
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
58 {
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
59 fprintf(fh,
1822
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
60 "%sFormat : %s [%s]\n",
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
61 indent, fmt->name, fmt->fext);
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
62 }
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
63
1728
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
64 if (img != NULL)
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
65 {
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
66 dmC64GetImageTypeString(typeStr2, sizeof(typeStr2), img->type, TRUE);
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
67
1728
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
68 fprintf(fh,
1822
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
69 "%sType : %s [%s]\n"
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
70 "%sBanks : %d\n",
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
71 indent, typeStr, typeStr2,
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
72 indent, img->nbanks);
1728
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
73
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
74 if (img->type & D64_FMT_ILACE)
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
75 {
1728
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
76 char *tmps;
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
77 switch (img->laceType)
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
78 {
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
79 case D64_ILACE_COLOR: tmps = "color"; break;
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
80 case D64_ILACE_RES: tmps = "resolution"; break;
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
81 default: tmps = "ERROR"; break;
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
82 }
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
83 fprintf(fh,
1822
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
84 "%sInterlace type : %s\n",
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
85 indent, tmps);
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
86 }
1728
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
87
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
88 fprintf(fh,
1822
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
89 "%sWidth x Height : %d x %d [%d x %d]\n"
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
90 "%sCHwidth x CHheight : %d x %d [%d x %d]\n",
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
91 indent, img->width, img->height,
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
92 fmt->format->width, fmt->format->height,
1822
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
93 indent, img->chWidth, img->chHeight,
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
94 fmt->format->chWidth, fmt->format->chHeight);
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
95 }
1728
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
96 else
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
97 {
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
98 fprintf(fh,
1822
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
99 "%sType : %s\n"
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
100 "%sWidth x Height : %d x %d\n"
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
101 "%sCHwidth x CHheight : %d x %d\n",
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
102 indent, typeStr,
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
103 indent, fmt->format->width, fmt->format->height,
9bec535956fd Add indentation parameter to dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1821
diff changeset
104 indent, fmt->format->chWidth, fmt->format->chHeight);
1728
80adcda72210 Allow image pointer argument to be NULL for dmC64ImageDump().
Matti Hamalainen <ccr@tnsp.org>
parents: 1727
diff changeset
105 }
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
106 }
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
107
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1487
diff changeset
108
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
109 void dmSetDefaultC64Palette(DMImage *img)
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
110 {
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
111 img->constpal = TRUE;
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
112 img->pal = dmDefaultC64Palette;
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
113 img->ncolors = C64_NCOLORS;
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
114 img->ctransp = 255;
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
115 }
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
116
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
117
1732
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
118 BOOL dmSetMixedColorC64Palette(DMImage *img)
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
119 {
1735
eeb6a82b4654 Oops, left in wrong variable name. :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1732
diff changeset
120 if (!dmImagePaletteAlloc(img, C64_NCOLORS * C64_NCOLORS, -1))
1732
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
121 return FALSE;
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
122
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
123 int n = 0;
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
124 for (int n1 = 0; n1 < C64_NCOLORS; n1++)
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
125 {
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
126 const DMColor *col1 = &dmDefaultC64Palette[n1];
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
127 for (int n2 = 0; n2 < C64_NCOLORS; n2++)
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
128 {
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
129 const DMColor *col2 = &dmDefaultC64Palette[n2];
1735
eeb6a82b4654 Oops, left in wrong variable name. :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1732
diff changeset
130 img->pal[n].r = (col1->r + col2->r) / 2;
eeb6a82b4654 Oops, left in wrong variable name. :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1732
diff changeset
131 img->pal[n].g = (col1->g + col2->g) / 2;
eeb6a82b4654 Oops, left in wrong variable name. :S
Matti Hamalainen <ccr@tnsp.org>
parents: 1732
diff changeset
132 img->pal[n].b = (col1->b + col2->b) / 2;
1732
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
133 n++;
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
134 }
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
135 }
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
136
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
137 return TRUE;
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
138 }
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
139
07111a60cd4e Add dmSetMixedColorC64Palette() for setting a 256 entry "mixed color"
Matti Hamalainen <ccr@tnsp.org>
parents: 1731
diff changeset
140
1780
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
141 BOOL dmCompareAddr16(const DMGrowBuf *buf, const size_t offs, const Uint16 addr)
1381
b6782b785457 Move things around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
142 {
1780
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
143 return
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
144 offs + 1 < buf->len &&
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
145 buf->data[offs ] == DM_GET_ADDR_LO(addr) &&
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
146 buf->data[offs + 1] == DM_GET_ADDR_HI(addr);
1381
b6782b785457 Move things around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
147 }
b6782b785457 Move things around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
148
b6782b785457 Move things around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
149
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
150 int dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt)
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
151 {
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
152 int nbanks = 0;
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
153 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
154 {
1591
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
155 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
156 if (op->type == DO_LAST)
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
157 break;
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
158
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
159 if (op->bank > nbanks)
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
160 nbanks = op->bank;
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
161 }
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
162
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
163 return nbanks + 1;
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
164 }
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
165
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
166
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
167 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
168 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
169 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
170 return DMERR_MALLOC;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
171
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
172 blk->size = size;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
173 return DMERR_OK;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
174 }
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
175
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
176
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
177 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
178 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
179 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
180 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
181 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
182 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
183 return DMERR_MALLOC;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
184
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
185 memcpy(dst->data, src->data, src->size);
1824
adf9f05c26e1 Improve error handling of dmC64MemBlockCopy().
Matti Hamalainen <ccr@tnsp.org>
parents: 1822
diff changeset
186 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
187 }
1824
adf9f05c26e1 Improve error handling of dmC64MemBlockCopy().
Matti Hamalainen <ccr@tnsp.org>
parents: 1822
diff changeset
188 else
adf9f05c26e1 Improve error handling of dmC64MemBlockCopy().
Matti Hamalainen <ccr@tnsp.org>
parents: 1822
diff changeset
189 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
190 }
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
191
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
192
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
193 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
194 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
195 if (blk != NULL)
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
196 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
197 dmFreeR(&blk->data);
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
198 blk->size = 0;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
199 }
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
200 }
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
201
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
202
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
203 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
204 {
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
205 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
206
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
207 if (img == NULL)
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
208 return NULL;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
209
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
210 // Initialize image information
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
211 img->type = fmt->format->type;
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
212 img->width = fmt->format->width;
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
213 img->height = fmt->format->height;
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
214 img->chWidth = fmt->format->chWidth;
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
215 img->chHeight = fmt->format->chHeight;
1491
b329fea6f013 Reindent polishing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1489
diff changeset
216 img->nbanks = dmC64ImageGetNumBanks(fmt);
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
217
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
218 // Allocate banks
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
219 if ((img->color = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL ||
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
220 (img->bitmap = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL ||
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
221 (img->screen = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL ||
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
222 (img->charData = dmCalloc(img->nbanks, sizeof(DMC64MemBlock))) == NULL)
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
223 goto err;
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
224
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
225 return img;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
226
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
227 err:
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
228 dmC64ImageFree(img);
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
229 return NULL;
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
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
232
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
233 void dmC64ImageFree(DMC64Image *img)
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
234 {
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
235 if (img != NULL)
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
236 {
1462
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
237 // Free the allocated areas
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
238 for (int i = 0; i < img->nbanks; i++)
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
239 {
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
240 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
241 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
242 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
243 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
244 }
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
245
1462
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
246 // 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
247 dmFree(img->color);
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
248 dmFree(img->bitmap);
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
249 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
250 dmFree(img->charData);
1462
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
251
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
252 // Extra data ..
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
253 for (int i = 0; i < C64_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
254 dmC64MemBlockFree(&img->extraData[i]);
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
255
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1134
diff changeset
256 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
257 dmFree(img);
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
258 }
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
259 }
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
260
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
261
827
c8beac5313c3 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
262 int dmC64ConvertCSDataToImage(DMImage *img,
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
263 int xoffs, int yoffs, const Uint8 *buf,
915
ba6b210c9bf4 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
264 int width, int height, BOOL multicolor,
ba6b210c9bf4 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
265 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
266 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 int yc, widthpx = width * 8;
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
268 Uint8 *dp;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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 if (img == NULL)
517
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
271 return DMERR_NULLPTR;
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
272
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
273 if (xoffs < 0 || yoffs < 0 ||
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
274 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
275 yoffs > img->height - height)
517
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
276 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
277
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278 dp = img->data + (yoffs * img->pitch) + xoffs;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 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
281 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 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
283 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 const int offs = yc * width;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 int xc;
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
286 Uint8 *d = dp;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
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 for (xc = 0; xc < widthpx / 2; xc++)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 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
291 const int v = 6 - ((xc * 2) & 6);
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
292 const Uint8 c = colors[(b >> v) & 3];
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
293
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294 *d++ = c;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 *d++ = c;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 dp += img->pitch;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 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
304 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 const int offs = yc * width;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306 int xc;
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
307 Uint8 *d = dp;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 for (xc = 0; xc < widthpx; xc++)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 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
312 const int v = 7 - (xc & 7);
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
313 const Uint8 c = colors[(b >> v) & 1];
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
314
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 *d++ = c;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 dp += img->pitch;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 }
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
321
517
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
322 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
323 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
326 void dmGenericRLEAnalyze(const DMGrowBuf *buf, DMCompParams *cfg)
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
327 {
1542
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
328 #define DM_STAT_MAX 256
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
329 size_t *stats;
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
330
1542
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
331 // Allocate statistics counts buffer
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
332 if ((stats = dmMalloc0(DM_STAT_MAX * sizeof(size_t))) == NULL)
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
333 return;
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
334
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
335 // 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
336 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
337 stats[buf->data[offs]]++;
1542
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
338
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
339 // 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
340 switch (cfg->type)
1542
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
341 {
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
342 case DM_COMP_RLE_MARKER:
1542
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
343 {
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
344 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
345 smallest = buf->len;
1542
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
346
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
347 // 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
348 for (size_t n = 0; n < DM_STAT_MAX; n++)
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
349 {
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
350 if (stats[n] < smallest)
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
351 {
1821
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
352 switch (cfg->flags & DM_RLE_RUNS_MASK)
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
353 {
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
354 case DM_RLE_BYTE_RUNS | DM_RLE_WORD_RUNS:
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
355 cfg->rleMarkerW = selected;
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
356 cfg->rleMarkerB = selected = n;
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
357 break;
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
358
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
359 case DM_RLE_BYTE_RUNS:
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
360 cfg->rleMarkerB = selected = n;
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
361 break;
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
362
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
363 case DM_RLE_WORD_RUNS:
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
364 cfg->rleMarkerW = selected = n;
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
365 break;
ee2383d1a21e Improve dmGenericRLEAnalyze() by being better at selecting rleMarker bytes
Matti Hamalainen <ccr@tnsp.org>
parents: 1820
diff changeset
366 }
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
367 smallest = stats[n];
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
368 }
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
369 }
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
370 }
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
371 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
372
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
373 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
374 cfg->rleMarkerMask = 0xC0;
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
375 cfg->rleMarkerBits = 0xC0;
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
376 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
377 break;
1542
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
378 }
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
379
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
380 dmFree(stats);
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
381 }
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
382
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
383
1713
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
384 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
385 {
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
386 if (cfg->flags & DM_RLE_BACKWARDS_INPUT)
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
387 {
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
388 src->offs = src->len - 1;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
389 src->backwards = TRUE;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
390 }
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
391
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
392 if (cfg->flags & DM_RLE_BACKWARDS_OUTPUT)
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
393 {
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
394 dst->backwards = TRUE;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
395 dst->offs = dst->size - 1;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
396 }
1718
bed88d17f28c Fix a commit blunder here ..
Matti Hamalainen <ccr@tnsp.org>
parents: 1717
diff changeset
397 }
bed88d17f28c Fix a commit blunder here ..
Matti Hamalainen <ccr@tnsp.org>
parents: 1717
diff changeset
398
bed88d17f28c Fix a commit blunder here ..
Matti Hamalainen <ccr@tnsp.org>
parents: 1717
diff changeset
399
1713
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
400 void dmFinishRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg)
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
401 {
1741
6f1313c761aa Actually fix the warnings .. sigh.
Matti Hamalainen <ccr@tnsp.org>
parents: 1740
diff changeset
402 (void) src;
6f1313c761aa Actually fix the warnings .. sigh.
Matti Hamalainen <ccr@tnsp.org>
parents: 1740
diff changeset
403
1713
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
404 if (cfg->flags & DM_RLE_BACKWARDS_OUTPUT)
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
405 {
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
406 memmove(dst->data, dst->data + dst->offs, dst->len);
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
407 dst->offs = 0;
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
408 }
1720
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
409
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
410 switch (cfg->flags & DM_OUT_CROP_MASK)
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
411 {
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
412 case DM_OUT_CROP_END:
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
413 if (cfg->cropOutLen < dst->len)
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
414 {
1790
523c1d1270d6 Fix output buffer cropping in dmFinishRLEBuffers() for DM_OUT_CROP_END case.
Matti Hamalainen <ccr@tnsp.org>
parents: 1783
diff changeset
415 memmove(dst->data, dst->data + dst->len - cfg->cropOutLen + 1, cfg->cropOutLen - 1);
1720
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
416 dst->len = cfg->cropOutLen;
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
417 }
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
418 break;
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
419
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
420 case DM_OUT_CROP_START:
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
421 if (cfg->cropOutLen <= dst->len)
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
422 dst->len = cfg->cropOutLen;
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
423 break;
77a4d8fab5cc Add output buffer cropping to dmFinishRLEBuffers() and the flags and fields to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1718
diff changeset
424 }
1713
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
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
427
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
428 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
429 {
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
430 unsigned int scount;
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
431 for (scount = count; scount; scount--)
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
432 {
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
433 if (!dmGrowBufPutU8(dst, data))
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
434 {
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
435 return dmError(DMERR_MALLOC,
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
436 "%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
437 "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
438 cfg->func, count, data, dst->offs, dst->size);
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
439 }
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
440 }
0a9110b4d036 Add few RLE helper functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1710
diff changeset
441 return DMERR_OK;
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
442 }
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
443
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
444
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
445 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
446 {
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
447 int res;
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
448 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
449 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
450
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
451 // 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
452 // 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
453 dmGrowBufConstCopy(&src, psrc);
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
454 dmSetupRLEBuffers(dst, &src, cfg);
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
455
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
456 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
457 {
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
458 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
459
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
460 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
461 {
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
462 // A simple marker byte RLE variant: [Marker] [count] [data]
1744
e40227e994e2 Fix unitialized data accesses.
Matti Hamalainen <ccr@tnsp.org>
parents: 1741
diff changeset
463 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
464 {
1750
b9f3c1796fba More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1747
diff changeset
465 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
466 {
1727
8eb5ff34864a Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1726
diff changeset
467 res = dmError(DMERR_INVALID_DATA,
1750
b9f3c1796fba More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1747
diff changeset
468 "%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
469 cfg->func);
b9f3c1796fba More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1747
diff changeset
470 goto out;
b9f3c1796fba More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1747
diff changeset
471 }
b9f3c1796fba More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1747
diff changeset
472 if (!dmGrowBufGetU8(&src, &tmp2))
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 res = dmError(DMERR_INVALID_DATA,
b9f3c1796fba More granular error handling in RLE decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1747
diff changeset
475 "%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
476 cfg->func);
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
477 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
478 }
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
479 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
480 {
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
481 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
482 count = tmp1;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
483 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
484 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
485
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
486 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
487 data = tmp1;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
488 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
489 break;
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
490 }
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
491
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
492 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
493 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
494 }
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
495 else
1744
e40227e994e2 Fix unitialized data accesses.
Matti Hamalainen <ccr@tnsp.org>
parents: 1741
diff changeset
496 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
497 {
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
498 if (!dmGrowBufGetU8(&src, &tmp1) ||
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
499 !dmGrowBufGetU8(&src, &tmp2) ||
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
500 !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
501 {
1727
8eb5ff34864a Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1726
diff changeset
502 res = dmError(DMERR_INVALID_DATA,
8eb5ff34864a Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1726
diff changeset
503 "%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
504 cfg->func);
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
505 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
506 }
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
507 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
508 {
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
509 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
510 count = (tmp2 << 8) | tmp1;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
511 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
512 break;
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
513
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
514 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
515 data = tmp1;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
516 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
517 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
518 }
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
519
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
520 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
521 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
522 }
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
523 }
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 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
525 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
526 {
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
527 // 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
528 // 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
529 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
530 {
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
531 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
532 {
1727
8eb5ff34864a Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1726
diff changeset
533 res = dmError(DMERR_INVALID_DATA,
8eb5ff34864a Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1726
diff changeset
534 "%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
535 cfg->func);
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
536 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
537 }
1466
bc75be0546fc More work on RLE decoder/encoder changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
538
1660
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
539 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
540 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
541 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
542 }
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
543
1715
c0c6fd8b288a Use dmGenericRLEOutputRun().
Matti Hamalainen <ccr@tnsp.org>
parents: 1713
diff changeset
544 if ((res = dmGenericRLEOutputRun(dst, cfg, data, count)) != DMERR_OK)
c0c6fd8b288a Use dmGenericRLEOutputRun().
Matti Hamalainen <ccr@tnsp.org>
parents: 1713
diff changeset
545 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
546 }
523
d0c0c6baeb57 Split the RLE decoding from DrazPaint/Lace and Amica paint decoders to a
Matti Hamalainen <ccr@tnsp.org>
parents: 519
diff changeset
547
1717
7de37c01dbd4 Use dmFinishRLEBuffers() in dmDecodeGenericRLE()
Matti Hamalainen <ccr@tnsp.org>
parents: 1716
diff changeset
548 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
549 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
550
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
551 out:
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
552 return res;
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
553 }
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
554
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
555
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
556 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
557 {
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
558 int res;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
559 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
560 return res;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
561
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
562 return dmDecodeGenericRLE(dst, src, cfg);
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
563 }
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
564
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
565
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
566 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
567 {
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
568 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
569 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
570
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
571 switch (cfg->type)
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
572 {
1650
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
573 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
574 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
575 (count >= cfg->rleMinCountW || data == cfg->rleMarkerW))
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
576 {
1818
7bafe5f0998d Implement DM_RLE_ZERO_COUNT_MAX support in the generic RLE compressor.
Matti Hamalainen <ccr@tnsp.org>
parents: 1814
diff changeset
577 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
578 count = 0;
7bafe5f0998d Implement DM_RLE_ZERO_COUNT_MAX support in the generic RLE compressor.
Matti Hamalainen <ccr@tnsp.org>
parents: 1814
diff changeset
579
1660
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
580 if (!dmGrowBufPutU8(dst, cfg->rleMarkerW))
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
581 goto err;
1660
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
582
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
583 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
584 {
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
585 case DM_RLE_ORDER_1:
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
586 if (!dmGrowBufPutU16LE(dst, count) ||
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
587 !dmGrowBufPutU8(dst, data))
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
588 goto err;
1660
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
589 break;
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
590
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
591 case DM_RLE_ORDER_2:
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
592 if (!dmGrowBufPutU8(dst, data) ||
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
593 !dmGrowBufPutU16LE(dst, count))
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
594 goto err;
1660
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
595 break;
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
596 }
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 else
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
599 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
600 (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
601 {
1818
7bafe5f0998d Implement DM_RLE_ZERO_COUNT_MAX support in the generic RLE compressor.
Matti Hamalainen <ccr@tnsp.org>
parents: 1814
diff changeset
602 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
603 count = 0;
7bafe5f0998d Implement DM_RLE_ZERO_COUNT_MAX support in the generic RLE compressor.
Matti Hamalainen <ccr@tnsp.org>
parents: 1814
diff changeset
604
1660
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
605 if (!dmGrowBufPutU8(dst, cfg->rleMarkerB))
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
606 goto err;
1573
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
607
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
608 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
609 {
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
610 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
611 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
612 !dmGrowBufPutU8(dst, data))
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
613 goto err;
1573
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
614 break;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
615
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
616 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
617 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
618 !dmGrowBufPutU8(dst, count))
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
619 goto err;
1573
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
620 break;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
621 }
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
622 }
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
623 else
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
624 copyOnly = TRUE;
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
625 break;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
626
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
627 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
628 if (count >= cfg->rleMinCountB || (data & cfg->rleMarkerMask) == cfg->rleMarkerBits)
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
629 {
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
630 // Mask marker RLE: usually high bit(s) of byte mark RLE sequence
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
631 // 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
632 if (!dmGrowBufPutU8(dst, cfg->rleMarkerBits | count) ||
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
633 !dmGrowBufPutU8(dst, data))
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
634 goto err;
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
635 }
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
636 else
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
637 copyOnly = TRUE;
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
638 break;
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
639 }
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
640
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
641 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
642 return res;
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
643
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
644 return DMERR_OK;
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
645
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
646 err:
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
647 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
648 "%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
649 cfg->func, count, data);
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
650 }
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
651
1466
bc75be0546fc More work on RLE decoder/encoder changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
652
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
653 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
654 {
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
655 DMGrowBuf src;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
656 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
657 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
658 Uint8 data;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
659
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
660 // 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
661 // 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
662 dmGrowBufConstCopy(&src, psrc);
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
663 dmSetupRLEBuffers(dst, &src, cfg);
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
664
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
665 while (dmGrowBufGetU8(&src, &data))
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
666 {
1660
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
667 // 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
668 // for the active runs mode(s) .. then encode the run.
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
669 if (data != prev ||
7555c8803529 More work on improving the generic RLE decoder/encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1650
diff changeset
670 ((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
671 (((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
672 {
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
673 if ((res = dmEncodeGenericRLESequence(dst, prev, count, cfg)) != DMERR_OK)
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
674 goto err;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
675
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
676 count = 1;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
677 }
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
678 else
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
679 count++;
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
680
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
681 prev = data;
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
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
684 // 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
685 if ((res = dmEncodeGenericRLESequence(dst, prev, count, cfg)) != DMERR_OK)
1518
24b8b452925e Improve error handling of RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1513
diff changeset
686 goto err;
24b8b452925e Improve error handling of RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1513
diff changeset
687
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
688 dmFinishRLEBuffers(dst, &src, cfg);
1478
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 err:
1716
9731b0bdec64 Improve error handling of dmEncodeGenericRLESequence() and use dmGenericRLEOutputRun() here as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1715
diff changeset
691 return res;
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
692 }
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
693
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
694
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
695 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
696 {
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
697 int res;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
698 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
699 return res;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
700
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
701 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
702 }
d0c0c6baeb57 Split the RLE decoding from DrazPaint/Lace and Amica paint decoders to a
Matti Hamalainen <ccr@tnsp.org>
parents: 519
diff changeset
703
519
feaaf0e2ecbe Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
704
1537
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1534
diff changeset
705 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
706 {
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
707 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
708 {
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
709 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
710 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
711 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
712 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
713 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
714 switch (op->subject)
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
715 {
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
716 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
717 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
718 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
719 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
720 if (op->bank < 0 || op->bank > img->nbanks)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
721 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
722 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
723 "Invalid bank %d / %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
724 op->bank, img->nbanks, 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
725 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
726 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
727
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
728 case DS_EXTRA_DATA:
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
729 if (op->bank < 0 || op->bank >= C64_MAX_EXTRA_DATA)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
730 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
731 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
732 "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
733 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
734 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
735 break;
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
736 }
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
737 break;
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
738
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
739 // Just list the allowed ops here
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
740 case DO_DEC_FUNC:
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
741 case DO_ENC_FUNC:
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
742 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
743 case DO_LAST:
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
744 break;
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
745
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
746 default:
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
747 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
748 "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
749 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
750 break;
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
751 }
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
752
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
753 return DMERR_OK;
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
754 }
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
755
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
756
1537
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1534
diff changeset
757 BOOL dmC64GetOpSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt, size_t *size)
927
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
758 {
1725
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
759 switch (op->subject)
927
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
760 {
1725
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
761 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
762 case DS_COLOR_RAM:
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
763 *size = fmt->format->chHeight * fmt->format->chWidth;
1725
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
764 break;
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
765
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
766 case DS_BITMAP_RAM:
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
767 *size = fmt->format->chHeight * fmt->format->chWidth * 8;
1725
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
768 break;
927
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
769
1725
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
770 case DS_CHAR_DATA:
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
771 *size = C64_MAX_CHARS * C64_CHR_SIZE;
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
772 break;
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_D020:
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_BGCOL:
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
776 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
777 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
778 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
779 case DS_D024:
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
780 *size = 1;
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
781 break;
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
782
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
783 default:
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
784 // Default to size of 0
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
785 *size = 0;
40a5ba0b3838 Return size of subject in dmC64GetOpSize() despite what the operator type is.
Matti Hamalainen <ccr@tnsp.org>
parents: 1722
diff changeset
786 break;
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
787 }
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
788
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
789 // If the operator specified size is larger, use it.
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
790 if (op->size > *size)
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
791 *size = op->size;
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
792
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
793 return TRUE;
927
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
794 }
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
795
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
796
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
797 void dmC64GetOpMemBlockAndName(const DMC64Image *img, const int subject, const int bank, const DMC64MemBlock **blk, char **blkname)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
798 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
799 switch (subject)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
800 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
801 case DS_COLOR_RAM : *blk = &img->color[bank]; *blkname = "Color RAM"; break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
802 case DS_SCREEN_RAM : *blk = &img->screen[bank]; *blkname = "Screen RAM"; break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
803 case DS_BITMAP_RAM : *blk = &img->bitmap[bank]; *blkname = "Bitmap RAM"; break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
804 case DS_CHAR_DATA : *blk = &img->charData[bank]; *blkname = "Character data"; break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
805 case DS_EXTRA_DATA : *blk = &img->extraData[bank]; *blkname = "Extra data"; break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
806 default: *blk = NULL; *blkname = NULL; break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
807 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
808 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
809
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
810
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
811 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
812 {
1460
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
813 int res = DMERR_OK;
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
814
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
815 if (buf == NULL || buf->data == NULL || img == NULL || fmt == NULL)
513
486067f39bc1 Add sanity checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
816 return DMERR_NULLPTR;
486067f39bc1 Add sanity checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
817
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
818 // Clear the image structure, set basics
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
819 img->type = fmt->format->type;
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
820 img->width = fmt->format->width;
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
821 img->height = fmt->format->height;
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
822 img->chWidth = fmt->format->chWidth;
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
823 img->chHeight = fmt->format->chHeight;
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
824 img->nbanks = dmC64ImageGetNumBanks(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
825
518
63849f85db57 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 517
diff changeset
826 // Perform decoding
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
827 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
828 {
1591
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
829 const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i);
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
830 const Uint8 *src;
1600
e28e67358ff6 Fix some uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1597
diff changeset
831 DMC64MemBlock *blk = NULL;
e28e67358ff6 Fix some uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1597
diff changeset
832 char *blkname = NULL;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
833 size_t size;
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
834 Uint8 value;
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
835
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
836 // Check for last operator
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
837 if (op->type == DO_LAST)
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
838 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
839
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
840 // Check operation validity
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
841 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK)
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
842 return res;
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
843
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
844 // Check size
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
845 if (!dmC64GetOpSize(op, fmt, &size))
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
846 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
847 return dmError(DMERR_INVALID_DATA,
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
848 "Decode op SIZE out of bounds, op #%d type=%d, subj=%d, offs=%d ($%04x), "
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
849 "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n",
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
850 i, op->type, op->subject, op->offs, op->offs, op->bank, size, size, op->size, op->size);
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
851 }
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
852
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
853 // Is the operation inside the bounds?
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
854 if (op->offs + size > buf->len + 1)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
855 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
856 return dmError(DMERR_INVALID_DATA,
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
857 "Decode DATA out of bounds, op #%d type=%d, subj=%d, offs=%d ($%04x), "
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
858 "bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
859 i, op->type, op->subject, op->offs, op->offs, op->bank,
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
860 size, size, buf->len, buf->len);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
861 }
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
862
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
863 src = buf->data + op->offs;
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
864
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
865 // Perform operation
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
866 switch (op->type)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
867 {
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
868 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
869 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
870 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
871 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
872 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
873 switch (op->subject)
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
874 {
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
875 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
876 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
877 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
878 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
879 case DS_EXTRA_DATA:
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
880 // XXX BZZZT .. a nasty cast here --v
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
881 dmC64GetOpMemBlockAndName(img, op->subject, op->bank, (const DMC64MemBlock **) &blk, &blkname);
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
882 if ((dmC64MemBlockAlloc(blk, size)) != DMERR_OK)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
883 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
884 return dmError(DMERR_MALLOC,
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
885 "Could not allocate '%s' block! "
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
886 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
887 blkname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
888 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
889 switch (op->type)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
890 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
891 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
892 memcpy(blk->data, src, size);
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
893 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
894
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
895 case DO_SET_MEM:
1814
0b7062d874ef Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1801
diff changeset
896 dmMemset(blk->data, *src, size);
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
897 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
898
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
899 case DO_SET_OP:
1814
0b7062d874ef Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1801
diff changeset
900 dmMemset(blk->data, op->offs, size);
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
901 break;
1727
8eb5ff34864a Improve error messages in the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1726
diff changeset
902
1721
c9a6f1dae756 Add one default case error handler.
Matti Hamalainen <ccr@tnsp.org>
parents: 1720
diff changeset
903 default:
c9a6f1dae756 Add one default case error handler.
Matti Hamalainen <ccr@tnsp.org>
parents: 1720
diff changeset
904 return dmError(DMERR_INTERNAL,
c9a6f1dae756 Add one default case error handler.
Matti Hamalainen <ccr@tnsp.org>
parents: 1720
diff changeset
905 "Unhandled op type %d in "
c9a6f1dae756 Add one default case error handler.
Matti Hamalainen <ccr@tnsp.org>
parents: 1720
diff changeset
906 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
c9a6f1dae756 Add one default case error handler.
Matti Hamalainen <ccr@tnsp.org>
parents: 1720
diff changeset
907 op->type, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
908 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
909 break;
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
910
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
911 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
912 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
913 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
914 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
915 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
916 case DS_D024:
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
917 switch (op->type)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
918 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
919 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
920 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
921 value = *src;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
922 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
923
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
924 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
925 value = op->offs;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
926 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
927
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
928 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
929 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
930 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
931
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
932 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
933 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
934 break;
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
935 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
936 switch (op->subject)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
937 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
938 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
939 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
940 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
941 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
942 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
943 case DS_D024: img->d024 = value; break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
944 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
945 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
946
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
947 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
948 return dmError(DMERR_INTERNAL,
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
949 "Unhandled subject %d in "
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
950 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
951 op->subject, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
952 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
953 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
954
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
955 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
956 switch (op->subject)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
957 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
958 case D64_CHCFG_SCREEN:
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
959 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
960
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
961 case D64_CHCFG_LINEAR:
1672
09adf5328510 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1668
diff changeset
962 for (int bank = 0; bank < img->nbanks; bank++)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
963 {
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
964 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
965 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
966 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
967 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
968
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
969 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
970 return dmError(DMERR_INTERNAL,
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
971 "Unhandled DO_CHAR_CFG mode %d in ",
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
972 "op #%d, bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
973 op->subject, i, op->bank, size, size, buf->len, buf->len);
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
974 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
975 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
976
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
977 case DO_DEC_FUNC:
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
978 if (op->decFunction == NULL)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
979 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
980 return dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
981 "Decode op is a function, but function ptr is NULL: "
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
982 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
983 i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
984 }
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
985 if (!op->decFunction(img, op, buf, 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
986 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
987 return dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
988 "Decode op custom function failed: op #%d, "
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
989 "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
990 i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
991 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
992 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
993 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
994 }
916
3985f596ece5 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 915
diff changeset
995
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
996 // Sanity check certain things ..
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
997 if ((fmt->format->type & D64_FMT_ILACE) && img->laceType == D64_ILACE_NONE)
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
998 {
948d6fda722d Add sanity check for interlaced formats: check that the interlace type flags are set.
Matti Hamalainen <ccr@tnsp.org>
parents: 1645
diff changeset
999 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
1000 "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
1001 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
1002 }
948d6fda722d Add sanity check for interlaced formats: check that the interlace type flags are set.
Matti Hamalainen <ccr@tnsp.org>
parents: 1645
diff changeset
1003
508
1ed5025c2538 Return DMLIB error values instead of arbitrary 0/negatives.
Matti Hamalainen <ccr@tnsp.org>
parents: 507
diff changeset
1004 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
1005 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1006
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1007
1499
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1008 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
1009 {
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
1010 int res = DMERR_OK;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1011
1469
0046b4e1b35f Various fixes in bmp encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1467
diff changeset
1012 if (img == NULL || fmt == NULL)
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1013 return DMERR_NULLPTR;
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1014
1499
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1015 // Allocate the output buffer if requested
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1016 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
1017 {
1472
b9d3577d8290 Improve error handling and checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 1471
diff changeset
1018 dmError(res,
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
1019 "Could not allocate %d bytes of memory for C64 image encoding buffer.\n",
1465
88845f95e791 Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1463
diff changeset
1020 fmt->size);
1447
de5f7e31a8bf Rename labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 1443
diff changeset
1021 goto err;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1022 }
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1023
1697
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1672
diff changeset
1024 if (buf->backwards)
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1672
diff changeset
1025 {
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1672
diff changeset
1026 dmError(DMERR_INVALID_DATA,
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1672
diff changeset
1027 "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
1028 goto err;
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1672
diff changeset
1029 }
1506
4fd4e7a00db4 Fix handling of predefined DMGrowBuffer in dmC64EncodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents: 1505
diff changeset
1030
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1031 // Perform encoding
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
1032 for (int i = 0; i < D64_MAX_ENCDEC_OPS; i++)
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1033 {
1591
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
1034 const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i);
1364
0d61895e1763 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1362
diff changeset
1035 size_t size, chksize;
1600
e28e67358ff6 Fix some uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1597
diff changeset
1036 const DMC64MemBlock *blk = NULL;
e28e67358ff6 Fix some uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1597
diff changeset
1037 char *blkname = NULL;
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1038 Uint8 value;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1039
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
1040 // Check for last operator
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1041 if (op->type == DO_LAST)
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
1042 break;
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
1043
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
1044 // Check operation validity
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
1045 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK)
1447
de5f7e31a8bf Rename labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 1443
diff changeset
1046 goto err;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1047
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
1048 // Check size
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1049 if (!dmC64GetOpSize(op, fmt, &size))
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1050 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
1051 res = dmError(DMERR_INVALID_DATA,
1511
62ede0de6ab0 Fix an error message, should be "Encode", not "Decode".
Matti Hamalainen <ccr@tnsp.org>
parents: 1510
diff changeset
1052 "Encode op SIZE out of bounds, op #%d type=%d, offs=%d ($%04x), "
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1053 "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n",
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1054 i, op->type, op->offs, op->offs, op->bank, size, size, buf->size, buf->size);
1447
de5f7e31a8bf Rename labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 1443
diff changeset
1055 goto err;
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1056 }
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1057
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
1058 // Do we need to reallocate some more space?
1697
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1672
diff changeset
1059 chksize = buf->offs + op->offs + size;
1465
88845f95e791 Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1463
diff changeset
1060 if (!dmGrowBufCheckGrow(buf, chksize))
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1061 {
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
1062 res = dmError(DMERR_MALLOC,
88845f95e791 Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1463
diff changeset
1063 "Could not re-allocate %d bytes of memory for C64 image encoding buffer.\n",
88845f95e791 Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1463
diff changeset
1064 chksize);
88845f95e791 Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1463
diff changeset
1065 goto err;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1066 }
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1067
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
1068 // Perform operation
1697
1036b0dcccb5 Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents: 1672
diff changeset
1069 Uint8 *dst = buf->data + buf->offs + op->offs;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1070 switch (op->type)
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1071 {
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1072 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
1073 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
1074 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
1075 switch (op->subject)
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
1076 {
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1077 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
1078 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
1079 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
1080 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
1081 case DS_EXTRA_DATA:
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1082 dmC64GetOpMemBlockAndName(img, op->subject, op->bank, &blk, &blkname);
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1083 switch (op->type)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1084 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1085 case DO_COPY:
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1086 if (blk->data == NULL)
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1087 {
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1088 res = dmError(DMERR_NULLPTR,
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1089 "'%s' block is NULL in "
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1090 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1091 blkname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1092 goto err;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1093 }
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1094 if (size > blk->size)
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1095 {
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1096 res = dmError(DMERR_INTERNAL,
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1097 "'%s' size mismatch %d <> %d in "
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1098 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1099 blkname, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1100 goto err;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1101 }
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1102 memcpy(dst, blk->data, size);
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1103 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1104
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1105 case DO_SET_MEM:
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1106 // This operation makes no sense, so do nothing
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1107 break;
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1108
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1109 case DO_SET_OP:
1814
0b7062d874ef Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1801
diff changeset
1110 dmMemset(dst, op->offs, size);
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1111 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1112 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1113 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1114
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1115 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
1116 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
1117 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
1118 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
1119 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
1120 case DS_D024:
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1121 switch (op->subject)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1122 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1123 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
1124 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
1125 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
1126 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
1127 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
1128 case DS_D024: value = img->d024; break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1129 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1130 switch (op->type)
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1131 {
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1132 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
1133 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
1134 *dst = value;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1135 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1136
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
1137 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
1138 *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
1139 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
1140
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
1141 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
1142 *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
1143 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
1144
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1145 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
1146 // Do nothing in this case
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1147 break;
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1148 }
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1149 break;
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1150
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1151 default:
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1152 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
1153 "Unhandled subject %d in "
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
1154 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1155 op->subject, i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1156 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1157 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1158
1668
1741717b1ae5 Big overhaul to the enc/dec operator system to be more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1660
diff changeset
1159 case DO_ENC_FUNC:
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
1160 if (op->encFunction == NULL)
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
1161 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
1162 res = dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
1163 "Encode op is a function, but function ptr is NULL: "
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
1164 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\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
1165 i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);
1447
de5f7e31a8bf Rename labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 1443
diff changeset
1166 goto err;
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
1167 }
1486
bc13af8954d7 Add DMC64ImageFormat to C64 bitmap format encoding/decoding ops function parameters.
Matti Hamalainen <ccr@tnsp.org>
parents: 1485
diff changeset
1168 if (!op->encFunction(op, buf, img, fmt))
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
1169 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
1170 res = dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
1171 "Encode op custom function failed: op #%d, "
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
1172 "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1486
bc13af8954d7 Add DMC64ImageFormat to C64 bitmap format encoding/decoding ops function parameters.
Matti Hamalainen <ccr@tnsp.org>
parents: 1485
diff changeset
1173 i, op->offs, op->offs, op->bank, size, size, buf->len, buf->len);
bc13af8954d7 Add DMC64ImageFormat to C64 bitmap format encoding/decoding ops function parameters.
Matti Hamalainen <ccr@tnsp.org>
parents: 1485
diff changeset
1174 goto err;
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
1175 }
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1176 break;
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1177 }
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1178 }
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1179
1448
50402c225ef4 Do not insert load address to the buffer beginning in dmC64EncodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents: 1447
diff changeset
1180 res = DMERR_OK;
535
ab8d9696225c Add helper macros and use them to set the loading address while encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
1181
1447
de5f7e31a8bf Rename labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 1443
diff changeset
1182 err:
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1183 return res;
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1184 }
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1185
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
1186
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1187 // Convert a generic "C64" format bitmap in DMC64Image struct to
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1188 // a indexed/paletted bitmap image.
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
1189 int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, 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
1190 {
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
1191 DMC64GetPixelFunc getPixel;
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1192
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1193 // Sanity check arguments
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1194 if (dst == NULL || src == NULL)
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1195 return DMERR_NULLPTR;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1196
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1197 if (dst->width < src->width || dst->height < src->height)
1460
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
1198 {
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
1199 return dmError(DMERR_INVALID_DATA,
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
1200 "Invalid src vs. dst width/height %d x %d <-> %d x %d\n",
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
1201 src->width, src->height, dst->width, dst->height);
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
1202 }
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1203
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1134
diff changeset
1204 dmMemset(dst->data, 0, dst->size);
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1205
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
1206 // Check pixel getter function
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1207 if (fmt->format->getPixel != NULL)
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1208 getPixel = fmt->format->getPixel;
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
1209 else
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1210 getPixel = (fmt->format->type & D64_FMT_MC) ? fmtGetGenericMCPixel : fmtGetGenericSCPixel;
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
1211
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1212 // Resolution interlaced pics need to halve the source width
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1213 int rwidth = src->width;
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1214 if ((src->type & D64_FMT_ILACE) && src->laceType == D64_ILACE_RES)
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1215 rwidth /= 2;
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1216
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1217 // Perform conversion
1411
a9afb2ad39cb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1396
diff changeset
1218 Uint8 *dp = dst->data;
a9afb2ad39cb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1396
diff changeset
1219 for (int yc = 0; yc < src->height; yc++)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1220 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1221 Uint8 *d = dp;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1222 const int y = yc / 8, yb = yc & 7;
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
1223 const int scroffsy = y * src->chWidth;
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1224 int xc;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1225
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1226 if (src->type & D64_FMT_CHAR)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1227 {
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1228 // Charmode conversion
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1229 if ((src->type & D64_FMT_MC) == D64_FMT_HIRES)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1230 // Hi-res charmap
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1231 for (xc = 0; xc < rwidth; xc++)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1232 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1233 const int x = xc / 8;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1234 const int scroffs = scroffsy + x;
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
1235 const int chr = src->screen[0].data[scroffs];
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1236 const int v = 7 - (xc & 7);
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1237
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
1238 if ((src->charData[0].data[chr * C64_CHR_SIZE + yb] >> v) & 1)
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
1239 *d++ = src->color[0].data[scroffs];
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1240 else
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1241 *d++ = src->bgcolor;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1242 }
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1243 else
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1244 // Multicolor variants
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1245 for (xc = 0; xc < rwidth; xc++)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1246 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1247 const int x = xc / 4;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1248 const int scroffs = scroffsy + x;
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
1249 const int chr = src->screen[0].data[scroffs];
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
1250 const int col = src->color[0].data[scroffs] & 15;
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
1251
944
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1252 if (col & 8)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1253 {
944
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1254 const int v = 6 - ((xc * 2) & 6);
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
1255 switch ((src->charData[0].data[chr * C64_CHR_SIZE + yb] >> v) & 3)
944
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1256 {
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1257 case 0: *d++ = src->bgcolor; break;
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1258 case 1: *d++ = src->d022; break;
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1259 case 2: *d++ = src->d023; break;
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1260 case 3: *d++ = col;
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1261 }
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1262 }
944
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1263 else
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1264 {
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1265 const int v = 7 - (xc & 7);
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
1266 if ((src->charData[0].data[chr * C64_CHR_SIZE + yb] >> v) & 1)
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
1267 *d++ = src->color[0].data[scroffs];
944
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1268 else
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1269 *d++ = src->bgcolor;
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
1270 }
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1271 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
1272 }
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1273 else
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1274 {
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1275 // Perform generic BITMAP conversion
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
1276 const int bmoffsy = y * src->chWidth * 8 + yb;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1277
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1278 if ((src->type & D64_FMT_MC) == D64_FMT_HIRES)
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
1279 // Hi-res bitmap
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1280 for (xc = 0; xc < rwidth; xc++)
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1281 {
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1282 const int x = xc / 8;
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1283 const int scroffs = scroffsy + x;
940
ff18d2511843 Remove the doubleMC madness completely. Should be replaced with x/y aspect
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1284 const int bmoffs = bmoffsy + (x * 8);
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
1285 const int vshift = 7 - (xc & 7);
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1286
1764
52e31cfc1e36 Implement fake X raster position for the pixel getting functions. At some
Matti Hamalainen <ccr@tnsp.org>
parents: 1750
diff changeset
1287 *d++ = getPixel(src, bmoffs, scroffs, vshift, 0, xc, yc);
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1288 }
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1289 else
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1290 // Multicolor bitmap and variants
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1291 for (xc = 0; xc < rwidth; xc++)
529
1bce06b5026f Combine conversion of interlaced and normal multicolor images to one function.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
1292 {
901
f532262f90b1 Actually fix commit 16aa5955dfb5.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
1293 const int x = xc / 4;
f532262f90b1 Actually fix commit 16aa5955dfb5.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
1294 const int scroffs = scroffsy + x;
940
ff18d2511843 Remove the doubleMC madness completely. Should be replaced with x/y aspect
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1295 const int bmoffs = bmoffsy + (x * 8);
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
1296 const int vshift = 6 - ((xc * 2) & 6);
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1297
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1298 if (src->type & D64_FMT_ILACE)
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1299 {
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1300 switch (src->laceType)
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1301 {
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1302 case D64_ILACE_RES:
1764
52e31cfc1e36 Implement fake X raster position for the pixel getting functions. At some
Matti Hamalainen <ccr@tnsp.org>
parents: 1750
diff changeset
1303 *d++ = getPixel(src, bmoffs, scroffs, vshift, 0, xc, yc);
52e31cfc1e36 Implement fake X raster position for the pixel getting functions. At some
Matti Hamalainen <ccr@tnsp.org>
parents: 1750
diff changeset
1304 *d++ = getPixel(src, bmoffs, scroffs, vshift, 1, xc, yc);
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1305 break;
1366
d4387509a363 Return DMERR_NOT_SUPPORTED for decoding color-interlaced images, for now
Matti Hamalainen <ccr@tnsp.org>
parents: 1365
diff changeset
1306
d4387509a363 Return DMERR_NOT_SUPPORTED for decoding color-interlaced images, for now
Matti Hamalainen <ccr@tnsp.org>
parents: 1365
diff changeset
1307 default:
d4387509a363 Return DMERR_NOT_SUPPORTED for decoding color-interlaced images, for now
Matti Hamalainen <ccr@tnsp.org>
parents: 1365
diff changeset
1308 return DMERR_NOT_SUPPORTED;
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1309 }
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1310 }
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1311 else
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1312 {
1764
52e31cfc1e36 Implement fake X raster position for the pixel getting functions. At some
Matti Hamalainen <ccr@tnsp.org>
parents: 1750
diff changeset
1313 *d++ = getPixel(src, bmoffs, scroffs, vshift, 0, xc, yc);
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1314 }
529
1bce06b5026f Combine conversion of interlaced and normal multicolor images to one function.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
1315 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1316 }
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1317 dp += dst->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
1318 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1319
508
1ed5025c2538 Return DMLIB error values instead of arbitrary 0/negatives.
Matti Hamalainen <ccr@tnsp.org>
parents: 507
diff changeset
1320 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
1321 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1322
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1323
940
ff18d2511843 Remove the doubleMC madness completely. Should be replaced with x/y aspect
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1324 int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt)
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1325 {
940
ff18d2511843 Remove the doubleMC madness completely. Should be replaced with x/y aspect
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1326 int res;
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1327 DMImage *dst;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1328
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1329 if (pdst == NULL || src == NULL)
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1330 return DMERR_NULLPTR;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1331
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1332 // Allocate image structure
1801
0562dd55a1f6 s/DM_IFMT_/DM_COLFMT_/g
Matti Hamalainen <ccr@tnsp.org>
parents: 1799
diff changeset
1333 if ((*pdst = dst = dmImageAlloc(src->width, src->height, DM_COLFMT_PALETTE, -1)) == NULL)
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1334 return DMERR_MALLOC;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1335
1426
4c7b456d7f0b Rename global dmC64Palette to dmDefaultC64Palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 1425
diff changeset
1336 // Set partial palette information
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1337 dst->ncolors = C64_NCOLORS;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1338 dst->constpal = TRUE;
1730
881a3fc421d8 Use the default C64 palette whenever we need it, but make it possible to override it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1728
diff changeset
1339 dst->pal = dmDefaultC64Palette;
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1340
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1341 // Convert
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1342 if (fmt->format->convertFrom != NULL)
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1343 res = fmt->format->convertFrom(dst, src, fmt);
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1344 else
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
1345 res = dmC64ConvertGenericBMP2Image(dst, src, fmt);
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1346
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1347 return res;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1348 }
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1349
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1350
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1351 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
1352 const size_t probeOffs, const size_t loadOffs,
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 515
diff changeset
1353 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
1354 {
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1355 DMGrowBuf tmp;
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1356
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1357 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
1358 return DMERR_NULLPTR;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1359
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1360 // Check for forced format
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1361 if (forced != NULL)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1362 *fmt = forced;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1363 else
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1364 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1365 // 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
1366 if (probeOffs >= buf->len)
1460
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
1367 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
1368
1747
5e928618fdc8 Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 1744
diff changeset
1369 dmGrowBufConstCopyOffs(&tmp, buf, probeOffs);
1780
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
1370 if (dmC64ProbeBMP(&tmp, fmt) == DM_PROBE_SCORE_FALSE)
1460
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
1371 return DMERR_NOT_SUPPORTED;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1372 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1373
1710
1f0fac3af8e3 Use buf->len instead of tmp.len, as it might not be initialized.
Matti Hamalainen <ccr@tnsp.org>
parents: 1707
diff changeset
1374 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
1375 return DMERR_INVALID_ARGS;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1376
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1377 if (*fmt == NULL)
1548
20cd589366d7 Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1542
diff changeset
1378 return DMERR_NOT_SUPPORTED;
20cd589366d7 Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1542
diff changeset
1379
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1380 // Format supports only reading?
1548
20cd589366d7 Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1542
diff changeset
1381 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
1382 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
1383
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1384 // Allocate memory
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
1385 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
1386 return DMERR_MALLOC;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1387
1747
5e928618fdc8 Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents: 1744
diff changeset
1388 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
1389
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1390 // 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
1391 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
1392 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
1393 else
1707
a0986cfd6f9d More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents: 1697
diff changeset
1394 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
1395 }
1467
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1396
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1397
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1398 // Convert a generic bitmap image to DMC64Image
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1399 int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, 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
1400 {
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1401 if (dst == NULL || src == NULL || 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
1402 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
1403
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1404 return DMERR_OK;
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1405 }
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1406
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1407
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1408 int dmC64ConvertImage2BMP(DMC64Image **pdst, const DMImage *src, 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
1409 {
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1410 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
1411 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
1412
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1413 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
1414 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
1415
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1416 // 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
1417 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
1418 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
1419
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1420 // Convert
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1421 if (fmt->format->convertTo != NULL)
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1422 res = fmt->format->convertTo(dst, src, 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
1423 else
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1424 res = dmC64ConvertGenericImage2BMP(dst, src, fmt);
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1425
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1426 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
1427 }
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1428
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1429
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1430 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
1431 {
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1432 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
1433
1580
72f809e6eb3c Add NULL check for growbuf pointer.
Matti Hamalainen <ccr@tnsp.org>
parents: 1573
diff changeset
1434 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
1435 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
1436
1548
20cd589366d7 Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1542
diff changeset
1437 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
1438 return DMERR_NOT_SUPPORTED;
20cd589366d7 Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1542
diff changeset
1439
1499
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1440 // Allocate a buffer
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1441 if ((res = dmGrowBufAlloc(buf, BUF_SIZE_INITIAL, BUF_SIZE_GROW)) != DMERR_OK)
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1442 goto err;
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1443
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1444 // Add the loading address
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1445 if (!dmGrowBufPutU8(buf, DM_GET_ADDR_LO(fmt->addr)) ||
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1446 !dmGrowBufPutU8(buf, DM_GET_ADDR_HI(fmt->addr)))
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1447 goto err;
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1448
1467
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1449 // 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
1450 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
1451 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
1452 else
1499
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1453 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
1454
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1455 if (res != DMERR_OK)
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1456 goto err;
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1457
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
1458 // 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
1459 // 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
1460 // 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
1461 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
1462 !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
1463 {
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
1464 res = DMERR_MALLOC;
5204fab92c9e If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents: 1790
diff changeset
1465 goto err;
5204fab92c9e If the c64 image format has a set size and our buffer after encoding in
Matti Hamalainen <ccr@tnsp.org>
parents: 1790
diff changeset
1466 }
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
1467
1469
0046b4e1b35f Various fixes in bmp encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1467
diff changeset
1468 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
1469
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1470 err:
1799
708d333734f9 Comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 1797
diff changeset
1471 // 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
1472 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
1473 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
1474 }
1774
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1475
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1476
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1477 // 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
1478 // 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
1479 // "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
1480 // 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
1481 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
1482 {
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1483 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
1484
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1485 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
1486 {
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1487 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1488 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
1489 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
1490 {
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1491 // 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
1492 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
1493 score = DM_PROBE_SCORE_GOOD;
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1494 }
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1495 else
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1496 if (fmt->probe != NULL)
1780
5ea4713e9e0f Change c64 format probing API to use DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents: 1775
diff changeset
1497 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
1498
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1499 if (score > scoreMax)
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1500 {
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1501 scoreMax = score;
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1502 scoreIndex = i;
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1503 }
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1504 }
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1505
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1506 if (scoreIndex >= 0)
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1507 {
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1508 *pfmt = &dmC64ImageFormats[scoreIndex];
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1509 return scoreMax;
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1510 }
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1511 else
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1512 return DM_PROBE_SCORE_FALSE;
88354355b8e1 Move dmC64ProbeBMP() to more logical place in the source.
Matti Hamalainen <ccr@tnsp.org>
parents: 1764
diff changeset
1513 }
1775
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1514
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1515
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1516 void dmC64InitializeFormats(void)
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1517 {
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1518 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
1519 {
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1520 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
1521 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
1522 fmt->format = &fmt->formatDef;
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1523 }
4e4d54135baf Refactor the c64 bitmap format definitions handling to be more flexible. Again.
Matti Hamalainen <ccr@tnsp.org>
parents: 1774
diff changeset
1524 }