Mercurial > hg > dmlib
annotate tools/libgfx.c @ 2095:80786a28caf0
Mark image format flags with the color formats they support.
This information is not yet used.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 05 Mar 2019 09:57:32 +0200 |
parents | 4276b8c0fef0 |
children | 6b2bac1e3445 |
rev | line source |
---|---|
435 | 1 /* |
1308
8f71ca1900ea
Update header blurps and copyrights.
Matti Hamalainen <ccr@tnsp.org>
parents:
1307
diff
changeset
|
2 * Functions for reading and converting various graphics file formats |
435 | 3 * Programmed and designed by Matti 'ccr' Hamalainen |
1894 | 4 * (C) Copyright 2012-2018 Tecnic Software productions (TNSP) |
435 | 5 * |
6 * Please read file 'COPYING' for information on license and distribution. | |
7 */ | |
8 #include "libgfx.h" | |
9 | |
10 #ifdef DM_USE_LIBPNG | |
11 #include <png.h> | |
12 #endif | |
13 | |
14 | |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
15 int dmGFXErrorMode = DM_ERRMODE_FAIL; |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
16 |
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
17 |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
18 void dmInitBitStreamContext(DMBitStreamContext *ctx) |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
19 { |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
20 ctx->outBuf = 0; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
21 ctx->outByteCount = 0; |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
22 ctx->outBitCount = 0; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
23 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
24 ctx->inBuf = 0; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
25 ctx->inByteCount = 0; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
26 ctx->inBitCount = 0; |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
27 } |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
28 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
29 |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
30 int dmPutBits(DMBitStreamContext *ctx, const unsigned int val, const unsigned int n) |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
31 { |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
32 for (unsigned int i = 0; i < n; i++) |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
33 { |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
34 ctx->outBuf <<= 1; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
35 |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
36 if (val & (1 << (n - 1 - i))) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
37 ctx->outBuf |= 1; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
38 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
39 ctx->outBitCount++; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
40 if (ctx->outBitCount == 8) |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
41 { |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
42 int ret; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
43 if ((ret = ctx->putByte(ctx)) != DMERR_OK) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
44 return ret; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
45 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
46 ctx->outBitCount = 0; |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
47 ctx->outByteCount++; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
48 } |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
49 } |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
50 |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
51 return DMERR_OK; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
52 } |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
53 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
54 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
55 int dmGetBits(DMBitStreamContext *ctx, unsigned int *val, const unsigned int n) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
56 { |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
57 *val = 0; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
58 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
59 for (unsigned int i = 0; i < n; i++) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
60 { |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
61 if (ctx->inBitCount == 0) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
62 { |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
63 int ret; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
64 if ((ret = ctx->getByte(ctx)) != DMERR_OK) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
65 return ret; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
66 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
67 ctx->inBitCount = 8; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
68 ctx->inByteCount++; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
69 } |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
70 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
71 *val <<= 1; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
72 *val |= ctx->inBuf >> 7 & 1; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
73 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
74 ctx->inBuf <<= 1; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
75 ctx->inBitCount--; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
76 } |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
77 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
78 return DMERR_OK; |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
79 } |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
80 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
81 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
82 int dmFlushBitStream(DMBitStreamContext *ctx) |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
83 { |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
84 if (ctx == NULL) |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
85 return DMERR_NULLPTR; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
86 |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
87 if (ctx->outBitCount > 0) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
88 return dmPutBits(ctx, 0, 8 - ctx->outBitCount); |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
89 |
2083
feed844a5ae1
Return DMERR_OK where appropriate instead of 0.
Matti Hamalainen <ccr@tnsp.org>
parents:
2082
diff
changeset
|
90 return DMERR_OK; |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
91 } |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
92 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
93 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
94 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, const BOOL alpha) |
487
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
95 { |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
96 if (c1->r == c2->r && |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
97 c1->g == c2->g && |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
98 c1->b == c2->b) |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
99 return alpha ? (c1->a == c2->a) : TRUE; |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
100 else |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
101 return FALSE; |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
102 } |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
103 |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
104 |
1286 | 105 int dmImageGetBytesPerPixel(const int format) |
106 { | |
107 switch (format) | |
108 { | |
2092
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
109 case DM_COLFMT_GRAYSCALE : return 1; |
1801 | 110 case DM_COLFMT_PALETTE : return 1; |
111 case DM_COLFMT_RGB : return 3; | |
112 case DM_COLFMT_RGBA : return 4; | |
113 default : return -1; | |
1286 | 114 } |
115 } | |
116 | |
117 | |
2091 | 118 int dmImageGetBitsPerPixel(const int format) |
119 { | |
120 return dmImageGetBytesPerPixel(format) * 8; | |
121 } | |
122 | |
123 | |
1286 | 124 DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp) |
435 | 125 { |
928
ebe0d93e03c0
Use dmMalloc0() instead of dmCalloc() here.
Matti Hamalainen <ccr@tnsp.org>
parents:
902
diff
changeset
|
126 DMImage *img = dmMalloc0(sizeof(DMImage)); |
435 | 127 if (img == NULL) |
128 return NULL; | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
129 |
1286 | 130 img->width = width; |
131 img->height = height; | |
132 img->format = format; | |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
133 img->bpp = (bpp <= 0) ? dmImageGetBitsPerPixel(format) : bpp; |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
134 img->pitch = (width * img->bpp) / 8; |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
135 img->size = img->pitch * img->height; |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
136 img->aspect = -1; |
930 | 137 |
929
e1378398be0f
Add size field for allocated data size in DMImage.
Matti Hamalainen <ccr@tnsp.org>
parents:
928
diff
changeset
|
138 if ((img->data = dmMalloc(img->size)) == NULL) |
435 | 139 { |
140 dmFree(img); | |
141 return NULL; | |
142 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
143 |
435 | 144 return img; |
145 } | |
146 | |
147 | |
148 void dmImageFree(DMImage *img) | |
149 { | |
150 if (img != NULL) | |
151 { | |
152 if (!img->constpal) | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
153 dmPaletteFree(img->pal); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
154 |
435 | 155 dmFree(img->data); |
156 dmFree(img); | |
157 } | |
158 } | |
159 | |
160 | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
161 int dmPaletteAlloc(DMPalette **ppal, const int ncolors, const int ctransp) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
162 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
163 DMPalette *pal; |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
164 if (ppal == NULL) |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
165 return DMERR_NULLPTR; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
166 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
167 *ppal = NULL; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
168 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
169 // Allocate palette struct |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
170 if ((pal = dmMalloc0(sizeof(DMPalette))) == NULL) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
171 return DMERR_MALLOC; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
172 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
173 pal->ncolors = ncolors; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
174 pal->ctransp = ctransp; |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
175 |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
176 // Allocate desired amount of palette |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
177 if ((pal->colors = dmCalloc(pal->ncolors, sizeof(DMColor))) == NULL) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
178 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
179 dmFree(pal); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
180 return DMERR_MALLOC; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
181 } |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
182 |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
183 // Set alpha values to max, except for transparent color |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
184 for (int i = 0; i < pal->ncolors; i++) |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
185 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
186 pal->colors[i].a = (i == pal->ctransp) ? 0x00 : 0xff; |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
187 } |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
188 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
189 *ppal = pal; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
190 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
191 return DMERR_OK; |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
192 } |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
193 |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
194 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
195 int dmPaletteResize(DMPalette **ppal, const int ncolors) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
196 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
197 DMPalette *pal; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
198 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
199 if (ppal == NULL) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
200 return DMERR_NULLPTR; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
201 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
202 if (ncolors <= 0 || ncolors > 256) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
203 return DMERR_INVALID_ARGS; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
204 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
205 if (*ppal == NULL) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
206 return dmPaletteAlloc(ppal, ncolors, -1); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
207 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
208 pal = *ppal; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
209 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
210 if (pal->ncolors == ncolors) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
211 return DMERR_OK; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
212 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
213 if ((pal->colors = dmRealloc(pal->colors, sizeof(DMColor) * ncolors)) == NULL) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
214 return DMERR_MALLOC; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
215 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
216 if (ncolors - pal->ncolors > 0) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
217 memset(&(pal->colors[pal->ncolors]), 0, sizeof(DMColor) * (ncolors - pal->ncolors)); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
218 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
219 return DMERR_OK; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
220 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
221 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
222 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
223 int dmPaletteCopy(DMPalette **pdst, const DMPalette *src) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
224 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
225 DMPalette *pal; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
226 if (pdst == NULL) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
227 return DMERR_NULLPTR; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
228 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
229 *pdst = NULL; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
230 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
231 // Allocate palette struct |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
232 if ((pal = dmMalloc(sizeof(DMPalette))) == NULL) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
233 return DMERR_MALLOC; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
234 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
235 memcpy(pal, src, sizeof(DMPalette)); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
236 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
237 // Allocate desired amount of palette |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
238 if ((pal->colors = dmCalloc(pal->ncolors, sizeof(DMColor))) == NULL) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
239 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
240 dmFree(pal); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
241 return DMERR_MALLOC; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
242 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
243 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
244 memcpy(pal->colors, src->colors, sizeof(DMColor) * pal->ncolors); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
245 *pdst = pal; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
246 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
247 return DMERR_OK; |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
248 } |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
249 |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
250 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
251 void dmPaletteFree(DMPalette *pal) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
252 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
253 if (pal != NULL) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
254 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
255 dmFree(pal->colors); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
256 dmFree(pal); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
257 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
258 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
259 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
260 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
261 static int dmPaletteReadData(DMResource *fp, DMPalette *pal, int ncolors) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
262 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
263 if (pal->ncolors < ncolors) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
264 return DMERR_INVALID_ARGS; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
265 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
266 for (int i = 0; i < ncolors; i++) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
267 { |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
268 Uint8 colR, colG, colB; |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
269 if (!dmf_read_byte(fp, &colR) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
270 !dmf_read_byte(fp, &colG) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
271 !dmf_read_byte(fp, &colB)) |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
272 return DMERR_FREAD; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
273 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
274 pal->colors[i].r = colR; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
275 pal->colors[i].g = colG; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
276 pal->colors[i].b = colB; |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
277 } |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
278 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
279 return DMERR_OK; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
280 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
281 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
282 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
283 static int dmPaletteWriteData(DMResource *fp, const DMPalette *pal, const int ncolors, const int npad) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
284 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
285 int i; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
286 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
287 if (pal == NULL || fp == NULL) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
288 return DMERR_NULLPTR; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
289 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
290 if (pal->ncolors < ncolors) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
291 return DMERR_INVALID_ARGS; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
292 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
293 for (i = 0; i < ncolors; i++) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
294 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
295 DMColor *col = &pal->colors[i]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
296 if (!dmf_write_byte(fp, col->r) || |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
297 !dmf_write_byte(fp, col->g) || |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
298 !dmf_write_byte(fp, col->b)) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
299 return DMERR_FWRITE; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
300 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
301 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
302 for (; i < npad; i++) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
303 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
304 if (!dmf_write_byte(fp, 0) || |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
305 !dmf_write_byte(fp, 0) || |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
306 !dmf_write_byte(fp, 0)) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
307 return DMERR_FWRITE; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
308 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
309 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
310 return DMERR_OK; |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
311 } |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
312 |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
313 |
2091 | 314 int dmWriteImageData(const DMImage *img, void *cbdata, |
315 int (*writeRowCB)(void *, const Uint8 *, const size_t), | |
316 const DMImageConvSpec *spec) | |
435 | 317 { |
318 int x, y, yscale, xscale, res = 0, rowSize, rowWidth; | |
319 Uint8 *row = NULL; | |
320 | |
321 // Allocate memory for row buffer | |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
322 rowWidth = img->width * spec->scaleX; |
435 | 323 rowSize = rowWidth * dmImageGetBytesPerPixel(spec->format); |
324 | |
325 if ((row = dmMalloc(rowSize + 16)) == NULL) | |
326 { | |
327 res = DMERR_MALLOC; | |
328 goto done; | |
329 } | |
330 | |
331 // Generate the image | |
332 for (y = 0; y < img->height; y++) | |
333 { | |
436
86f956e4580f
Cosmetics, rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
435
diff
changeset
|
334 Uint8 *ptr1 = row, |
435 | 335 *ptr2 = ptr1 + rowWidth, |
1291 | 336 *ptr3 = ptr2 + rowWidth, |
337 *ptr4 = ptr3 + rowWidth; | |
435 | 338 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
339 if (img->format == DM_COLFMT_PALETTE || |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
340 img->format == DM_COLFMT_GRAYSCALE) |
435 | 341 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
342 for (x = 0; x < img->width; x++) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
343 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
344 Uint8 c = img->data[(y * img->pitch) + (x * img->bpp) / 8], |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
345 qr, qg, qb, qa; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
346 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
347 if (c >= img->pal->ncolors) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
348 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
349 res = DMERR_INVALID_DATA; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
350 goto done; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
351 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
352 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
353 switch (spec->format) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
354 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
355 case DM_COLFMT_PALETTE: |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
356 case DM_COLFMT_GRAYSCALE: |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
357 for (xscale = 0; xscale < spec->scaleX; xscale++) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
358 *ptr1++ = c; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
359 break; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
360 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
361 case DM_COLFMT_RGBA: |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
362 qr = img->pal->colors[c].r; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
363 qg = img->pal->colors[c].g; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
364 qb = img->pal->colors[c].b; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
365 qa = img->pal->colors[c].a; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
366 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
367 if (spec->planar) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
368 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
369 for (xscale = 0; xscale < spec->scaleX; xscale++) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
370 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
371 *ptr1++ = qr; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
372 *ptr2++ = qg; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
373 *ptr3++ = qb; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
374 *ptr4++ = qa; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
375 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
376 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
377 else |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
378 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
379 for (xscale = 0; xscale < spec->scaleX; xscale++) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
380 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
381 *ptr1++ = qr; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
382 *ptr1++ = qg; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
383 *ptr1++ = qb; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
384 *ptr1++ = qa; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
385 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
386 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
387 break; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
388 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
389 case DM_COLFMT_RGB: |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
390 qr = img->pal->colors[c].r; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
391 qg = img->pal->colors[c].g; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
392 qb = img->pal->colors[c].b; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
393 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
394 if (spec->planar) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
395 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
396 for (xscale = 0; xscale < spec->scaleX; xscale++) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
397 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
398 *ptr1++ = qr; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
399 *ptr2++ = qg; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
400 *ptr3++ = qb; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
401 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
402 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
403 else |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
404 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
405 for (xscale = 0; xscale < spec->scaleX; xscale++) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
406 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
407 *ptr1++ = qr; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
408 *ptr1++ = qg; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
409 *ptr1++ = qb; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
410 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
411 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
412 break; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
413 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
414 default: |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
415 res = DMERR_NOT_SUPPORTED; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
416 goto done; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
417 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
418 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
419 } |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
420 else |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
421 if (img->format == DM_COLFMT_RGB || |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
422 img->format == DM_COLFMT_RGBA) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
423 { |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
424 Uint8 *sp = img->data + (y * img->pitch); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
425 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
426 for (x = 0; x < img->width; x++, sp += img->bpp / 8) |
435 | 427 switch (spec->format) |
428 { | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
429 case DM_COLFMT_RGBA: |
1291 | 430 if (spec->planar) |
435 | 431 { |
1291 | 432 for (xscale = 0; xscale < spec->scaleX; xscale++) |
433 { | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
434 *ptr1++ = sp[0]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
435 *ptr2++ = sp[1]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
436 *ptr3++ = sp[2]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
437 *ptr4++ = sp[3]; |
1291 | 438 } |
439 } | |
440 else | |
441 { | |
442 for (xscale = 0; xscale < spec->scaleX; xscale++) | |
443 { | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
444 *ptr1++ = sp[0]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
445 *ptr1++ = sp[1]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
446 *ptr1++ = sp[2]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
447 *ptr1++ = sp[3]; |
1291 | 448 } |
435 | 449 } |
450 break; | |
451 | |
1801 | 452 case DM_COLFMT_RGB: |
1291 | 453 if (spec->planar) |
435 | 454 { |
1291 | 455 for (xscale = 0; xscale < spec->scaleX; xscale++) |
456 { | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
457 *ptr1++ = sp[0]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
458 *ptr2++ = sp[1]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
459 *ptr3++ = sp[2]; |
1291 | 460 } |
435 | 461 } |
1291 | 462 else |
435 | 463 { |
1291 | 464 for (xscale = 0; xscale < spec->scaleX; xscale++) |
465 { | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
466 *ptr1++ = sp[0]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
467 *ptr1++ = sp[1]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
468 *ptr1++ = sp[2]; |
1291 | 469 } |
435 | 470 } |
471 break; | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
472 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
473 default: |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
474 res = DMERR_NOT_SUPPORTED; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
475 goto done; |
435 | 476 } |
477 } | |
478 | |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
479 for (yscale = 0; yscale < spec->scaleY; yscale++) |
435 | 480 { |
808
f8126fa1df9b
Use dmlib error code return value in cases where a plain boolean was used
Matti Hamalainen <ccr@tnsp.org>
parents:
800
diff
changeset
|
481 if ((res = writeRowCB(cbdata, row, rowSize)) != DMERR_OK) |
435 | 482 goto done; |
483 } | |
484 } | |
485 | |
486 done: | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
487 dmFree(row); |
435 | 488 return res; |
489 } | |
490 | |
491 | |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
492 #define DMCOL(x) (((x) >> 4) & 0xf) |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
493 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
494 int dmWriteIFFMasterRAWHeader( |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
495 DMResource *fp, const char *filename, const char *prefix, |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2064
diff
changeset
|
496 const DMImage *img, const DMImageConvSpec *spec) |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
497 { |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
498 if (dmfprintf(fp, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
499 "%s_width: dw.w %d\n" |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
500 "%s_height: dw.w %d\n" |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
501 "%s_nplanes: dw.w %d\n", |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
502 prefix, img->width * spec->scaleX, |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
503 prefix, img->height * spec->scaleY, |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
504 prefix, spec->nplanes) < 0) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
505 return dmferror(fp); |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
506 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2064
diff
changeset
|
507 if (spec->fmtid == DM_IMGFMT_ARAW) |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
508 { |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
509 if (dmfprintf(fp, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
510 "%s_ncolors: dw.w %d\n" |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
511 "%s_palette:\n", |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
512 prefix, img->pal->ncolors, |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
513 prefix) < 0) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
514 return dmferror(fp); |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
515 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
516 for (int i = 0; i < (1 << spec->nplanes); i++) |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
517 { |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
518 Uint32 color; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
519 if (i < img->pal->ncolors) |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
520 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
521 color = (DMCOL(img->pal->colors[i].r) << 8) | |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
522 (DMCOL(img->pal->colors[i].g) << 4) | |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
523 (DMCOL(img->pal->colors[i].b)); |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
524 } |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
525 else |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
526 color = 0; |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
527 |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
528 if (dmfprintf(fp, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
529 "\tdc.w $%04X\n", |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
530 color) < 0) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
531 return dmferror(fp); |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
532 } |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
533 |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
534 if (dmfprintf(fp, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
535 "%s: incbin \"%s\"\n", |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
536 prefix, filename) < 0) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
537 return dmferror(fp); |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
538 } |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
539 |
1887
297aa8f0ca7f
Return DMERR_OK instead of dmferror(fp) dmWriteIFFMasterRAWHeader().
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
540 return DMERR_OK; |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
541 } |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
542 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
543 |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
544 static int dmWriteRAWRow(DMBitStreamContext *bs, const DMImage *img, |
2085 | 545 const DMImageConvSpec *spec, const int yc, const int plane) |
1872
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
546 { |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
547 const Uint8 *sp = img->data + (yc * img->pitch); |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
548 for (int xc = 0; xc < img->width; xc++) |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
549 { |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
550 int res; |
1872
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
551 for (int xscale = 0; xscale < spec->scaleX; xscale++) |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
552 if ((res = dmPutBits(bs, (sp[xc] >> plane) & 1, 1)) != DMERR_OK) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
553 return res; |
1872
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
554 } |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
555 return DMERR_OK; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
556 } |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
557 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
558 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
559 static int dmPutByteRes(DMBitStreamContext *ctx) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
560 { |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
561 DMResource *fp = (DMResource *) ctx->handle; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
562 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
563 if (!dmf_write_byte(fp, ctx->outBuf & 0xff)) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
564 return dmferror(fp); |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
565 else |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
566 return DMERR_OK; |
1872
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
567 } |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
568 |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
569 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
570 int dmWriteRAWImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) |
435 | 571 { |
1622 | 572 int res; |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
573 DMBitStreamContext ctx; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
574 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
575 dmInitBitStreamContext(&ctx); |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
576 ctx.putByte = dmPutByteRes; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
577 ctx.handle = (void *) fp; |
435 | 578 |
1291 | 579 if (spec->planar) |
435 | 580 { |
1339 | 581 // Output bitplanes in planar format |
582 // (each plane of line sequentially) | |
1622 | 583 for (int yc = 0; yc < img->height; yc++) |
1872
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
584 for (int yscale = 0; yscale < spec->scaleY; yscale++) |
1622 | 585 for (int plane = 0; plane < spec->nplanes; plane++) |
435 | 586 { |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
587 if ((res = dmWriteRAWRow(&ctx, img, spec, yc, plane)) != DMERR_OK) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
588 return res; |
435 | 589 } |
590 } | |
591 else | |
592 { | |
593 // Output each bitplane in sequence | |
1622 | 594 for (int plane = 0; plane < spec->nplanes; plane++) |
595 for (int yc = 0; yc < img->height; yc++) | |
1872
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
596 for (int yscale = 0; yscale < spec->scaleY; yscale++) |
435 | 597 { |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
598 if ((res = dmWriteRAWRow(&ctx, img, spec, yc, plane)) != DMERR_OK) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
599 return res; |
435 | 600 } |
601 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
602 |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
603 return dmFlushBitStream(&ctx); |
435 | 604 } |
605 | |
566
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
487
diff
changeset
|
606 |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
607 static int dmPutByteCDump(DMBitStreamContext *ctx) |
2047
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
608 { |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
609 DMResource *fp = (DMResource *) ctx->handle; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
610 |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
611 if (dmfprintf(fp, "0x%02x, ", ctx->outBuf & 0xff) < 2) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
612 return dmferror(fp); |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
613 else |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
614 return DMERR_OK; |
2047
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
615 } |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
616 |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
617 |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
618 int dmWriteCDumpImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
619 { |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
620 int res; |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
621 DMBitStreamContext ctx; |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
622 |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
623 if (dmfprintf(fp, |
2047
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
624 "#define SET_WIDTH %d\n" |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
625 "#define SET_HEIGHT %d\n" |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
626 "\n" |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
627 "Uint8 img_data[] = {\n", |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
628 img->width * spec->scaleX, |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
629 img->height * spec->scaleY) < 0) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
630 return dmferror(fp); |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
631 |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
632 dmInitBitStreamContext(&ctx); |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
633 ctx.putByte = dmPutByteCDump; |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
634 ctx.handle = (void *) fp; |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
635 |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
636 if (spec->planar) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
637 { |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
638 // Output bitplanes in planar format |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
639 // (each plane of line sequentially) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
640 for (int yc = 0; yc < img->height; yc++) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
641 for (int yscale = 0; yscale < spec->scaleY; yscale++) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
642 for (int plane = 0; plane < spec->nplanes; plane++) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
643 { |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
644 if ((res = dmWriteRAWRow(&ctx, img, spec, yc, plane)) != DMERR_OK) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
645 return res; |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
646 |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
647 if (dmfprintf(fp, "\n") < 0) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
648 return dmferror(fp); |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
649 } |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
650 } |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
651 else |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
652 { |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
653 // Output each bitplane in sequence |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
654 for (int plane = 0; plane < spec->nplanes; plane++) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
655 for (int yc = 0; yc < img->height; yc++) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
656 for (int yscale = 0; yscale < spec->scaleY; yscale++) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
657 { |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
658 if ((res = dmWriteRAWRow(&ctx, img, spec, yc, plane)) != DMERR_OK) |
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
659 return res; |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
660 |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
661 if (dmfprintf(fp, "\n") < 0) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
662 return dmferror(fp); |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
663 } |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
664 } |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
665 |
2086
aedadff9e116
Implement dmGetBits() to the DMBitStreamContext API. Also improve error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2085
diff
changeset
|
666 res = dmFlushBitStream(&ctx); |
2049
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
667 |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
668 if (res == DMERR_OK && |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
669 dmfprintf(fp, "};\n") < 0) |
a945a5f2fd70
Improve the cdump output format support of gfxconv. Also add some error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
2047
diff
changeset
|
670 res = dmferror(fp); |
2047
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
671 |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
672 return res; |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
673 } |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
674 |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
675 |
1301 | 676 static int dmWritePPMRow(void *cbdata, const Uint8 *row, const size_t len) |
435 | 677 { |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
678 if (dmf_write_str((DMResource *) cbdata, row, len)) |
808
f8126fa1df9b
Use dmlib error code return value in cases where a plain boolean was used
Matti Hamalainen <ccr@tnsp.org>
parents:
800
diff
changeset
|
679 return DMERR_OK; |
f8126fa1df9b
Use dmlib error code return value in cases where a plain boolean was used
Matti Hamalainen <ccr@tnsp.org>
parents:
800
diff
changeset
|
680 else |
f8126fa1df9b
Use dmlib error code return value in cases where a plain boolean was used
Matti Hamalainen <ccr@tnsp.org>
parents:
800
diff
changeset
|
681 return DMERR_FWRITE; |
435 | 682 } |
683 | |
684 | |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
685 int dmWritePPMImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) |
435 | 686 { |
1290
e7dc9bb9777e
Rename struct DMImageSpec to DMImageConvSpec.
Matti Hamalainen <ccr@tnsp.org>
parents:
1288
diff
changeset
|
687 DMImageConvSpec tmpSpec; |
2092
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
688 char *tmpFmt; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
689 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
690 memcpy(&tmpSpec, spec, sizeof(DMImageConvSpec)); |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
691 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
692 switch (spec->format) |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
693 { |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
694 case DM_COLFMT_RGB: |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
695 case DM_COLFMT_RGBA: |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
696 case DM_COLFMT_PALETTE: |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
697 tmpSpec.format = DM_COLFMT_RGB; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
698 tmpFmt = "6"; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
699 break; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
700 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
701 case DM_COLFMT_GRAYSCALE: |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
702 tmpFmt = "5"; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
703 break; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
704 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
705 default: |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
706 return dmError(DMERR_NOT_SUPPORTED, |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
707 "PPM: Not a supported color format for PPM/PGM format image.\n"); |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
708 } |
1288 | 709 |
435 | 710 // Write PPM header |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
711 char *tmp = dm_strdup_printf( |
2092
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
712 "P%s\n%d %d\n255\n", |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
713 tmpFmt, |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
714 img->width * spec->scaleX, |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
715 img->height * spec->scaleY); |
435 | 716 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
717 if (tmp == NULL) |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
718 return DMERR_MALLOC; |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
719 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
720 dmfputs(tmp, fp); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
721 dmFree(tmp); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
722 |
435 | 723 // Write image data |
1288 | 724 return dmWriteImageData(img, (void *) fp, dmWritePPMRow, &tmpSpec); |
435 | 725 } |
726 | |
727 | |
2092
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
728 int dmReadPPMImage(DMResource *fp, DMImage **pimg) |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
729 { |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
730 DMImage *img = NULL; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
731 unsigned int width, height; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
732 int itype, res = DMERR_OK; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
733 char hdr1[8], hdr2[32], hdr3[16]; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
734 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
735 // Read PPM header |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
736 if (dmfgets(hdr1, sizeof(hdr1), fp) == NULL || |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
737 dmfgets(hdr2, sizeof(hdr2), fp) == NULL || |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
738 dmfgets(hdr3, sizeof(hdr3), fp) == NULL) |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
739 { |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
740 res = dmError(DMERR_FREAD, |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
741 "PPM: Could not read image header data.\n"); |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
742 goto error; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
743 } |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
744 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
745 if (hdr1[0] != 'P' || !isdigit(hdr1[1]) || |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
746 !isdigit(hdr2[0]) || !isdigit(hdr3[0])) |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
747 { |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
748 res = dmError(DMERR_NOT_SUPPORTED, |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
749 "PPM: Not a supported PPM/PGM format image.\n"); |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
750 goto error; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
751 } |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
752 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
753 switch (hdr1[1]) |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
754 { |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
755 case '6': itype = DM_COLFMT_RGB; break; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
756 case '5': itype = DM_COLFMT_GRAYSCALE; break; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
757 default: |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
758 res = dmError(DMERR_NOT_SUPPORTED, |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
759 "PPM: Unsupported PPM/PNM/PGM subtype.\n"); |
2092
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
760 goto error; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
761 } |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
762 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
763 if (sscanf(hdr2, "%u %u", &width, &height) != 2) |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
764 { |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
765 res = dmError(DMERR_INVALID_DATA, |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
766 "PPM: Invalid PPM/PGM image dimensions.\n"); |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
767 goto error; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
768 } |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
769 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
770 dmMsg(2, "PPM: %d x %d, type=%d\n", |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
771 width, height, itype); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
772 |
2092
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
773 if ((*pimg = img = dmImageAlloc(width, height, itype, -1)) == NULL) |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
774 { |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
775 res = dmError(DMERR_MALLOC, |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
776 "PPM: Could not allocate image data.\n"); |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
777 goto error; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
778 } |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
779 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
780 if (!dmf_read_str(fp, img->data, img->size)) |
2092
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
781 { |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
782 res = dmError(DMERR_FREAD, |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
783 "PPM: Could not read image data.\n"); |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
784 goto error; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
785 } |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
786 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
787 error: |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
788 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
789 return res; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
790 } |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
791 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
792 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
793 static int fmtProbePPM(const Uint8 *buf, const size_t len) |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
794 { |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
795 if (len > 32 && |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
796 buf[0] == 'P' && |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
797 buf[1] == '5' && |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
798 buf[2] == 0x0a && isdigit(buf[3])) |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
799 return DM_PROBE_SCORE_MAX; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
800 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
801 return DM_PROBE_SCORE_FALSE; |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
802 } |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
803 |
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
804 |
435 | 805 #ifdef DM_USE_LIBPNG |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
806 static int fmtProbePNG(const Uint8 *buf, const size_t len) |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
807 { |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
808 if (len > 64 && buf[0] == 0x89 && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
809 buf[1] == 'P' && buf[2] == 'N' && buf[3] == 'G' && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
810 buf[4] == 0x0d && buf[5] == 0x0a) |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
811 { |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
812 if (buf[12] == 'I' && buf[13] == 'H' && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
813 buf[14] == 'D' && buf[15] == 'R') |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
814 return DM_PROBE_SCORE_MAX; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
815 else |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
816 return DM_PROBE_SCORE_GOOD; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
817 } |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
818 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
819 return DM_PROBE_SCORE_FALSE; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
820 } |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
821 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
822 |
1301 | 823 static int dmWritePNGRow(void *cbdata, const Uint8 *row, const size_t len) |
435 | 824 { |
825 png_structp png_ptr = cbdata; | |
826 (void) len; | |
827 | |
828 if (setjmp(png_jmpbuf(png_ptr))) | |
808
f8126fa1df9b
Use dmlib error code return value in cases where a plain boolean was used
Matti Hamalainen <ccr@tnsp.org>
parents:
800
diff
changeset
|
829 return DMERR_INTERNAL; |
435 | 830 |
831 png_write_row(png_ptr, row); | |
832 | |
808
f8126fa1df9b
Use dmlib error code return value in cases where a plain boolean was used
Matti Hamalainen <ccr@tnsp.org>
parents:
800
diff
changeset
|
833 return DMERR_OK; |
435 | 834 } |
835 | |
836 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
837 static void dmPNGWriteData(png_structp png_ptr, png_bytep data, png_size_t length) |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
838 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
839 DMResource *res = (DMResource *) png_get_io_ptr(png_ptr); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
840 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
841 // XXX TODO: How the fuck does one do error handling here? |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
842 dmf_write_str(res, data, length); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
843 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
844 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
845 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
846 static void dmPNGWriteFlush(png_structp png_ptr) |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
847 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
848 (void) png_ptr; |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
849 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
850 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
851 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
852 int dmWritePNGImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) |
435 | 853 { |
854 png_structp png_ptr = NULL; | |
855 png_infop info_ptr = NULL; | |
1304
e968b259605b
Fix a warning about potentially clobbered variable due to setjmp() use.
Matti Hamalainen <ccr@tnsp.org>
parents:
1303
diff
changeset
|
856 int fmt, res; |
435 | 857 |
858 // Create PNG structures | |
859 png_ptr = png_create_write_struct( | |
860 PNG_LIBPNG_VER_STRING, | |
861 NULL, NULL, NULL); | |
862 | |
863 if (png_ptr == NULL) | |
864 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
865 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
866 "PNG: png_create_write_struct() failed.\n"); |
435 | 867 goto error; |
868 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
869 |
435 | 870 info_ptr = png_create_info_struct(png_ptr); |
871 if (info_ptr == NULL) | |
872 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
873 res = dmError(DMERR_INIT_FAIL, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
874 "PNG: png_create_info_struct(%p) failed.\n", |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
875 png_ptr); |
435 | 876 goto error; |
877 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
878 |
435 | 879 if (setjmp(png_jmpbuf(png_ptr))) |
880 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
881 res = dmError(DMERR_INIT_FAIL, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
882 "PNG: Error during image writing..\n"); |
435 | 883 goto error; |
884 } | |
885 | |
1304
e968b259605b
Fix a warning about potentially clobbered variable due to setjmp() use.
Matti Hamalainen <ccr@tnsp.org>
parents:
1303
diff
changeset
|
886 res = DMERR_OK; |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
887 png_set_write_fn(png_ptr, fp, dmPNGWriteData, dmPNGWriteFlush); |
435 | 888 |
889 // Write PNG header info | |
890 switch (spec->format) | |
891 { | |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
892 case DM_COLFMT_PALETTE : fmt = PNG_COLOR_TYPE_PALETTE; break; |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
893 case DM_COLFMT_GRAYSCALE : fmt = PNG_COLOR_TYPE_GRAY; break; |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
894 case DM_COLFMT_RGB : fmt = PNG_COLOR_TYPE_RGB; break; |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
895 case DM_COLFMT_RGBA : fmt = PNG_COLOR_TYPE_RGB_ALPHA; break; |
435 | 896 default: |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
897 res = dmError(DMERR_NOT_SUPPORTED, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
898 "PNG: Unsupported image format %d.\n", |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
899 spec->format); |
435 | 900 goto error; |
901 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
902 |
2022
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2020
diff
changeset
|
903 png_set_compression_level(png_ptr, spec->compression); |
eb6dafdd36dc
Add option -C for controlling output file compression (PNG and IFF for now) in gfxconv.
Matti Hamalainen <ccr@tnsp.org>
parents:
2020
diff
changeset
|
904 |
435 | 905 png_set_IHDR(png_ptr, info_ptr, |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
906 img->width * spec->scaleX, |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
907 img->height * spec->scaleY, |
2091 | 908 8, // bits per component: TODO: FIXME: calculate and use |
435 | 909 fmt, |
910 PNG_INTERLACE_NONE, | |
911 PNG_COMPRESSION_TYPE_DEFAULT, | |
912 PNG_FILTER_TYPE_DEFAULT); | |
913 | |
1287
32051ad352c8
Adjust debug messages and debug message levels in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1286
diff
changeset
|
914 dmMsg(2, "PNG: %d x %d, depth=%d, type=%d\n", |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
915 img->width * spec->scaleX, |
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
916 img->height * spec->scaleY, |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
917 8, fmt); |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
918 |
435 | 919 // Palette |
1801 | 920 if (spec->format == DM_COLFMT_PALETTE) |
435 | 921 { |
858
e7019bd83cca
Fix potential longjmp clobbering of variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
834
diff
changeset
|
922 png_colorp palette = png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * sizeof(png_color)); |
435 | 923 |
924 if (palette == NULL) | |
925 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
926 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
927 "PNG: Could not allocate palette structure."); |
435 | 928 goto error; |
929 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
930 |
1167 | 931 dmMemset(palette, 0, PNG_MAX_PALETTE_LENGTH * sizeof(png_color)); |
435 | 932 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
933 for (int i = 0; i < img->pal->ncolors; i++) |
435 | 934 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
935 palette[i].red = img->pal->colors[i].r; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
936 palette[i].green = img->pal->colors[i].g; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
937 palette[i].blue = img->pal->colors[i].b; |
435 | 938 } |
939 | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
940 png_set_PLTE(png_ptr, info_ptr, palette, img->pal->ncolors); |
1938
a8e475eede4a
Fix two memory leaks in the PNG writer/reader of libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1921
diff
changeset
|
941 png_free(png_ptr, palette); |
435 | 942 } |
943 | |
944 // png_set_gAMA(png_ptr, info_ptr, 2.2); | |
945 | |
946 png_write_info(png_ptr, info_ptr); | |
947 | |
948 | |
949 // Write compressed image data | |
950 dmWriteImageData(img, (void *) png_ptr, dmWritePNGRow, spec); | |
951 | |
952 // Write footer | |
953 png_write_end(png_ptr, NULL); | |
954 | |
955 error: | |
956 if (png_ptr && info_ptr) | |
957 png_destroy_write_struct(&png_ptr, &info_ptr); | |
958 | |
959 return res; | |
960 } | |
961 | |
962 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
963 void dmPNGReadData(png_structp png_ptr, png_bytep data, png_size_t length) |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
964 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
965 DMResource *res = (DMResource *) png_get_io_ptr(png_ptr); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
966 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
967 // XXX TODO: How the fuck does one do error handling here? |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
968 dmf_read_str(res, data, length); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
969 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
970 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
971 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
972 int dmReadPNGImage(DMResource *fp, DMImage **pimg) |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
973 { |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
974 png_structp png_ptr = NULL; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
975 png_infop info_ptr = NULL; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
976 png_colorp palette = NULL; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
977 png_bytep *row_pointers = NULL; |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
978 png_bytep trans = NULL; |
1940
c77019065b96
Initialize two variables to zero, as valgrind complains about them despite
Matti Hamalainen <ccr@tnsp.org>
parents:
1939
diff
changeset
|
979 png_uint_32 width, height, res_x = 0, res_y = 0; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
980 int res, itype, bit_depth, color_type, ncolors, ntrans, unit_type; |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
981 DMImage *img; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
982 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
983 // Create PNG structures |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
984 png_ptr = png_create_read_struct( |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
985 PNG_LIBPNG_VER_STRING, |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
986 NULL, NULL, NULL); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
987 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
988 if (png_ptr == NULL) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
989 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
990 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
991 "PNG: png_create_write_struct() failed.\n"); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
992 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
993 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
994 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
995 info_ptr = png_create_info_struct(png_ptr); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
996 if (info_ptr == NULL) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
997 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
998 res = dmError(DMERR_INIT_FAIL, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
999 "PNG: png_create_info_struct(%p) failed.\n", |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1000 png_ptr); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1001 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1002 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1003 |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1004 if (setjmp(png_jmpbuf(png_ptr))) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1005 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1006 res = dmError(DMERR_INIT_FAIL, |
1291 | 1007 "PNG: Error during image reading.\n"); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1008 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1009 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1010 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1011 png_set_read_fn(png_ptr, fp, dmPNGReadData); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1012 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1013 // Read image information |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1014 png_read_info(png_ptr, info_ptr); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1015 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1016 png_get_IHDR(png_ptr, info_ptr, &width, &height, |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1017 &bit_depth, &color_type, NULL, NULL, NULL); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1018 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1019 if (width < 1 || height < 1) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1020 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1021 res = dmError(DMERR_INVALID_DATA, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1022 "PNG: Invalid width or height (%d x %d)\n", |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1023 width, height); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1024 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1025 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1026 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1027 switch (color_type) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1028 { |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1029 case PNG_COLOR_TYPE_GRAY: |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1030 if (bit_depth > 8) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1031 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1032 res = dmError(DMERR_NOT_SUPPORTED, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1033 "PNG: Unsupported bit depth for grayscale image: %d\n", |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1034 bit_depth); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1035 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1036 } |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1037 |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1038 if (bit_depth < 8) |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1039 png_set_expand_gray_1_2_4_to_8(png_ptr); |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1040 |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1041 itype = DM_COLFMT_GRAYSCALE; |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1042 break; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1043 |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1044 case PNG_COLOR_TYPE_PALETTE: |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1045 png_set_packing(png_ptr); |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1046 itype = DM_COLFMT_PALETTE; |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1047 break; |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1048 |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1049 case PNG_COLOR_TYPE_RGB: |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1050 itype = DM_COLFMT_RGB; |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1051 break; |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1052 |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1053 case PNG_COLOR_TYPE_RGBA: |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1054 itype = DM_COLFMT_RGBA; |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1055 break; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1056 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1057 default: |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1058 res = dmError(DMERR_NOT_SUPPORTED, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1059 "PNG: RGB/RGBA images not supported for loading.\n"); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1060 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1061 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1062 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1063 // Allocate image |
1287
32051ad352c8
Adjust debug messages and debug message levels in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1286
diff
changeset
|
1064 dmMsg(2, "PNG: %d x %d, depth=%d, type=%d\n", |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1065 width, height, bit_depth, color_type); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1066 |
1300
fd442faa705f
"Fix" the PNG/ILBM decoding to not use actual bitdepths for indexed images, but force 8bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1299
diff
changeset
|
1067 if ((*pimg = img = dmImageAlloc(width, height, |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1068 itype, |
1300
fd442faa705f
"Fix" the PNG/ILBM decoding to not use actual bitdepths for indexed images, but force 8bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1299
diff
changeset
|
1069 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp |
fd442faa705f
"Fix" the PNG/ILBM decoding to not use actual bitdepths for indexed images, but force 8bits.
Matti Hamalainen <ccr@tnsp.org>
parents:
1299
diff
changeset
|
1070 -1 /* bit_depth */)) == NULL) |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1071 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1072 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1073 "PNG: Could not allocate image data.\n"); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1074 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1075 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1076 |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1077 // Set image aspect ratio |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1078 png_get_pHYs(png_ptr, info_ptr, &res_x, &res_y, &unit_type); |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1079 |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1080 if (res_x > 0 && res_y > 0 && |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1081 res_y / res_x != (unsigned) (img->height / img->width)) |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1082 img->aspect = (float) res_y / (float) res_x; |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1083 |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1084 // ... |
1938
a8e475eede4a
Fix two memory leaks in the PNG writer/reader of libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1921
diff
changeset
|
1085 if ((row_pointers = png_malloc(png_ptr, height * sizeof(png_bytep))) == NULL) |
a8e475eede4a
Fix two memory leaks in the PNG writer/reader of libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1921
diff
changeset
|
1086 goto error; |
a8e475eede4a
Fix two memory leaks in the PNG writer/reader of libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1921
diff
changeset
|
1087 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1088 for (int i = 0; i < img->height; i++) |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1089 row_pointers[i] = img->data + (i * img->pitch); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1090 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1091 png_read_image(png_ptr, row_pointers); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1092 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1093 png_read_end(png_ptr, NULL); |
1945
80d67f0e8567
Better fix for the PNG reader memory leak.
Matti Hamalainen <ccr@tnsp.org>
parents:
1942
diff
changeset
|
1094 png_free(png_ptr, row_pointers); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1095 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1096 // Create palette |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1097 if (color_type == PNG_COLOR_TYPE_PALETTE) |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1098 { |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1099 png_get_PLTE(png_ptr, info_ptr, &palette, &ncolors); |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1100 if (ncolors > 0 && palette != NULL) |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1101 { |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1102 dmMsg(2, "PNG: Palette of %d colors found.\n", ncolors); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1103 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1104 if ((res = dmPaletteAlloc(&(img->pal), ncolors, -1)) != DMERR_OK) |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1105 goto error; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1106 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1107 for (int i = 0; i < img->pal->ncolors; i++) |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1108 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1109 img->pal->colors[i].r = palette[i].red; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1110 img->pal->colors[i].g = palette[i].green; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1111 img->pal->colors[i].b = palette[i].blue; |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1112 } |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1113 } |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1114 |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
1115 png_get_tRNS(png_ptr, info_ptr, &trans, &ntrans, NULL); |
467
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
1116 if (trans != NULL && ntrans > 0) |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
1117 { |
2091 | 1118 dmMsg(2, "PNG: %d transparent colors.\n", ntrans); |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1119 for (int i = 0; i < img->pal->ncolors && i < ntrans; i++) |
467
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
1120 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1121 img->pal->colors[i].a = trans[i]; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1122 if (img->pal->ctransp < 0 && trans[i] == 0) |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1123 img->pal->ctransp = i; |
467
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
1124 } |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
1125 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1126 } |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
1127 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1128 res = DMERR_OK; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1129 |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1130 error: |
1939 | 1131 if (png_ptr != NULL && info_ptr != NULL) |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1132 png_destroy_read_struct(&png_ptr, &info_ptr, NULL); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1133 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1134 return res; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
1135 } |
435 | 1136 #endif |
1137 | |
1138 | |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1139 // |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1140 // Z-Soft PCX format |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1141 // |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1142 #define DMPCX_PAL_COLORS 16 // Number of internal palette colors |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1143 |
435 | 1144 typedef struct |
1145 { | |
1146 Uint8 r,g,b; | |
1147 } DMPCXColor; | |
1148 | |
1149 | |
1150 typedef struct | |
1151 { | |
2091 | 1152 Uint8 |
1153 manufacturer, // always 0x0a | |
1154 version, // Z-Soft PC Paintbrush version: | |
1288 | 1155 // 0 = v2.5 |
1156 // 2 = v2.8 with palette, | |
1157 // 3 = v2.8 without palette | |
1158 // 4 = PC Paintbrush for Windows | |
1159 // 5 = v3.0 or better | |
2091 | 1160 encoding, // usually 0x01 = RLE, 0x00 = uncompressed |
1161 bitsPerPlane; // bits per pixel per plane | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1162 |
435 | 1163 Uint16 xmin, ymin, xmax, ymax; |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1164 Uint16 hres, vres; // resolution in DPI, can be image dimensions as well. |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1165 DMPCXColor colorMap[DMPCX_PAL_COLORS]; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1166 Uint8 reserved; // should be set to 0 |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1167 Uint8 nplanes; // number of planes |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1168 Uint16 bpl; // bytes per plane LINE |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1169 Uint16 palInfo; // 1 = color/BW, 2 = grayscale |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1170 Uint16 hScreenSize, vScreenSize; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1171 Uint8 filler[54]; |
435 | 1172 } DMPCXHeader; |
1173 | |
1174 | |
1175 typedef struct | |
1176 { | |
1177 DMPCXHeader *header; | |
1178 Uint8 *buf; | |
1179 size_t bufLen, bufOffs; | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1180 DMResource *fp; |
435 | 1181 } DMPCXData; |
1182 | |
1183 | |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1184 static int fmtProbePCX(const Uint8 *buf, const size_t len) |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1185 { |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1186 if (len > 128 + 32 && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1187 (buf[1] == 5 || buf[1] == 2 || buf[1] == 3) && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1188 buf[2] == 1 && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1189 (buf[3] == 8 || buf[3] == 4 || buf[3] == 3 || buf[3] == 1) && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1190 buf[65] >= 1 && buf[65] <= 4) |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1191 return DM_PROBE_SCORE_GOOD; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1192 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1193 return DM_PROBE_SCORE_FALSE; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1194 } |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1195 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1196 |
1298 | 1197 // Returns one byte from row buffer (of length len) at offset soffs, |
1198 // OR zero if the offset is outside buffer. | |
1301 | 1199 static inline Uint8 dmPCXGetByte(const Uint8 *row, const size_t len, const size_t soffs) |
435 | 1200 { |
1201 return (soffs < len) ? row[soffs] : 0; | |
1202 } | |
1203 | |
1204 static BOOL dmPCXFlush(DMPCXData *pcx) | |
1205 { | |
1206 BOOL ret = TRUE; | |
1207 if (pcx->bufOffs > 0) | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1208 ret = dmf_write_str(pcx->fp, pcx->buf, pcx->bufOffs); |
1297 | 1209 |
435 | 1210 pcx->bufOffs = 0; |
1211 return ret; | |
1212 } | |
1213 | |
1214 static inline BOOL dmPCXPutByte(DMPCXData *pcx, const Uint8 val) | |
1215 { | |
1216 if (pcx->bufOffs < pcx->bufLen) | |
1217 { | |
1218 pcx->buf[pcx->bufOffs++] = val; | |
1219 return TRUE; | |
1220 } | |
1221 else | |
1222 return dmPCXFlush(pcx); | |
1223 } | |
1224 | |
1297 | 1225 |
1226 static int dmPCXPutData(DMPCXData *pcx, const Uint8 data, const int count) | |
1227 { | |
1228 if (count == 1 && (data & 0xC0) != 0xC0) | |
1229 { | |
1230 if (!dmPCXPutByte(pcx, data)) | |
1231 return DMERR_FWRITE; | |
1232 } | |
1233 else | |
1234 { | |
1235 if (!dmPCXPutByte(pcx, 0xC0 | count) || | |
1236 !dmPCXPutByte(pcx, data)) | |
1237 return DMERR_FWRITE; | |
1238 } | |
1239 return DMERR_OK; | |
1240 } | |
1241 | |
1242 | |
1301 | 1243 static int dmWritePCXRow(void *cbdata, const Uint8 *row, const size_t len) |
435 | 1244 { |
1245 DMPCXData *pcx = (DMPCXData *) cbdata; | |
1297 | 1246 int err; |
435 | 1247 size_t soffs = 0; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1248 |
435 | 1249 pcx->bufOffs = 0; |
1250 | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1251 for (int plane = 0; plane < pcx->header->nplanes; plane++) |
435 | 1252 { |
1253 Uint8 data = dmPCXGetByte(row, len, soffs++), | |
1254 count = 1; | |
1255 | |
1297 | 1256 size_t blen = pcx->header->bpl * pcx->header->nplanes; |
435 | 1257 while (soffs < blen) |
1258 { | |
1297 | 1259 if (data == dmPCXGetByte(row, len, soffs) && count < 0x3F) |
435 | 1260 { |
1261 count++; | |
1262 soffs++; | |
1263 } | |
1264 else | |
1265 { | |
1297 | 1266 if ((err = dmPCXPutData(pcx, data, count)) != DMERR_OK) |
1267 return err; | |
435 | 1268 |
1269 data = dmPCXGetByte(row, len, soffs++); | |
1270 count = 1; | |
1271 } | |
1272 } | |
1273 | |
1297 | 1274 if ((err = dmPCXPutData(pcx, data, count)) != DMERR_OK) |
1275 return err; | |
435 | 1276 |
1277 if (!dmPCXFlush(pcx)) | |
808
f8126fa1df9b
Use dmlib error code return value in cases where a plain boolean was used
Matti Hamalainen <ccr@tnsp.org>
parents:
800
diff
changeset
|
1278 return DMERR_FWRITE; |
435 | 1279 } |
1280 | |
808
f8126fa1df9b
Use dmlib error code return value in cases where a plain boolean was used
Matti Hamalainen <ccr@tnsp.org>
parents:
800
diff
changeset
|
1281 return DMERR_OK; |
435 | 1282 } |
1283 | |
1284 | |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
1285 int dmWritePCXImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *pspec) |
435 | 1286 { |
1287 DMPCXData pcx; | |
1288 DMPCXHeader hdr; | |
1303 | 1289 DMImageConvSpec spec; |
435 | 1290 int res; |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1291 |
1303 | 1292 // Always force planar for PCX |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1293 memcpy(&spec, pspec, sizeof(DMImageConvSpec)); |
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1294 spec.planar = TRUE; |
435 | 1295 |
1450
61a486e25dc7
24bit PCX writing does not work correctly, so return DMERR_NOT_SUPPORTED in the writer function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1341
diff
changeset
|
1296 // XXX: 24bit PCX does not work yet .. |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1297 if (spec.format != DM_COLFMT_PALETTE && |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1298 spec.format != DM_COLFMT_GRAYSCALE) |
1800
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1299 { |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1300 return dmError(DMERR_NOT_SUPPORTED, |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1301 "24bit PCX not supported yet.\n"); |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1302 } |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1303 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2064
diff
changeset
|
1304 if (spec.format == DM_COLFMT_PALETTE && img->pal == NULL) |
1800
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1305 { |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1306 return dmError(DMERR_NULLPTR, |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1307 "Image spec says paletted/indexed image, but palette pointer is NULL.\n"); |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
1308 } |
1450
61a486e25dc7
24bit PCX writing does not work correctly, so return DMERR_NOT_SUPPORTED in the writer function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1341
diff
changeset
|
1309 |
435 | 1310 // Create output file |
1311 pcx.buf = NULL; | |
1312 pcx.header = &hdr; | |
1313 pcx.fp = fp; | |
1314 | |
1315 // Create PCX header | |
1167 | 1316 dmMemset(&hdr, 0, sizeof(hdr)); |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1317 if (spec.format == DM_COLFMT_PALETTE || |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1318 spec.format == DM_COLFMT_GRAYSCALE) |
435 | 1319 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1320 const int ncolors = img->pal->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->pal->ncolors; |
2016 | 1321 for (int i = 0; i < ncolors; i++) |
435 | 1322 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1323 hdr.colorMap[i].r = img->pal->colors[i].r; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1324 hdr.colorMap[i].g = img->pal->colors[i].g; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1325 hdr.colorMap[i].b = img->pal->colors[i].b; |
435 | 1326 } |
1327 } | |
1328 hdr.manufacturer = 10; | |
1329 hdr.version = 5; | |
1330 hdr.encoding = 1; | |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1331 hdr.hres = img->width * spec.scaleX; |
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1332 hdr.vres = img->height * spec.scaleY; |
435 | 1333 hdr.xmin = hdr.ymin = 0; |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1334 hdr.xmax = (img->width * spec.scaleX) - 1; |
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1335 hdr.ymax = (img->height * spec.scaleY) - 1; |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1336 hdr.palInfo = 1; |
1283
642a0dd98c6e
Oops, forgot to adjust the writing and reading when adding two members to
Matti Hamalainen <ccr@tnsp.org>
parents:
1281
diff
changeset
|
1337 hdr.hScreenSize = hdr.hres; |
642a0dd98c6e
Oops, forgot to adjust the writing and reading when adding two members to
Matti Hamalainen <ccr@tnsp.org>
parents:
1281
diff
changeset
|
1338 hdr.vScreenSize = hdr.vres; |
435 | 1339 |
1291 | 1340 // TODO XXX .. maybe actually compute these asdf |
1341 hdr.bitsPerPlane = 8; | |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1342 hdr.nplanes = dmImageGetBytesPerPixel(spec.format); |
1291 | 1343 |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1344 res = img->width * spec.scaleX; |
435 | 1345 hdr.bpl = res / 2; |
1346 if (res % 2) hdr.bpl++; | |
1347 hdr.bpl *= 2; | |
1348 | |
1297 | 1349 dmMsg(2, |
1350 "PCX: xmin=%d, ymin=%d, xmax=%d, ymax=%d, res=%dx%d, scr=%dx%d\n", | |
1351 hdr.xmin, hdr.ymin, hdr.xmax, hdr.ymax, | |
1352 hdr.hres, hdr.vres, | |
1353 hdr.hScreenSize, hdr.vScreenSize); | |
1354 | |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2064
diff
changeset
|
1355 dmMsg(2, "PCX: nplanes=%d, bpp=%d, bpl=%d, colfmt=%d, planar=%s\n", |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1356 hdr.nplanes, hdr.bitsPerPlane, hdr.bpl, |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2064
diff
changeset
|
1357 spec.format, |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1358 spec.planar ? "yes" : "no" |
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1359 ); |
435 | 1360 |
1291 | 1361 // TODO XXX this is also bogus |
435 | 1362 pcx.bufLen = hdr.bpl * 4; |
1363 if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL) | |
1364 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1365 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1366 "PCX: Could not allocate %d bytes for RLE compression buffer.\n", |
435 | 1367 pcx.bufLen); |
1368 goto error; | |
1369 } | |
1370 | |
1371 // Write PCX header | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1372 if (!dmf_write_byte(pcx.fp, hdr.manufacturer) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1373 !dmf_write_byte(pcx.fp, hdr.version) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1374 !dmf_write_byte(pcx.fp, hdr.encoding) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1375 !dmf_write_byte(pcx.fp, hdr.bitsPerPlane)) |
435 | 1376 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1377 res = dmError(DMERR_FWRITE, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1378 "PCX: Could not write basic header data.\n"); |
435 | 1379 goto error; |
1380 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1381 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1382 if (!dmf_write_le16(pcx.fp, hdr.xmin) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1383 !dmf_write_le16(pcx.fp, hdr.ymin) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1384 !dmf_write_le16(pcx.fp, hdr.xmax) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1385 !dmf_write_le16(pcx.fp, hdr.ymax) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1386 !dmf_write_le16(pcx.fp, hdr.hres) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1387 !dmf_write_le16(pcx.fp, hdr.vres)) |
435 | 1388 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1389 res = dmError(DMERR_FWRITE, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1390 "PCX: Could not write image dimensions.\n"); |
435 | 1391 goto error; |
1392 } | |
1393 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1394 if (!dmf_write_str(pcx.fp, (Uint8 *) &hdr.colorMap, sizeof(hdr.colorMap))) |
435 | 1395 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1396 res = dmError(DMERR_FWRITE, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1397 "PCX: Could not write colormap.\n"); |
435 | 1398 goto error; |
1399 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1400 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1401 if (!dmf_write_byte(pcx.fp, hdr.reserved) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1402 !dmf_write_byte(pcx.fp, hdr.nplanes) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1403 !dmf_write_le16(pcx.fp, hdr.bpl) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1404 !dmf_write_le16(pcx.fp, hdr.palInfo) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1405 !dmf_write_le16(pcx.fp, hdr.hScreenSize) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1406 !dmf_write_le16(pcx.fp, hdr.vScreenSize) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1407 !dmf_write_str(pcx.fp, (Uint8 *) &hdr.filler, sizeof(hdr.filler))) |
435 | 1408 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1409 res = dmError(DMERR_FWRITE, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1410 "PCX: Could not write header remainder.\n"); |
435 | 1411 goto error; |
1412 } | |
1413 | |
1414 // Write image data | |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1415 res = dmWriteImageData(img, (void *) &pcx, dmWritePCXRow, &spec); |
435 | 1416 |
1417 // Write VGA palette | |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1418 if (spec.format == DM_COLFMT_PALETTE || |
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1419 spec.format == DM_COLFMT_GRAYSCALE) |
435 | 1420 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1421 dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->pal->ncolors); |
1294
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1422 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1423 dmf_write_byte(pcx.fp, 0x0C); |
435 | 1424 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1425 if ((res = dmPaletteWriteData(fp, img->pal, img->pal->ncolors, 256)) != DMERR_OK) |
435 | 1426 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1427 res = dmError(DMERR_FWRITE, |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1428 "PCX: Could not write palette data.\n"); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1429 goto error; |
435 | 1430 } |
1431 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1432 |
435 | 1433 error: |
1434 dmFree(pcx.buf); | |
1435 return res; | |
1436 } | |
1437 | |
1438 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1439 static BOOL dmPCXDecodeRLERow(DMResource *fp, Uint8 *buf, const size_t bufLen) |
435 | 1440 { |
1441 size_t offs = 0; | |
1442 do | |
1443 { | |
1444 int count; | |
1445 Uint8 data; | |
1446 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1447 if (!dmf_read_byte(fp, &data)) |
435 | 1448 return FALSE; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1449 |
435 | 1450 if ((data & 0xC0) == 0xC0) |
1451 { | |
1284 | 1452 BOOL skip = FALSE; |
435 | 1453 count = data & 0x3F; |
1284 | 1454 if (count == 0) |
1455 { | |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1456 switch (dmGFXErrorMode) |
1284 | 1457 { |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1458 case DM_ERRMODE_RECOV_1: |
1284 | 1459 // Use as literal |
1460 skip = TRUE; | |
1461 count = 1; | |
1462 break; | |
1463 | |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1464 case DM_ERRMODE_RECOV_2: |
1284 | 1465 // Ignore completely |
1466 skip = TRUE; | |
1467 break; | |
1468 | |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1469 case DM_ERRMODE_FAIL: |
1284 | 1470 default: |
1471 // Error out on "invalid" data | |
1472 return FALSE; | |
1473 } | |
1474 } | |
1475 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1476 if (!skip && !dmf_read_byte(fp, &data)) |
435 | 1477 return FALSE; |
1478 } | |
1479 else | |
1480 count = 1; | |
1481 | |
1482 while (count-- && offs < bufLen) | |
1483 buf[offs++] = data; | |
1484 | |
1284 | 1485 // Check for remaining output count, error out if we wish to |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1486 if (count > 0 && dmGFXErrorMode == DM_ERRMODE_FAIL) |
1284 | 1487 return FALSE; |
1488 | |
435 | 1489 } while (offs < bufLen); |
1490 | |
1491 return TRUE; | |
1492 } | |
1493 | |
1494 | |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
1495 int dmReadPCXImage(DMResource *fp, DMImage **pimg) |
435 | 1496 { |
1497 DMImage *img; | |
1498 DMPCXData pcx; | |
1499 DMPCXHeader hdr; | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1500 int res = 0; |
1286 | 1501 BOOL isPaletted; |
435 | 1502 pcx.buf = NULL; |
1503 | |
1504 // Read PCX header | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1505 if (!dmf_read_byte(fp, &hdr.manufacturer) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1506 !dmf_read_byte(fp, &hdr.version) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1507 !dmf_read_byte(fp, &hdr.encoding) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1508 !dmf_read_byte(fp, &hdr.bitsPerPlane) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1509 !dmf_read_le16(fp, &hdr.xmin) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1510 !dmf_read_le16(fp, &hdr.ymin) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1511 !dmf_read_le16(fp, &hdr.xmax) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1512 !dmf_read_le16(fp, &hdr.ymax) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1513 !dmf_read_le16(fp, &hdr.hres) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1514 !dmf_read_le16(fp, &hdr.vres) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1515 !dmf_read_str(fp, (Uint8 *) &hdr.colorMap, sizeof(hdr.colorMap)) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1516 !dmf_read_byte(fp, &hdr.reserved) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1517 !dmf_read_byte(fp, &hdr.nplanes) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1518 !dmf_read_le16(fp, &hdr.bpl) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1519 !dmf_read_le16(fp, &hdr.palInfo) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1520 !dmf_read_le16(fp, &hdr.hScreenSize) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1521 !dmf_read_le16(fp, &hdr.vScreenSize) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1522 !dmf_read_str(fp, (Uint8 *) &hdr.filler, sizeof(hdr.filler))) |
435 | 1523 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1524 res = dmError(DMERR_FREAD, |
1298 | 1525 "PCX: Could not read image header data.\n"); |
1526 goto error; | |
1527 } | |
1528 | |
1529 if (hdr.manufacturer != 10 || | |
1530 hdr.version > 5 || | |
1531 hdr.encoding != 1) | |
1532 { | |
1533 res = dmError(DMERR_NOT_SUPPORTED, | |
1534 "PCX: Not a PCX file, or unsupported variant.\n"); | |
435 | 1535 goto error; |
1536 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1537 |
1299
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1538 if (hdr.nplanes == 4 && hdr.bitsPerPlane == 4) |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1539 { |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1540 dmMsg(2, |
2078
b2f1ce24f81b
Be more informative when attempting to figure out broken PCX file.
Matti Hamalainen <ccr@tnsp.org>
parents:
2071
diff
changeset
|
1541 "PCX: Probably invalid combination of nplanes=%d and bpp=%d, attempting to fix ..\n", |
b2f1ce24f81b
Be more informative when attempting to figure out broken PCX file.
Matti Hamalainen <ccr@tnsp.org>
parents:
2071
diff
changeset
|
1542 hdr.nplanes, hdr.bitsPerPlane); |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1543 |
1299
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1544 hdr.bitsPerPlane = 1; |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1545 } |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1546 |
1295
7a986f33895e
Fix isPaletted check in PCX reader :P
Matti Hamalainen <ccr@tnsp.org>
parents:
1294
diff
changeset
|
1547 isPaletted = (hdr.bitsPerPlane * hdr.nplanes) <= 8; |
1291 | 1548 |
1549 dmMsg(2, | |
1550 "PCX: xmin=%d, ymin=%d, xmax=%d, ymax=%d, res=%dx%d, scr=%dx%d\n", | |
1551 hdr.xmin, hdr.ymin, hdr.xmax, hdr.ymax, | |
1552 hdr.hres, hdr.vres, | |
1553 hdr.hScreenSize, hdr.vScreenSize); | |
1554 | |
1555 dmMsg(2, | |
1556 "PCX: nplanes=%d, bpp=%d, bpl=%d, isPaletted=%s\n", | |
1557 hdr.nplanes, hdr.bitsPerPlane, hdr.bpl, isPaletted ? "yes" : "no"); | |
1558 | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1559 if (hdr.nplanes < 1 || hdr.nplanes > 8) |
435 | 1560 { |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1561 res = dmError(DMERR_NOT_SUPPORTED, |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1562 "PCX: Unsupported number of bitplanes %d.\n", |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1563 hdr.nplanes); |
435 | 1564 goto error; |
1565 } | |
1566 | |
1286 | 1567 if (!isPaletted) |
1568 { | |
1569 res = dmError(DMERR_NOT_SUPPORTED, | |
1570 "PCX: Non-indexed (truecolour) PCX images not supported for loading.\n"); | |
1571 goto error; | |
1572 } | |
1573 | |
435 | 1574 // Allocate image |
1286 | 1575 if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1, |
2093
d17512dbb4ef
Some work on reading >8bpp images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2092
diff
changeset
|
1576 isPaletted ? DM_COLFMT_PALETTE : DM_COLFMT_RGB, |
1299
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1577 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1578 // isPaletted ? (hdr.bitsPerPlane * hdr.nplanes) : -1 |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1579 -1 |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1580 )) == NULL) |
435 | 1581 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1582 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1583 "PCX: Could not allocate image structure.\n"); |
435 | 1584 goto error; |
1585 } | |
1586 | |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1587 // Set image aspect ratio |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1588 if (hdr.hScreenSize > 0 && hdr.vScreenSize > 0 && |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1589 hdr.vScreenSize / hdr.hScreenSize != img->height / img->width) |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1590 img->aspect = (float) hdr.vScreenSize / (float) hdr.hScreenSize; |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1591 |
1298 | 1592 // Sanity check bytes per line value |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1593 if (hdr.bpl < (img->width * hdr.bitsPerPlane) / 8) |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1594 { |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1595 res = dmError(DMERR_MALLOC, |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1596 "PCX: The bytes per plane line value %d is smaller than width*bpp/8 = %d!\n", |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1597 hdr.bpl, (img->width * hdr.bitsPerPlane) / 8); |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1598 goto error; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1599 } |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1600 |
435 | 1601 pcx.bufLen = hdr.nplanes * hdr.bpl; |
1602 if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL) | |
1603 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1604 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1605 "PCX: Could not allocate RLE buffer.\n"); |
435 | 1606 goto error; |
1607 } | |
1608 | |
1299
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1609 dmMsg(2, |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1610 "PCX: bufLen=%d\n", |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1611 pcx.bufLen); |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1612 |
435 | 1613 // Read image data |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1614 Uint8 *dp = img->data; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1615 for (int yc = 0; yc < img->height; yc++) |
435 | 1616 { |
1617 // Decode row of RLE'd data | |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1618 if (!dmPCXDecodeRLERow(fp, pcx.buf, pcx.bufLen)) |
435 | 1619 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1620 res = dmError(DMERR_INVALID_DATA, |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1621 "PCX: Error decoding RLE compressed data.\n"); |
435 | 1622 goto error; |
1623 } | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1624 |
435 | 1625 // Decode bitplanes |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1626 switch (hdr.bitsPerPlane) |
435 | 1627 { |
1296 | 1628 case 24: |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1629 case 8: |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1630 { |
1286 | 1631 // Actually bytes and bits per plane per pixel .. |
1632 const int bytesPerPlane = hdr.bitsPerPlane / 8; | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1633 |
1286 | 1634 for (int nplane = 0; nplane < hdr.nplanes; nplane++) |
1635 { | |
1636 Uint8 *dptr = dp + (nplane * bytesPerPlane), | |
1637 *sptr = pcx.buf + (hdr.bpl * nplane); | |
1638 | |
1639 memcpy(dptr, sptr, img->width * bytesPerPlane); | |
1640 } | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1641 } |
435 | 1642 break; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1643 |
1280
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1644 case 1: |
1814
0b7062d874ef
Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
1810
diff
changeset
|
1645 dmMemset(dp, 0, img->width); |
1296 | 1646 |
1280
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1647 for (int nplane = 0; nplane < hdr.nplanes; nplane++) |
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1648 { |
1296 | 1649 Uint8 *sptr = pcx.buf + (hdr.bpl * nplane); |
1280
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1650 |
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1651 for (int xc = 0; xc < img->width; xc++) |
1296 | 1652 { |
1299
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1653 const int px = 7 - (xc & 7); |
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1654 dp[xc] |= ((sptr[xc / 8] & (1 << px)) >> px) << nplane; |
1296 | 1655 } |
1280
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1656 } |
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1657 break; |
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1658 |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1659 default: |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1660 res = dmError(DMERR_NOT_SUPPORTED, |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1661 "PCX: Unsupported number of bits per plane %d.\n", |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1662 hdr.bitsPerPlane); |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1663 goto error; |
435 | 1664 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1665 |
435 | 1666 dp += img->pitch; |
1667 } | |
1668 | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1669 // Read additional VGA palette, if available |
1286 | 1670 if (isPaletted) |
435 | 1671 { |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1672 int ncolors; |
435 | 1673 Uint8 tmpb; |
1674 BOOL read; | |
1675 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1676 if (!dmf_read_byte(fp, &tmpb) || tmpb != 0x0C) |
435 | 1677 { |
1678 read = FALSE; | |
1299
b0c0be4c76f9
Aaand some more work on PCX loader. Actually works with 4/1 planes/bpp images now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1298
diff
changeset
|
1679 ncolors = DMPCX_PAL_COLORS; |
435 | 1680 } |
1681 else | |
1682 { | |
1683 read = TRUE; | |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1684 ncolors = 256; |
435 | 1685 } |
1686 | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1687 if ((res = dmPaletteAlloc(&(img->pal), ncolors, -1)) != DMERR_OK) |
435 | 1688 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1689 res = dmError(res, |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1690 "PCX: Could not allocate palette data!\n"); |
435 | 1691 goto error; |
1692 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1693 |
435 | 1694 if (read) |
1695 { | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1696 // Okay, attempt to read the palette data |
1296 | 1697 dmMsg(2, "PCX: Reading palette of %d colors\n", ncolors); |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1698 if ((res = dmPaletteReadData(fp, img->pal, ncolors)) != DMERR_OK) |
435 | 1699 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1700 dmErrorMsg("PCX: Error reading palette.\n"); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1701 goto error; |
435 | 1702 } |
1703 } | |
1704 else | |
1705 { | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1706 const int nmax = img->pal->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->pal->ncolors; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1707 |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1708 // If the extra palette is not available, copy the colors from |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1709 // the header palette to our internal palette structure. |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1710 dmMsg(2, "PCX: Initializing palette from header of %d colors (%d)\n", ncolors, nmax); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1711 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1712 for (int i = 0; i < nmax; i++) |
435 | 1713 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1714 img->pal->colors[i].r = hdr.colorMap[i].r; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1715 img->pal->colors[i].g = hdr.colorMap[i].g; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1716 img->pal->colors[i].b = hdr.colorMap[i].b; |
435 | 1717 } |
1718 } | |
1719 } | |
1720 | |
1721 error: | |
1722 dmFree(pcx.buf); | |
1723 return res; | |
1724 } | |
1725 | |
1726 | |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1727 // |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1728 // IFF ILBM / PBM format |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1729 // |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1730 #define IFF_ID_FORM 0x464F524D // "FORM" |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1731 #define IFF_ID_ILBM 0x494C424D // "ILBM" |
464 | 1732 #define IFF_ID_PBM 0x50424D20 // "PBM " |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1733 #define IFF_ID_BMHD 0x424D4844 // "BMHD" |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1734 #define IFF_ID_CMAP 0x434D4150 // "CMAP" |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1735 #define IFF_ID_BODY 0x424F4459 // "BODY" |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1736 #define IFF_ID_CAMG 0x43414D47 // "CAMG" |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1737 #define IFF_ID_ACBM 0x4143424D // "ACBM" |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1738 #define IFF_ID_ABIT 0x41424954 // "ABIT" |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1739 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1740 #define IFF_MASK_NONE 0 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1741 #define IFF_MASK_HAS_MASK 1 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1742 #define IFF_MASK_TRANSP 2 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1743 #define IFF_MASK_LASSO 3 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1744 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1745 #define IFF_COMP_NONE 0 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1746 #define IFF_COMP_BYTERUN1 1 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1747 |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1748 #define IFF_CAMG_LACE 0x00000004 |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1749 #define IFF_CAMG_HALFBRITE 0x00000080 |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
1750 #define IFF_CAMG_HAM 0x00000800 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1751 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1752 typedef struct |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1753 { |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1754 Uint32 id; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1755 Uint32 size; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1756 int count; |
1656
2de258f2eb2e
Get rid of a basically redundant function in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1655
diff
changeset
|
1757 char idStr[6]; |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
1758 off_t offs; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1759 } DMIFFChunk; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1760 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1761 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1762 typedef struct |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1763 { |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1764 Uint16 w, h; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1765 Sint16 x, y; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1766 Uint8 nplanes; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1767 Uint8 masking; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1768 Uint8 compression; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1769 Uint8 pad1; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1770 Uint16 transp; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1771 Uint8 xasp, yasp; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1772 Sint16 pagew, pageh; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1773 } DMIFFBMHD; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1774 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1775 |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1776 typedef struct |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1777 { |
1810 | 1778 DMIFFChunk chFORM, chBMHD, chCMAP, chBODY; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1779 DMIFFBMHD bmhd; |
1810 | 1780 Uint32 camg; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1781 int ncolors; |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
1782 DMPalette *pal; |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1783 Uint32 idsig; |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
1784 char *idstr; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1785 } DMIFF; |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1786 |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1787 |
2068 | 1788 static int fmtProbeIFF(const Uint8 *buf, const size_t len, const Uint32 id) |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1789 { |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1790 if (len > 32 && |
2068 | 1791 DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 0)) == IFF_ID_FORM && |
1792 DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 8)) == id) | |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1793 { |
2063 | 1794 if (DM_BE32_TO_NATIVE(*(Uint32 *) (buf + 12)) == IFF_ID_BMHD) |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1795 return DM_PROBE_SCORE_MAX; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1796 else |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1797 return DM_PROBE_SCORE_GOOD; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1798 } |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1799 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1800 return DM_PROBE_SCORE_FALSE; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1801 } |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1802 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1803 |
2068 | 1804 static int fmtProbeIFF_ILBM(const Uint8 *buf, const size_t len) |
1805 { | |
1806 return fmtProbeIFF(buf, len, IFF_ID_ILBM); | |
1807 } | |
1808 | |
1809 | |
1810 static int fmtProbeIFF_PBM(const Uint8 *buf, const size_t len) | |
1811 { | |
1812 return fmtProbeIFF(buf, len, IFF_ID_PBM); | |
1813 } | |
1814 | |
1815 | |
1816 static int fmtProbeIFF_ACBM(const Uint8 *buf, const size_t len) | |
1817 { | |
1818 return fmtProbeIFF(buf, len, IFF_ID_ACBM); | |
1819 } | |
1820 | |
1821 | |
1657
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1822 static void dmMakeIFFChunkIDStr(DMIFFChunk *chunk) |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1823 { |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1824 chunk->idStr[0] = (chunk->id >> 24) & 0xff; |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1825 chunk->idStr[1] = (chunk->id >> 16) & 0xff; |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1826 chunk->idStr[2] = (chunk->id >> 8) & 0xff; |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1827 chunk->idStr[3] = (chunk->id) & 0xff; |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1828 chunk->idStr[4] = 0; |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1829 } |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1830 |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1831 |
1654
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1832 static int dmReadIFFChunkHdr(DMResource *fp, DMIFFChunk *chunk) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1833 { |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1834 if (!dmf_read_be32(fp, &chunk->id) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1835 !dmf_read_be32(fp, &chunk->size)) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1836 { |
1654
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1837 return dmError(DMERR_FREAD, |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
1838 "IFF: Could not read IFF chunk header.\n"); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1839 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1840 else |
1656
2de258f2eb2e
Get rid of a basically redundant function in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1655
diff
changeset
|
1841 { |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
1842 chunk->offs = dmftell(fp); |
1657
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1843 dmMakeIFFChunkIDStr(chunk); |
1654
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1844 return DMERR_OK; |
1656
2de258f2eb2e
Get rid of a basically redundant function in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1655
diff
changeset
|
1845 } |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1846 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1847 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1848 |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
1849 static int dmSkipIFFChunkRest(DMResource *fp, const DMIFFChunk *chunk) |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1850 { |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1851 off_t read = dmftell(fp) - chunk->offs, |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1852 size = chunk->size; |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1853 |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1854 if (size & 1) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1855 { |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1856 dmMsg(3, "IFF: Chunk size %d is uneven, adjusting to %d.\n", |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1857 size, size + 1); |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1858 size++; |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1859 } |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1860 |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1861 if (size > read) |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1862 { |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1863 dmMsg(3, "IFF: Skipping %d bytes (%d of %d consumed)\n", |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1864 size - read, read, size); |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1865 |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1866 if (dmfseek(fp, size - read, SEEK_CUR) != 0) |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1867 { |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1868 return dmError(DMERR_FSEEK, |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
1869 "IFF: Failed to skip chunk end.\n"); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1870 } |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1871 } |
1903 | 1872 |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1873 return DMERR_OK; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1874 } |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1875 |
1656
2de258f2eb2e
Get rid of a basically redundant function in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1655
diff
changeset
|
1876 |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1877 static int dmCheckIFFChunk(DMIFFChunk *dest, const DMIFFChunk *chunk, |
445 | 1878 const BOOL multi, const Uint32 minSize) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1879 { |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1880 if (dest->count > 0 && !multi) |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1881 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1882 return dmError(DMERR_INVALID_DATA, |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
1883 "IFF: Multiple instances of chunk %s found.\n", |
1656
2de258f2eb2e
Get rid of a basically redundant function in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1655
diff
changeset
|
1884 chunk->idStr); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1885 } |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1886 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1887 dest->count++; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1888 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1889 if (chunk->size < minSize) |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1890 { |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1891 return dmError(DMERR_OUT_OF_DATA, |
1907
571109a14967
Add some more informative messages in IFF loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1906
diff
changeset
|
1892 "IFF: Chunk %s is too small (%d < %d).\n", |
571109a14967
Add some more informative messages in IFF loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1906
diff
changeset
|
1893 chunk->idStr, chunk->size, minSize); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1894 } |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1895 |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1896 return DMERR_OK; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1897 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1898 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1899 |
2055
6c6a4ea67540
Make two functions static and one not.
Matti Hamalainen <ccr@tnsp.org>
parents:
2054
diff
changeset
|
1900 BOOL dmIFFDecodeByteRun1Row(DMResource *fp, Uint8 *buf, const size_t bufLen) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1901 { |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1902 size_t offs = 0; |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1903 do |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1904 { |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1905 Uint8 data, ucount; |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1906 |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1907 if (!dmf_read_byte(fp, &ucount)) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1908 return FALSE; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1909 |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1910 if (ucount == 0x80) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1911 { |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1912 if (!dmf_read_byte(fp, &data)) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1913 return FALSE; |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1914 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1915 else |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1916 if (ucount & 0x80) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1917 { |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1918 Uint8 count = (ucount ^ 0xff) + 2; |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1919 if (!dmf_read_byte(fp, &data)) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1920 return FALSE; |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1921 |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1922 while (count-- && offs < bufLen) |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1923 buf[offs++] = data; |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1924 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1925 else |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1926 { |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1927 Uint8 count = ucount + 1; |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1928 while (count-- && offs < bufLen) |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1929 { |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1930 if (!dmf_read_byte(fp, &data)) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1931 return FALSE; |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1932 |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1933 buf[offs++] = data; |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1934 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1935 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1936 } while (offs < bufLen); |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1937 |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1938 return TRUE; |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1939 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1940 |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1941 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1942 static BOOL dmIFFReadOneRow(DMResource *fp, DMIFF *iff, Uint8 *buf, const size_t bufLen) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1943 { |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1944 if (iff->bmhd.compression == IFF_COMP_BYTERUN1) |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1945 return dmIFFDecodeByteRun1Row(fp, buf, bufLen); |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1946 else |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1947 return dmf_read_str(fp, buf, bufLen); |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1948 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1949 |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1950 |
1622 | 1951 static inline Uint8 dmDecodeBit(const Uint8 *buf, const int xc) |
1619
dacf4c2f7a86
Remove slight code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1618
diff
changeset
|
1952 { |
dacf4c2f7a86
Remove slight code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1618
diff
changeset
|
1953 return (buf[xc / 8] >> (7 - (xc & 7))) & 1; |
dacf4c2f7a86
Remove slight code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1618
diff
changeset
|
1954 } |
dacf4c2f7a86
Remove slight code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1618
diff
changeset
|
1955 |
dacf4c2f7a86
Remove slight code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1618
diff
changeset
|
1956 |
1903 | 1957 static int dmDecodeIFFBody(DMResource *fp, DMIFF *iff, DMImage *img) |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1958 { |
1903 | 1959 Uint8 *buf = NULL; |
1960 size_t bufLen = 0; | |
1618 | 1961 int res = DMERR_OK; |
1659 | 1962 const int nplanes = iff->bmhd.nplanes; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1963 |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1964 if (iff->idsig == IFF_ID_ILBM) |
1903 | 1965 { |
1966 bufLen = ((img->width + 15) / 16) * 2; | |
1906
09d46bf9fe71
Use a consistent message between IFF encoding and decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1905
diff
changeset
|
1967 dmMsg(2, "IFF: Line / plane row size %d bytes.\n", bufLen); |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1968 |
1903 | 1969 } |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1970 else |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1971 if (iff->idsig == IFF_ID_ACBM) |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1972 { |
2082
a0a6f5a3fbbf
Fix plane buffer size calculation for IFF ACBM to round up to nearest byte (minimum of 1).
Matti Hamalainen <ccr@tnsp.org>
parents:
2081
diff
changeset
|
1973 bufLen = (img->width * img->height + 7) / 8; |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1974 dmMsg(2, "IFF: Plane buffer size %d bytes.\n", bufLen); |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1975 } |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1976 |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1977 if (bufLen > 0 && (buf = dmMalloc(bufLen)) == NULL) |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1978 return DMERR_MALLOC; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1979 |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1980 // Decode the chunk |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1981 if (iff->idsig == IFF_ID_ACBM) |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1982 { |
2081
a14286e2710e
Initialize the destination image data in case of IFF ACBM loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
2078
diff
changeset
|
1983 // Initialize destination image data |
a14286e2710e
Initialize the destination image data in case of IFF ACBM loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
2078
diff
changeset
|
1984 dmMemset(img->data, 0, img->size); |
a14286e2710e
Initialize the destination image data in case of IFF ACBM loading.
Matti Hamalainen <ccr@tnsp.org>
parents:
2078
diff
changeset
|
1985 |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1986 for (int plane = 0; plane < nplanes; plane++) |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1987 { |
2069 | 1988 // Decompress or read data |
1989 if (!dmIFFReadOneRow(fp, iff, buf, bufLen)) | |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1990 { |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1991 res = dmError(DMERR_FREAD, |
2069 | 1992 "IFF: Error in reading ACBM image plane #%d.\n", |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1993 plane); |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1994 goto out; |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1995 } |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1996 |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1997 for (int yc = 0; yc < img->height; yc++) |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1998 { |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
1999 Uint8 *dp = img->data + (yc * img->pitch); |
2067
430c010d97c1
Fix hardcoding in ACBM decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
2065
diff
changeset
|
2000 Uint8 *sp = buf + (yc * img->width) / 8; |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2001 for (int xc = 0; xc < img->width; xc++) |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2002 { |
2067
430c010d97c1
Fix hardcoding in ACBM decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
2065
diff
changeset
|
2003 dp[xc] |= dmDecodeBit(sp, xc) << plane; |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2004 } |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2005 } |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2006 } |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2007 } |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2008 else |
1618 | 2009 for (int yc = 0; yc < img->height; yc++) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2010 { |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2011 Uint8 *dp = img->data + (yc * img->pitch); |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2012 |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2013 if (iff->idsig == IFF_ID_ILBM) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2014 { |
1907
571109a14967
Add some more informative messages in IFF loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1906
diff
changeset
|
2015 // Clear planar decoding buffer |
1903 | 2016 dmMemset(dp, 0, img->pitch); |
2017 | |
2018 for (int plane = 0; plane < nplanes; plane++) | |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2019 { |
1903 | 2020 // Decompress or read data |
2021 if (!dmIFFReadOneRow(fp, iff, buf, bufLen)) | |
2022 { | |
2023 res = dmError(DMERR_FREAD, | |
2069 | 2024 "IFF: Error in reading ILBM image plane #%d @ %d.\n", |
1903 | 2025 plane, yc); |
2026 goto out; | |
2027 } | |
2028 | |
2029 // Decode bitplane | |
2030 for (int xc = 0; xc < img->width; xc++) | |
2031 dp[xc] |= dmDecodeBit(buf, xc) << plane; | |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2032 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2033 |
1903 | 2034 // Read mask data |
2035 if (iff->bmhd.masking == IFF_MASK_HAS_MASK) | |
2036 { | |
2037 // Decompress or read data | |
2038 if (!dmIFFReadOneRow(fp, iff, buf, bufLen)) | |
2039 { | |
2040 res = dmError(DMERR_FREAD, | |
2069 | 2041 "IFF: Error in reading ILBM mask plane.\n"); |
1903 | 2042 goto out; |
2043 } | |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2044 |
1903 | 2045 // Decode mask |
2046 for (int xc = 0; xc < img->width; xc++) | |
2047 { | |
2048 const Uint8 data = dmDecodeBit(buf, xc); | |
2049 | |
2050 // Black out any pixels with mask bit 0 | |
2051 if (!data) | |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2052 dp[xc] = img->pal->ctransp < 0 ? 0 : img->pal->ctransp; |
1903 | 2053 } |
2054 } | |
2055 } | |
2056 else | |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2057 if (iff->idsig == IFF_ID_PBM) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2058 { |
1903 | 2059 if (!dmIFFReadOneRow(fp, iff, dp, img->width)) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2060 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2061 res = dmError(DMERR_FREAD, |
1903 | 2062 "IFF: Error reading PBM image row #%d.\n", yc); |
2063 goto out; | |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2064 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2065 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2066 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2067 |
1903 | 2068 out: |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2069 dmFree(buf); |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2070 return res; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2071 } |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2072 |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2073 |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2074 int dmReadIFFImage(DMResource *fp, DMImage **pimg) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2075 { |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2076 DMIFFChunk chunk; |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2077 DMIFF iff; |
1903 | 2078 BOOL parsed = FALSE; |
1627 | 2079 int res = DMERR_OK; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2080 |
1167 | 2081 dmMemset(&iff, 0, sizeof(iff)); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2082 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2083 // Read IFF FORM header |
1654
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
2084 if ((res = dmReadIFFChunkHdr(fp, &chunk)) != DMERR_OK) |
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
2085 return res; |
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
2086 |
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
2087 if (chunk.id != IFF_ID_FORM || chunk.size < 32) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2088 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2089 return dmError(DMERR_NOT_SUPPORTED, |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2090 "IFF: Not a IFF file (%08X vs %08X / %d).\n", |
1265
4e074b9b4789
Improve IFF FORM validity error message.
Matti Hamalainen <ccr@tnsp.org>
parents:
1264
diff
changeset
|
2091 chunk.id, IFF_ID_FORM, chunk.size); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2092 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2093 |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2094 // Check IFF ILBM/PBM signature |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2095 if (!dmf_read_be32(fp, &iff.idsig) || |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2096 (iff.idsig != IFF_ID_ILBM && |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2097 iff.idsig != IFF_ID_PBM && |
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2098 iff.idsig != IFF_ID_ACBM)) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2099 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2100 return dmError(DMERR_INVALID_DATA, |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2101 "IFF: Not a IFF ILBM/PBM/ACBM file.\n"); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2102 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2103 |
2023
362fb8295f0c
Be more informative about the actual sub-format of the IFF image (PBM/ILBM).
Matti Hamalainen <ccr@tnsp.org>
parents:
2022
diff
changeset
|
2104 dmMsg(3, "IFF: FORM is %s format image, with size %d bytes.\n", |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2105 iff.idsig == IFF_ID_ILBM ? "ILBM" : |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2106 (iff.idsig == IFF_ID_PBM ? "PBM" : "ACBM"), |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2107 chunk.size); |
1907
571109a14967
Add some more informative messages in IFF loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1906
diff
changeset
|
2108 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2109 while (!parsed && !dmfeof(fp)) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2110 { |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
2111 // Read chunk header |
1654
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
2112 if ((res = dmReadIFFChunkHdr(fp, &chunk)) != DMERR_OK) |
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
2113 return res; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2114 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2115 switch (chunk.id) |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2116 { |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2117 case IFF_ID_BMHD: |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2118 // Check for multiple occurences of BMHD |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2119 if ((res = dmCheckIFFChunk(&iff.chBMHD, &chunk, FALSE, sizeof(iff.bmhd))) != DMERR_OK) |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2120 return res; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2121 |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2122 // Read BMHD data |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2123 if (!dmf_read_be16(fp, &iff.bmhd.w) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2124 !dmf_read_be16(fp, &iff.bmhd.h) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2125 !dmf_read_be16(fp, (Uint16 *) &iff.bmhd.x) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2126 !dmf_read_be16(fp, (Uint16 *) &iff.bmhd.y) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2127 !dmf_read_byte(fp, &iff.bmhd.nplanes) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2128 !dmf_read_byte(fp, &iff.bmhd.masking) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2129 !dmf_read_byte(fp, &iff.bmhd.compression) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2130 !dmf_read_byte(fp, &iff.bmhd.pad1) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2131 !dmf_read_be16(fp, &iff.bmhd.transp) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2132 !dmf_read_byte(fp, &iff.bmhd.xasp) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2133 !dmf_read_byte(fp, &iff.bmhd.yasp) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2134 !dmf_read_be16(fp, (Uint16 *) &iff.bmhd.pagew) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2135 !dmf_read_be16(fp, (Uint16 *) &iff.bmhd.pageh)) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2136 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2137 return dmError(DMERR_FREAD, |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2138 "IFF: Error reading BMHD chunk.\n"); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2139 } |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2140 |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2141 dmMsg(1, "IFF: BMHD %d x %d @ %d, %d : nplanes=%d, comp=%d, mask=%d, transp=%d\n", |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2142 iff.bmhd.w, iff.bmhd.h, iff.bmhd.x, iff.bmhd.y, |
1655 | 2143 iff.bmhd.nplanes, iff.bmhd.compression, iff.bmhd.masking, |
2144 iff.bmhd.transp); | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2145 |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2146 // Sanity check |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2147 if (iff.bmhd.nplanes < 1 || iff.bmhd.nplanes > 8 || |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2148 (iff.bmhd.compression != IFF_COMP_NONE && |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2149 iff.bmhd.compression != IFF_COMP_BYTERUN1) || |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2150 (iff.bmhd.masking != IFF_MASK_NONE && |
448
f1aab48a76fe
Add transp mask support to IFF ILBM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
447
diff
changeset
|
2151 iff.bmhd.masking != IFF_MASK_HAS_MASK && |
f1aab48a76fe
Add transp mask support to IFF ILBM loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
447
diff
changeset
|
2152 iff.bmhd.masking != IFF_MASK_TRANSP)) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2153 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2154 return dmError(DMERR_NOT_SUPPORTED, |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2155 "IFF: Unsupported features, refusing to load.\n"); |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2156 } |
2069 | 2157 |
2158 if (iff.idsig == IFF_ID_ACBM && | |
2159 iff.bmhd.compression != IFF_COMP_NONE) | |
2160 { | |
2161 dmMsg(1, "IFF: ACBM image with compression != none (%d). Ignoring.\n", | |
2162 iff.bmhd.compression); | |
2163 | |
2164 iff.bmhd.compression = IFF_COMP_NONE; | |
2165 } | |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2166 break; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2167 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2168 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2169 case IFF_ID_CMAP: |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2170 // Check for multiple occurences of CMAP |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2171 if ((res = dmCheckIFFChunk(&iff.chCMAP, &chunk, FALSE, 3)) != DMERR_OK) |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2172 return res; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2173 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2174 // Check for sanity |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2175 if (chunk.size % 3 != 0) |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2176 { |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2177 // Non-fatal |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2178 dmError(DMERR_INVALID_DATA, |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2179 "IFF: CMAP chunk size not divisible by 3, possibly broken file.\n"); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2180 } |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2181 |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2182 iff.ncolors = chunk.size / 3; |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2183 dmMsg(2, "IFF: CMAP %d entries (%d bytes)\n", |
1624
9a8395b56d1a
Remove unused message argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
1623
diff
changeset
|
2184 iff.ncolors, chunk.size); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2185 |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2186 if (iff.bmhd.nplanes > 0 && iff.ncolors != 1 << iff.bmhd.nplanes) |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2187 dmMsg(2, "IFF: Expected %d entries in CMAP.\n", 1 << iff.bmhd.nplanes); |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2188 |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
2189 // Read palette |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
2190 if (iff.ncolors > 0) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2191 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2192 if ((res = dmPaletteAlloc(&iff.pal, iff.ncolors, |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2193 (iff.bmhd.masking == IFF_MASK_TRANSP) ? iff.bmhd.transp : -1)) != DMERR_OK) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2194 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2195 dmErrorMsg("IFF: Could not allocate palette data.\n"); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2196 return res; |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
2197 } |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2198 if ((res = dmPaletteReadData(fp, iff.pal, iff.ncolors)) != DMERR_OK) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
2199 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2200 dmErrorMsg("IFF: Error reading CMAP.\n"); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2201 return res; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2202 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2203 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2204 |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2205 if (iff.chBMHD.count && iff.chBODY.count) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2206 parsed = TRUE; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2207 break; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2208 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2209 case IFF_ID_BODY: |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2210 case IFF_ID_ABIT: |
1621 | 2211 // Check for multiple occurences of BODY |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2212 if ((res = dmCheckIFFChunk(&iff.chBODY, &chunk, FALSE, 1)) != DMERR_OK) |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2213 return res; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2214 |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2215 // Check for sanity |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2216 if (!iff.chBMHD.count) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2217 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2218 return dmError(DMERR_INVALID_DATA, |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2219 "IFF: %s chunk before BMHD?\n", chunk.idStr); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2220 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2221 |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2222 dmMsg(2, "IFF: %s chunk size %d bytes\n", chunk.idStr, chunk.size); |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2223 |
1626
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
2224 // Allocate image |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
2225 if ((*pimg = dmImageAlloc(iff.bmhd.w, iff.bmhd.h, |
1801 | 2226 iff.bmhd.nplanes <= 8 ? DM_COLFMT_PALETTE : DM_COLFMT_RGBA, |
1626
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
2227 // XXX TODO? When/if we ever handle < 8bit indexed correctly, we can use the actual bpp |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
2228 //iff->bmhd.nplanes <= 8 ? iff->bmhd.nplanes : -1 |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
2229 -1 |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
2230 )) == NULL) |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
2231 return DMERR_MALLOC; |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
2232 |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
2233 // Set image aspect ratio |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
2234 if (iff.bmhd.xasp > 0 && iff.bmhd.yasp > 0) |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
2235 (*pimg)->aspect = (float) iff.bmhd.yasp / (float) iff.bmhd.xasp; |
1626
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
2236 |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2237 // Decode the body |
1903 | 2238 if ((res = dmDecodeIFFBody(fp, &iff, *pimg)) != DMERR_OK) |
2239 return res; | |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2240 |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
2241 if ((res = dmSkipIFFChunkRest(fp, &chunk)) != DMERR_OK) |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2242 return res; |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2243 |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
2244 if (iff.chCMAP.count) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2245 parsed = TRUE; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2246 break; |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2247 |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2248 case IFF_ID_CAMG: |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
2249 if (!dmf_read_be32(fp, &iff.camg)) |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2250 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2251 return dmError(DMERR_FREAD, |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2252 "IFF: Error reading CAMG chunk.\n"); |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2253 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2254 |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2255 dmMsg(2, "IFF: CAMG value 0x%08x\n", iff.camg); |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2256 |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2257 if ((iff.camg & IFF_CAMG_HAM)) |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2258 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2259 return dmError(DMERR_NOT_SUPPORTED, |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2260 "IFF: HAM files are not supported.\n"); |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2261 } |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2262 break; |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2263 |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2264 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2265 default: |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
2266 dmMsg(3, "Unknown chunk ID '%s', size %d\n", |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
2267 chunk.idStr, chunk.size); |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2268 |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
2269 if (dmfseek(fp, chunk.size, SEEK_CUR) != 0) |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
2270 { |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
2271 return dmError(DMERR_FSEEK, |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
2272 "IFF: Error skipping in file."); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2273 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2274 break; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2275 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2276 |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
2277 if ((res = dmSkipIFFChunkRest(fp, &chunk)) != DMERR_OK) |
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
2278 return res; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2279 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2280 |
1948
5790b52c339e
Check that we have a CMAP/palette for IFF images that should have it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1945
diff
changeset
|
2281 // Check if we should have a palette |
2019 | 2282 if (*pimg != NULL && (*pimg)->format == DM_COLFMT_PALETTE) |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2283 { |
1948
5790b52c339e
Check that we have a CMAP/palette for IFF images that should have it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1945
diff
changeset
|
2284 // Check that we DO have a palette .. |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2285 if (iff.pal == NULL || iff.pal->ncolors == 0) |
1948
5790b52c339e
Check that we have a CMAP/palette for IFF images that should have it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1945
diff
changeset
|
2286 { |
5790b52c339e
Check that we have a CMAP/palette for IFF images that should have it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1945
diff
changeset
|
2287 return dmError(DMERR_INVALID_DATA, |
5790b52c339e
Check that we have a CMAP/palette for IFF images that should have it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1945
diff
changeset
|
2288 "IFF: A paletted/indexed color image with no CMAP. Bailing out.\n"); |
5790b52c339e
Check that we have a CMAP/palette for IFF images that should have it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1945
diff
changeset
|
2289 } |
5790b52c339e
Check that we have a CMAP/palette for IFF images that should have it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1945
diff
changeset
|
2290 |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2291 // If halfbrite is used, duplicate the palette |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2292 if (iff.camg & IFF_CAMG_HALFBRITE) |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2293 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2294 int ncolors = iff.ncolors; |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2295 if (iff.idsig != IFF_ID_ILBM) |
1625
c8afa3e6c413
Print an error/warning about PBM files that have half-brite set.
Matti Hamalainen <ccr@tnsp.org>
parents:
1624
diff
changeset
|
2296 { |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2297 dmErrorMsg("IFF: Non-planar PBM file with Halfbrite enabled! This might not work.\n"); |
1625
c8afa3e6c413
Print an error/warning about PBM files that have half-brite set.
Matti Hamalainen <ccr@tnsp.org>
parents:
1624
diff
changeset
|
2298 } |
834 | 2299 |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2300 if (iff.ncolors > 128) |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2301 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
2302 return dmError(DMERR_NOT_SUPPORTED, |
1892
cbc911ffd21e
Rename ILBM functions to IFF, which is more approriate as we support both ILBM and PBM variants of the IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
1887
diff
changeset
|
2303 "IFF: Halfbrite enabled, but ncolors > 128.\n"); |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2304 } |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2305 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2306 if ((res = dmPaletteResize(&iff.pal, ncolors * 2)) != DMERR_OK) |
834 | 2307 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2308 dmPaletteFree(iff.pal); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2309 return res; |
834 | 2310 } |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2311 |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2312 for (int i = 0; i < ncolors; i++) |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2313 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2314 int i2 = ncolors + i; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2315 iff.pal->colors[i2].r = iff.pal->colors[i].r / 2; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2316 iff.pal->colors[i2].g = iff.pal->colors[i].g / 2; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2317 iff.pal->colors[i2].b = iff.pal->colors[i].b / 2; |
449
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2318 } |
117f94b253af
Add support for CAMG chunk reading and possibly half-brite handling in IFF ILBM reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
448
diff
changeset
|
2319 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
2320 |
447
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2321 (*pimg)->pal = iff.pal; |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2322 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
2323 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2324 return res; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2325 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2326 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2327 |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2328 static int dmWriteIFFChunkHdr(DMResource *fp, DMIFFChunk *chunk, const Uint32 id) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2329 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2330 chunk->offs = dmftell(fp); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2331 chunk->id = id; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2332 dmMakeIFFChunkIDStr(chunk); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2333 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2334 if (!dmf_write_be32(fp, chunk->id) || |
1942
f171b929b631
Do not reference uninitialized value in IFF writer, although in this case
Matti Hamalainen <ccr@tnsp.org>
parents:
1940
diff
changeset
|
2335 !dmf_write_be32(fp, 0)) |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2336 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2337 return dmError(DMERR_FREAD, |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2338 "IFF: Could not write IFF '%s' chunk header.\n", |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2339 chunk->idStr); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2340 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2341 else |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2342 return DMERR_OK; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2343 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2344 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2345 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2346 static int dmWriteIFFChunkFinish(DMResource *fp, DMIFFChunk *chunk) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2347 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2348 off_t curr = dmftell(fp); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2349 if (curr < 0) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2350 return dmferror(fp); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2351 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2352 chunk->size = curr - chunk->offs - (sizeof(Uint32) * 2); |
1900 | 2353 if (chunk->size & 1) |
2354 { | |
2020 | 2355 dmMsg(3, "Padding chunk ID '%s', size %d ++\n", |
2356 chunk->idStr, chunk->size); | |
2357 | |
1900 | 2358 if (!dmf_write_byte(fp, 0)) |
2359 return dmferror(fp); | |
2360 | |
2020 | 2361 curr++; |
1900 | 2362 } |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2363 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2364 if (dmfseek(fp, chunk->offs, SEEK_SET) < 0) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2365 return dmferror(fp); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2366 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2367 if (!dmf_write_be32(fp, chunk->id) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2368 !dmf_write_be32(fp, chunk->size)) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2369 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2370 return dmError(DMERR_FREAD, |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2371 "IFF: Could not write IFF '%s' chunk header.\n", |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2372 chunk->idStr); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2373 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2374 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2375 if (dmfseek(fp, curr, SEEK_SET) < 0) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2376 return dmferror(fp); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2377 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2378 return DMERR_OK; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2379 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2380 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2381 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2382 enum |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2383 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2384 DMODE_LIT, |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2385 DMODE_RLE, |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2386 }; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2387 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2388 |
2055
6c6a4ea67540
Make two functions static and one not.
Matti Hamalainen <ccr@tnsp.org>
parents:
2054
diff
changeset
|
2389 static BOOL dmIFFEncodeByteRun1LIT(DMResource *fp, |
2050
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2390 const Uint8 *buf, const size_t offs, |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2391 const size_t count) |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2392 { |
2050
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2393 if (count <= 0) |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2394 return TRUE; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2395 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2396 Uint8 tmp = count - 1; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2397 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2398 return |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2399 dmf_write_byte(fp, tmp) && |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2400 dmf_write_str(fp, buf + offs, count); |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2401 } |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2402 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2403 |
2055
6c6a4ea67540
Make two functions static and one not.
Matti Hamalainen <ccr@tnsp.org>
parents:
2054
diff
changeset
|
2404 static BOOL dmIFFEncodeByteRun1RLE(DMResource *fp, |
2050
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2405 const Uint8 *buf, const size_t offs, |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2406 const size_t count) |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2407 { |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2408 if (count <= 0) |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2409 return TRUE; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2410 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2411 Uint8 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2412 tmp = ((Uint8) count - 2) ^ 0xff, |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2413 data = buf[offs]; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2414 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2415 return |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2416 dmf_write_byte(fp, tmp) && |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2417 dmf_write_byte(fp, data); |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2418 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2419 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2420 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2421 BOOL dmIFFEncodeByteRun1Row(DMResource *fp, const Uint8 *buf, const size_t bufLen) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2422 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2423 int prev = -1, mode = DMODE_LIT; |
2050
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2424 size_t offs, l_offs, r_offs; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2425 BOOL ret = TRUE; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2426 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2427 for (offs = l_offs = r_offs = 0; offs < bufLen; offs++) |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2428 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2429 Uint8 data = buf[offs]; |
2050
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2430 BOOL flush = FALSE; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2431 int pmode = mode; |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2432 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2433 if (data == prev) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2434 { |
2050
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2435 if (mode == DMODE_LIT && |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2436 offs - r_offs >= 2) |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2437 { |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2438 ret = dmIFFEncodeByteRun1LIT(fp, buf, l_offs, r_offs - l_offs); |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2439 mode = DMODE_RLE; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2440 } |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2441 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2442 else |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2443 { |
2050
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2444 if (mode != DMODE_LIT) |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2445 { |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2446 ret = dmIFFEncodeByteRun1RLE(fp, buf, r_offs, offs - r_offs); |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2447 mode = DMODE_LIT; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2448 l_offs = offs; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2449 } |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2450 r_offs = offs; |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2451 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2452 |
2050
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2453 if (!ret) |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2454 goto out; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2455 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2456 // NOTE! RLE and LIT max are both 128, checked against DP2e |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2457 flush = |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2458 (pmode == DMODE_RLE && offs - r_offs >= 128) || |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2459 (pmode == DMODE_LIT && offs - l_offs >= 128); |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2460 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2461 // Check for last byte of input |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2462 if (offs == bufLen - 1) |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2463 { |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2464 offs++; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2465 flush = TRUE; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2466 pmode = mode; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2467 } |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2468 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2469 if (flush) |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2470 { |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2471 if (pmode == DMODE_RLE) |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2472 ret = dmIFFEncodeByteRun1RLE(fp, buf, r_offs, offs - r_offs); |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2473 else |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2474 ret = dmIFFEncodeByteRun1LIT(fp, buf, l_offs, offs - l_offs); |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2475 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2476 r_offs = l_offs = offs; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2477 mode = DMODE_LIT; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2478 |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2479 if (!ret) |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2480 goto out; |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2481 } |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2482 |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2483 prev = data; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2484 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2485 |
2050
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2486 out: |
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2487 return ret; |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2488 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2489 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2490 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2491 static BOOL dmIFFWriteOneRow(DMResource *fp, DMIFF *iff, const Uint8 *buf, const size_t bufLen) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2492 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2493 if (iff->bmhd.compression == IFF_COMP_BYTERUN1) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2494 return dmIFFEncodeByteRun1Row(fp, buf, bufLen); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2495 else |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2496 return dmf_write_str(fp, buf, bufLen); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2497 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2498 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2499 |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2500 int dmWriteIFFImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2501 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2502 DMIFF iff; |
1904 | 2503 Uint8 *buf = NULL; |
2504 size_t bufLen; | |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2505 int res = DMERR_OK; |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2506 |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2507 // XXX: Non-paletted IFF not supported! |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2064
diff
changeset
|
2508 if (spec->format != DM_COLFMT_PALETTE) |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2509 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2510 return dmError(DMERR_NOT_SUPPORTED, |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2511 "Non-paletted IFF is not supported.\n"); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2512 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2513 |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2064
diff
changeset
|
2514 switch (spec->fmtid) |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2515 { |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2516 case DM_IMGFMT_IFF_ILBM: iff.idsig = IFF_ID_ILBM; iff.idstr = "ILBM"; break; |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2517 case DM_IMGFMT_IFF_PBM : iff.idsig = IFF_ID_PBM; iff.idstr = "PBM"; break; |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2518 case DM_IMGFMT_IFF_ACBM: iff.idsig = IFF_ID_ACBM; iff.idstr = "ACBM"; break; |
2065
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2064
diff
changeset
|
2519 default: |
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2064
diff
changeset
|
2520 return dmError(DMERR_NOT_SUPPORTED, |
451980580189
Refactor how paletted/indexed formats are handled in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
2064
diff
changeset
|
2521 "Invalid IFF format.\n"); |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2522 } |
2026
b137d324e13f
Force 8 bitplanes for IFF PBM images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2025
diff
changeset
|
2523 |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2524 // Setup headers |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2525 iff.bmhd.x = 0; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2526 iff.bmhd.y = 0; |
1904 | 2527 iff.bmhd.w = img->width * spec->scaleX; |
2528 iff.bmhd.h = img->height * spec->scaleY; | |
2529 iff.bmhd.pagew = img->width * spec->scaleX; | |
2530 iff.bmhd.pageh = img->height * spec->scaleY; | |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2531 iff.bmhd.pad1 = 0; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2532 iff.bmhd.xasp = 1; // XXX TODO: compute the xasp/yasp from the img->aspect |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2533 iff.bmhd.yasp = 1; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2534 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2535 iff.camg = 0; // XXX TODO: when/if HAM support |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2536 iff.bmhd.masking = (img->pal && img->pal->ctransp < 0) ? IFF_MASK_NONE : spec->mask; |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2537 iff.bmhd.transp = (img->pal && img->pal->ctransp >= 0 && spec->mask == IFF_MASK_TRANSP) ? img->pal->ctransp : 0xffff; |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2538 iff.bmhd.nplanes = (iff.idsig == IFF_ID_PBM && spec->nplanes < 8) ? 8 : spec->nplanes; |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2539 |
2069 | 2540 // Apparently ACBM can't/should not use compression .. even though |
2541 // some files in the wild have bmhd.compression != 0 (but are not | |
2542 // actually compressed.) To be more compliant with the spec, | |
2543 iff.bmhd.compression = (spec->compression && iff.idsig != IFF_ID_ACBM) ? IFF_COMP_BYTERUN1 : IFF_COMP_NONE; | |
2544 | |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2545 dmMsg(2, "IFF: nplanes=%d, comp=%d, mask=%d\n", |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2546 iff.bmhd.nplanes, iff.bmhd.compression, iff.bmhd.masking); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2547 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2548 // Write IFF FORM header |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2549 if ((res = dmWriteIFFChunkHdr(fp, &iff.chFORM, IFF_ID_FORM)) != DMERR_OK) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2550 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2551 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2552 // Write IFF ILBM/PBM signature |
2053
6dfbe976d740
Implement basic initial support for IFF ACBM format images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2050
diff
changeset
|
2553 if (!dmf_write_be32(fp, iff.idsig)) |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2554 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2555 res = dmError(DMERR_FWRITE, |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2556 "IFF: Error writing %s signature.\n", |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2557 iff.idstr); |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2558 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2559 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2560 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2561 // Write BMHD chunk and data |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2562 if ((res = dmWriteIFFChunkHdr(fp, &iff.chBMHD, IFF_ID_BMHD)) != DMERR_OK || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2563 !dmf_write_be16(fp, iff.bmhd.w) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2564 !dmf_write_be16(fp, iff.bmhd.h) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2565 !dmf_write_be16(fp, iff.bmhd.x) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2566 !dmf_write_be16(fp, iff.bmhd.y) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2567 !dmf_write_byte(fp, iff.bmhd.nplanes) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2568 !dmf_write_byte(fp, iff.bmhd.masking) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2569 !dmf_write_byte(fp, iff.bmhd.compression) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2570 !dmf_write_byte(fp, iff.bmhd.pad1) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2571 !dmf_write_be16(fp, iff.bmhd.transp) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2572 !dmf_write_byte(fp, iff.bmhd.xasp) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2573 !dmf_write_byte(fp, iff.bmhd.yasp) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2574 !dmf_write_be16(fp, iff.bmhd.pagew) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2575 !dmf_write_be16(fp, iff.bmhd.pageh)) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2576 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2577 res = dmError(DMERR_FWRITE, |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2578 "IFF: Error writing BMHD chunk.\n"); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2579 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2580 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2581 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2582 if ((res = dmWriteIFFChunkFinish(fp, &iff.chBMHD)) != DMERR_OK) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2583 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2584 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2585 // |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2586 // CMAP |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2587 // |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2588 if (img->pal->ncolors > 0 && spec->format == DM_COLFMT_PALETTE) |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2589 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2590 if ((res = dmWriteIFFChunkHdr(fp, &iff.chCMAP, IFF_ID_CMAP)) != DMERR_OK) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2591 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2592 |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2593 if ((res = dmPaletteWriteData(fp, img->pal, img->pal->ncolors, -1)) != DMERR_OK) |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2594 { |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2595 res = dmError(DMERR_FWRITE, |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2596 "IFF: Could not write CMAP palette.\n"); |
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2597 goto out; |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2598 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2599 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2600 if ((res = dmWriteIFFChunkFinish(fp, &iff.chCMAP)) != DMERR_OK) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2601 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2602 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2603 dmMsg(2, "IFF: CMAP %d entries (%d bytes)\n", |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2604 img->pal->ncolors, iff.chCMAP.size); |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2605 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2606 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2607 // |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2608 // CAMG |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2609 // |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2610 if ((res = dmWriteIFFChunkHdr(fp, &iff.chCMAP, IFF_ID_CAMG)) != DMERR_OK) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2611 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2612 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2613 if (!dmf_write_be32(fp, iff.camg)) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2614 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2615 return dmError(DMERR_FREAD, |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2616 "IFF: Error writing CAMG chunk.\n"); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2617 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2618 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2619 if ((res = dmWriteIFFChunkFinish(fp, &iff.chCMAP)) != DMERR_OK) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2620 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2621 |
2050
416af5a842ec
Fixes to the ByteRun1 encoder. Could use some cleanups now, tho.
Matti Hamalainen <ccr@tnsp.org>
parents:
2049
diff
changeset
|
2622 |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2623 // |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2624 // Encode the body |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2625 // |
2069 | 2626 if ((res = dmWriteIFFChunkHdr(fp, &iff.chBODY, |
2627 (iff.idsig == IFF_ID_ACBM) ? IFF_ID_ABIT : IFF_ID_BODY)) != DMERR_OK) | |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2628 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2629 |
1904 | 2630 // Allocate encoding buffer |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2631 if (iff.idsig == IFF_ID_ILBM) |
2082
a0a6f5a3fbbf
Fix plane buffer size calculation for IFF ACBM to round up to nearest byte (minimum of 1).
Matti Hamalainen <ccr@tnsp.org>
parents:
2081
diff
changeset
|
2632 bufLen = ((img->width * spec->scaleX + 15) / 16) * 2; |
1904 | 2633 else |
2069 | 2634 if (iff.idsig == IFF_ID_ACBM) |
2082
a0a6f5a3fbbf
Fix plane buffer size calculation for IFF ACBM to round up to nearest byte (minimum of 1).
Matti Hamalainen <ccr@tnsp.org>
parents:
2081
diff
changeset
|
2635 bufLen = (img->width * spec->scaleX * img->height * spec->scaleY + 7) / 8; |
2069 | 2636 else |
1904 | 2637 bufLen = img->width * spec->scaleX; |
2638 | |
2639 dmMsg(2, "IFF: Line/plane row size %d bytes.\n", bufLen); | |
2640 | |
2641 if ((buf = dmMalloc(bufLen)) == NULL) | |
2642 return DMERR_MALLOC; | |
2643 | |
2644 // Encode the body | |
2069 | 2645 if (iff.idsig == IFF_ID_ACBM) |
2646 { | |
2647 for (int plane = 0; plane < iff.bmhd.nplanes; plane++) | |
2648 { | |
2649 // Encode bitplane | |
2650 dmMemset(buf, 0, bufLen); | |
2651 | |
2652 for (int yc = 0; yc < img->height * spec->scaleY; yc++) | |
2653 { | |
2654 Uint8 *sp = img->data + (yc * img->pitch); | |
2655 Uint8 *dp = buf + (yc * img->width * spec->scaleX) / 8; | |
2656 for (int xc = 0; xc < img->width * spec->scaleX; xc++) | |
2657 dp[xc / 8] |= ((sp[xc / spec->scaleX] >> plane) & 1) << (7 - (xc & 7)); | |
2658 } | |
2659 | |
2660 if (!dmIFFWriteOneRow(fp, &iff, buf, bufLen)) | |
2661 { | |
2662 res = dmError(DMERR_FWRITE, | |
2663 "IFF: Error writing ACBM image plane %d.\n", | |
2664 plane); | |
2665 goto out; | |
2666 } | |
2667 } | |
2668 } | |
2669 else | |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2670 { |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2671 for (int yc = 0; yc < img->height; yc++) |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2672 for (int yscale = 0; yscale < spec->scaleY; yscale++) |
1904 | 2673 { |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2674 const Uint8 *sp = img->data + (yc * img->pitch); |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2675 |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2676 if (iff.idsig == IFF_ID_ILBM) |
1904 | 2677 { |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2678 for (int plane = 0; plane < spec->nplanes; plane++) |
1904 | 2679 { |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2680 // Encode bitplane |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2681 dmMemset(buf, 0, bufLen); |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2682 |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2683 for (int xc = 0; xc < img->width * spec->scaleX; xc++) |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2684 buf[xc / 8] |= ((sp[xc / spec->scaleX] >> plane) & 1) << (7 - (xc & 7)); |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2685 |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2686 // Compress / write data |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2687 if (!dmIFFWriteOneRow(fp, &iff, buf, bufLen)) |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2688 { |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2689 res = dmError(DMERR_FWRITE, |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2690 "IFF: Error writing ILBM image plane #%d @ row %d.\n", |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2691 plane, yc); |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2692 goto out; |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2693 } |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2694 } |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2695 |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2696 // Write mask data, if any |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2697 if (iff.bmhd.masking == IFF_MASK_HAS_MASK) |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2698 { |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2699 dmMemset(buf, 0, bufLen); |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2700 |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2701 for (int xc = 0; xc < img->width * spec->scaleX; xc++) |
2094
4276b8c0fef0
Revamp how the DMImage palette system and color formats work, as preparation
Matti Hamalainen <ccr@tnsp.org>
parents:
2093
diff
changeset
|
2702 buf[xc / 8] |= (sp[xc / spec->scaleX] == img->pal->ctransp) << (7 - (xc & 7)); |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2703 |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2704 if (!dmIFFWriteOneRow(fp, &iff, buf, bufLen)) |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2705 { |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2706 res = dmError(DMERR_FWRITE, |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2707 "IFF: Error writing ILBM mask plane %d.\n", yc); |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2708 goto out; |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2709 } |
1904 | 2710 } |
2711 } | |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2712 else |
1904 | 2713 { |
2714 for (int xc = 0; xc < img->width * spec->scaleX; xc++) | |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2715 buf[xc] = sp[xc / spec->scaleX]; |
1904 | 2716 |
2717 if (!dmIFFWriteOneRow(fp, &iff, buf, bufLen)) | |
2718 { | |
2719 res = dmError(DMERR_FWRITE, | |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2720 "IFF: Error writing PBM image row #%d.\n", yc); |
1904 | 2721 goto out; |
2722 } | |
2723 } | |
2724 } | |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2725 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2726 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2727 if ((res = dmWriteIFFChunkFinish(fp, &iff.chBODY)) != DMERR_OK) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2728 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2729 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2730 // Finish the FORM chunk |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2731 if ((res = dmWriteIFFChunkFinish(fp, &iff.chFORM)) != DMERR_OK) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2732 goto out; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2733 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2734 out: |
1904 | 2735 dmFree(buf); |
1896
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2736 return res; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2737 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2738 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2739 |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2740 // |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2741 // List of formats |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2742 // |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2743 const DMImageFormat dmImageFormatList[] = |
435 | 2744 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2745 #ifdef DM_USE_LIBPNG |
435 | 2746 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2747 "png", "Portable Network Graphics", |
2095
80786a28caf0
Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
2748 DM_IMGFMT_PNG, DM_FMT_RDWR | DM_COLFMT_ANY, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
2749 fmtProbePNG, dmReadPNGImage, dmWritePNGImage, |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2750 }, |
435 | 2751 #endif |
2752 { | |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2753 "ppm", "Portable PixMap", |
2095
80786a28caf0
Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
2754 DM_IMGFMT_PPM, DM_FMT_RDWR | DM_COLFMT_GRAYSCALE | DM_COLFMT_RGB, |
2092
614b161c0aa5
Initial support for reading PPM/PGM.
Matti Hamalainen <ccr@tnsp.org>
parents:
2091
diff
changeset
|
2755 fmtProbePPM, dmReadPPMImage, dmWritePPMImage, |
435 | 2756 }, |
2757 { | |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2758 "pcx", "Z-Soft Paintbrush", |
2095
80786a28caf0
Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
2759 DM_IMGFMT_PCX, DM_FMT_RDWR | DM_COLFMT_PALETTE | DM_COLFMT_RGB, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
2760 fmtProbePCX, dmReadPCXImage, dmWritePCXImage, |
435 | 2761 }, |
2762 { | |
2071 | 2763 "ilbm", "IFF ILBM (interleaved/old DP2)", |
2095
80786a28caf0
Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
2764 DM_IMGFMT_IFF_ILBM, DM_FMT_RDWR | DM_COLFMT_PALETTE, |
2068 | 2765 fmtProbeIFF_ILBM, dmReadIFFImage, dmWriteIFFImage, |
2064
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2766 }, |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2767 { |
3617ef01c1de
Separate ILBM and PBM subformats of IFF images.
Matti Hamalainen <ccr@tnsp.org>
parents:
2063
diff
changeset
|
2768 "pbm", "IFF PBM (DP2e)", |
2095
80786a28caf0
Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
2769 DM_IMGFMT_IFF_PBM, DM_FMT_RDWR | DM_COLFMT_PALETTE, |
2068 | 2770 fmtProbeIFF_PBM, dmReadIFFImage, dmWriteIFFImage, |
2771 }, | |
2772 { | |
2773 "acbm", "IFF ACBM (Amiga Basic)", | |
2095
80786a28caf0
Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
2774 DM_IMGFMT_IFF_ACBM, DM_FMT_RDWR | DM_COLFMT_PALETTE, |
2068 | 2775 fmtProbeIFF_ACBM, dmReadIFFImage, dmWriteIFFImage, |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2776 }, |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2777 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2778 "raw", "Plain bitplaned (planar or non-planar) RAW", |
2095
80786a28caf0
Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
2779 DM_IMGFMT_RAW, DM_FMT_WR | DM_COLFMT_PALETTE, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
2780 NULL, NULL, dmWriteRAWImage, |
566
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
487
diff
changeset
|
2781 }, |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
487
diff
changeset
|
2782 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2783 "araw", "IFFMaster Amiga RAW", |
2095
80786a28caf0
Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
2784 DM_IMGFMT_ARAW, DM_FMT_WR | DM_COLFMT_PALETTE, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
2785 NULL, NULL, dmWriteRAWImage, |
2047
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
2786 }, |
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
2787 { |
2057
02fa60b27af5
Correct description of 'cdump' format.
Matti Hamalainen <ccr@tnsp.org>
parents:
2055
diff
changeset
|
2788 "cdump", "'C' dump (image data only)", |
2095
80786a28caf0
Mark image format flags with the color formats they support.
Matti Hamalainen <ccr@tnsp.org>
parents:
2094
diff
changeset
|
2789 DM_IMGFMT_CDUMP, DM_FMT_WR | DM_COLFMT_ANY, |
2047
3829c292df02
Add 'cdump' image output format, mainly for debugging purposes.
Matti Hamalainen <ccr@tnsp.org>
parents:
2026
diff
changeset
|
2790 NULL, NULL, dmWriteCDumpImage, |
435 | 2791 } |
2792 }; | |
2793 | |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2794 const int ndmImageFormatList = sizeof(dmImageFormatList) / sizeof(dmImageFormatList[0]); |
435 | 2795 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2796 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2797 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **pfmt, int *index) |
435 | 2798 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2799 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; |
435 | 2800 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2801 for (int i = 0; i < ndmImageFormatList; i++) |
435 | 2802 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2803 const DMImageFormat *fmt = &dmImageFormatList[i]; |
442
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2804 if (fmt->probe != NULL) |
435 | 2805 { |
442
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2806 int score = fmt->probe(buf, len); |
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2807 if (score > scoreMax) |
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2808 { |
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2809 scoreMax = score; |
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2810 scoreIndex = i; |
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2811 } |
435 | 2812 } |
2813 } | |
2814 | |
2815 if (scoreIndex >= 0) | |
2816 { | |
2817 *pfmt = &dmImageFormatList[scoreIndex]; | |
2818 *index = scoreIndex; | |
2819 return scoreMax; | |
2820 } | |
2821 else | |
2822 return DM_PROBE_SCORE_FALSE; | |
2823 } |