comparison libgfx.h @ 435:e4a3f183e463

Modularize some more.
author Matti Hamalainen <ccr@tnsp.org>
date Sat, 03 Nov 2012 16:08:30 +0200
parents
children f7c9d1619c74
comparison
equal deleted inserted replaced
434:380c226c75af 435:e4a3f183e463
1 /*
2 * Functions for loading and saving bitmap images
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 LIBMGFX_H
9 #define LIBMGFX_H 1
10
11 #include "dmlib.h"
12 #include "dmfile.h"
13
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17
18
19 enum
20 {
21 IMGFMT_PNG,
22 IMGFMT_PPM,
23 IMGFMT_PCX,
24 IMGFMT_ARAW,
25
26 IMGFMT_LAST
27 };
28
29
30 enum
31 {
32 DM_IFMT_PALETTE,
33 DM_IFMT_RGB,
34 DM_IFMT_RGBA,
35 DM_IFMT_RGB_PLANE,
36 };
37
38
39 // RGBx color struct
40 typedef struct
41 {
42 Uint8 r, g, b, x;
43 } DMColor;
44
45
46 // Bitmapped image struct (can be one of types specified by DM_IFMT_*)
47 typedef struct
48 {
49 int width, height, pitch;
50 BOOL constpal;
51 int ncolors, ctrans;
52 DMColor *pal;
53 Uint8 *data;
54 } DMImage;
55
56
57 typedef struct
58 {
59 int scale, nplanes, format;
60 BOOL interleave, paletted;
61 } DMImageSpec;
62
63
64 typedef struct
65 {
66 char *fext;
67 char *desc;
68 int (*probe)(const Uint8 *buf, const size_t len);
69 int (*read)(const char *filename, DMImage **pimg);
70 int (*readFILE)(FILE *fp, DMImage **pimg);
71 int (*write)(const char *filename, DMImage *pimg, DMImageSpec *spec);
72 int (*writeFILE)(FILE *fp, DMImage *pimg, DMImageSpec *spec);
73 } DMImageFormat;
74
75
76 // Probe scores
77 #define DM_PROBE_SCORE_MAX 1000
78 #define DM_PROBE_SCORE_GOOD 750
79 #define DM_PROBE_SCORE_AVG 500
80 #define DM_PROBE_SCORE_MAYBE 250
81 #define DM_PROBE_SCORE_FALSE 0
82
83
84 extern DMImageFormat dmImageFormatList[IMGFMT_LAST];
85
86
87 DMImage * dmImageAlloc(int width, int height);
88 void dmImageFree(DMImage *img);
89 int dmImageGetBytesPerPixel(int format);
90 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, DMImageFormat **fmt, int *index);
91
92
93 int dmWriteImageData(DMImage *img, void *cbdata, BOOL (*writeRowCB)(void *, Uint8 *, size_t), const DMImageSpec *spec);
94
95 int dmWriteIFFMasterRAWPalette(const char *filename, DMImage *img, int ncolors);
96 int dmWriteIFFMasterRAWImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec);
97 int dmWriteIFFMasterRAWImage(const char *filename, DMImage *img, DMImageSpec *spec);
98
99 int dmWritePPMImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec);
100 int dmWritePPMImage(const char *filename, DMImage *img, DMImageSpec *spec);
101
102 #ifdef DM_USE_LIBPNG
103 int dmWritePNGImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec);
104 int dmWritePNGImage(const char *filename, DMImage *img, DMImageSpec *spec);
105 #endif
106
107 int dmWritePCXImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec);
108 int dmWritePCXImage(const char *filename, DMImage *img, DMImageSpec *spec);
109 int dmReadPCXImageFILE(FILE *fp, DMImage **pimg);
110 int dmReadPCXImage(const char *filename, DMImage **pimg);
111
112
113 #ifdef __cplusplus
114 }
115 #endif
116
117 #endif // LIBMGFX_H