annotate tools/lib64gfx.c @ 1632:2a1866fd546e

Use C64 encdec operator specified size for the element if it is larger than the default size.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 25 May 2018 01:41:31 +0300
parents ed5ccf00b959
children 9d9a0e852b3d
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
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
15 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt)
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
16 {
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
17 char typeStr[64];
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
18
1494
3b220604ae3c Add short format attribute names to dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents: 1492
diff changeset
19 dmC64GetImageTypeString(typeStr, sizeof(typeStr), 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
20
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
21 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
22 {
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
23 fprintf(fh,
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
24 "Format : %s [%s]\n",
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
25 fmt->name, fmt->fext);
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
26 }
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
27
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
28 fprintf(fh,
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
29 "Type : %s\n"
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
30 "Banks : %d\n",
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
31 typeStr,
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
32 img->nbanks);
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
33
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
34 if (img->type & D64_FMT_ILACE)
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
35 {
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
36 char *tmps;
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
37 switch(img->laceType)
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
38 {
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
39 case D64_ILACE_COLOR: tmps = "color"; break;
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
40 case D64_ILACE_RES: tmps = "resolution"; break;
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
41 default: tmps = "ERROR"; break;
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
42 }
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
43 fprintf(fh,
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
44 "Interlace type : %s\n",
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
45 tmps);
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
46 }
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
47
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
48 fprintf(fh,
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
49 "Width x Height : %d x %d\n"
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
50 "CHwidth x CHheight : %d x %d\n",
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
51 img->width, img->height,
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 img->chWidth, img->chHeight);
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
53 }
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
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
55
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
56 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
57 {
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
58 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
59 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
60 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
61 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
62 }
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
63
dcff9ac95d3f Add function to set DMImage's palette to default C64 palette and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1456
diff changeset
64
1494
3b220604ae3c Add short format attribute names to dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents: 1492
diff changeset
65 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng)
1489
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
66 {
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
67 snprintf(buf, len,
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
68 "%s%s%s%s",
1494
3b220604ae3c Add short format attribute names to dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents: 1492
diff changeset
69 (type & D64_FMT_MC) ? (lng ? "MultiColor " : "MC ") : "HiRes ",
3b220604ae3c Add short format attribute names to dmC64GetImageTypeString().
Matti Hamalainen <ccr@tnsp.org>
parents: 1492
diff changeset
70 (type & D64_FMT_ILACE) ? (lng ? "Interlaced " : "ILace ") : "",
1489
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
71 (type & D64_FMT_FLI) ? "FLI " : "",
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
72 (type & D64_FMT_CHAR) ? "CHAR" : ""
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
73 );
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
74
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
75 return buf;
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
76 }
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
77
71e847ea9d22 Move one function to a better place in the code.
Matti Hamalainen <ccr@tnsp.org>
parents: 1488
diff changeset
78
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
79 BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr)
1381
b6782b785457 Move things around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
80 {
b6782b785457 Move things around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
81 return buf[offs ] == DM_GET_ADDR_LO(addr) &&
b6782b785457 Move things around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
82 buf[offs + 1] == DM_GET_ADDR_HI(addr);
b6782b785457 Move things around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
83 }
b6782b785457 Move things around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
84
b6782b785457 Move things around a bit.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
85
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
86 int dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt)
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
87 {
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
88 int nbanks = 0;
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
89 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
90 {
1591
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
91 const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i);
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
92 if (op->type == DT_LAST)
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
93 break;
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
94
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
95 if (op->bank > nbanks)
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
96 nbanks = op->bank;
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
97 }
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
98
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
99 return nbanks + 1;
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
100 }
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
101
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
102
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
103 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
104 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
105 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
106 return DMERR_MALLOC;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
107
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
108 blk->size = size;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
109 return DMERR_OK;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
110 }
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
111
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
112
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
113 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
114 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
115 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
116 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
117 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
118 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
119 return DMERR_MALLOC;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
120
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
121 memcpy(dst->data, src->data, src->size);
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
122 }
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
123
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
124 return DMERR_OK;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
125 }
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
126
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
127
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
128 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
129 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
130 if (blk != NULL)
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
131 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
132 dmFreeR(&blk->data);
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
133 blk->size = 0;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
134 }
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
135 }
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
136
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
137
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
138 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
139 {
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
140 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
141
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
142 if (img == NULL)
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
143 return NULL;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
144
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
145 // Initialize image information
1492
5f9080d24f3c Set DMC64Image::type in dmC64ImageAlloc() from format type.
Matti Hamalainen <ccr@tnsp.org>
parents: 1491
diff changeset
146 img->type = fmt->type;
1491
b329fea6f013 Reindent polishing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1489
diff changeset
147 img->width = fmt->width;
b329fea6f013 Reindent polishing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1489
diff changeset
148 img->height = fmt->height;
b329fea6f013 Reindent polishing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1489
diff changeset
149 img->chWidth = fmt->chWidth;
b329fea6f013 Reindent polishing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1489
diff changeset
150 img->chHeight = fmt->chHeight;
b329fea6f013 Reindent polishing.
Matti Hamalainen <ccr@tnsp.org>
parents: 1489
diff changeset
151 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
152
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
153 // Allocate banks
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
154 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
155 (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
156 (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
157 (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
158 goto err;
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
159
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
160 return img;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
161
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
162 err:
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
163 dmC64ImageFree(img);
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
164 return NULL;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
165 }
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
166
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
167
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
168 void dmC64ImageFree(DMC64Image *img)
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
169 {
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
170 if (img != NULL)
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
171 {
1462
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
172 // Free the allocated areas
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
173 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
174 {
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
175 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
176 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
177 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
178 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
179 }
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
180
1462
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
181 // 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
182 dmFree(img->color);
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
183 dmFree(img->bitmap);
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
184 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
185 dmFree(img->charData);
1462
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
186
9cb6dd1046bf Fix memory leaks by freeing more things in dmC64ImageFree().
Matti Hamalainen <ccr@tnsp.org>
parents: 1461
diff changeset
187 // Extra data ..
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
188 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
189 dmC64MemBlockFree(&img->extraData[i]);
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
190
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1134
diff changeset
191 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
192 dmFree(img);
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
193 }
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
194 }
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
195
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
196
827
c8beac5313c3 Rename a function.
Matti Hamalainen <ccr@tnsp.org>
parents: 812
diff changeset
197 int dmC64ConvertCSDataToImage(DMImage *img,
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
198 int xoffs, int yoffs, const Uint8 *buf,
915
ba6b210c9bf4 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
199 int width, int height, BOOL multicolor,
ba6b210c9bf4 Cosmetic.
Matti Hamalainen <ccr@tnsp.org>
parents: 912
diff changeset
200 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
201 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 int yc, widthpx = width * 8;
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
203 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
204
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 if (img == NULL)
517
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
206 return DMERR_NULLPTR;
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
207
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
208 if (xoffs < 0 || yoffs < 0 ||
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
209 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
210 yoffs > img->height - height)
517
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
211 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
212
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213 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
214
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 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
216 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 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
218 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 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
220 int xc;
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
221 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
222
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 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
224 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 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
226 const int v = 6 - ((xc * 2) & 6);
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
227 const Uint8 c = colors[(b >> v) & 3];
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
228
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 *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
230 *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
231 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 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
234 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 else
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 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
239 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 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
241 int xc;
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
242 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
243
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 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
245 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246 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
247 const int v = 7 - (xc & 7);
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
248 const Uint8 c = colors[(b >> v) & 1];
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
249
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 *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
251 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 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
254 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 }
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
256
517
e2a76bb59888 Return better error values, using DMERR_* enums.
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
257 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
258 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
261 void dmGenericRLEAnalyze(const DMGrowBuf *buf, Uint8 *rleMarker, const int rleType)
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
262 {
1542
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
263 #define DM_STAT_MAX 256
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
264 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
265
1542
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
266 // Allocate statistics counts buffer
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
267 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
268 return;
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
269
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
270 // Get statistics on the data
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
271 for (size_t offs = 0; offs < buf->len; offs++)
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
272 stats[buf->data[offs]]++;
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
273
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
274 // According to compression type ..
1573
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
275 if (rleType == DM_COMP_RLE_MARKER1 || rleType == DM_COMP_RLE_MARKER2)
1542
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
276 {
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
277 size_t selected = 0,
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
278 smallest = buf->len;
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
279
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
280 // Find least used byte value
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
281 for (size_t n = 0; n < DM_STAT_MAX; n++)
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
282 {
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
283 if (stats[n] < smallest)
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
284 {
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
285 selected = n;
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
286 smallest = stats[n];
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
287 }
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
288 }
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
289
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
290 *rleMarker = selected;
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
291 }
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
292 else
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
293 *rleMarker = 0xC0;
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
294
69fa95707e65 Implement dmGenericRLEAnalyze() and use it where appropriate.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
295 dmFree(stats);
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
296 }
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
297
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1501
diff changeset
298
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
299 int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, 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
300 {
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
301 int res;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
303 // Perform RLE decode
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
304 while (src < srcEnd)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 {
1476
f0232684857a Cleanup the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1475
diff changeset
306 Uint8 data = *src++;
f0232684857a Cleanup the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1475
diff changeset
307 int count = 1;
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
308
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
309 switch (cfg->type)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 {
1573
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
311 case DM_COMP_RLE_MARKER1:
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
312 case DM_COMP_RLE_MARKER2:
1476
f0232684857a Cleanup the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1475
diff changeset
313 // A simple marker byte RLE variant: [Marker] [count] [data]
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
314 if (data == cfg->rleMarker)
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
315 {
1597
501e31f11c29 Fix RLE decoder bounds checks for compressed sequences.
Matti Hamalainen <ccr@tnsp.org>
parents: 1591
diff changeset
316 if (srcEnd - src + 1 < 2)
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
317 {
1466
bc75be0546fc More work on RLE decoder/encoder changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
318 res = DMERR_INVALID_DATA;
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
319 goto err;
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
320 }
1573
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
321
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
322 switch (cfg->type)
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
323 {
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
324 case DM_COMP_RLE_MARKER1:
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
325 count = *src++;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
326 data = *src++;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
327 break;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
328
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
329 case DM_COMP_RLE_MARKER2:
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
330 data = *src++;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
331 count = *src++;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
332 break;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
333 }
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
334 }
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
335 break;
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
336
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
337 case DM_COMP_RLE_MASK:
1476
f0232684857a Cleanup the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1475
diff changeset
338 // Mask marker RLE: usually high bit(s) of byte mark RLE sequence
f0232684857a Cleanup the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1475
diff changeset
339 // and the lower bits contain the count: [Mask + count] [data]
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
340 if ((data & cfg->rleMask1) == cfg->rleMarker)
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
341 {
1597
501e31f11c29 Fix RLE decoder bounds checks for compressed sequences.
Matti Hamalainen <ccr@tnsp.org>
parents: 1591
diff changeset
342 if (srcEnd - src + 1 < 1)
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
343 {
1466
bc75be0546fc More work on RLE decoder/encoder changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
344 res = DMERR_INVALID_DATA;
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
345 goto err;
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
346 }
1466
bc75be0546fc More work on RLE decoder/encoder changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
347
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
348 count = data & cfg->rleMask2;
1476
f0232684857a Cleanup the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1475
diff changeset
349 data = *src++;
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
350 }
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
351 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
352 }
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
353
1476
f0232684857a Cleanup the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1475
diff changeset
354 while (count--)
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
355 {
1476
f0232684857a Cleanup the RLE decoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1475
diff changeset
356 if (!dmGrowBufPutU8(dst, data))
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
357 {
1466
bc75be0546fc More work on RLE decoder/encoder changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
358 res = DMERR_MALLOC;
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
359 goto err;
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
360 }
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
361 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
362 }
523
d0c0c6baeb57 Split the RLE decoding from DrazPaint/Lace and Amica paint decoders to a
Matti Hamalainen <ccr@tnsp.org>
parents: 519
diff changeset
363
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
364 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
365
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
366 err:
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
367 return res;
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
368 }
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
369
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
370
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
371 int dmDecodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg)
1463
bde6a66bc2f6 Change dmDecodeGenericRLE() to use DMGrowBuf as output. Also add support
Matti Hamalainen <ccr@tnsp.org>
parents: 1462
diff changeset
372 {
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
373 int res;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
374 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
375 return res;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
376
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
377 return dmDecodeGenericRLE(dst, src, srcEnd, cfg);
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
378 }
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
379
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
380
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
381 static BOOL dmEncodeGenericRLESequence(DMGrowBuf *dst, const Uint8 data, Uint8 count, const DMCompParams *cfg)
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
382 {
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
383 BOOL copyOnly = FALSE;
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
384
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
385 switch (cfg->type)
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
386 {
1573
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
387 case DM_COMP_RLE_MARKER1:
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
388 case DM_COMP_RLE_MARKER2:
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
389 if (count >= cfg->rleMinCount || data == cfg->rleMarker)
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
390 {
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
391 // A simple marker byte RLE variant: [Marker] [count] [data]
1573
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
392 if (!dmGrowBufPutU8(dst, cfg->rleMarker))
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
393 return FALSE;
1573
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
394
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
395 switch (cfg->type)
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
396 {
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
397 case DM_COMP_RLE_MARKER1:
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
398 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
399 !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
400 return FALSE;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
401 break;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
402
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
403 case DM_COMP_RLE_MARKER2:
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
404 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
405 !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
406 return FALSE;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
407 break;
86373ac0861a Implement another RLE variant, with different ordering of marker, count and data bytes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1548
diff changeset
408 }
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
409 }
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
410 else
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
411 copyOnly = TRUE;
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
412 break;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
413
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
414 case DM_COMP_RLE_MASK:
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
415 if (count >= cfg->rleMinCount || (data & cfg->rleMarker) == cfg->rleMarker)
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
416 {
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
417 // 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
418 // and the lower bits contain the count: [Mask + count] [data]
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
419 if (!dmGrowBufPutU8(dst, cfg->rleMarker | count) ||
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
420 !dmGrowBufPutU8(dst, data))
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
421 return FALSE;
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
422 }
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
423 else
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
424 copyOnly = TRUE;
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
425 break;
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
426 }
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
427
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
428 if (copyOnly)
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
429 {
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
430 while (count--)
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
431 {
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
432 if (!dmGrowBufPutU8(dst, data))
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
433 return FALSE;
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
434 }
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
435 }
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
436
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
437 return TRUE;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
438 }
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
439
1466
bc75be0546fc More work on RLE decoder/encoder changes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
440
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
441 int dmEncodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg)
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
442 {
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
443 // Perform RLE encoding
1512
ee691fbf8f27 Initialize previous data value in RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1511
diff changeset
444 int count = 0, prev = -1;
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
445 while (src < srcEnd)
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
446 {
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
447 Uint8 data = *src++;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
448
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
449 if (data != prev || count >= cfg->rleMaxCount)
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
450 {
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
451 if (!dmEncodeGenericRLESequence(dst, prev, count, cfg))
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
452 goto err;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
453
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
454 count = 1;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
455 }
1496
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
456 else
5c46004dad15 Work on the RLE encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
457 count++;
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
458
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
459 prev = data;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
460 }
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
461
1518
24b8b452925e Improve error handling of RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1513
diff changeset
462 if (!dmEncodeGenericRLESequence(dst, prev, count, cfg))
24b8b452925e Improve error handling of RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1513
diff changeset
463 goto err;
24b8b452925e Improve error handling of RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1513
diff changeset
464
24b8b452925e Improve error handling of RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1513
diff changeset
465 return DMERR_OK;
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
466
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
467 err:
1518
24b8b452925e Improve error handling of RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1513
diff changeset
468 return dmError(DMERR_MALLOC,
24b8b452925e Improve error handling of RLE encoder.
Matti Hamalainen <ccr@tnsp.org>
parents: 1513
diff changeset
469 "Could reallocate memory for RLE encoding buffer.\n");
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
470 }
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
471
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
472
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
473 int dmEncodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg)
1478
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
474 {
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
475 int res;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
476 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
477 return res;
d883b4c1cf48 More work on RLE encoding/decoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1476
diff changeset
478
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
479 return dmEncodeGenericRLE(dst, src, srcEnd, 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
480 }
d0c0c6baeb57 Split the RLE decoding from DrazPaint/Lace and Amica paint decoders to a
Matti Hamalainen <ccr@tnsp.org>
parents: 519
diff changeset
481
519
feaaf0e2ecbe Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 518
diff changeset
482
518
63849f85db57 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 517
diff changeset
483 // Perform probing of the given data buffer, trying to determine
63849f85db57 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 517
diff changeset
484 // if it contains a supported "C64" image format. Returns the
63849f85db57 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 517
diff changeset
485 // "probe score", see libgfx.h for list of values. If a match
63849f85db57 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 517
diff changeset
486 // is found, pointer to format description is set to *pfmt.
537
32d9e67da189 Rename generic probing function to match the style of other lib64gfx functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 536
diff changeset
487 int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **pfmt)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
488 {
1380
959b34402b81 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1378
diff changeset
489 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -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
490
1380
959b34402b81 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1378
diff changeset
491 for (int i = 0; i < ndmC64ImageFormats; i++)
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
492 {
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 515
diff changeset
493 const DMC64ImageFormat *fmt = &dmC64ImageFormats[i];
511
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
494 int score = DM_PROBE_SCORE_FALSE;
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
495 if (fmt->probe == NULL && fmt->size > 0 && fmt->addr > 0)
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
496 {
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
497 // Generic probe just checks matching size and load address
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
498 if (len == fmt->size && dmCompareAddr16(buf, 0, fmt->addr))
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
499 score = DM_PROBE_SCORE_GOOD;
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
500 }
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
501 else
1134
d0898867ec4c Various fixes for issues reported by clang static analyzer.
Matti Hamalainen <ccr@tnsp.org>
parents: 958
diff changeset
502 if (fmt->probe != NULL)
511
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
503 score = fmt->probe(buf, len, fmt);
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
504
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
505 if (score > scoreMax)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
506 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
507 scoreMax = score;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
508 scoreIndex = i;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
509 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
510 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
511
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
512 if (scoreIndex >= 0)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
513 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
514 *pfmt = &dmC64ImageFormats[scoreIndex];
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
515 return scoreMax;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
516 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
517 else
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
518 return DM_PROBE_SCORE_FALSE;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
519 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
520
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
521
1537
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1534
diff changeset
522 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
523 {
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
524 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
525 {
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
526 case DT_COLOR_RAM:
1586
3c9e5962eca6 Rename DT_BITMAP to DT_BITMAP_RAM.
Matti Hamalainen <ccr@tnsp.org>
parents: 1580
diff changeset
527 case DT_BITMAP_RAM:
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
528 case DT_SCREEN_RAM:
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
529 case DT_CHAR_DATA:
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
530 if (op->bank < 0 || op->bank > img->nbanks)
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
531 {
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
532 return dmError(DMERR_INTERNAL,
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
533 "Invalid bank %d / %d definition in generic encode/decode operator %d @ #%d.\n",
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
534 op->bank, img->nbanks, op->type, i);
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
535 }
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
536 break;
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
537
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
538 case DT_EXTRA_DATA:
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
539 if (op->bank < 0 || op->bank >= C64_MAX_EXTRA_DATA)
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
540 {
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
541 return dmError(DMERR_INTERNAL,
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
542 "Invalid bank %d definition in generic encode/decode operator %d @ #%d.\n",
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
543 op->bank, op->type, i);
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
544 }
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
545 break;
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
546 }
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
547
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
548 if (op->type < 0 || op->type >= DT_LAST)
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
549 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
550 return dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
551 "Invalid encode/decode operator type %d @ #%d.\n",
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
552 op->type, i);
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
553 }
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
554
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
555 return DMERR_OK;
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
556 }
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
557
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
558
1537
776aa43b2c57 Tiny improvement in MC->FLI upconversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 1534
diff changeset
559 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
560 {
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
561 switch (op->type)
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
562 {
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
563 case DT_SCREEN_RAM:
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
564 case DT_COLOR_RAM:
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
565 *size = fmt->chHeight * fmt->chWidth;
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
566 break;
927
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
567
1586
3c9e5962eca6 Rename DT_BITMAP to DT_BITMAP_RAM.
Matti Hamalainen <ccr@tnsp.org>
parents: 1580
diff changeset
568 case DT_BITMAP_RAM:
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
569 *size = fmt->chHeight * fmt->chWidth * 8;
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
570 break;
927
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
571
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
572 case DT_CHAR_DATA:
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
573 *size = C64_MAX_CHARS * C64_CHR_SIZE;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
574 break;
927
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
575
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
576 case DT_COLOR_REG:
1519
19b5013ff190 Fix c64 bitmap encoding / decoding bounds checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 1518
diff changeset
577 *size = 1;
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
578 break;
927
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
579
1528
239dc13123fd Set size for DT_{DEC,ENC}_FUNCTION opcodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1521
diff changeset
580 case DT_DEC_FUNCTION:
239dc13123fd Set size for DT_{DEC,ENC}_FUNCTION opcodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1521
diff changeset
581 case DT_ENC_FUNCTION:
239dc13123fd Set size for DT_{DEC,ENC}_FUNCTION opcodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1521
diff changeset
582 case DT_EXTRA_DATA:
239dc13123fd Set size for DT_{DEC,ENC}_FUNCTION opcodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1521
diff changeset
583 *size = op->size;
239dc13123fd Set size for DT_{DEC,ENC}_FUNCTION opcodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1521
diff changeset
584 break;
239dc13123fd Set size for DT_{DEC,ENC}_FUNCTION opcodes.
Matti Hamalainen <ccr@tnsp.org>
parents: 1521
diff changeset
585
927
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
586 default:
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
587 *size = 0;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
588 }
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
589
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
590 // 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
591 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
592 *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
593
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
594 return TRUE;
927
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
595 }
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
596
db495f421242 Change dmC64DefaultSizes[] array into a function instead.
Matti Hamalainen <ccr@tnsp.org>
parents: 925
diff changeset
597
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
598 int dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf,
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
599 const size_t len, const DMC64ImageFormat *fmt)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
600 {
1460
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
601 int res = DMERR_OK;
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
602
513
486067f39bc1 Add sanity checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
603 if (buf == NULL || img == NULL || fmt == NULL)
486067f39bc1 Add sanity checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
604 return DMERR_NULLPTR;
486067f39bc1 Add sanity checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
605
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
606 // Clear the image structure, set basics
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
607 img->type = fmt->type;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
608 img->width = fmt->width;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
609 img->height = fmt->height;
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
610 img->chWidth = fmt->chWidth;
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
611 img->chHeight = fmt->chHeight;
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
612 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
613
518
63849f85db57 Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 517
diff changeset
614 // Perform decoding
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
615 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
616 {
1591
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
617 const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i);
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
618 const Uint8 *src;
1600
e28e67358ff6 Fix some uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1597
diff changeset
619 DMC64MemBlock *blk = NULL;
e28e67358ff6 Fix some uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1597
diff changeset
620 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
621 size_t size;
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
622
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
623 // Check for last operator
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
624 if (op->type == DT_LAST)
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
625 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
626
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
627 // Check operation validity
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
628 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
629 return res;
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
630
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
631 // Check size
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
632 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
633 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
634 return dmError(DMERR_INVALID_DATA,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
635 "Decode 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
636 "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n",
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
637 i, op->type, op->offs, op->offs, op->bank, size, size, op->size, op->size);
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
638 }
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
639
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
640 // Is the operation inside the bounds?
1519
19b5013ff190 Fix c64 bitmap encoding / decoding bounds checks.
Matti Hamalainen <ccr@tnsp.org>
parents: 1518
diff changeset
641 if (op->offs + size > 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
642 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
643 return dmError(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
644 "Decode DATA out of bounds, op #%d type=%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
645 "bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
646 i, op->type, op->offs, op->offs, op->bank, size, size, len, len);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
647 }
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
648
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
649 src = buf + op->offs;
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
650
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
651 // 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
652 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
653 {
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
654 case DT_COLOR_RAM:
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
655 case DT_SCREEN_RAM:
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
656 case DT_BITMAP_RAM:
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
657 case DT_CHAR_DATA:
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
658 case DT_EXTRA_DATA:
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
659 switch (op->type)
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
660 {
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
661 case DT_COLOR_RAM : blk = &img->color[op->bank]; blkname = "Color RAM"; break;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
662 case DT_SCREEN_RAM : blk = &img->screen[op->bank]; blkname = "Screen RAM"; break;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
663 case DT_BITMAP_RAM : blk = &img->bitmap[op->bank]; blkname = "Bitmap RAM"; break;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
664 case DT_CHAR_DATA : blk = &img->charData[op->bank]; blkname = "Character data"; break;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
665 case DT_EXTRA_DATA : blk = &img->extraData[op->bank]; blkname = "Extra data"; break;
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
666 }
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
667 if ((dmC64MemBlockAlloc(blk, size)) != DMERR_OK)
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
668 {
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
669 return dmError(DMERR_MALLOC,
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
670 "Could not allocate '%s' block! "
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
671 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
672 blkname, i, op->offs, op->offs, op->bank, size, size, len, len);
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
673 }
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
674 memcpy(blk->data, src, size);
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
675 break;
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
676
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
677 case DT_COLOR_REG:
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
678 switch (op->size)
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
679 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
680 case DC_D020: img->d020 = *src; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
681 case DC_BGCOL:
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
682 case DC_D021: img->bgcolor = *src; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
683 case DC_D022: img->d022 = *src; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
684 case DC_D023: img->d023 = *src; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
685 case DC_D024: img->d024 = *src; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
686 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
687 return dmError(DMERR_INTERNAL,
1371
e6b13426b50a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1370
diff changeset
688 "Unhandled DT_COLOR_REG mode %d in "
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
689 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
690 op->size, i, op->offs, op->offs, op->bank, size, size, len, len);
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
691 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
692 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
693
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
694 case DT_COLOR_SET:
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
695 switch (op->size)
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
696 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
697 case DC_D020: img->d020 = op->offs; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
698 case DC_BGCOL:
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
699 case DC_D021: img->bgcolor = op->offs; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
700 case DC_D022: img->d022 = op->offs; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
701 case DC_D023: img->d023 = op->offs; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
702 case DC_D024: img->d024 = op->offs; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
703 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
704 return dmError(DMERR_INTERNAL,
1371
e6b13426b50a Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1370
diff changeset
705 "Unhandled DT_COLOR_SET mode %d in "
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
706 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
707 op->size, i, op->offs, op->offs, op->bank, size, size, len, len);
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
708 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
709 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
710
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
711 case DT_CHAR_CONFIG:
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
712 switch (op->offs)
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
713 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
714 case D64_CHCFG_SCREEN:
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
715 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
716
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
717 case D64_CHCFG_LINEAR:
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
718 {
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
719 for (int bank = 0; bank < img->nbanks; bank++)
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
720 for (int offs = 0; offs < fmt->chHeight * fmt->chWidth; offs++)
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
721 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
722 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
723 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
724
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
725 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
726 return dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
727 "Unhandled DT_CHAR_CONFIG mode %d in ",
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
728 "op #%d, bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
729 op->offs, i, op->bank, size, size, len, len);
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
730 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
731 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
732
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 508
diff changeset
733 case DT_DEC_FUNCTION:
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
734 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
735 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
736 return dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
737 "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
738 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
739 i, op->offs, op->offs, op->bank, size, size, len, len);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
740 }
1486
bc13af8954d7 Add DMC64ImageFormat to C64 bitmap format encoding/decoding ops function parameters.
Matti Hamalainen <ccr@tnsp.org>
parents: 1485
diff changeset
741 if (!op->decFunction(img, op, buf, len, 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
742 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
743 return dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
744 "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
745 "offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
746 i, op->offs, op->offs, op->bank, size, size, len, len);
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
747 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
748 break;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
749 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
750 }
916
3985f596ece5 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 915
diff changeset
751
508
1ed5025c2538 Return DMLIB error values instead of arbitrary 0/negatives.
Matti Hamalainen <ccr@tnsp.org>
parents: 507
diff changeset
752 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
753 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
754
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
755
1499
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
756 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
757 {
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
758 int res = DMERR_OK;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
759
1469
0046b4e1b35f Various fixes in bmp encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1467
diff changeset
760 if (img == NULL || fmt == NULL)
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
761 return DMERR_NULLPTR;
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
762
1499
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
763 // Allocate the output buffer if requested
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
764 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
765 {
1472
b9d3577d8290 Improve error handling and checking.
Matti Hamalainen <ccr@tnsp.org>
parents: 1471
diff changeset
766 dmError(res,
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
767 "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
768 fmt->size);
1447
de5f7e31a8bf Rename labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 1443
diff changeset
769 goto err;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
770 }
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
771
1534
acad4974dc09 Use the DMGrowBuf push/pop functionality to better implement the stacked
Matti Hamalainen <ccr@tnsp.org>
parents: 1528
diff changeset
772 dmGrowBufPush(buf);
1506
4fd4e7a00db4 Fix handling of predefined DMGrowBuffer in dmC64EncodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents: 1505
diff changeset
773
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
774 // Perform encoding
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
775 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
776 {
1591
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
777 const DMC64EncDecOp *op = fmtGetEncDecOp(fmt, i);
1364
0d61895e1763 Cleanup.
Matti Hamalainen <ccr@tnsp.org>
parents: 1362
diff changeset
778 size_t size, chksize;
1600
e28e67358ff6 Fix some uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1597
diff changeset
779 const DMC64MemBlock *blk = NULL;
e28e67358ff6 Fix some uninitialized variable warnings.
Matti Hamalainen <ccr@tnsp.org>
parents: 1597
diff changeset
780 char *blkname = NULL;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
781
1365
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
782 // Check for last operator
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
783 if (op->type == DT_LAST)
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
784 break;
60d7240e1a63 Remove hardcoded encoding/decoding operator counts from the structures, use
Matti Hamalainen <ccr@tnsp.org>
parents: 1364
diff changeset
785
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
786 // Check operation validity
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
787 if ((res = dmC64SanityCheckEncDecOp(i, op, img)) != DMERR_OK)
1447
de5f7e31a8bf Rename labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 1443
diff changeset
788 goto err;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
789
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
790 // Check size
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
791 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
792 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
793 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
794 "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
795 "bank=%d, size=%d ($%04x) vs. allocated %d ($%04x)\n",
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
796 i, op->type, op->offs, op->offs, op->bank, size, size, op->size, op->size);
1447
de5f7e31a8bf Rename labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 1443
diff changeset
797 goto err;
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
798 }
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
799
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
800 // Do we need to reallocate some more space?
1534
acad4974dc09 Use the DMGrowBuf push/pop functionality to better implement the stacked
Matti Hamalainen <ccr@tnsp.org>
parents: 1528
diff changeset
801 chksize = 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
802 if (!dmGrowBufCheckGrow(buf, chksize))
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
803 {
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
804 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
805 "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
806 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
807 goto err;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
808 }
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
809
1487
06df2bdf5dc4 Various fixes to dmC64EncodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents: 1486
diff changeset
810 if (chksize > buf->len)
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
811 buf->len = chksize;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
812
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
813 // Perform operation
1534
acad4974dc09 Use the DMGrowBuf push/pop functionality to better implement the stacked
Matti Hamalainen <ccr@tnsp.org>
parents: 1528
diff changeset
814 Uint8 *dst = buf->data + op->offs;
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
815 switch (op->type)
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
816 {
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
817 case DT_COLOR_RAM:
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
818 case DT_SCREEN_RAM:
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
819 case DT_BITMAP_RAM:
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
820 case DT_CHAR_DATA:
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
821 case DT_EXTRA_DATA:
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
822 switch (op->type)
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
823 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
824 case DT_COLOR_RAM : blk = &img->color[op->bank]; blkname = "Color RAM"; break;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
825 case DT_SCREEN_RAM : blk = &img->screen[op->bank]; blkname = "Screen RAM"; break;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
826 case DT_BITMAP_RAM : blk = &img->bitmap[op->bank]; blkname = "Bitmap RAM"; break;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
827 case DT_CHAR_DATA : blk = &img->charData[op->bank]; blkname = "Character data"; break;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
828 case DT_EXTRA_DATA : blk = &img->extraData[op->bank]; blkname = "Extra data"; break;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
829 }
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
830 if (blk->data == NULL)
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
831 {
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
832 res = dmError(DMERR_NULLPTR,
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
833 "'%s' block is NULL in "
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
834 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
835 blkname, 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
836 goto err;
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
837 }
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
838 if (size > blk->size)
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
839 {
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
840 res = dmError(DMERR_INTERNAL,
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
841 "'%s' size mismatch %d <> %d in "
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
842 "op #%d, offs=%d ($%04x), bank=%d, size=%d ($%04x) @ %d ($%04x)\n",
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
843 blkname, op->size, blk->size, 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
844 goto err;
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
845 }
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
846 memcpy(dst, blk->data, size);
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1372
diff changeset
847 break;
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
848
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
849 case DT_COLOR_REG:
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
850 switch (op->size)
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
851 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
852 case DC_D020: *dst = img->d020; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
853 case DC_BGCOL:
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
854 case DC_D021: *dst = img->bgcolor; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
855 case DC_D022: *dst = img->d022; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
856 case DC_D023: *dst = img->d023; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
857 case DC_D024: *dst = img->d024; break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
858 default:
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
859 res = dmError(DMERR_INTERNAL,
1500
3223d01ac8e8 Fix some blunders in encode/decode error messages.
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
860 "Unhandled DT_COLOR_REG mode %d in "
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
861 "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
862 op->size, 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
863 goto err;
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
864 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
865 break;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
866
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
867 case DT_ENC_FUNCTION:
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1478
diff changeset
868 if (op->encFunction == NULL)
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
869 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
870 res = dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
871 "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
872 "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
873 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
874 goto err;
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
875 }
1486
bc13af8954d7 Add DMC64ImageFormat to C64 bitmap format encoding/decoding ops function parameters.
Matti Hamalainen <ccr@tnsp.org>
parents: 1485
diff changeset
876 if (!op->encFunction(op, buf, img, fmt))
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
877 {
958
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
878 res = dmError(DMERR_INTERNAL,
985225a93aeb Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents: 946
diff changeset
879 "Encode op custom function failed: op #%d, "
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
880 "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
881 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
882 goto err;
904
d3cd9f2a8ef1 Some dummy code for encfunctions.
Matti Hamalainen <ccr@tnsp.org>
parents: 903
diff changeset
883 }
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
884 break;
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
885 }
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
886 }
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
887
1534
acad4974dc09 Use the DMGrowBuf push/pop functionality to better implement the stacked
Matti Hamalainen <ccr@tnsp.org>
parents: 1528
diff changeset
888 dmGrowBufPop(buf);
acad4974dc09 Use the DMGrowBuf push/pop functionality to better implement the stacked
Matti Hamalainen <ccr@tnsp.org>
parents: 1528
diff changeset
889
1448
50402c225ef4 Do not insert load address to the buffer beginning in dmC64EncodeGenericBMP().
Matti Hamalainen <ccr@tnsp.org>
parents: 1447
diff changeset
890 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
891
1447
de5f7e31a8bf Rename labels.
Matti Hamalainen <ccr@tnsp.org>
parents: 1443
diff changeset
892 err:
532
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
893 return res;
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
894 }
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
895
128a50feff07 Implement initial generic bitmap "encoding" function, that constructs
Matti Hamalainen <ccr@tnsp.org>
parents: 531
diff changeset
896
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
897 // 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
898 // 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
899 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
900 {
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
901 DMC64GetPixelFunc getPixel;
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
902
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
903 // Sanity check arguments
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
904 if (dst == NULL || src == NULL)
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
905 return DMERR_NULLPTR;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
906
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
907 if (dst->width < src->width || dst->height < src->height)
1460
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
908 {
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
909 return dmError(DMERR_INVALID_DATA,
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
910 "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
911 src->width, src->height, dst->width, dst->height);
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
912 }
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
913
1167
848a88ce7a57 Use dmMemset().
Matti Hamalainen <ccr@tnsp.org>
parents: 1134
diff changeset
914 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
915
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
916 // Check pixel getter function
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
917 if (fmt->getPixel != NULL)
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
918 getPixel = fmt->getPixel;
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
919 else
1376
67ae449cf9e1 More work on making various FLI etc. format decoding more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1375
diff changeset
920 getPixel = (fmt->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
921
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
922 // 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
923 int rwidth = src->width;
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
924 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
925 rwidth /= 2;
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
926
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
927 // Perform conversion
1411
a9afb2ad39cb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1396
diff changeset
928 Uint8 *dp = dst->data;
a9afb2ad39cb Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1396
diff changeset
929 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
930 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
931 Uint8 *d = dp;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
932 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
933 const int scroffsy = y * src->chWidth;
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
934 int xc;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
935
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
936 if (src->type & D64_FMT_CHAR)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
937 {
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
938 // Charmode conversion
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
939 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
940 // Hi-res charmap
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
941 for (xc = 0; xc < rwidth; xc++)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
942 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
943 const int x = xc / 8;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
944 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
945 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
946 const int v = 7 - (xc & 7);
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
947
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
948 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
949 *d++ = src->color[0].data[scroffs];
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
950 else
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
951 *d++ = src->bgcolor;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
952 }
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
953 else
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
954 // Multicolor variants
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
955 for (xc = 0; xc < rwidth; xc++)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
956 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
957 const int x = xc / 4;
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
958 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
959 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
960 const int col = src->color[0].data[scroffs] & 15;
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
961
944
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
962 if (col & 8)
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
963 {
944
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
964 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
965 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
966 {
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
967 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
968 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
969 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
970 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
971 }
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
972 }
944
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
973 else
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
974 {
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
975 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
976 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
977 *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
978 else
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
979 *d++ = src->bgcolor;
c62bb4028cf0 Implement multicolor / standard switching support based on color ram value's
Matti Hamalainen <ccr@tnsp.org>
parents: 943
diff changeset
980 }
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
981 }
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
982 }
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
983 else
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
984 {
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
985 // 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
986 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
987
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
988 if ((src->type & D64_FMT_MC) == D64_FMT_HIRES)
811
aebc2f8b2c2d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 810
diff changeset
989 // Hi-res bitmap
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
990 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
991 {
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
992 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
993 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
994 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
995 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
996
1387
14d79e4d82cf Oops, 100L. Had forgotten to change singlecolor mode handling pixel getter
Matti Hamalainen <ccr@tnsp.org>
parents: 1385
diff changeset
997 *d++ = getPixel(src, bmoffs, scroffs, vshift, 0, yc);
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
998 }
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
999 else
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1000 // Multicolor bitmap and variants
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1001 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
1002 {
901
f532262f90b1 Actually fix commit 16aa5955dfb5.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
1003 const int x = xc / 4;
f532262f90b1 Actually fix commit 16aa5955dfb5.
Matti Hamalainen <ccr@tnsp.org>
parents: 857
diff changeset
1004 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
1005 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
1006 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
1007
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1008 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
1009 {
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1010 switch (src->laceType)
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1011 {
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1012 case D64_ILACE_RES:
1376
67ae449cf9e1 More work on making various FLI etc. format decoding more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1375
diff changeset
1013 *d++ = getPixel(src, bmoffs, scroffs, vshift, 0, yc);
67ae449cf9e1 More work on making various FLI etc. format decoding more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1375
diff changeset
1014 *d++ = getPixel(src, bmoffs, scroffs, vshift, 1, yc);
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1015 break;
1366
d4387509a363 Return DMERR_NOT_SUPPORTED for decoding color-interlaced images, for now
Matti Hamalainen <ccr@tnsp.org>
parents: 1365
diff changeset
1016
d4387509a363 Return DMERR_NOT_SUPPORTED for decoding color-interlaced images, for now
Matti Hamalainen <ccr@tnsp.org>
parents: 1365
diff changeset
1017 default:
d4387509a363 Return DMERR_NOT_SUPPORTED for decoding color-interlaced images, for now
Matti Hamalainen <ccr@tnsp.org>
parents: 1365
diff changeset
1018 return DMERR_NOT_SUPPORTED;
1362
7bc67ba68904 Better handling of resolution interlaced pictures.
Matti Hamalainen <ccr@tnsp.org>
parents: 1361
diff changeset
1019 }
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1020 }
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1021 else
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1022 {
1376
67ae449cf9e1 More work on making various FLI etc. format decoding more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1375
diff changeset
1023 *d++ = getPixel(src, bmoffs, scroffs, vshift, 0, yc);
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1024 }
529
1bce06b5026f Combine conversion of interlaced and normal multicolor images to one function.
Matti Hamalainen <ccr@tnsp.org>
parents: 528
diff changeset
1025 }
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1026 }
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 529
diff changeset
1027 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
1028 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1029
508
1ed5025c2538 Return DMLIB error values instead of arbitrary 0/negatives.
Matti Hamalainen <ccr@tnsp.org>
parents: 507
diff changeset
1030 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
1031 }
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1032
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1033
940
ff18d2511843 Remove the doubleMC madness completely. Should be replaced with x/y aspect
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1034 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
1035 {
940
ff18d2511843 Remove the doubleMC madness completely. Should be replaced with x/y aspect
Matti Hamalainen <ccr@tnsp.org>
parents: 939
diff changeset
1036 int res;
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1037 DMImage *dst;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1038
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1039 if (pdst == NULL || src == NULL)
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1040 return DMERR_NULLPTR;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1041
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1042 // Allocate image structure
1289
Matti Hamalainen <ccr@tnsp.org>
parents: 1235
diff changeset
1043 if ((*pdst = dst = dmImageAlloc(src->width, src->height, DM_IFMT_PALETTE, -1)) == NULL)
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1044 return DMERR_MALLOC;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1045
1426
4c7b456d7f0b Rename global dmC64Palette to dmDefaultC64Palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 1425
diff changeset
1046 // Set partial palette information
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1047 dst->ncolors = C64_NCOLORS;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1048 dst->constpal = TRUE;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1049
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1050 // Convert
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1051 if (fmt->convertFrom != NULL)
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
1052 res = fmt->convertFrom(dst, src, fmt);
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1053 else
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
1054 res = dmC64ConvertGenericBMP2Image(dst, src, fmt);
556
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1055
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1056 return res;
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1057 }
44d1e0d4acf3 Improve DMC64Image -> DMImage conversion facilities.
Matti Hamalainen <ccr@tnsp.org>
parents: 548
diff changeset
1058
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1059
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1060 int dmC64DecodeBMP(DMC64Image **img, const Uint8 *buf, const size_t len,
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1061 const size_t probeOffs, const size_t loadOffs,
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 515
diff changeset
1062 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
1063 {
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1064 if (img == NULL)
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1065 return DMERR_NULLPTR;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1066
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1067 // Check for forced format
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1068 if (forced != NULL)
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1069 *fmt = forced;
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1070 else
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1071 {
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1072 // Nope, perform a generic probe
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1073 if (probeOffs >= len)
1460
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
1074 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
1075
537
32d9e67da189 Rename generic probing function to match the style of other lib64gfx functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 536
diff changeset
1076 if (dmC64ProbeBMP(buf + probeOffs, len - probeOffs, fmt) == DM_PROBE_SCORE_FALSE)
1460
361cad3b8445 Improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
1077 return DMERR_NOT_SUPPORTED;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1078 }
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1079
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1080 if (loadOffs >= len)
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1081 return DMERR_INVALID_ARGS;
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1082
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1083 if (*fmt == NULL)
1548
20cd589366d7 Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1542
diff changeset
1084 return DMERR_NOT_SUPPORTED;
20cd589366d7 Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1542
diff changeset
1085
20cd589366d7 Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1542
diff changeset
1086 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
1087 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
1088
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1089 // Allocate memory
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1377
diff changeset
1090 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
1091 return DMERR_MALLOC;
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1092
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1093 // 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
1094 if ((*fmt)->decode != NULL)
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1095 return (*fmt)->decode(*img, buf + loadOffs, len - loadOffs, *fmt);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1096 else
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 927
diff changeset
1097 return dmC64DecodeGenericBMP(*img, buf + loadOffs, len - loadOffs, *fmt);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
1098 }
1467
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1099
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1100
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1101 // 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
1102 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
1103 {
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1104 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
1105 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
1106
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1107 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
1108 }
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1109
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1110
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1111 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
1112 {
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1113 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
1114 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
1115
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1116 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
1117 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
1118
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1119 // 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
1120 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
1121 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
1122
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1123 // Convert
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1124 if (fmt->convertTo != NULL)
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1125 res = fmt->convertTo(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
1126 else
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1127 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
1128
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1129 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
1130 }
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1131
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1132
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1133 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
1134 {
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1135 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
1136
1580
72f809e6eb3c Add NULL check for growbuf pointer.
Matti Hamalainen <ccr@tnsp.org>
parents: 1573
diff changeset
1137 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
1138 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
1139
1548
20cd589366d7 Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1542
diff changeset
1140 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
1141 return DMERR_NOT_SUPPORTED;
20cd589366d7 Check C64 bitmap format flags in encode/decode functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1542
diff changeset
1142
1499
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1143 // Allocate a buffer
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1144 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
1145 goto err;
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1146
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1147 // Add the loading address
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1148 if (!dmGrowBufPutU8(buf, DM_GET_ADDR_LO(fmt->addr)) ||
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1149 !dmGrowBufPutU8(buf, DM_GET_ADDR_HI(fmt->addr)))
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1150 goto err;
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1151
1467
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1152 // 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
1153 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
1154 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
1155 else
1499
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1498
diff changeset
1156 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
1157
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1158 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
1159 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
1160
1469
0046b4e1b35f Various fixes in bmp encoding.
Matti Hamalainen <ccr@tnsp.org>
parents: 1467
diff changeset
1161 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
1162
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1163 err:
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1466
diff changeset
1164 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
1165 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
1166 }