Mercurial > hg > dmlib
comparison tools/lib64gfx.h @ 1775:4e4d54135baf
Refactor the c64 bitmap format definitions handling to be more flexible. Again.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 12 Jun 2018 17:12:48 +0300 |
parents | 88354355b8e1 |
children | 5ea4713e9e0f |
comparison
equal
deleted
inserted
replaced
1774:88354355b8e1 | 1775:4e4d54135baf |
---|---|
184 | 184 |
185 | 185 |
186 typedef DMC64EncDecOp DMC64EncDecOpList[D64_MAX_ENCDEC_OPS]; | 186 typedef DMC64EncDecOp DMC64EncDecOpList[D64_MAX_ENCDEC_OPS]; |
187 | 187 |
188 | 188 |
189 typedef struct | |
190 { | |
191 int type; // Type flags, see D64_FMT_* | |
192 int width, height; // Width and height in pixels | |
193 int chWidth, chHeight; // Width and height in charblocks | |
194 | |
195 int (*convertFrom)(DMImage *, const DMC64Image *, const DMC64ImageFormat *fmt); | |
196 int (*convertTo)(DMC64Image *, const DMImage *, const DMC64ImageFormat *fmt); | |
197 | |
198 DMC64GetPixelFunc getPixel; | |
199 | |
200 DMC64EncDecOpList encdecOps; | |
201 } DMC64ImageCommonFormat; | |
202 | |
203 | |
189 typedef struct _DMC64ImageFormat | 204 typedef struct _DMC64ImageFormat |
190 { | 205 { |
191 int type; // Type flags, see D64_FMT_* | |
192 char *fext; // Filename extension | 206 char *fext; // Filename extension |
193 char *name; // Format description/name | 207 char *name; // Format description/name |
194 | 208 |
195 size_t addr; // Loading address (0 if no loading address) | 209 size_t addr; // Loading address (0 if no loading address) |
196 size_t size; // Size, including loading address. Only used in probing and encoding. | 210 size_t size; // Size, including loading address. Only used in probing and encoding. |
197 | 211 |
198 int flags; // DM_FMT_* flags, see libgfx.h | 212 int flags; // DM_FMT_* flags, see libgfx.h |
199 | 213 |
200 int width, height; // Width and height in pixels | 214 int (*probe)(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt); |
201 int chWidth, chHeight; // Width and height in charblocks | 215 |
202 | 216 int (*decode)(DMC64Image *img, const DMGrowBuf *buf, const DMC64ImageFormat *fmt); |
203 int (*probe)(const Uint8 *buf, const size_t len, const struct _DMC64ImageFormat *fmt); | 217 int (*encode)(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt); |
204 | 218 |
205 int (*decode)(DMC64Image *img, const DMGrowBuf *buf, const struct _DMC64ImageFormat *fmt); | 219 DMC64ImageCommonFormat formatDef, *format; |
206 int (*encode)(DMGrowBuf *buf, const DMC64Image *img, const struct _DMC64ImageFormat *fmt); | |
207 | |
208 int (*convertFrom)(DMImage *, const DMC64Image *, const struct _DMC64ImageFormat *fmt); | |
209 int (*convertTo)(DMC64Image *, const DMImage *, const struct _DMC64ImageFormat *fmt); | |
210 | |
211 DMC64GetPixelFunc getPixel; | |
212 | |
213 const DMC64EncDecOpList encdecOps, *encdecOpsRef; | |
214 } DMC64ImageFormat; | 220 } DMC64ImageFormat; |
215 | 221 |
216 | 222 |
217 // | 223 // |
218 // Compression types and flags | 224 // Compression types and flags |
271 | 277 |
272 // | 278 // |
273 // Global variables | 279 // Global variables |
274 // | 280 // |
275 extern DMColor dmDefaultC64Palette[C64_NCOLORS]; | 281 extern DMColor dmDefaultC64Palette[C64_NCOLORS]; |
276 extern const DMC64ImageFormat dmC64ImageFormats[]; | 282 extern DMC64ImageFormat dmC64ImageFormats[]; |
277 extern const int ndmC64ImageFormats; | 283 extern const int ndmC64ImageFormats; |
278 | 284 |
279 | 285 |
280 // | 286 // |
281 // Miscellaneous functions | 287 // Miscellaneous functions |
282 // | 288 // |
289 void dmC64InitializeFormats(void); | |
283 int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **fmt); | 290 int dmC64ProbeBMP(const Uint8 *buf, const size_t len, const DMC64ImageFormat **fmt); |
284 | 291 |
285 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng); | 292 char * dmC64GetImageTypeString(char *buf, const size_t len, const int type, const BOOL lng); |
286 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt); | 293 void dmC64ImageDump(FILE *fh, const DMC64Image *img, const DMC64ImageFormat *fmt); |
287 | 294 |
321 | 328 |
322 void dmGenericRLEAnalyze(const DMGrowBuf *buf, DMCompParams *cfg); | 329 void dmGenericRLEAnalyze(const DMGrowBuf *buf, DMCompParams *cfg); |
323 | 330 |
324 void dmSetupRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg); | 331 void dmSetupRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg); |
325 void dmFinishRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg); | 332 void dmFinishRLEBuffers(DMGrowBuf *dst, DMGrowBuf *src, const DMCompParams *cfg); |
333 | |
326 int dmGenericRLEOutputRun(DMGrowBuf *dst, const DMCompParams *cfg, const Uint8 data, const unsigned int count); | 334 int dmGenericRLEOutputRun(DMGrowBuf *dst, const DMCompParams *cfg, const Uint8 data, const unsigned int count); |
327 int dmEncodeGenericRLESequence(DMGrowBuf *dst, const Uint8 data, const unsigned int count, const DMCompParams *cfg); | 335 int dmEncodeGenericRLESequence(DMGrowBuf *dst, const Uint8 data, const unsigned int count, const DMCompParams *cfg); |
328 | 336 |
329 int dmDecodeGenericRLE(DMGrowBuf *dst, const DMGrowBuf *src, const DMCompParams *cfg); | 337 int dmDecodeGenericRLE(DMGrowBuf *dst, const DMGrowBuf *src, const DMCompParams *cfg); |
330 int dmDecodeGenericRLEAlloc(DMGrowBuf *dst, const DMGrowBuf *src, const DMCompParams *cfg); | 338 int dmDecodeGenericRLEAlloc(DMGrowBuf *dst, const DMGrowBuf *src, const DMCompParams *cfg); |
382 } | 390 } |
383 | 391 |
384 | 392 |
385 static inline const DMC64EncDecOp * fmtGetEncDecOp(const DMC64ImageFormat *fmt, const int index) | 393 static inline const DMC64EncDecOp * fmtGetEncDecOp(const DMC64ImageFormat *fmt, const int index) |
386 { | 394 { |
387 // Ooh .. look at that beaauuuutiful deref .. | 395 return &fmt->format->encdecOps[index]; |
388 return fmt->encdecOpsRef != NULL ? &(* (fmt->encdecOpsRef))[index] : &fmt->encdecOps[index]; | |
389 } | 396 } |
390 | 397 |
391 | 398 |
392 #ifdef __cplusplus | 399 #ifdef __cplusplus |
393 } | 400 } |