annotate tools/lib64gfx.h @ 1650:9233da9de92c

Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 30 May 2018 03:25:34 +0300
parents 948d6fda722d
children 7555c8803529
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 /*
418
b6a1dc3bd2c3 Update file description.
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
2 * Functions for reading and converting various restricted
b6a1dc3bd2c3 Update file description.
Matti Hamalainen <ccr@tnsp.org>
parents: 410
diff changeset
3 * C64/etc and/or indexed/paletted graphics formats.
407
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: 1449
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 #ifndef LIB64GFX_H
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #define LIB64GFX_H 1
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
12 #include "libgfx.h"
1465
88845f95e791 Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
13 #include "dmgrowbuf.h"
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
14
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
15 #ifdef __cplusplus
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
16 extern "C" {
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
17 #endif
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
18
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 // Bitmap constants
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 #define C64_SCR_WIDTH 320
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 #define C64_SCR_HEIGHT 200
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 #define C64_SCR_CH_WIDTH (C64_SCR_WIDTH/8)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 #define C64_SCR_CH_HEIGHT (C64_SCR_HEIGHT/8)
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1365
diff changeset
25 #define C64_MAX_EXTRA_DATA 64
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 // C64 video screen pixel aspect ratio on PAL
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 #define C64_SCR_PAR_XY (0.9365f)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 // Sprite constants
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 #define C64_SPR_WIDTH 3 // bytes
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 #define C64_SPR_HEIGHT 21 // lines
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 #define C64_SPR_WIDTH_PX (8 * C64_SPR_WIDTH)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #define C64_SPR_SIZE ((C64_SPR_WIDTH * C64_SPR_HEIGHT) + 1)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36 // Character constants
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 #define C64_CHR_WIDTH 1 // bytes
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38 #define C64_CHR_HEIGHT 8 // lines
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 #define C64_CHR_WIDTH_PX (8 * C64_CHR_WIDTH)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 #define C64_CHR_SIZE (C64_CHR_WIDTH * C64_CHR_HEIGHT)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 // Etc.
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 #define C64_NCOLORS 16
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44 #define C64_VIDBANK_SIZE (16*1024)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 #define C64_MAX_SPRITES (C64_VIDBANK_SIZE / C64_SPR_SIZE)
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 #define C64_MAX_CHARS 256
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
922
658bf4c452d0 Comments, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 921
diff changeset
48
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
49 #define DM_GET_ADDR_LO(addr) ((addr) & 0xff)
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
50 #define DM_GET_ADDR_HI(addr) (((addr) >> 8) & 0xff)
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
51
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
52
1637
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
53 // Different supported flags/modes
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 enum
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 {
1637
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
56 D64_FMT_HIRES = 0x0000, // Hi-res
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
57 D64_FMT_MC = 0x0001, // MultiColor
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
58 D64_FMT_ILACE = 0x0002, // Interlace
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
59 D64_FMT_FLI = 0x0004, // FLI
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
60 D64_FMT_CHAR = 0x0008, // Character mode
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62
1637
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
63
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
64 // Different types of interlace
530
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
65 enum
5b37a2e427b7 Greatly simplify and also improve the multicolor/hires/lace bitmap->image
Matti Hamalainen <ccr@tnsp.org>
parents: 516
diff changeset
66 {
1647
948d6fda722d Add sanity check for interlaced formats: check that the interlace type flags are set.
Matti Hamalainen <ccr@tnsp.org>
parents: 1645
diff changeset
67 D64_ILACE_NONE = 0x0000, // Not set (invalid for interlaced images)
1637
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
68 D64_ILACE_RES = 0x0001, // Interlace doubles resolution
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
69 D64_ILACE_COLOR = 0x0002, // Uses color mixing
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
936
5104a7c87d7b Remove some unused structures, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
72
5104a7c87d7b Remove some unused structures, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
73 // Charmode screen memory configuration
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
74 enum
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
75 {
936
5104a7c87d7b Remove some unused structures, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
76 D64_CHCFG_SCREEN, // Use screen memory
5104a7c87d7b Remove some unused structures, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
77 D64_CHCFG_LINEAR = 1, // Generate linear pattern so that first line
5104a7c87d7b Remove some unused structures, etc.
Matti Hamalainen <ccr@tnsp.org>
parents: 931
diff changeset
78 // of chars is 0-39, second 40-79, up to 255.
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
79 };
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
80
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
81
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 typedef struct
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 BOOL multicolor, xexpand, yexpand;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 int color, xc, yc;
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
86 Uint8 data[C64_SPR_HEIGHT][C64_SPR_WIDTH];
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 } DMC64Sprite;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
512
95a6b6af53f1 Add some structures and enums for future.
Matti Hamalainen <ccr@tnsp.org>
parents: 511
diff changeset
89
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
90 enum
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
91 {
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
92 DC_D020,
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
93 DC_BGCOL,
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
94 DC_D021,
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
95 DC_D022,
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
96 DC_D023,
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
97 DC_D024,
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
98 };
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
99
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
101 typedef struct
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
102 {
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
103 Uint8 *data;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
104 size_t size;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
105 } DMC64MemBlock;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
106
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
107
1374
9edb17aa4a0a Forward declare typedef struct _DMC64Image;
Matti Hamalainen <ccr@tnsp.org>
parents: 1373
diff changeset
108 typedef struct _DMC64Image
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 {
922
658bf4c452d0 Comments, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 921
diff changeset
110 int type, // Image type (D64_FMT_*)
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1376
diff changeset
111 laceType, // Interlace type (D64_ILACE_*)
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1376
diff changeset
112 nbanks;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 926
diff changeset
114 int width, height; // Width and height in pixels
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1467
diff changeset
115 int chWidth, chHeight; // Width and height in charblocks
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1467
diff changeset
116
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
117 // Bitmaps, color RAM, screen, etc. blocks * nbanks
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
118 // Not all of them may be allocated
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
119 DMC64MemBlock
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
120 *color,
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
121 *bitmap,
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
122 *screen,
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
123 *charData;
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 926
diff changeset
124
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
125 // Other standard colours
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
126 Uint8 d020, bgcolor, d022, d023, d024;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
128 // Extra data areas used by some formats,
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
129 // for example raster colours might be stored
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
130 DMC64MemBlock extraData[C64_MAX_EXTRA_DATA];
1376
67ae449cf9e1 More work on making various FLI etc. format decoding more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1375
diff changeset
131
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 DMC64Sprite sprites[C64_MAX_SPRITES];
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 } DMC64Image;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1374
diff changeset
136 typedef Uint8 (*DMC64GetPixelFunc)(
1376
67ae449cf9e1 More work on making various FLI etc. format decoding more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1375
diff changeset
137 const DMC64Image *img, const int bmoffs, const int scroffs,
67ae449cf9e1 More work on making various FLI etc. format decoding more flexible.
Matti Hamalainen <ccr@tnsp.org>
parents: 1375
diff changeset
138 const int vshift, const int vbitmap, const int raster);
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1374
diff changeset
139
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 enum
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 DT_COLOR_RAM,
1586
3c9e5962eca6 Rename DT_BITMAP to DT_BITMAP_RAM.
Matti Hamalainen <ccr@tnsp.org>
parents: 1584
diff changeset
143 DT_BITMAP_RAM,
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 DT_SCREEN_RAM,
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
145 DT_COLOR_REG,
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
146 DT_COLOR_SET,
1373
fc5ee5b4b0e9 Improve handling of extra data.
Matti Hamalainen <ccr@tnsp.org>
parents: 1365
diff changeset
147 DT_EXTRA_DATA,
916
3985f596ece5 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 915
diff changeset
148
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 507
diff changeset
149 DT_DEC_FUNCTION,
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 507
diff changeset
150 DT_ENC_FUNCTION,
917
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
151
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
152 DT_CHAR_DATA,
df3a74f230d9 Initial implementation of charmode support in lib64gfx.
Matti Hamalainen <ccr@tnsp.org>
parents: 916
diff changeset
153 DT_CHAR_CONFIG,
925
23b14d62bf67 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 924
diff changeset
154
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 DT_LAST,
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 };
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157
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
158
1379
1e67dd44351e Increase maximum number of enc/dec operations for C64 images.
Matti Hamalainen <ccr@tnsp.org>
parents: 1378
diff changeset
159 #define D64_MAX_ENCDEC_OPS 64
937
51dc33efd126 Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 936
diff changeset
160
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
161
1486
bc13af8954d7 Add DMC64ImageFormat to C64 bitmap format encoding/decoding ops function parameters.
Matti Hamalainen <ccr@tnsp.org>
parents: 1482
diff changeset
162 typedef struct _DMC64ImageFormat DMC64ImageFormat;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 507
diff changeset
164 typedef struct _DMC64EncDecOp
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 {
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 int type;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 size_t offs;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 int bank;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 size_t size;
1486
bc13af8954d7 Add DMC64ImageFormat to C64 bitmap format encoding/decoding ops function parameters.
Matti Hamalainen <ccr@tnsp.org>
parents: 1482
diff changeset
170 BOOL (*decFunction)(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt);
bc13af8954d7 Add DMC64ImageFormat to C64 bitmap format encoding/decoding ops function parameters.
Matti Hamalainen <ccr@tnsp.org>
parents: 1482
diff changeset
171 BOOL (*encFunction)(const struct _DMC64EncDecOp *op, DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt);
510
43ea59887c69 Start work on making C64 formats encoding possible by changing DMDecodeOps
Matti Hamalainen <ccr@tnsp.org>
parents: 507
diff changeset
172 } DMC64EncDecOp;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174
1592
91d1bb571fca Implement common encdec ops lists for sharing oplists between formats that
Matti Hamalainen <ccr@tnsp.org>
parents: 1591
diff changeset
175 typedef DMC64EncDecOp DMC64EncDecOpList[D64_MAX_ENCDEC_OPS];
91d1bb571fca Implement common encdec ops lists for sharing oplists between formats that
Matti Hamalainen <ccr@tnsp.org>
parents: 1591
diff changeset
176
91d1bb571fca Implement common encdec ops lists for sharing oplists between formats that
Matti Hamalainen <ccr@tnsp.org>
parents: 1591
diff changeset
177
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 typedef struct _DMC64ImageFormat
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 {
922
658bf4c452d0 Comments, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 921
diff changeset
180 int type; // Type flags, see D64_FMT_*
658bf4c452d0 Comments, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 921
diff changeset
181 char *fext; // Filename extension
658bf4c452d0 Comments, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 921
diff changeset
182 char *name; // Format description/name
658bf4c452d0 Comments, cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 921
diff changeset
183
511
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
184 size_t addr; // Loading address (0 if no loading address)
1495
acb607e2c350 Clarify a comment.
Matti Hamalainen <ccr@tnsp.org>
parents: 1494
diff changeset
185 size_t size; // Size, including loading address. Only used in probing and encoding.
924
732787cccca8 Add dimension (w/h) information fields to C64 image format struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 923
diff changeset
186
1545
3b613fcbf3ff Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
187 int flags; // DM_FMT_* flags, see libgfx.h
3b613fcbf3ff Improve how format read/write capabilities are marked and shown.
Matti Hamalainen <ccr@tnsp.org>
parents: 1537
diff changeset
188
924
732787cccca8 Add dimension (w/h) information fields to C64 image format struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 923
diff changeset
189 int width, height; // Width and height in pixels
1482
df6dacb48970 Rename some struct members, and sanitize handling of DMC64Image allocation more.
Matti Hamalainen <ccr@tnsp.org>
parents: 1467
diff changeset
190 int chWidth, chHeight; // Width and height in charblocks
924
732787cccca8 Add dimension (w/h) information fields to C64 image format struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 923
diff changeset
191
511
4cdcaeb68b54 Collapse most of the probing functions into one generic probe, as they only
Matti Hamalainen <ccr@tnsp.org>
parents: 510
diff changeset
192 int (*probe)(const Uint8 *buf, const size_t len, const struct _DMC64ImageFormat *fmt);
1442
3773281491c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1426
diff changeset
193
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
194 int (*decode)(DMC64Image *img, const Uint8 *buf, const size_t len, const struct _DMC64ImageFormat *fmt);
1465
88845f95e791 Change dmC64EncodeGenericBMP() to use DMGrowBuf, and make the necessary changes in gfxconv as well.
Matti Hamalainen <ccr@tnsp.org>
parents: 1457
diff changeset
195 int (*encode)(DMGrowBuf *buf, const DMC64Image *img, const struct _DMC64ImageFormat *fmt);
1442
3773281491c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1426
diff changeset
196
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1374
diff changeset
197 int (*convertFrom)(DMImage *, const DMC64Image *, const struct _DMC64ImageFormat *fmt);
1442
3773281491c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1426
diff changeset
198 int (*convertTo)(DMC64Image *, const DMImage *, const struct _DMC64ImageFormat *fmt);
3773281491c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1426
diff changeset
199
1375
f5368c13a872 Implement more flexible generic format decoding by separating the pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1374
diff changeset
200 DMC64GetPixelFunc getPixel;
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
1592
91d1bb571fca Implement common encdec ops lists for sharing oplists between formats that
Matti Hamalainen <ccr@tnsp.org>
parents: 1591
diff changeset
202 const DMC64EncDecOpList encdecOps, *encdecOpsRef;
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203 } DMC64ImageFormat;
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
1637
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
206 //
1650
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
207 // Compression types and flags
1637
58ef0124394d Add some comments.
Matti Hamalainen <ccr@tnsp.org>
parents: 1592
diff changeset
208 //
1650
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
209 enum
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
210 {
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
211 DM_COMP_RLE_MARKER = 1, // RLE with a separate marker byte
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
212 DM_COMP_RLE_MASK = 2, // RLE that has marker bits and lower part acts as run length
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
213 };
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
214
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
215 enum
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
216 {
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
217 DM_RLE_8BIT_RUNS = 0x0001, // Uses one-byte runs
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
218 DM_RLE_16BIT_RUNS = 0x0002, // Uses two-byte runs
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
219 DM_RLE_RUNS_MASK = 0x000f,
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
220
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
221 DM_RLE_ORDER_1 = 0x0000, // Order: <marker>, <count/run length>, <data>
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
222 DM_RLE_ORDER_2 = 0x0010, // Order: <marker>, <data>, <count/run length>
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
223 DM_RLE_ORDER_MASK = 0x00f0,
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
224 };
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
225
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
226
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
227 typedef struct
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
228 {
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
229 int type;
1650
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
230 int flags;
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
231 Uint8
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
232 rleMarker1, rleMarker2,
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
233 rleMask1, rleMask2,
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
234 rleMinCount, rleMaxCount;
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
235 } DMCompParams;
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
236
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
237
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
238 //
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
239 // Global variables
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
240 //
1426
4c7b456d7f0b Rename global dmC64Palette to dmDefaultC64Palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 1380
diff changeset
241 extern DMColor dmDefaultC64Palette[C64_NCOLORS];
516
6f141f760c54 Constify.
Matti Hamalainen <ccr@tnsp.org>
parents: 515
diff changeset
242 extern const DMC64ImageFormat dmC64ImageFormats[];
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 extern const int ndmC64ImageFormats;
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1486
diff changeset
245
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
246 //
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
247 // Miscellaneous functions
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
248 //
1644
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1637
diff changeset
249 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng);
1488
c71b6c5204af Factor the C64 bitmap image format info dump function to lib64gfx and use it from 64vw.
Matti Hamalainen <ccr@tnsp.org>
parents: 1486
diff changeset
250 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt);
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
251
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
252 void dmSetDefaultC64Palette(DMImage *img);
1644
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1637
diff changeset
253 BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr);
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
254 int dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt);
1645
262300a0359b Add helper functions dmReverse{Get,Put}Byte().
Matti Hamalainen <ccr@tnsp.org>
parents: 1644
diff changeset
255 BOOL dmReverseGetByte(const Uint8 *buf, size_t *offs, Uint8 *data);
262300a0359b Add helper functions dmReverse{Get,Put}Byte().
Matti Hamalainen <ccr@tnsp.org>
parents: 1644
diff changeset
256 BOOL dmReversePutByte(Uint8 *buf, size_t *offs, const Uint8 data);
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
257
1644
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1637
diff changeset
258 // C64 bitmap image allocation/freeing
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
259 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
260 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
261 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
262
1378
c465860e44ed Make c64 image bank allocation dynamic.
Matti Hamalainen <ccr@tnsp.org>
parents: 1376
diff changeset
263 DMC64Image *dmC64ImageAlloc(const DMC64ImageFormat *fmt);
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 926
diff changeset
264 void dmC64ImageFree(DMC64Image *img);
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 926
diff changeset
265
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 926
diff changeset
266
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
267 // Encoding and decoding of formats and images
1644
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1637
diff changeset
268 int dmC64ConvertCSDataToImage(DMImage *img, int xoffs, int yoffs, const Uint8 *inBuf, int width, int height, BOOL multicolor, int *colors);
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1637
diff changeset
269
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1637
diff changeset
270 int dmC64SanityCheckEncDecOp(const int i, const DMC64EncDecOp *op, const DMC64Image *img);
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1637
diff changeset
271 BOOL dmC64GetOpSize(const DMC64EncDecOp *op, const DMC64ImageFormat *fmt, size_t *size);
9d9a0e852b3d Reorder some functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 1637
diff changeset
272
1442
3773281491c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1426
diff changeset
273 int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **fmt);
3773281491c9 Cleanups.
Matti Hamalainen <ccr@tnsp.org>
parents: 1426
diff changeset
274
410
e4b2f689aff6 Stdint -> SDL types conversion.
Matti Hamalainen <ccr@tnsp.org>
parents: 407
diff changeset
275 int dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt);
1499
32640e1934d5 Simplify some encoding bits.
Matti Hamalainen <ccr@tnsp.org>
parents: 1495
diff changeset
276 int dmC64EncodeGenericBMP(const BOOL allocate, DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt);
537
32d9e67da189 Rename generic probing function to match the style of other lib64gfx functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 534
diff changeset
277
940
ff18d2511843 Remove the doubleMC madness completely. Should be replaced with x/y aspect
Matti Hamalainen <ccr@tnsp.org>
parents: 937
diff changeset
278 int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt);
1467
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
279 int dmC64ConvertImage2BMP(DMC64Image **pdst, const DMImage *src, const DMC64ImageFormat *fmt);
1446
948b32bd67ef Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1442
diff changeset
280
931
2270d7f3af77 Refactor the DMC64Image handling to be more dynamic, and start
Matti Hamalainen <ccr@tnsp.org>
parents: 926
diff changeset
281 int dmC64DecodeBMP(DMC64Image **img, const Uint8 *buf, const size_t len, const size_t probeOffs, const size_t loadOffs, const DMC64ImageFormat **fmt, const DMC64ImageFormat *forced);
1467
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
282 int dmC64EncodeBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt);
419
936bc27a79d6 Modularize some functions to lib64gfx, fix bitmap -> image conversion,
Matti Hamalainen <ccr@tnsp.org>
parents: 418
diff changeset
283
1446
948b32bd67ef Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1442
diff changeset
284 int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt);
1467
32203356c652 Add some new functions that are mostly just stubs and not working tho.
Matti Hamalainen <ccr@tnsp.org>
parents: 1465
diff changeset
285 int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, const DMC64ImageFormat *fmt);
1446
948b32bd67ef Cosmetics.
Matti Hamalainen <ccr@tnsp.org>
parents: 1442
diff changeset
286
1650
9233da9de92c Refactor RLE encoding a bit, and add support for 16bit run counts and make things more configurable.
Matti Hamalainen <ccr@tnsp.org>
parents: 1647
diff changeset
287 void dmGenericRLEAnalyze(const Uint8 *buf, const size_t len, DMCompParams *cfg);
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
288
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
289 int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg);
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
290 int dmDecodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg);
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
291
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
292 int dmEncodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg);
3265175b24d2 Change the passing of RLE compression/decompression parameters to be in a dedicated struct.
Matti Hamalainen <ccr@tnsp.org>
parents: 1503
diff changeset
293 int dmEncodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg);
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
294
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
295
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
296 //
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
297 // Inline helper functions for pixel format decoding
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
298 //
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
299 static inline Uint8 dmC64GetGenericSCPixel(
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
300 const DMC64Image *img, const int bmoffs, const int scroffs,
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
301 const int vshift, const int vbank, const int vbitmap, const int cbank)
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
302 {
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
303 (void) cbank;
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
304 if ((img->bitmap[vbitmap].data[bmoffs] >> vshift) & 1)
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
305 return img->screen[vbank].data[scroffs] >> 4;
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
306 else
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
307 return img->screen[vbank].data[scroffs] & 15;
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
308 }
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
309
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
310
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
311 static inline Uint8 dmC64GetGenericMCPixel(
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
312 const DMC64Image *img, const int bmoffs, const int scroffs,
1577
632f1dbc83eb Get rid of some code duplication by merging functionality of certain pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1573
diff changeset
313 const int vshift, const int vbank, const int vbitmap, const int cbank,
632f1dbc83eb Get rid of some code duplication by merging functionality of certain pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1573
diff changeset
314 const int bgcolor)
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
315 {
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
316 switch ((img->bitmap[vbitmap].data[bmoffs] >> vshift) & 3)
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
317 {
1577
632f1dbc83eb Get rid of some code duplication by merging functionality of certain pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1573
diff changeset
318 case 0: return bgcolor;
1588
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
319 case 1: return img->screen[vbank].data[scroffs] >> 4;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
320 case 2: return img->screen[vbank].data[scroffs] & 15;
ca087c0cc9c4 Refactor the c64 format memory handling a bit for more flexibility.
Matti Hamalainen <ccr@tnsp.org>
parents: 1586
diff changeset
321 default: return img->color[cbank].data[scroffs] & 15;
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
322 }
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
323 }
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
324
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
325
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
326 static inline Uint8 fmtGetGenericSCPixel(
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
327 const DMC64Image *img, const int bmoffs, const int scroffs,
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
328 const int vshift, const int vbitmap, const int raster)
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
329 {
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
330 (void) raster;
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
331 return dmC64GetGenericSCPixel(img, bmoffs, scroffs, vshift, 0, vbitmap, 0);
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
332 }
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
333
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
334
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
335 static inline Uint8 fmtGetGenericMCPixel(
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
336 const DMC64Image *img, const int bmoffs, const int scroffs,
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
337 const int vshift, const int vbitmap, const int raster)
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
338 {
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
339 (void) raster;
1577
632f1dbc83eb Get rid of some code duplication by merging functionality of certain pixel
Matti Hamalainen <ccr@tnsp.org>
parents: 1573
diff changeset
340 return dmC64GetGenericMCPixel(img, bmoffs, scroffs, vshift, 0, vbitmap, 0, img->bgcolor);
1503
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
341 }
c7b9ef56319b Factor all the c64 file format specific things into lib64fmt.c
Matti Hamalainen <ccr@tnsp.org>
parents: 1499
diff changeset
342
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
343
1591
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
344 static inline const DMC64EncDecOp * fmtGetEncDecOp(const DMC64ImageFormat *fmt, const int index)
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
345 {
1592
91d1bb571fca Implement common encdec ops lists for sharing oplists between formats that
Matti Hamalainen <ccr@tnsp.org>
parents: 1591
diff changeset
346 // Ooh .. look at that beaauuuutiful deref ..
91d1bb571fca Implement common encdec ops lists for sharing oplists between formats that
Matti Hamalainen <ccr@tnsp.org>
parents: 1591
diff changeset
347 return fmt->encdecOpsRef != NULL ? &(* (fmt->encdecOpsRef))[index] : &fmt->encdecOps[index];
1591
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
348 }
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
349
3cc7b2aadda3 Add inline helper function fmtGetEncDecOp() and use it.
Matti Hamalainen <ccr@tnsp.org>
parents: 1588
diff changeset
350
435
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
351 #ifdef __cplusplus
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
352 }
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
353 #endif
e4a3f183e463 Modularize some more.
Matti Hamalainen <ccr@tnsp.org>
parents: 419
diff changeset
354
407
59244a7ae37f Move c64 utilities to the engine lib, as we benefit from a common framework.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
355 #endif // LIB64GFX_H