comparison tools/lib64gfx.h @ 912:70cbbd5b7aea

Moved lib64gfx files under tools, as it's not generic DMLIB module really.
author Matti Hamalainen <ccr@tnsp.org>
date Tue, 24 Feb 2015 00:47:39 +0200
parents src/lib64gfx.h@f29a6164ec80
children ba6b210c9bf4
comparison
equal deleted inserted replaced
911:602b4aa34293 912:70cbbd5b7aea
1 /*
2 * Functions for reading and converting various restricted
3 * C64/etc and/or indexed/paletted graphics formats.
4 * Programmed and designed by Matti 'ccr' Hamalainen
5 * (C) Copyright 2012 Tecnic Software productions (TNSP)
6 *
7 * Please read file 'COPYING' for information on license and distribution.
8 */
9 #ifndef LIB64GFX_H
10 #define LIB64GFX_H 1
11
12 #include "libgfx.h"
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18
19 // Bitmap constants
20 #define C64_SCR_WIDTH 320
21 #define C64_SCR_HEIGHT 200
22 #define C64_SCR_CH_WIDTH (C64_SCR_WIDTH/8)
23 #define C64_SCR_CH_HEIGHT (C64_SCR_HEIGHT/8)
24 #define C64_SCR_COLOR_SIZE (C64_SCR_CH_WIDTH * C64_SCR_CH_HEIGHT)
25 #define C64_SCR_SCREEN_SIZE (C64_SCR_CH_WIDTH * C64_SCR_CH_HEIGHT)
26 #define C64_SCR_BITMAP_SIZE (C64_SCR_WIDTH * C64_SCR_HEIGHT/8)
27 #define C64_SCR_EXTRADATA 1024
28 #define C64_SCR_MAX_BANK 8
29
30 // C64 video screen pixel aspect ratio on PAL
31 #define C64_SCR_PAR_XY (0.9365f)
32
33 // Sprite constants
34 #define C64_SPR_WIDTH 3 // bytes
35 #define C64_SPR_HEIGHT 21 // lines
36 #define C64_SPR_WIDTH_PX (8 * C64_SPR_WIDTH)
37 #define C64_SPR_SIZE ((C64_SPR_WIDTH * C64_SPR_HEIGHT) + 1)
38
39 // Character constants
40 #define C64_CHR_WIDTH 1 // bytes
41 #define C64_CHR_HEIGHT 8 // lines
42 #define C64_CHR_WIDTH_PX (8 * C64_CHR_WIDTH)
43 #define C64_CHR_SIZE (C64_CHR_WIDTH * C64_CHR_HEIGHT)
44
45 // Etc.
46 #define C64_RAM_SIZE (64*1024)
47 #define C64_NCOLORS 16
48 #define C64_MAX_COLORS 16
49 #define C64_VIDBANK_SIZE (16*1024)
50 #define C64_MAX_SPRITES (C64_VIDBANK_SIZE / C64_SPR_SIZE)
51 #define C64_MAX_CHARS 256
52
53 // Different supported C64 bitmap "modes"
54 enum
55 {
56 D64_FMT_HIRES = 0x0000,
57 D64_FMT_MC = 0x0001,
58 D64_FMT_ILACE = 0x0002,
59 D64_FMT_FLI = 0x0004,
60
61 D64_FMT_MODE_MASK = 0x000f,
62
63 };
64
65 enum
66 {
67 D64_FLI_2BANK,
68 D64_FLI_4BANK,
69 D64_FLI_8BANK,
70 };
71
72 enum
73 {
74 D64_ILACE_COLOR,
75 D64_ILACE_RES,
76 };
77
78 typedef struct
79 {
80 BOOL multicolor, xexpand, yexpand;
81 int color, xc, yc;
82 Uint8 data[C64_SPR_HEIGHT][C64_SPR_WIDTH];
83 } DMC64Sprite;
84
85 enum
86 {
87 D64_CHR_GLOBAL, // use font-global setting
88 D64_CHR_MULTICOLOR, // character is multicolor
89 D64_CHR_HIRES,
90 };
91
92 typedef struct
93 {
94 int mode, color;
95 Uint8 data[C64_CHR_HEIGHT];
96 } DMC64Char;
97
98
99 typedef struct
100 {
101 BOOL multicolor;
102 int colbg, color, col1, col2;
103 int nglyphs;
104 DMC64Char *glyphs;
105 } DMC64Font;
106
107
108
109 typedef struct
110 {
111 int type, // Image type (D64_FMT_*)
112 fliType, // FLI type (if FLI used)
113 laceType, // Interlace type (D64_ILACE_*)
114 laceBank1,
115 laceBank2;
116
117 Uint8 color[C64_SCR_MAX_BANK][C64_SCR_COLOR_SIZE],
118 bitmap[C64_SCR_MAX_BANK][C64_SCR_BITMAP_SIZE],
119 screen[C64_SCR_MAX_BANK][C64_SCR_SCREEN_SIZE],
120 extradata[C64_SCR_EXTRADATA],
121 d020, bgcolor, d022, d023, d024;
122
123 Uint8 charset[C64_MAX_CHARS][C64_CHR_HEIGHT * C64_CHR_WIDTH];
124 DMC64Sprite sprites[C64_MAX_SPRITES];
125 } DMC64Image;
126
127
128 enum
129 {
130 DT_COLOR_RAM,
131 DT_BITMAP,
132 DT_SCREEN_RAM,
133 DT_BGCOLOR,
134 DT_BGCOLOR_SET,
135 DT_EXTRADATA,
136
137 DT_DEC_FUNCTION,
138 DT_ENC_FUNCTION,
139
140 DT_LAST,
141 };
142
143
144 typedef struct _DMC64EncDecOp
145 {
146 int type;
147 size_t offs;
148 int bank;
149 size_t size;
150 BOOL (*decfunction)(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len);
151 BOOL (*encfunction)(const struct _DMC64EncDecOp *op, Uint8 **buf, size_t *len, const DMC64Image *img);
152 } DMC64EncDecOp;
153
154
155 typedef struct _DMC64ImageFormat
156 {
157 int type;
158 char *fext;
159 char *name;
160 size_t addr; // Loading address (0 if no loading address)
161 size_t size; // Size, including loading address. Only used in encoding, if even there (0 if no static size)
162 int (*probe)(const Uint8 *buf, const size_t len, const struct _DMC64ImageFormat *fmt);
163 int (*decode)(DMC64Image *img, const Uint8 *buf, const size_t len, const struct _DMC64ImageFormat *fmt);
164 int (*encode)(DMC64Image *img, Uint8 **buf, size_t *len, const struct _DMC64ImageFormat *fmt);
165 int (*convertFrom)(DMImage *, const DMC64Image *, const BOOL doubleMC);
166 int (*convertTo)(DMImage *, DMC64Image *);
167
168 int nencdecOps;
169 DMC64EncDecOp encdecOps[16];
170 } DMC64ImageFormat;
171
172
173 extern const size_t dmC64DefaultSizes[DT_LAST];
174 extern DMColor dmC64Palette[C64_NCOLORS];
175 extern const DMC64ImageFormat dmC64ImageFormats[];
176 extern const int ndmC64ImageFormats;
177
178
179 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type);
180 int dmC64ConvertCSDataToImage(DMImage *img, int xoffs, int yoffs, const Uint8 *inBuf, int width, int height, BOOL multicolor, int *colors);
181
182 int dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt);
183 int dmC64EncodeGenericBMP(Uint8 **pbuf, size_t *plen, const DMC64Image *img, const DMC64ImageFormat *fmt);
184 int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const BOOL doubleMC);
185
186 int dmC64ConvertBMP2Image(DMImage **pdst, const DMC64Image *src, const DMC64ImageFormat *fmt, const BOOL doubleMC);
187 int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **fmt);
188 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);
189
190
191 #ifdef __cplusplus
192 }
193 #endif
194
195 #endif // LIB64GFX_H