Mercurial > hg > dmlib
view 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 |
line wrap: on
line source
/* * Functions for reading and manipulating some C64/etc graphics formats * Programmed and designed by Matti 'ccr' Hamalainen * (C) Copyright 2012 Tecnic Software productions (TNSP) * * Please read file 'COPYING' for information on license and distribution. */ #ifndef LIB64GFX_H #define LIB64GFX_H 1 #include "dmlib.h" // Bitmap constants #define C64_SCR_WIDTH 320 #define C64_SCR_HEIGHT 200 #define C64_SCR_CH_WIDTH (C64_SCR_WIDTH/8) #define C64_SCR_CH_HEIGHT (C64_SCR_HEIGHT/8) #define C64_SCR_COLOR_SIZE (C64_SCR_CH_WIDTH * C64_SCR_CH_HEIGHT) #define C64_SCR_SCREEN_SIZE (C64_SCR_CH_WIDTH * C64_SCR_CH_HEIGHT) #define C64_SCR_BITMAP_SIZE (C64_SCR_WIDTH * C64_SCR_HEIGHT/8) #define C64_SCR_EXTRADATA 1024 #define C64_SCR_MAX_BANK 8 // C64 video screen pixel aspect ratio on PAL #define C64_SCR_PAR_XY (0.9365f) // Sprite constants #define C64_SPR_WIDTH 3 // bytes #define C64_SPR_HEIGHT 21 // lines #define C64_SPR_WIDTH_PX (8 * C64_SPR_WIDTH) #define C64_SPR_SIZE ((C64_SPR_WIDTH * C64_SPR_HEIGHT) + 1) // Character constants #define C64_CHR_WIDTH 1 // bytes #define C64_CHR_HEIGHT 8 // lines #define C64_CHR_WIDTH_PX (8 * C64_CHR_WIDTH) #define C64_CHR_SIZE (C64_CHR_WIDTH * C64_CHR_HEIGHT) // Etc. #define C64_RAM_SIZE (64*1024) #define C64_NCOLORS 16 #define C64_MAX_COLORS 16 #define C64_VIDBANK_SIZE (16*1024) #define C64_MAX_SPRITES (C64_VIDBANK_SIZE / C64_SPR_SIZE) #define C64_MAX_CHARS 256 // Probe scores #define DM_PROBE_SCORE_MAX 1000 #define DM_PROBE_SCORE_GOOD 750 #define DM_PROBE_SCORE_AVG 500 #define DM_PROBE_SCORE_MAYBE 250 #define DM_PROBE_SCORE_FALSE 0 enum { DM_IFMT_PALETTE, DM_IFMT_RGB, DM_IFMT_RGBA, DM_IFMT_RGB_PLANE, }; // RGBx color struct typedef struct { uint8_t r, g, b, x; } DMColor; // Bitmapped image struct (can be one of types specified by DM_IFMT_*) typedef struct { int width, height, pitch; BOOL constpal; int ncolors, ctrans; DMColor *pal; uint8_t *data; } DMImage; // Different supported C64 bitmap "modes" enum { DM_C64IFMT_HIRES, DM_C64IFMT_MC, DM_C64IFMT_HIRES_ILACE, DM_C64IFMT_MC_ILACE, DM_C64IFMT_HIRES_FLI, DM_C64IFMT_MC_FLI, DM_C64IFMT_LAST_TYPE }; enum { DM_C64ILACE_COLOR, DM_C64ILACE_RES, }; typedef struct { BOOL multicolor, xexpand, yexpand; int color, xc, yc; uint8_t data[C64_SPR_HEIGHT][C64_SPR_WIDTH]; } DMC64Sprite; typedef struct { int type, // Image type (DM_C64IFMT_*) laceType, // Interlace type (DM_C64ILACE_*) fliType, // FLI type (if FLI used) fliLines, // FLI on every # line laceBank2; uint8_t color[C64_SCR_MAX_BANK][C64_SCR_COLOR_SIZE], bitmap[C64_SCR_MAX_BANK][C64_SCR_BITMAP_SIZE], screen[C64_SCR_MAX_BANK][C64_SCR_SCREEN_SIZE], extradata[C64_SCR_EXTRADATA], d020, bgcolor, d022, d023, d024; uint8_t charset[C64_MAX_CHARS][C64_CHR_HEIGHT * C64_CHR_WIDTH]; DMC64Sprite sprites[C64_MAX_SPRITES]; } DMC64Image; enum { DT_COLOR_RAM, DT_BITMAP, DT_SCREEN_RAM, DT_BGCOLOR, DT_EXTRADATA, DT_FUNCTION, DT_LAST, }; typedef struct _DMDecodeOp { int type; size_t offs; int bank; size_t size; BOOL (*function)(DMC64Image *img, const struct _DMDecodeOp *op, const uint8_t *buf, const size_t len); } DMDecodeOp; typedef struct _DMC64ImageFormat { int type; char *extension; char *name; int (*probe)(const uint8_t *buf, const size_t len); int (*decode)(DMC64Image *img, const uint8_t *buf, const size_t len, const struct _DMC64ImageFormat *fmt); int (*convert)(DMImage *, DMC64Image *); int ndecodeOps; DMDecodeOp decodeOps[16]; } DMC64ImageFormat; extern const size_t dmC64DefaultSizes[DT_LAST]; extern DMColor dmC64Palette[C64_NCOLORS]; extern DMC64ImageFormat dmC64ImageFormats[]; extern const int ndmC64ImageFormats; extern const char * dmC64ImageTypeNames[]; DMImage * dmImageAlloc(int width, int height); void dmImageFree(DMImage *img); int dmImageGetBytesPerPixel(int format); int dmC64ConvertCSData(DMImage *img, int xoffs, int yoffs, const uint8_t *inBuf, int width, int height, BOOL multicolor, int *colors); int dmC64ProbeGeneric(const uint8_t *buf, const size_t len, DMC64ImageFormat **fmt); int dmC64DecodeGenericBMP(DMC64Image *img, const uint8_t *buf, const size_t len, const DMC64ImageFormat *fmt); int dmC64ConvertGenericBMP2Image(DMImage *screen, const DMC64Image *img); int dmReadDataFile(const char *filename, uint8_t **buf, size_t *size); #endif // LIB64GFX_H