Mercurial > hg > dmlib
annotate src/libgfx.h @ 1286:b812fad6f33e
Work on libgfx.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 18 Aug 2017 15:20:44 +0300 |
parents | e4bda4909d72 |
children | 6c8b19d1d196 |
rev | line source |
---|---|
435 | 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" | |
947
5ac8f5513978
Delete useless include line.
Matti Hamalainen <ccr@tnsp.org>
parents:
929
diff
changeset
|
12 |
435 | 13 |
14 #ifdef __cplusplus | |
15 extern "C" { | |
16 #endif | |
17 | |
18 | |
19 enum | |
20 { | |
21 IMGFMT_PNG, | |
22 IMGFMT_PPM, | |
23 IMGFMT_PCX, | |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
435
diff
changeset
|
24 IMGFMT_ILBM, |
566
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
487
diff
changeset
|
25 IMGFMT_RAW, |
435 | 26 IMGFMT_ARAW, |
27 | |
28 IMGFMT_LAST | |
29 }; | |
30 | |
31 | |
32 enum | |
33 { | |
34 DM_IFMT_PALETTE, | |
35 DM_IFMT_RGB, | |
36 DM_IFMT_RGBA, | |
37 DM_IFMT_RGB_PLANE, | |
38 }; | |
39 | |
40 | |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
41 enum |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
42 { |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
43 DM_ERRMODE_FAIL = 0, |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
44 DM_ERRMODE_RECOV_1, |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
45 DM_ERRMODE_RECOV_2, |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
46 }; |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
47 |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
48 |
1286 | 49 // Bitmapped image struct |
435 | 50 typedef struct |
51 { | |
1286 | 52 int format; // one of types specified by DM_IFMT_* |
53 int width, height; | |
54 int pitch; // bytes per scanline | |
55 int bpp; // bits per pixel | |
56 | |
57 int ncolors; // number of colors in palette, if any | |
58 int ctransp; // transparency color index | |
59 BOOL constpal; // is the palette a const? | |
60 DMColor *pal; // pointer to palette struct, NULL if no palette | |
61 | |
929
e1378398be0f
Add size field for allocated data size in DMImage.
Matti Hamalainen <ccr@tnsp.org>
parents:
902
diff
changeset
|
62 size_t size; |
435 | 63 Uint8 *data; |
64 } DMImage; | |
65 | |
66 | |
67 typedef struct | |
68 { | |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
812
diff
changeset
|
69 int scaleX, scaleY, nplanes, format; |
435 | 70 BOOL interleave, paletted; |
71 } DMImageSpec; | |
72 | |
73 | |
74 typedef struct | |
75 { | |
76 char *fext; | |
77 char *desc; | |
78 int (*probe)(const Uint8 *buf, const size_t len); | |
79 int (*read)(const char *filename, DMImage **pimg); | |
80 int (*readFILE)(FILE *fp, DMImage **pimg); | |
81 int (*write)(const char *filename, DMImage *pimg, DMImageSpec *spec); | |
82 int (*writeFILE)(FILE *fp, DMImage *pimg, DMImageSpec *spec); | |
83 } DMImageFormat; | |
84 | |
85 | |
86 // Probe scores | |
87 #define DM_PROBE_SCORE_MAX 1000 | |
88 #define DM_PROBE_SCORE_GOOD 750 | |
89 #define DM_PROBE_SCORE_AVG 500 | |
90 #define DM_PROBE_SCORE_MAYBE 250 | |
91 #define DM_PROBE_SCORE_FALSE 0 | |
92 | |
93 | |
94 extern DMImageFormat dmImageFormatList[IMGFMT_LAST]; | |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
971
diff
changeset
|
95 extern int dmGFXErrorMode; |
435 | 96 |
97 | |
1286 | 98 DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp); |
435 | 99 void dmImageFree(DMImage *img); |
1286 | 100 int dmImageGetBytesPerPixel(const int format); |
435 | 101 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, DMImageFormat **fmt, int *index); |
102 | |
487
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
462
diff
changeset
|
103 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, BOOL alpha); |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
462
diff
changeset
|
104 |
435 | 105 |
808
f8126fa1df9b
Use dmlib error code return value in cases where a plain boolean was used
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
106 int dmWriteImageData(DMImage *img, void *cbdata, int (*writeRowCB)(void *, Uint8 *, size_t), const DMImageSpec *spec); |
435 | 107 |
462 | 108 int dmWriteIFFMasterRAWPalette(FILE *fp, DMImage *img, int ncolors, const char *indent, const char *type); |
566
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
487
diff
changeset
|
109 int dmWriteRAWImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec); |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
487
diff
changeset
|
110 int dmWriteRAWImage(const char *filename, DMImage *img, DMImageSpec *spec); |
435 | 111 |
112 int dmWritePPMImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec); | |
113 int dmWritePPMImage(const char *filename, DMImage *img, DMImageSpec *spec); | |
114 | |
115 #ifdef DM_USE_LIBPNG | |
116 int dmWritePNGImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec); | |
117 int dmWritePNGImage(const char *filename, DMImage *img, DMImageSpec *spec); | |
118 #endif | |
119 | |
120 int dmWritePCXImageFILE(FILE *fp, DMImage *img, DMImageSpec *spec); | |
121 int dmWritePCXImage(const char *filename, DMImage *img, DMImageSpec *spec); | |
122 int dmReadPCXImageFILE(FILE *fp, DMImage **pimg); | |
123 int dmReadPCXImage(const char *filename, DMImage **pimg); | |
124 | |
125 | |
126 #ifdef __cplusplus | |
127 } | |
128 #endif | |
129 | |
130 #endif // LIBMGFX_H |