comparison tools/lib64gfx.h @ 1503:c7b9ef56319b

Factor all the c64 file format specific things into lib64fmt.c
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 11 May 2018 07:41:55 +0300
parents 32640e1934d5
children 3265175b24d2
comparison
equal deleted inserted replaced
1502:aa87cb6cf33b 1503:c7b9ef56319b
49 #define C64_VIDBANK_SIZE (16*1024) 49 #define C64_VIDBANK_SIZE (16*1024)
50 #define C64_MAX_SPRITES (C64_VIDBANK_SIZE / C64_SPR_SIZE) 50 #define C64_MAX_SPRITES (C64_VIDBANK_SIZE / C64_SPR_SIZE)
51 #define C64_MAX_CHARS 256 51 #define C64_MAX_CHARS 256
52 52
53 53
54 #define DM_RLE_MARKER 1
55 #define DM_RLE_MASK 2
56
57
58 #define DM_GET_ADDR_LO(addr) ((addr) & 0xff)
59 #define DM_GET_ADDR_HI(addr) (((addr) >> 8) & 0xff)
60
61
54 // Different supported C64 bitmap "modes" 62 // Different supported C64 bitmap "modes"
55 enum 63 enum
56 { 64 {
57 D64_FMT_HIRES = 0x0000, 65 D64_FMT_HIRES = 0x0000,
58 D64_FMT_MC = 0x0001, 66 D64_FMT_MC = 0x0001,
188 196
189 DMC64EncDecOp encdecOps[D64_MAX_ENCDEC_OPS]; 197 DMC64EncDecOp encdecOps[D64_MAX_ENCDEC_OPS];
190 } DMC64ImageFormat; 198 } DMC64ImageFormat;
191 199
192 200
201 //
202 // Global variables
203 //
193 extern DMColor dmDefaultC64Palette[C64_NCOLORS]; 204 extern DMColor dmDefaultC64Palette[C64_NCOLORS];
194 extern const DMC64ImageFormat dmC64ImageFormats[]; 205 extern const DMC64ImageFormat dmC64ImageFormats[];
195 extern const int ndmC64ImageFormats; 206 extern const int ndmC64ImageFormats;
196 207
197 208
209 //
210 // Miscellaneous functions
211 //
198 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt); 212 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt);
199 void dmSetDefaultC64Palette(DMImage *img); 213 void dmSetDefaultC64Palette(DMImage *img);
200 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng); 214 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng);
201 215 int dmC64ConvertCSDataToImage(DMImage *img, int xoffs, int yoffs, const Uint8 *inBuf, int width, int height, BOOL multicolor, int *colors);
202 216 int dmC64ImageGetNumBanks(const DMC64ImageFormat *fmt);
217 BOOL dmCompareAddr16(const Uint8 *buf, const size_t offs, const Uint16 addr);
218
219
220 // C64 bitmap image allocation/freeing
203 DMC64Image *dmC64ImageAlloc(const DMC64ImageFormat *fmt); 221 DMC64Image *dmC64ImageAlloc(const DMC64ImageFormat *fmt);
204 void dmC64ImageFree(DMC64Image *img); 222 void dmC64ImageFree(DMC64Image *img);
205 223
206 224
207 int dmC64ConvertCSDataToImage(DMImage *img, int xoffs, int yoffs, const Uint8 *inBuf, int width, int height, BOOL multicolor, int *colors); 225 // Encoding and decoding of formats and images
208
209 int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **fmt); 226 int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **fmt);
210 227
211 int dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt); 228 int dmC64DecodeGenericBMP(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt);
212 int dmC64EncodeGenericBMP(const BOOL allocate, DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt); 229 int dmC64EncodeGenericBMP(const BOOL allocate, DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt);
213 230
218 int dmC64EncodeBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt); 235 int dmC64EncodeBMP(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt);
219 236
220 int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt); 237 int dmC64ConvertGenericBMP2Image(DMImage *dst, const DMC64Image *src, const DMC64ImageFormat *fmt);
221 int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, const DMC64ImageFormat *fmt); 238 int dmC64ConvertGenericImage2BMP(DMC64Image *dst, const DMImage *src, const DMC64ImageFormat *fmt);
222 239
240 void dmGenericRLEAnalyze(const DMGrowBuf *buf, Uint8 *rleMarker, const int rleType);
241
242 int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd,
243 const Uint8 rleMarker, const Uint8 rleMask1, const Uint8 rleMask2, const int rleType);
244 int dmDecodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd,
245 const Uint8 rleMarker, const Uint8 rleMask1, const Uint8 rleMask2, const int rleType);
246
247 int dmEncodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd,
248 const Uint8 rleMarker, const Uint8 rleMinCount, const Uint8 rleMaxCount, const int rleType);
249 int dmEncodeGenericRLEAlloc(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd,
250 const Uint8 rleMarker, const Uint8 rleMinCount, const Uint8 rleMaxCount, const int rleType);
251
252
253 //
254 // Inline helper functions for pixel format decoding
255 //
256 static inline Uint8 dmC64GetGenericSCPixel(
257 const DMC64Image *img, const int bmoffs, const int scroffs,
258 const int vshift, const int vbank, const int vbitmap, const int cbank)
259 {
260 (void) cbank;
261 if ((img->bitmap[vbitmap][bmoffs] >> vshift) & 1)
262 return img->screen[vbank][scroffs] >> 4;
263 else
264 return img->screen[vbank][scroffs] & 15;
265 }
266
267
268 static inline Uint8 dmC64GetGenericMCPixel(
269 const DMC64Image *img, const int bmoffs, const int scroffs,
270 const int vshift, const int vbank, const int vbitmap, const int cbank)
271 {
272 switch ((img->bitmap[vbitmap][bmoffs] >> vshift) & 3)
273 {
274 case 0: return img->bgcolor; break;
275 case 1: return img->screen[vbank][scroffs] >> 4; break;
276 case 2: return img->screen[vbank][scroffs] & 15; break;
277 default: return img->color[cbank][scroffs] & 15; break;
278 }
279 }
280
281
282 static inline Uint8 fmtGetGenericSCPixel(
283 const DMC64Image *img, const int bmoffs, const int scroffs,
284 const int vshift, const int vbitmap, const int raster)
285 {
286 (void) raster;
287 return dmC64GetGenericSCPixel(img, bmoffs, scroffs, vshift, 0, vbitmap, 0);
288 }
289
290
291 static inline Uint8 fmtGetGenericMCPixel(
292 const DMC64Image *img, const int bmoffs, const int scroffs,
293 const int vshift, const int vbitmap, const int raster)
294 {
295 (void) raster;
296 return dmC64GetGenericMCPixel(img, bmoffs, scroffs, vshift, 0, vbitmap, 0);
297 }
298
223 299
224 #ifdef __cplusplus 300 #ifdef __cplusplus
225 } 301 }
226 #endif 302 #endif
227 303