comparison lib64gfx.h @ 407:59244a7ae37f

Move c64 utilities to the engine lib, as we benefit from a common framework.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 03 Nov 2012 02:19:51 +0200
parents
children e4b2f689aff6
comparison
equal deleted inserted replaced
406:a0160ffdf7e5 407:59244a7ae37f
1 /*
2 * Functions for reading and manipulating some C64/etc graphics formats
3 * Programmed and designed by Matti 'ccr' Hamalainen
4 * (C) Copyright 2012 Tecnic Software productions (TNSP)
5 *
6 * Please read file 'COPYING' for information on license and distribution.
7 */
8 #ifndef LIB64GFX_H
9 #define LIB64GFX_H 1
10
11 #include "dmlib.h"
12
13 // Bitmap constants
14 #define C64_SCR_WIDTH 320
15 #define C64_SCR_HEIGHT 200
16 #define C64_SCR_CH_WIDTH (C64_SCR_WIDTH/8)
17 #define C64_SCR_CH_HEIGHT (C64_SCR_HEIGHT/8)
18 #define C64_SCR_COLOR_SIZE (C64_SCR_CH_WIDTH * C64_SCR_CH_HEIGHT)
19 #define C64_SCR_SCREEN_SIZE (C64_SCR_CH_WIDTH * C64_SCR_CH_HEIGHT)
20 #define C64_SCR_BITMAP_SIZE (C64_SCR_WIDTH * C64_SCR_HEIGHT/8)
21 #define C64_SCR_EXTRADATA 1024
22 #define C64_SCR_MAX_BANK 8
23
24 // C64 video screen pixel aspect ratio on PAL
25 #define C64_SCR_PAR_XY (0.9365f)
26
27 // Sprite constants
28 #define C64_SPR_WIDTH 3 // bytes
29 #define C64_SPR_HEIGHT 21 // lines
30 #define C64_SPR_WIDTH_PX (8 * C64_SPR_WIDTH)
31 #define C64_SPR_SIZE ((C64_SPR_WIDTH * C64_SPR_HEIGHT) + 1)
32
33 // Character constants
34 #define C64_CHR_WIDTH 1 // bytes
35 #define C64_CHR_HEIGHT 8 // lines
36 #define C64_CHR_WIDTH_PX (8 * C64_CHR_WIDTH)
37 #define C64_CHR_SIZE (C64_CHR_WIDTH * C64_CHR_HEIGHT)
38
39 // Etc.
40 #define C64_RAM_SIZE (64*1024)
41 #define C64_NCOLORS 16
42 #define C64_MAX_COLORS 16
43 #define C64_VIDBANK_SIZE (16*1024)
44 #define C64_MAX_SPRITES (C64_VIDBANK_SIZE / C64_SPR_SIZE)
45 #define C64_MAX_CHARS 256
46
47 // Probe scores
48 #define DM_PROBE_SCORE_MAX 1000
49 #define DM_PROBE_SCORE_GOOD 750
50 #define DM_PROBE_SCORE_AVG 500
51 #define DM_PROBE_SCORE_MAYBE 250
52 #define DM_PROBE_SCORE_FALSE 0
53
54 enum
55 {
56 DM_IFMT_PALETTE,
57 DM_IFMT_RGB,
58 DM_IFMT_RGBA,
59 DM_IFMT_RGB_PLANE,
60 };
61
62
63 // RGBx color struct
64 typedef struct
65 {
66 uint8_t r, g, b, x;
67 } DMColor;
68
69
70 // Bitmapped image struct (can be one of types specified by DM_IFMT_*)
71 typedef struct
72 {
73 int width, height, pitch;
74 BOOL constpal;
75 int ncolors, ctrans;
76 DMColor *pal;
77 uint8_t *data;
78 } DMImage;
79
80
81 // Different supported C64 bitmap "modes"
82 enum
83 {
84 DM_C64IFMT_HIRES,
85 DM_C64IFMT_MC,
86 DM_C64IFMT_HIRES_ILACE,
87 DM_C64IFMT_MC_ILACE,
88 DM_C64IFMT_HIRES_FLI,
89 DM_C64IFMT_MC_FLI,
90
91 DM_C64IFMT_LAST_TYPE
92 };
93
94
95 enum
96 {
97 DM_C64ILACE_COLOR,
98 DM_C64ILACE_RES,
99 };
100
101 typedef struct
102 {
103 BOOL multicolor, xexpand, yexpand;
104 int color, xc, yc;
105 uint8_t data[C64_SPR_HEIGHT][C64_SPR_WIDTH];
106 } DMC64Sprite;
107
108
109 typedef struct
110 {
111 int type, // Image type (DM_C64IFMT_*)
112 laceType, // Interlace type (DM_C64ILACE_*)
113 fliType, // FLI type (if FLI used)
114 fliLines, // FLI on every # line
115 laceBank2;
116
117 uint8_t 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_t 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_EXTRADATA,
135
136 DT_FUNCTION,
137
138 DT_LAST,
139 };
140
141
142 typedef struct _DMDecodeOp
143 {
144 int type;
145 size_t offs;
146 int bank;
147 size_t size;
148 BOOL (*function)(DMC64Image *img, const struct _DMDecodeOp *op, const uint8_t *buf, const size_t len);
149 } DMDecodeOp;
150
151
152 typedef struct _DMC64ImageFormat
153 {
154 int type;
155 char *extension;
156 char *name;
157 int (*probe)(const uint8_t *buf, const size_t len);
158 int (*decode)(DMC64Image *img, const uint8_t *buf, const size_t len, const struct _DMC64ImageFormat *fmt);
159 int (*convert)(DMImage *, DMC64Image *);
160
161 int ndecodeOps;
162 DMDecodeOp decodeOps[16];
163 } DMC64ImageFormat;
164
165
166 extern const size_t dmC64DefaultSizes[DT_LAST];
167 extern DMColor dmC64Palette[C64_NCOLORS];
168 extern DMC64ImageFormat dmC64ImageFormats[];
169 extern const int ndmC64ImageFormats;
170 extern const char * dmC64ImageTypeNames[];
171
172
173 DMImage * dmImageAlloc(int width, int height);
174 void dmImageFree(DMImage *img);
175 int dmImageGetBytesPerPixel(int format);
176
177
178 int dmC64ConvertCSData(DMImage *img, int xoffs, int yoffs, const uint8_t *inBuf, int width, int height, BOOL multicolor, int *colors);
179 int dmC64ProbeGeneric(const uint8_t *buf, const size_t len, DMC64ImageFormat **fmt);
180 int dmC64DecodeGenericBMP(DMC64Image *img, const uint8_t *buf, const size_t len, const DMC64ImageFormat *fmt);
181 int dmC64ConvertGenericBMP2Image(DMImage *screen, const DMC64Image *img);
182 int dmReadDataFile(const char *filename, uint8_t **buf, size_t *size);
183
184 #endif // LIB64GFX_H