Mercurial > hg > dmlib
annotate tools/libgfx.c @ 1908:2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 26 Jun 2018 16:55:27 +0300 |
parents | 571109a14967 |
children | be7492a121f0 |
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; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
22 ctx->outBitCount = 8; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
23 } |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
24 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
25 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
26 BOOL dmPutBits(DMBitStreamContext *ctx, const int val, const int n) |
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 unsigned int mask = 1 << (n - 1); |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
29 |
1583 | 30 for (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
|
31 { |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
32 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
|
33 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
34 if (val & mask) |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
35 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
|
36 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
37 mask >>= 1; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
38 ctx->outBitCount--; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
39 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
40 if (ctx->outBitCount == 0) |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
41 { |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
42 if (!ctx->putByte(ctx, ctx->outBuf & 0xff)) |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
43 return FALSE; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
44 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
45 ctx->outBitCount = 8; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
46 ctx->outByteCount++; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
47 } |
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 return TRUE; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
51 } |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
52 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
53 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
54 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
|
55 { |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
56 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
|
57 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
|
58 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
59 if (ctx->outBitCount != 8) |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
60 dmPutBits(ctx, 0, ctx->outBitCount); |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
61 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
62 return 0; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
63 } |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
64 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
65 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
66 static BOOL dmPutByteFILE(DMBitStreamContext *ctx, const Uint8 val) |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
67 { |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
68 return dmf_write_byte((DMResource *) ctx->handle, val); |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
69 } |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
70 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
71 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
72 int dmInitBitStreamFILE(DMBitStreamContext *ctx, DMResource *fp) |
1309
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
73 { |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
74 if (ctx == NULL || fp == NULL) |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
75 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
|
76 |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
77 ctx->putByte = dmPutByteFILE; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
78 ctx->handle = (void *) fp; |
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 dmInitBitStreamContext(ctx); |
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 return DMERR_OK; |
5ad7d780a09b
Move bitstream reading functions to libgfx, as they were only used there.
Matti Hamalainen <ccr@tnsp.org>
parents:
1308
diff
changeset
|
83 } |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
84 |
1339 | 85 |
487
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
86 BOOL dmCompareColor(const DMColor *c1, const DMColor *c2, BOOL alpha) |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
87 { |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
88 if (c1->r == c2->r && |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
89 c1->g == c2->g && |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
90 c1->b == c2->b) |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
91 return alpha ? (c1->a == c2->a) : TRUE; |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
92 else |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
93 return FALSE; |
b89598501cec
Move dmCompareColor() to libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
472
diff
changeset
|
94 } |
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 |
1286 | 97 int dmImageGetBytesPerPixel(const int format) |
98 { | |
99 switch (format) | |
100 { | |
1801 | 101 case DM_COLFMT_PALETTE : return 1; |
102 case DM_COLFMT_RGB : return 3; | |
103 case DM_COLFMT_RGBA : return 4; | |
104 default : return -1; | |
1286 | 105 } |
106 } | |
107 | |
108 | |
109 DMImage * dmImageAlloc(const int width, const int height, const int format, const int bpp) | |
435 | 110 { |
928
ebe0d93e03c0
Use dmMalloc0() instead of dmCalloc() here.
Matti Hamalainen <ccr@tnsp.org>
parents:
902
diff
changeset
|
111 DMImage *img = dmMalloc0(sizeof(DMImage)); |
435 | 112 if (img == NULL) |
113 return NULL; | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
114 |
1286 | 115 img->width = width; |
116 img->height = height; | |
117 img->format = format; | |
118 img->bpp = (bpp <= 0) ? dmImageGetBytesPerPixel(format) * 8 : bpp; | |
119 img->pitch = width * img->bpp; | |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
120 img->size = img->pitch * img->height; |
1286 | 121 img->ctransp = -1; |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
122 img->aspect = -1; |
930 | 123 |
929
e1378398be0f
Add size field for allocated data size in DMImage.
Matti Hamalainen <ccr@tnsp.org>
parents:
928
diff
changeset
|
124 if ((img->data = dmMalloc(img->size)) == NULL) |
435 | 125 { |
126 dmFree(img); | |
127 return NULL; | |
128 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
129 |
435 | 130 return img; |
131 } | |
132 | |
133 | |
134 void dmImageFree(DMImage *img) | |
135 { | |
136 if (img != NULL) | |
137 { | |
138 if (!img->constpal) | |
139 { | |
140 dmFree(img->pal); | |
141 } | |
142 dmFree(img->data); | |
143 dmFree(img); | |
144 } | |
145 } | |
146 | |
147 | |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
148 BOOL dmPaletteAlloc(DMColor **ppal, int ncolors, int ctransp) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
149 { |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
150 if (ppal == NULL) |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
151 return FALSE; |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
152 |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
153 // Allocate desired amount of palette |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
154 if ((*ppal = dmCalloc(ncolors, sizeof(DMColor))) == NULL) |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
155 return FALSE; |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
156 |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
157 // Set alpha values to max, except for transparent color |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
158 for (int i = 0; i < ncolors; i++) |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
159 { |
1655 | 160 (*ppal)[i].a = (i == ctransp) ? 0x00 : 0xff; |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
161 } |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
162 |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
163 return TRUE; |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
164 } |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
165 |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
166 |
1655 | 167 BOOL dmImagePaletteAlloc(DMImage *img, int ncolors, int ctransp) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
168 { |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
169 if (img == NULL) |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
170 return FALSE; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
171 |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
172 img->ncolors = ncolors; |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
173 img->ctransp = ctransp; |
1730
881a3fc421d8
Use the default C64 palette whenever we need it, but make it possible to override it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1698
diff
changeset
|
174 img->constpal = FALSE; |
881a3fc421d8
Use the default C64 palette whenever we need it, but make it possible to override it.
Matti Hamalainen <ccr@tnsp.org>
parents:
1698
diff
changeset
|
175 |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
176 return dmPaletteAlloc(&(img->pal), ncolors, ctransp); |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
177 } |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
178 |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
179 |
1655 | 180 static BOOL dmPaletteReadData(DMResource *fp, DMColor *pal, int ncolors) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
181 { |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
182 for (int i = 0; i < ncolors; i++) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
183 { |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
184 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
|
185 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
|
186 !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
|
187 !dmf_read_byte(fp, &colB)) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
188 return FALSE; |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
189 |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
190 pal[i].r = colR; |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
191 pal[i].g = colG; |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
192 pal[i].b = colB; |
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 |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
195 return TRUE; |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
196 } |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
197 |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
198 |
1341 | 199 int dmWriteImageData(const DMImage *img, void *cbdata, int (*writeRowCB)(void *, const Uint8 *, const size_t), const DMImageConvSpec *spec) |
435 | 200 { |
201 int x, y, yscale, xscale, res = 0, rowSize, rowWidth; | |
202 Uint8 *row = NULL; | |
203 | |
204 // 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
|
205 rowWidth = img->width * spec->scaleX; |
435 | 206 rowSize = rowWidth * dmImageGetBytesPerPixel(spec->format); |
207 | |
208 if ((row = dmMalloc(rowSize + 16)) == NULL) | |
209 { | |
210 res = DMERR_MALLOC; | |
211 goto done; | |
212 } | |
213 | |
214 // Generate the image | |
215 for (y = 0; y < img->height; y++) | |
216 { | |
436
86f956e4580f
Cosmetics, rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
435
diff
changeset
|
217 Uint8 *ptr1 = row, |
435 | 218 *ptr2 = ptr1 + rowWidth, |
1291 | 219 *ptr3 = ptr2 + rowWidth, |
220 *ptr4 = ptr3 + rowWidth; | |
435 | 221 |
222 for (x = 0; x < img->width; x++) | |
223 { | |
1291 | 224 Uint8 c = img->data[(y * img->pitch) + (x * img->bpp) / 8], |
225 qr, qg, qb, qa; | |
226 | |
435 | 227 switch (spec->format) |
228 { | |
1801 | 229 case DM_COLFMT_PALETTE: |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
230 for (xscale = 0; xscale < spec->scaleX; xscale++) |
436
86f956e4580f
Cosmetics, rename a variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
435
diff
changeset
|
231 *ptr1++ = c; |
435 | 232 break; |
233 | |
1801 | 234 case DM_COLFMT_RGBA: |
435 | 235 qr = img->pal[c].r; |
236 qg = img->pal[c].g; | |
237 qb = img->pal[c].b; | |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
238 qa = img->pal[c].a; |
1292 | 239 |
1291 | 240 if (spec->planar) |
435 | 241 { |
1291 | 242 for (xscale = 0; xscale < spec->scaleX; xscale++) |
243 { | |
244 *ptr1++ = qr; | |
245 *ptr2++ = qg; | |
246 *ptr3++ = qb; | |
247 *ptr4++ = qa; | |
248 } | |
249 } | |
250 else | |
251 { | |
252 for (xscale = 0; xscale < spec->scaleX; xscale++) | |
253 { | |
254 *ptr1++ = qr; | |
255 *ptr1++ = qg; | |
256 *ptr1++ = qb; | |
257 *ptr1++ = qa; | |
258 } | |
435 | 259 } |
260 break; | |
261 | |
1801 | 262 case DM_COLFMT_RGB: |
435 | 263 qr = img->pal[c].r; |
264 qg = img->pal[c].g; | |
265 qb = img->pal[c].b; | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
266 |
1291 | 267 if (spec->planar) |
435 | 268 { |
1291 | 269 for (xscale = 0; xscale < spec->scaleX; xscale++) |
270 { | |
271 *ptr1++ = qr; | |
272 *ptr2++ = qg; | |
273 *ptr3++ = qb; | |
274 } | |
435 | 275 } |
1291 | 276 else |
435 | 277 { |
1291 | 278 for (xscale = 0; xscale < spec->scaleX; xscale++) |
279 { | |
280 *ptr1++ = qr; | |
281 *ptr1++ = qg; | |
282 *ptr1++ = qb; | |
283 } | |
435 | 284 } |
285 break; | |
286 } | |
287 } | |
288 | |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
289 for (yscale = 0; yscale < spec->scaleY; yscale++) |
435 | 290 { |
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
|
291 if ((res = writeRowCB(cbdata, row, rowSize)) != DMERR_OK) |
435 | 292 goto done; |
293 } | |
294 } | |
295 | |
296 done: | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
297 dmFree(row); |
435 | 298 return res; |
299 } | |
300 | |
301 | |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
302 #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
|
303 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
304 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
|
305 DMResource *fp, const char *filename, const char *prefix, |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
306 const DMImage *img, const DMImageConvSpec *spec, const int fmtid) |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
307 { |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
308 dmfprintf(fp, |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
309 "%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
|
310 "%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
|
311 "%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
|
312 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
|
313 prefix, img->height * spec->scaleY, |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
314 prefix, spec->nplanes); |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
315 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
316 if (fmtid == DM_IMGFMT_ARAW) |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
317 { |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
318 dmfprintf(fp, |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
319 "%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
|
320 "%s_palette:\n", |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
321 prefix, img->ncolors, |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
322 prefix); |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
323 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
324 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
|
325 { |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
326 Uint32 color; |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
327 if (i < img->ncolors) |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
328 { |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
329 color = (DMCOL(img->pal[i].r) << 8) | |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
330 (DMCOL(img->pal[i].g) << 4) | |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
331 (DMCOL(img->pal[i].b)); |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
332 } |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
333 else |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
334 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
|
335 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
336 dmfprintf(fp, |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
337 "\tdc.w $%04X\n", |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
338 color); |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
339 } |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
340 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
341 dmfprintf(fp, |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
342 "%s: incbin \"%s\"\n", |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
343 prefix, filename); |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
344 } |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
345 |
1887
297aa8f0ca7f
Return DMERR_OK instead of dmferror(fp) dmWriteIFFMasterRAWHeader().
Matti Hamalainen <ccr@tnsp.org>
parents:
1886
diff
changeset
|
346 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
|
347 } |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
348 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
349 |
1872
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
350 static BOOL dmWriteRAWRow(DMBitStreamContext *bs, const DMImage *img, const DMImageConvSpec *spec, const int yc, const int plane) |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
351 { |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
352 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
|
353 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
|
354 { |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
355 for (int xscale = 0; xscale < spec->scaleX; xscale++) |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
356 if (!dmPutBits(bs, (sp[xc] & (1 << plane)) ? 1 : 0, 1)) |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
357 return FALSE; |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
358 } |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
359 return TRUE; |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
360 } |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
361 |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
362 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
363 int dmWriteRAWImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) |
435 | 364 { |
1622 | 365 int res; |
800
c63e24f9aa9a
Modularize bitstream reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
366 DMBitStreamContext bs; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
367 |
800
c63e24f9aa9a
Modularize bitstream reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
566
diff
changeset
|
368 if ((res = dmInitBitStreamFILE(&bs, fp)) != DMERR_OK) |
435 | 369 return res; |
370 | |
1291 | 371 if (spec->planar) |
435 | 372 { |
1339 | 373 // Output bitplanes in planar format |
374 // (each plane of line sequentially) | |
1622 | 375 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
|
376 for (int yscale = 0; yscale < spec->scaleY; yscale++) |
1622 | 377 for (int plane = 0; plane < spec->nplanes; plane++) |
435 | 378 { |
1872
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
379 if (!dmWriteRAWRow(&bs, img, spec, yc, plane)) |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
380 return DMERR_FWRITE; |
435 | 381 } |
382 } | |
383 else | |
384 { | |
385 // Output each bitplane in sequence | |
1622 | 386 for (int plane = 0; plane < spec->nplanes; plane++) |
387 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
|
388 for (int yscale = 0; yscale < spec->scaleY; yscale++) |
435 | 389 { |
1872
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
390 if (!dmWriteRAWRow(&bs, img, spec, yc, plane)) |
fe15412eec10
Actually fix also the ARAW/RAW image data writing to honor the scaling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1814
diff
changeset
|
391 return DMERR_FWRITE; |
435 | 392 } |
393 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
394 |
435 | 395 return dmFlushBitStream(&bs); |
396 } | |
397 | |
566
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
487
diff
changeset
|
398 |
1301 | 399 static int dmWritePPMRow(void *cbdata, const Uint8 *row, const size_t len) |
435 | 400 { |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
401 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
|
402 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
|
403 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
|
404 return DMERR_FWRITE; |
435 | 405 } |
406 | |
407 | |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
408 int dmWritePPMImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) |
435 | 409 { |
1290
e7dc9bb9777e
Rename struct DMImageSpec to DMImageConvSpec.
Matti Hamalainen <ccr@tnsp.org>
parents:
1288
diff
changeset
|
410 DMImageConvSpec tmpSpec; |
1288 | 411 |
435 | 412 // 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
|
413 char *tmp = dm_strdup_printf( |
435 | 414 "P6\n%d %d\n255\n", |
902
c6c480e8e1c8
Add separate X and Y scaling to gfxconv and libgfx outputters.
Matti Hamalainen <ccr@tnsp.org>
parents:
858
diff
changeset
|
415 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
|
416 img->height * spec->scaleY); |
435 | 417 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
418 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
|
419 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
|
420 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
421 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
|
422 dmFree(tmp); |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
423 |
435 | 424 // Write image data |
1290
e7dc9bb9777e
Rename struct DMImageSpec to DMImageConvSpec.
Matti Hamalainen <ccr@tnsp.org>
parents:
1288
diff
changeset
|
425 memcpy(&tmpSpec, spec, sizeof(DMImageConvSpec)); |
1801 | 426 tmpSpec.format = DM_COLFMT_RGB; |
1288 | 427 return dmWriteImageData(img, (void *) fp, dmWritePPMRow, &tmpSpec); |
435 | 428 } |
429 | |
430 | |
431 #ifdef DM_USE_LIBPNG | |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
432 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
|
433 { |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
434 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
|
435 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
|
436 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
|
437 { |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
438 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
|
439 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
|
440 return DM_PROBE_SCORE_MAX; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
441 else |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
442 return DM_PROBE_SCORE_GOOD; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
443 } |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
444 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
445 return DM_PROBE_SCORE_FALSE; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
446 } |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
447 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
448 |
1301 | 449 static int dmWritePNGRow(void *cbdata, const Uint8 *row, const size_t len) |
435 | 450 { |
451 png_structp png_ptr = cbdata; | |
452 (void) len; | |
453 | |
454 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
|
455 return DMERR_INTERNAL; |
435 | 456 |
457 png_write_row(png_ptr, row); | |
458 | |
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
|
459 return DMERR_OK; |
435 | 460 } |
461 | |
462 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
463 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
|
464 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
465 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
|
466 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
467 // 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
|
468 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
|
469 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
470 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
471 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
472 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
|
473 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
474 (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
|
475 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
476 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
477 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
478 int dmWritePNGImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) |
435 | 479 { |
480 png_structp png_ptr = NULL; | |
481 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
|
482 int fmt, res; |
435 | 483 |
484 // Create PNG structures | |
485 png_ptr = png_create_write_struct( | |
486 PNG_LIBPNG_VER_STRING, | |
487 NULL, NULL, NULL); | |
488 | |
489 if (png_ptr == NULL) | |
490 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
491 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
492 "PNG: png_create_write_struct() failed.\n"); |
435 | 493 goto error; |
494 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
495 |
435 | 496 info_ptr = png_create_info_struct(png_ptr); |
497 if (info_ptr == NULL) | |
498 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
499 res = dmError(DMERR_INIT_FAIL, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
500 "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
|
501 png_ptr); |
435 | 502 goto error; |
503 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
504 |
435 | 505 if (setjmp(png_jmpbuf(png_ptr))) |
506 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
507 res = dmError(DMERR_INIT_FAIL, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
508 "PNG: Error during image writing..\n"); |
435 | 509 goto error; |
510 } | |
511 | |
1304
e968b259605b
Fix a warning about potentially clobbered variable due to setjmp() use.
Matti Hamalainen <ccr@tnsp.org>
parents:
1303
diff
changeset
|
512 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
|
513 png_set_write_fn(png_ptr, fp, dmPNGWriteData, dmPNGWriteFlush); |
435 | 514 |
515 // Write PNG header info | |
516 switch (spec->format) | |
517 { | |
1801 | 518 case DM_COLFMT_PALETTE: fmt = PNG_COLOR_TYPE_PALETTE; break; |
519 case DM_COLFMT_RGB : fmt = PNG_COLOR_TYPE_RGB; break; | |
520 case DM_COLFMT_RGBA : fmt = PNG_COLOR_TYPE_RGB_ALPHA; break; | |
435 | 521 default: |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
522 res = dmError(DMERR_NOT_SUPPORTED, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
523 "PNG: Unsupported image format %d.\n", |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
524 spec->format); |
435 | 525 goto error; |
526 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
527 |
435 | 528 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
|
529 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
|
530 img->height * spec->scaleY, |
435 | 531 8, /* bits per component */ |
532 fmt, | |
533 PNG_INTERLACE_NONE, | |
534 PNG_COMPRESSION_TYPE_DEFAULT, | |
535 PNG_FILTER_TYPE_DEFAULT); | |
536 | |
1287
32051ad352c8
Adjust debug messages and debug message levels in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1286
diff
changeset
|
537 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
|
538 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
|
539 img->height * spec->scaleY, |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
540 8, fmt); |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
541 |
435 | 542 // Palette |
1801 | 543 if (spec->format == DM_COLFMT_PALETTE) |
435 | 544 { |
545 int i; | |
858
e7019bd83cca
Fix potential longjmp clobbering of variable.
Matti Hamalainen <ccr@tnsp.org>
parents:
834
diff
changeset
|
546 png_colorp palette = png_malloc(png_ptr, PNG_MAX_PALETTE_LENGTH * sizeof(png_color)); |
435 | 547 |
548 if (palette == NULL) | |
549 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
550 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
551 "PNG: Could not allocate palette structure."); |
435 | 552 goto error; |
553 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
554 |
1167 | 555 dmMemset(palette, 0, PNG_MAX_PALETTE_LENGTH * sizeof(png_color)); |
435 | 556 |
557 for (i = 0; i < img->ncolors; i++) | |
558 { | |
559 palette[i].red = img->pal[i].r; | |
560 palette[i].green = img->pal[i].g; | |
561 palette[i].blue = img->pal[i].b; | |
562 } | |
563 | |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
564 png_set_PLTE(png_ptr, info_ptr, palette, img->ncolors); |
435 | 565 } |
566 | |
567 // png_set_gAMA(png_ptr, info_ptr, 2.2); | |
568 | |
569 png_write_info(png_ptr, info_ptr); | |
570 | |
571 | |
572 // Write compressed image data | |
573 dmWriteImageData(img, (void *) png_ptr, dmWritePNGRow, spec); | |
574 | |
575 // Write footer | |
576 png_write_end(png_ptr, NULL); | |
577 | |
578 error: | |
579 if (png_ptr && info_ptr) | |
580 png_destroy_write_struct(&png_ptr, &info_ptr); | |
581 | |
582 return res; | |
583 } | |
584 | |
585 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
586 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
|
587 { |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
588 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
|
589 |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
590 // 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
|
591 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
|
592 } |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
593 |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
594 |
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
595 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
|
596 { |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
597 png_structp png_ptr = NULL; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
598 png_infop info_ptr = NULL; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
599 png_colorp palette = NULL; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
600 png_bytep *row_pointers = NULL; |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
601 png_bytep trans = NULL; |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
602 png_uint_32 width, height, res_x, res_y; |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
603 int i, 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
|
604 int res = DMERR_OK; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
605 DMImage *img; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
606 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
607 // Create PNG structures |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
608 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
|
609 PNG_LIBPNG_VER_STRING, |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
610 NULL, NULL, NULL); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
611 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
612 if (png_ptr == NULL) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
613 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
614 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
615 "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
|
616 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
617 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
618 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
619 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
|
620 if (info_ptr == NULL) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
621 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
622 res = dmError(DMERR_INIT_FAIL, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
623 "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
|
624 png_ptr); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
625 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
626 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
627 |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
628 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
|
629 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
630 res = dmError(DMERR_INIT_FAIL, |
1291 | 631 "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
|
632 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
633 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
634 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
635 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
|
636 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
637 // Read image information |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
638 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
|
639 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
640 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
|
641 &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
|
642 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
643 if (width < 1 || height < 1) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
644 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
645 res = dmError(DMERR_INVALID_DATA, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
646 "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
|
647 width, height); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
648 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
649 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
650 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
651 switch (color_type) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
652 { |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
653 case PNG_COLOR_TYPE_GRAY: |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
654 if (bit_depth < 8) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
655 png_set_expand_gray_1_2_4_to_8(png_ptr); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
656 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
657 if (bit_depth > 8) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
658 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
659 res = dmError(DMERR_NOT_SUPPORTED, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
660 "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
|
661 bit_depth); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
662 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
663 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
664 break; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
665 |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
666 case PNG_COLOR_TYPE_PALETTE: |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
667 png_set_packing(png_ptr); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
668 break; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
669 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
670 default: |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
671 res = dmError(DMERR_NOT_SUPPORTED, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
672 "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
|
673 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
674 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
675 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
676 // Allocate image |
1287
32051ad352c8
Adjust debug messages and debug message levels in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1286
diff
changeset
|
677 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
|
678 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
|
679 |
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
|
680 if ((*pimg = img = dmImageAlloc(width, height, |
1801 | 681 DM_COLFMT_PALETTE, |
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
|
682 // 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
|
683 -1 /* bit_depth */)) == NULL) |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
684 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
685 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
686 "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
|
687 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
688 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
689 |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
690 // Set image aspect ratio |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
691 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
|
692 |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
693 if (res_x > 0 && res_y > 0 && |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
694 res_y / res_x != (unsigned) (img->height / img->width)) |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
695 img->aspect = (float) res_y / (float) res_x; |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
696 |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
697 // ... |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
698 row_pointers = png_malloc(png_ptr, height * sizeof(png_bytep)); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
699 for (i = 0; i < img->height; i++) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
700 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
|
701 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
702 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
|
703 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
704 png_read_end(png_ptr, NULL); |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
705 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
706 // Create palette |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
707 switch (color_type) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
708 { |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
709 case PNG_COLOR_TYPE_GRAY: |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
710 ncolors = 256; |
1287
32051ad352c8
Adjust debug messages and debug message levels in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1286
diff
changeset
|
711 dmMsg(2, "PNG: Generating %d color grayscale palette.\n", ncolors); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
712 |
1655 | 713 if (!dmImagePaletteAlloc(img, ncolors, -1)) |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
714 { |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
715 res = DMERR_MALLOC; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
716 goto error; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
717 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
718 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
719 for (i = 0; i < img->ncolors; i++) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
720 { |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
721 img->pal[i].r = img->pal[i].g = img->pal[i].b = i; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
722 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
723 break; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
724 |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
725 case PNG_COLOR_TYPE_PALETTE: |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
726 png_get_PLTE(png_ptr, info_ptr, &palette, &ncolors); |
1287
32051ad352c8
Adjust debug messages and debug message levels in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1286
diff
changeset
|
727 dmMsg(2, "PNG: Palette of %d colors found.\n", ncolors); |
467
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
728 if (ncolors > 0 && palette != NULL) |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
729 { |
1655 | 730 if (!dmImagePaletteAlloc(img, ncolors, -1)) |
467
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
731 { |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
732 res = DMERR_MALLOC; |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
733 goto error; |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
734 } |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
735 |
467
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
736 for (i = 0; i < img->ncolors; i++) |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
737 { |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
738 img->pal[i].r = palette[i].red; |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
739 img->pal[i].g = palette[i].green; |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
740 img->pal[i].b = palette[i].blue; |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
741 } |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
742 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
743 break; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
744 } |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
745 |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
746 if (color_type == PNG_COLOR_TYPE_PALETTE || |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
747 color_type == PNG_COLOR_TYPE_GRAY) |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
748 { |
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
749 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
|
750 if (trans != NULL && ntrans > 0) |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
751 { |
467
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
752 for (i = 0; i < img->ncolors && i < ntrans; i++) |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
753 { |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
754 img->pal[i].a = trans[i]; |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
755 if (img->ctransp < 0 && trans[i] == 0) |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
756 img->ctransp = i; |
80d09ea85e75
Check for NULL pointers from png_get_tRNS and png_get_PLTE.
Matti Hamalainen <ccr@tnsp.org>
parents:
465
diff
changeset
|
757 } |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
758 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
759 } |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
760 |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
761 error: |
460
0af039b6c0ae
Improve transparent color handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
453
diff
changeset
|
762 // png_free(png_ptr, palette); |
453
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
763 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
764 if (png_ptr && info_ptr) |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
765 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
|
766 |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
767 return res; |
349a2ff11531
Implement PNG (1-8bpp indexed) reading support via libPNG.
Matti Hamalainen <ccr@tnsp.org>
parents:
452
diff
changeset
|
768 } |
435 | 769 #endif |
770 | |
771 | |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
772 // |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
773 // Z-Soft PCX format |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
774 // |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
775 #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
|
776 |
435 | 777 typedef struct |
778 { | |
779 Uint8 r,g,b; | |
780 } DMPCXColor; | |
781 | |
782 | |
783 typedef struct | |
784 { | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
785 Uint8 manufacturer, // always 0x0a |
1288 | 786 version, // Z-Soft PC Paintbrush version: |
787 // 0 = v2.5 | |
788 // 2 = v2.8 with palette, | |
789 // 3 = v2.8 without palette | |
790 // 4 = PC Paintbrush for Windows | |
791 // 5 = v3.0 or better | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
792 encoding, // usually 0x01 = RLE, 0x00 = uncompressed |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
793 bitsPerPlane; // bits per pixel per plane |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
794 |
435 | 795 Uint16 xmin, ymin, xmax, ymax; |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
796 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
|
797 DMPCXColor colorMap[DMPCX_PAL_COLORS]; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
798 Uint8 reserved; // should be set to 0 |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
799 Uint8 nplanes; // number of planes |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
800 Uint16 bpl; // bytes per plane LINE |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
801 Uint16 palInfo; // 1 = color/BW, 2 = grayscale |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
802 Uint16 hScreenSize, vScreenSize; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
803 Uint8 filler[54]; |
435 | 804 } DMPCXHeader; |
805 | |
806 | |
807 typedef struct | |
808 { | |
809 DMPCXHeader *header; | |
810 Uint8 *buf; | |
811 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
|
812 DMResource *fp; |
435 | 813 } DMPCXData; |
814 | |
815 | |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
816 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
|
817 { |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
818 if (len > 128 + 32 && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
819 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
820 (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
|
821 buf[2] == 1 && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
822 (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
|
823 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
|
824 return DM_PROBE_SCORE_GOOD; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
825 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
826 return DM_PROBE_SCORE_FALSE; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
827 } |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
828 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
829 |
1298 | 830 // Returns one byte from row buffer (of length len) at offset soffs, |
831 // OR zero if the offset is outside buffer. | |
1301 | 832 static inline Uint8 dmPCXGetByte(const Uint8 *row, const size_t len, const size_t soffs) |
435 | 833 { |
834 return (soffs < len) ? row[soffs] : 0; | |
835 } | |
836 | |
837 static BOOL dmPCXFlush(DMPCXData *pcx) | |
838 { | |
839 BOOL ret = TRUE; | |
840 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
|
841 ret = dmf_write_str(pcx->fp, pcx->buf, pcx->bufOffs); |
1297 | 842 |
435 | 843 pcx->bufOffs = 0; |
844 return ret; | |
845 } | |
846 | |
847 static inline BOOL dmPCXPutByte(DMPCXData *pcx, const Uint8 val) | |
848 { | |
849 if (pcx->bufOffs < pcx->bufLen) | |
850 { | |
851 pcx->buf[pcx->bufOffs++] = val; | |
852 return TRUE; | |
853 } | |
854 else | |
855 return dmPCXFlush(pcx); | |
856 } | |
857 | |
1297 | 858 |
859 static int dmPCXPutData(DMPCXData *pcx, const Uint8 data, const int count) | |
860 { | |
861 if (count == 1 && (data & 0xC0) != 0xC0) | |
862 { | |
863 if (!dmPCXPutByte(pcx, data)) | |
864 return DMERR_FWRITE; | |
865 } | |
866 else | |
867 { | |
868 if (!dmPCXPutByte(pcx, 0xC0 | count) || | |
869 !dmPCXPutByte(pcx, data)) | |
870 return DMERR_FWRITE; | |
871 } | |
872 return DMERR_OK; | |
873 } | |
874 | |
875 | |
1301 | 876 static int dmWritePCXRow(void *cbdata, const Uint8 *row, const size_t len) |
435 | 877 { |
878 DMPCXData *pcx = (DMPCXData *) cbdata; | |
1297 | 879 int err; |
435 | 880 size_t soffs = 0; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
881 |
435 | 882 pcx->bufOffs = 0; |
883 | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
884 for (int plane = 0; plane < pcx->header->nplanes; plane++) |
435 | 885 { |
886 Uint8 data = dmPCXGetByte(row, len, soffs++), | |
887 count = 1; | |
888 | |
1297 | 889 size_t blen = pcx->header->bpl * pcx->header->nplanes; |
435 | 890 while (soffs < blen) |
891 { | |
1297 | 892 if (data == dmPCXGetByte(row, len, soffs) && count < 0x3F) |
435 | 893 { |
894 count++; | |
895 soffs++; | |
896 } | |
897 else | |
898 { | |
1297 | 899 if ((err = dmPCXPutData(pcx, data, count)) != DMERR_OK) |
900 return err; | |
435 | 901 |
902 data = dmPCXGetByte(row, len, soffs++); | |
903 count = 1; | |
904 } | |
905 } | |
906 | |
1297 | 907 if ((err = dmPCXPutData(pcx, data, count)) != DMERR_OK) |
908 return err; | |
435 | 909 |
910 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
|
911 return DMERR_FWRITE; |
435 | 912 } |
913 | |
914 | |
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
|
915 return DMERR_OK; |
435 | 916 } |
917 | |
918 | |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
919 int dmWritePCXImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *pspec) |
435 | 920 { |
921 DMPCXData pcx; | |
922 DMPCXHeader hdr; | |
1303 | 923 DMImageConvSpec spec; |
435 | 924 int res; |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
925 |
1303 | 926 // Always force planar for PCX |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
927 memcpy(&spec, pspec, sizeof(DMImageConvSpec)); |
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
928 spec.planar = TRUE; |
435 | 929 |
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
|
930 // XXX: 24bit PCX does not work yet .. |
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
|
931 if (!spec.paletted) |
1800
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
932 { |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
933 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
|
934 "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
|
935 } |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
936 |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
937 if (spec.paletted && img->pal == NULL) |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
938 { |
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
939 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
|
940 "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
|
941 } |
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
|
942 |
435 | 943 // Create output file |
944 pcx.buf = NULL; | |
945 pcx.header = &hdr; | |
946 pcx.fp = fp; | |
947 | |
948 // Create PCX header | |
1167 | 949 dmMemset(&hdr, 0, sizeof(hdr)); |
1800
45e7688336dc
Fix checks for NULL palette in index/palette images. Also improve error
Matti Hamalainen <ccr@tnsp.org>
parents:
1730
diff
changeset
|
950 if (spec.paletted) |
435 | 951 { |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
952 for (int i = 0; i < (img->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->ncolors); i++) |
435 | 953 { |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
954 hdr.colorMap[i].r = img->pal[i].r; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
955 hdr.colorMap[i].g = img->pal[i].g; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
956 hdr.colorMap[i].b = img->pal[i].b; |
435 | 957 } |
958 } | |
959 hdr.manufacturer = 10; | |
960 hdr.version = 5; | |
961 hdr.encoding = 1; | |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
962 hdr.hres = img->width * spec.scaleX; |
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
963 hdr.vres = img->height * spec.scaleY; |
435 | 964 hdr.xmin = hdr.ymin = 0; |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
965 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
|
966 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
|
967 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
|
968 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
|
969 hdr.vScreenSize = hdr.vres; |
435 | 970 |
1291 | 971 // TODO XXX .. maybe actually compute these asdf |
972 hdr.bitsPerPlane = 8; | |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
973 hdr.nplanes = dmImageGetBytesPerPixel(spec.format); |
1291 | 974 |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
975 res = img->width * spec.scaleX; |
435 | 976 hdr.bpl = res / 2; |
977 if (res % 2) hdr.bpl++; | |
978 hdr.bpl *= 2; | |
979 | |
1297 | 980 dmMsg(2, |
981 "PCX: xmin=%d, ymin=%d, xmax=%d, ymax=%d, res=%dx%d, scr=%dx%d\n", | |
982 hdr.xmin, hdr.ymin, hdr.xmax, hdr.ymax, | |
983 hdr.hres, hdr.vres, | |
984 hdr.hScreenSize, hdr.vScreenSize); | |
985 | |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
986 dmMsg(2, "PCX: nplanes=%d, bpp=%d, bpl=%d, isPaletted=%s, planar=%s\n", |
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
987 hdr.nplanes, hdr.bitsPerPlane, hdr.bpl, |
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
988 spec.paletted ? "yes" : "no", |
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
989 spec.planar ? "yes" : "no" |
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
990 ); |
435 | 991 |
1291 | 992 // TODO XXX this is also bogus |
435 | 993 pcx.bufLen = hdr.bpl * 4; |
994 if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL) | |
995 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
996 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
997 "PCX: Could not allocate %d bytes for RLE compression buffer.\n", |
435 | 998 pcx.bufLen); |
999 goto error; | |
1000 } | |
1001 | |
1002 // 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
|
1003 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
|
1004 !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
|
1005 !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
|
1006 !dmf_write_byte(pcx.fp, hdr.bitsPerPlane)) |
435 | 1007 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1008 res = dmError(DMERR_FWRITE, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1009 "PCX: Could not write basic header data.\n"); |
435 | 1010 goto error; |
1011 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1012 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1013 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
|
1014 !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
|
1015 !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
|
1016 !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
|
1017 !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
|
1018 !dmf_write_le16(pcx.fp, hdr.vres)) |
435 | 1019 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1020 res = dmError(DMERR_FWRITE, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1021 "PCX: Could not write image dimensions.\n"); |
435 | 1022 goto error; |
1023 } | |
1024 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1025 if (!dmf_write_str(pcx.fp, (Uint8 *) &hdr.colorMap, sizeof(hdr.colorMap))) |
435 | 1026 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1027 res = dmError(DMERR_FWRITE, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1028 "PCX: Could not write colormap.\n"); |
435 | 1029 goto error; |
1030 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1031 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1032 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
|
1033 !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
|
1034 !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
|
1035 !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
|
1036 !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
|
1037 !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
|
1038 !dmf_write_str(pcx.fp, (Uint8 *) &hdr.filler, sizeof(hdr.filler))) |
435 | 1039 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1040 res = dmError(DMERR_FWRITE, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1041 "PCX: Could not write header remainder.\n"); |
435 | 1042 goto error; |
1043 } | |
1044 | |
1045 // Write image data | |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1046 res = dmWriteImageData(img, (void *) &pcx, dmWritePCXRow, &spec); |
435 | 1047 |
1048 // Write VGA palette | |
1302
38614c07c2e2
Now with "almost" working 24bit PCX output. Almost.
Matti Hamalainen <ccr@tnsp.org>
parents:
1301
diff
changeset
|
1049 if (spec.paletted) |
435 | 1050 { |
1051 int i; | |
1294
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1052 dmMsg(2, "PCX: Writing palette of %d active entries.\n", img->ncolors); |
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1053 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1054 dmf_write_byte(pcx.fp, 0x0C); |
435 | 1055 |
1056 for (i = 0; i < img->ncolors; i++) | |
1057 { | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1058 if (!dmf_write_byte(pcx.fp, img->pal[i].r) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1059 !dmf_write_byte(pcx.fp, img->pal[i].g) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1060 !dmf_write_byte(pcx.fp, img->pal[i].b)) |
1294
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1061 { |
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1062 res = dmError(DMERR_FWRITE, |
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1063 "PCX: Could not write palette data.\n"); |
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1064 goto error; |
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1065 } |
435 | 1066 } |
1067 | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1068 // Pad the palette, if necessary |
435 | 1069 for (; i < 256; i++) |
1070 { | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1071 if (!dmf_write_byte(pcx.fp, 0) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1072 !dmf_write_byte(pcx.fp, 0) || |
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1073 !dmf_write_byte(pcx.fp, 0)) |
1294
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1074 { |
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1075 res = dmError(DMERR_FWRITE, |
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1076 "PCX: Could not write palette data.\n"); |
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1077 goto error; |
9f2117f1584a
Improve error checking in PCX writer.
Matti Hamalainen <ccr@tnsp.org>
parents:
1292
diff
changeset
|
1078 } |
435 | 1079 } |
1080 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1081 |
435 | 1082 error: |
1083 dmFree(pcx.buf); | |
1084 return res; | |
1085 } | |
1086 | |
1087 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1088 static BOOL dmPCXDecodeRLERow(DMResource *fp, Uint8 *buf, const size_t bufLen) |
435 | 1089 { |
1090 size_t offs = 0; | |
1091 do | |
1092 { | |
1093 int count; | |
1094 Uint8 data; | |
1095 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1096 if (!dmf_read_byte(fp, &data)) |
435 | 1097 return FALSE; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1098 |
435 | 1099 if ((data & 0xC0) == 0xC0) |
1100 { | |
1284 | 1101 BOOL skip = FALSE; |
435 | 1102 count = data & 0x3F; |
1284 | 1103 if (count == 0) |
1104 { | |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1105 switch (dmGFXErrorMode) |
1284 | 1106 { |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1107 case DM_ERRMODE_RECOV_1: |
1284 | 1108 // Use as literal |
1109 skip = TRUE; | |
1110 count = 1; | |
1111 break; | |
1112 | |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1113 case DM_ERRMODE_RECOV_2: |
1284 | 1114 // Ignore completely |
1115 skip = TRUE; | |
1116 break; | |
1117 | |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1118 case DM_ERRMODE_FAIL: |
1284 | 1119 default: |
1120 // Error out on "invalid" data | |
1121 return FALSE; | |
1122 } | |
1123 } | |
1124 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1125 if (!skip && !dmf_read_byte(fp, &data)) |
435 | 1126 return FALSE; |
1127 } | |
1128 else | |
1129 count = 1; | |
1130 | |
1131 while (count-- && offs < bufLen) | |
1132 buf[offs++] = data; | |
1133 | |
1284 | 1134 // 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
|
1135 if (count > 0 && dmGFXErrorMode == DM_ERRMODE_FAIL) |
1284 | 1136 return FALSE; |
1137 | |
435 | 1138 } while (offs < bufLen); |
1139 | |
1140 return TRUE; | |
1141 } | |
1142 | |
1143 | |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
1144 int dmReadPCXImage(DMResource *fp, DMImage **pimg) |
435 | 1145 { |
1146 DMImage *img; | |
1147 DMPCXData pcx; | |
1148 DMPCXHeader hdr; | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1149 int res = 0; |
1286 | 1150 BOOL isPaletted; |
435 | 1151 pcx.buf = NULL; |
1152 | |
1153 // 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
|
1154 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
|
1155 !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
|
1156 !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
|
1157 !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
|
1158 !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
|
1159 !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
|
1160 !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
|
1161 !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
|
1162 !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
|
1163 !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
|
1164 !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
|
1165 !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
|
1166 !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
|
1167 !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
|
1168 !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
|
1169 !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
|
1170 !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
|
1171 !dmf_read_str(fp, (Uint8 *) &hdr.filler, sizeof(hdr.filler))) |
435 | 1172 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1173 res = dmError(DMERR_FREAD, |
1298 | 1174 "PCX: Could not read image header data.\n"); |
1175 goto error; | |
1176 } | |
1177 | |
1178 if (hdr.manufacturer != 10 || | |
1179 hdr.version > 5 || | |
1180 hdr.encoding != 1) | |
1181 { | |
1182 res = dmError(DMERR_NOT_SUPPORTED, | |
1183 "PCX: Not a PCX file, or unsupported variant.\n"); | |
435 | 1184 goto error; |
1185 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1186 |
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
|
1187 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
|
1188 { |
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
|
1189 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
|
1190 "PCX: Probably invalid combination of nplanes and bpp, attempting to fix ..\n"); |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1191 |
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
|
1192 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
|
1193 } |
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
|
1194 |
1295
7a986f33895e
Fix isPaletted check in PCX reader :P
Matti Hamalainen <ccr@tnsp.org>
parents:
1294
diff
changeset
|
1195 isPaletted = (hdr.bitsPerPlane * hdr.nplanes) <= 8; |
1291 | 1196 |
1197 dmMsg(2, | |
1198 "PCX: xmin=%d, ymin=%d, xmax=%d, ymax=%d, res=%dx%d, scr=%dx%d\n", | |
1199 hdr.xmin, hdr.ymin, hdr.xmax, hdr.ymax, | |
1200 hdr.hres, hdr.vres, | |
1201 hdr.hScreenSize, hdr.vScreenSize); | |
1202 | |
1203 dmMsg(2, | |
1204 "PCX: nplanes=%d, bpp=%d, bpl=%d, isPaletted=%s\n", | |
1205 hdr.nplanes, hdr.bitsPerPlane, hdr.bpl, isPaletted ? "yes" : "no"); | |
1206 | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1207 if (hdr.nplanes < 1 || hdr.nplanes > 8) |
435 | 1208 { |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1209 res = dmError(DMERR_NOT_SUPPORTED, |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1210 "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
|
1211 hdr.nplanes); |
435 | 1212 goto error; |
1213 } | |
1214 | |
1286 | 1215 if (!isPaletted) |
1216 { | |
1217 res = dmError(DMERR_NOT_SUPPORTED, | |
1218 "PCX: Non-indexed (truecolour) PCX images not supported for loading.\n"); | |
1219 goto error; | |
1220 } | |
1221 | |
435 | 1222 // Allocate image |
1286 | 1223 if ((*pimg = img = dmImageAlloc(hdr.xmax - hdr.xmin + 1, hdr.ymax - hdr.ymin + 1, |
1801 | 1224 isPaletted ? DM_COLFMT_PALETTE : DM_COLFMT_RGBA, |
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
|
1225 // 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
|
1226 // 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
|
1227 -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
|
1228 )) == NULL) |
435 | 1229 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1230 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1231 "PCX: Could not allocate image structure.\n"); |
435 | 1232 goto error; |
1233 } | |
1234 | |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1235 // Set image aspect ratio |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1236 if (hdr.hScreenSize > 0 && hdr.vScreenSize > 0 && |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1237 hdr.vScreenSize / hdr.hScreenSize != img->height / img->width) |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1238 img->aspect = (float) hdr.vScreenSize / (float) hdr.hScreenSize; |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1239 |
1298 | 1240 // Sanity check bytes per line value |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1241 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
|
1242 { |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1243 res = dmError(DMERR_MALLOC, |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1244 "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
|
1245 hdr.bpl, (img->width * hdr.bitsPerPlane) / 8); |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1246 goto error; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1247 } |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1248 |
435 | 1249 pcx.bufLen = hdr.nplanes * hdr.bpl; |
1250 if ((pcx.buf = dmMalloc(pcx.bufLen)) == NULL) | |
1251 { | |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1252 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1253 "PCX: Could not allocate RLE buffer.\n"); |
435 | 1254 goto error; |
1255 } | |
1256 | |
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
|
1257 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
|
1258 "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
|
1259 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
|
1260 |
435 | 1261 // Read image data |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1262 Uint8 *dp = img->data; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1263 for (int yc = 0; yc < img->height; yc++) |
435 | 1264 { |
1265 // 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
|
1266 if (!dmPCXDecodeRLERow(fp, pcx.buf, pcx.bufLen)) |
435 | 1267 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1268 res = dmError(DMERR_INVALID_DATA, |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1269 "PCX: Error decoding RLE compressed data.\n"); |
435 | 1270 goto error; |
1271 } | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1272 |
435 | 1273 // Decode bitplanes |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1274 switch (hdr.bitsPerPlane) |
435 | 1275 { |
1296 | 1276 case 32: |
1277 case 24: | |
1278 case 16: | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1279 case 8: |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1280 { |
1286 | 1281 // Actually bytes and bits per plane per pixel .. |
1282 const int bytesPerPlane = hdr.bitsPerPlane / 8; | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1283 |
1286 | 1284 for (int nplane = 0; nplane < hdr.nplanes; nplane++) |
1285 { | |
1286 Uint8 *dptr = dp + (nplane * bytesPerPlane), | |
1287 *sptr = pcx.buf + (hdr.bpl * nplane); | |
1288 | |
1289 memcpy(dptr, sptr, img->width * bytesPerPlane); | |
1290 } | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1291 } |
435 | 1292 break; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1293 |
1280
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1294 case 1: |
1814
0b7062d874ef
Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
1810
diff
changeset
|
1295 dmMemset(dp, 0, img->width); |
1296 | 1296 |
1280
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1297 for (int nplane = 0; nplane < hdr.nplanes; nplane++) |
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1298 { |
1296 | 1299 Uint8 *sptr = pcx.buf + (hdr.bpl * nplane); |
1280
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1300 |
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1301 for (int xc = 0; xc < img->width; xc++) |
1296 | 1302 { |
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
|
1303 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
|
1304 dp[xc] |= ((sptr[xc / 8] & (1 << px)) >> px) << nplane; |
1296 | 1305 } |
1280
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1306 } |
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1307 break; |
300a51e98fc3
Bump version and copyright.
Matti Hamalainen <ccr@tnsp.org>
parents:
1279
diff
changeset
|
1308 |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1309 default: |
1285
e4bda4909d72
Make libgfx error mode a global variable, at least for now.
Matti Hamalainen <ccr@tnsp.org>
parents:
1284
diff
changeset
|
1310 res = dmError(DMERR_NOT_SUPPORTED, |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1311 "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
|
1312 hdr.bitsPerPlane); |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1313 goto error; |
435 | 1314 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1315 |
435 | 1316 dp += img->pitch; |
1317 } | |
1318 | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1319 // Read additional VGA palette, if available |
1286 | 1320 if (isPaletted) |
435 | 1321 { |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1322 int ncolors; |
435 | 1323 Uint8 tmpb; |
1324 BOOL read; | |
1325 | |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1326 if (!dmf_read_byte(fp, &tmpb) || tmpb != 0x0C) |
435 | 1327 { |
1328 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
|
1329 ncolors = DMPCX_PAL_COLORS; |
435 | 1330 } |
1331 else | |
1332 { | |
1333 read = TRUE; | |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1334 ncolors = 256; |
435 | 1335 } |
1336 | |
1655 | 1337 if (!dmImagePaletteAlloc(img, ncolors, -1)) |
435 | 1338 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1339 res = dmError(DMERR_MALLOC, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1340 "PCX: Could not allocate palette data!\n"); |
435 | 1341 goto error; |
1342 } | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1343 |
435 | 1344 if (read) |
1345 { | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1346 // Okay, attempt to read the palette data |
1296 | 1347 dmMsg(2, "PCX: Reading palette of %d colors\n", ncolors); |
1655 | 1348 if (!dmPaletteReadData(fp, img->pal, ncolors)) |
435 | 1349 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1350 res = dmError(DMERR_FREAD, |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1351 "PCX: Error reading palette.\n"); |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1352 goto error; |
435 | 1353 } |
1354 } | |
1355 else | |
1356 { | |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1357 // 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
|
1358 // the header palette to our internal palette structure. |
1296 | 1359 dmMsg(2, "PCX: Initializing palette from header of %d colors\n", ncolors); |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1360 for (int i = 0; i < (img->ncolors > DMPCX_PAL_COLORS ? DMPCX_PAL_COLORS : img->ncolors); i++) |
435 | 1361 { |
1279
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1362 img->pal[i].r = hdr.colorMap[i].r; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1363 img->pal[i].g = hdr.colorMap[i].g; |
0d3f5f44c0c4
Somewhat improve PCX read support in libgfx.
Matti Hamalainen <ccr@tnsp.org>
parents:
1265
diff
changeset
|
1364 img->pal[i].b = hdr.colorMap[i].b; |
435 | 1365 } |
1366 } | |
1367 } | |
1368 | |
1369 error: | |
1370 dmFree(pcx.buf); | |
1371 return res; | |
1372 } | |
1373 | |
1374 | |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1375 // |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1376 // IFF ILBM / PBM format |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1377 // |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1378 #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
|
1379 #define IFF_ID_ILBM 0x494C424D // "ILBM" |
464 | 1380 #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
|
1381 #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
|
1382 #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
|
1383 #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
|
1384 #define IFF_ID_CAMG 0x43414D47 // "CAMG" |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1385 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1386 #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
|
1387 #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
|
1388 #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
|
1389 #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
|
1390 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1391 #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
|
1392 #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
|
1393 |
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
|
1394 #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
|
1395 #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
|
1396 #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
|
1397 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1398 typedef struct |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1399 { |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1400 Uint32 id; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1401 Uint32 size; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1402 int count; |
1656
2de258f2eb2e
Get rid of a basically redundant function in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1655
diff
changeset
|
1403 char idStr[6]; |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
1404 off_t offs; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1405 } DMIFFChunk; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1406 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1407 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1408 typedef struct |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1409 { |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1410 Uint16 w, h; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1411 Sint16 x, y; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1412 Uint8 nplanes; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1413 Uint8 masking; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1414 Uint8 compression; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1415 Uint8 pad1; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1416 Uint16 transp; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1417 Uint8 xasp, yasp; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1418 Sint16 pagew, pageh; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1419 } DMIFFBMHD; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1420 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1421 |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1422 typedef struct |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1423 { |
1810 | 1424 DMIFFChunk chFORM, chBMHD, chCMAP, chBODY; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1425 DMIFFBMHD bmhd; |
1903 | 1426 BOOL planar; |
1810 | 1427 Uint32 camg; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1428 int ncolors; |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1429 DMColor *pal; |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1430 } DMIFF; |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1431 |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1432 |
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
|
1433 static int fmtProbeIFF(const Uint8 *buf, const size_t len) |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1434 { |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1435 if (len > 32 && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1436 buf[ 0] == 'F' && buf[ 1] == 'O' && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1437 buf[ 2] == 'R' && buf[ 3] == 'M' && ( |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1438 (buf[ 8] == 'I' && buf[ 9] == 'L' && buf[10] == 'B' && buf[11] == 'M') || |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1439 (buf[ 8] == 'P' && buf[ 9] == 'B' && buf[10] == 'M' && buf[11] == 0x20) |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1440 )) |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1441 { |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1442 if (buf[12] == 'B' && buf[13] == 'M' && |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1443 buf[14] == 'H' && buf[15] == 'D') |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1444 return DM_PROBE_SCORE_MAX; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1445 else |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1446 return DM_PROBE_SCORE_GOOD; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1447 } |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1448 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1449 return DM_PROBE_SCORE_FALSE; |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1450 } |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1451 |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
1452 |
1657
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1453 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
|
1454 { |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1455 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
|
1456 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
|
1457 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
|
1458 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
|
1459 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
|
1460 } |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1461 |
2b6dbdd602b5
Split IFF chunk id string from id creation into separate function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1656
diff
changeset
|
1462 |
1654
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1463 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
|
1464 { |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1465 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
|
1466 !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
|
1467 { |
1654
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1468 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
|
1469 "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
|
1470 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1471 else |
1656
2de258f2eb2e
Get rid of a basically redundant function in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1655
diff
changeset
|
1472 { |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
1473 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
|
1474 dmMakeIFFChunkIDStr(chunk); |
1654
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1475 return DMERR_OK; |
1656
2de258f2eb2e
Get rid of a basically redundant function in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1655
diff
changeset
|
1476 } |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1477 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1478 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1479 |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
1480 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
|
1481 { |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1482 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
|
1483 size = chunk->size; |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1484 |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1485 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
|
1486 { |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1487 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
|
1488 size, size + 1); |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1489 size++; |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1490 } |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1491 |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1492 if (size > read) |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1493 { |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1494 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
|
1495 size - read, read, size); |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1496 |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1497 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
|
1498 { |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1499 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
|
1500 "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
|
1501 } |
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
|
1502 } |
1903 | 1503 |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1504 return DMERR_OK; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1505 } |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1506 |
1656
2de258f2eb2e
Get rid of a basically redundant function in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1655
diff
changeset
|
1507 |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1508 static int dmCheckIFFChunk(DMIFFChunk *dest, DMIFFChunk *chunk, |
445 | 1509 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
|
1510 { |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1511 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
|
1512 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1513 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
|
1514 "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
|
1515 chunk->idStr); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1516 } |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1517 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1518 dest->count++; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1519 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1520 if (chunk->size < minSize) |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1521 { |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1522 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
|
1523 "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
|
1524 chunk->idStr, chunk->size, minSize); |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1525 } |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1526 |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1527 return DMERR_OK; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1528 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1529 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1530 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1531 static 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
|
1532 { |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1533 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
|
1534 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
|
1535 { |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1536 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
|
1537 |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1538 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
|
1539 return FALSE; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1540 |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1541 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
|
1542 { |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1543 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
|
1544 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
|
1545 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1546 else |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1547 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
|
1548 { |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1549 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
|
1550 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
|
1551 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
|
1552 |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1553 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
|
1554 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
|
1555 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1556 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
|
1557 { |
1905
425259977bc5
Don't use signed arithmatic in IFF ByteRun1 decoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1904
diff
changeset
|
1558 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
|
1559 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
|
1560 { |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1561 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
|
1562 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
|
1563 |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1564 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
|
1565 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1566 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1567 } 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
|
1568 |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1569 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
|
1570 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1571 |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1572 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1573 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
|
1574 { |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1575 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
|
1576 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
|
1577 else |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1578 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
|
1579 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1580 |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1581 |
1622 | 1582 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
|
1583 { |
dacf4c2f7a86
Remove slight code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1618
diff
changeset
|
1584 return (buf[xc / 8] >> (7 - (xc & 7))) & 1; |
dacf4c2f7a86
Remove slight code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1618
diff
changeset
|
1585 } |
dacf4c2f7a86
Remove slight code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1618
diff
changeset
|
1586 |
dacf4c2f7a86
Remove slight code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1618
diff
changeset
|
1587 |
1903 | 1588 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
|
1589 { |
1903 | 1590 Uint8 *buf = NULL; |
1591 size_t bufLen = 0; | |
1618 | 1592 int res = DMERR_OK; |
1659 | 1593 const int nplanes = iff->bmhd.nplanes; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1594 |
1903 | 1595 if (iff->planar) |
1596 { | |
1597 // Allocate planar decoding buffer | |
1598 bufLen = ((img->width + 15) / 16) * 2; | |
1599 if ((buf = dmMalloc(bufLen)) == NULL) | |
1600 return DMERR_MALLOC; | |
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
|
1601 |
1906
09d46bf9fe71
Use a consistent message between IFF encoding and decoding.
Matti Hamalainen <ccr@tnsp.org>
parents:
1905
diff
changeset
|
1602 dmMsg(2, "IFF: Line / plane row size %d bytes.\n", bufLen); |
1903 | 1603 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1604 |
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
|
1605 // Decode the chunk |
1618 | 1606 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
|
1607 { |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1608 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
|
1609 |
1903 | 1610 if (iff->planar) |
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
|
1611 { |
1907
571109a14967
Add some more informative messages in IFF loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1906
diff
changeset
|
1612 // Clear planar decoding buffer |
1903 | 1613 dmMemset(dp, 0, img->pitch); |
1614 | |
1615 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
|
1616 { |
1903 | 1617 // Decompress or read data |
1618 if (!dmIFFReadOneRow(fp, iff, buf, bufLen)) | |
1619 { | |
1620 res = dmError(DMERR_FREAD, | |
1621 "IFF: Error in reading image plane #%d @ %d.\n", | |
1622 plane, yc); | |
1623 goto out; | |
1624 } | |
1625 | |
1626 // Decode bitplane | |
1627 for (int xc = 0; xc < img->width; xc++) | |
1628 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
|
1629 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1630 |
1903 | 1631 // Read mask data |
1632 if (iff->bmhd.masking == IFF_MASK_HAS_MASK) | |
1633 { | |
1634 // Decompress or read data | |
1635 if (!dmIFFReadOneRow(fp, iff, buf, bufLen)) | |
1636 { | |
1637 res = dmError(DMERR_FREAD, | |
1638 "IFF: Error in reading mask plane.\n"); | |
1639 goto out; | |
1640 } | |
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
|
1641 |
1903 | 1642 // Decode mask |
1643 for (int xc = 0; xc < img->width; xc++) | |
1644 { | |
1645 const Uint8 data = dmDecodeBit(buf, xc); | |
1646 | |
1647 // Black out any pixels with mask bit 0 | |
1648 if (!data) | |
1649 dp[xc] = img->ctransp < 0 ? 0 : img->ctransp; | |
1650 } | |
1651 } | |
1652 } | |
1653 else | |
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
|
1654 { |
1903 | 1655 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
|
1656 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1657 res = dmError(DMERR_FREAD, |
1903 | 1658 "IFF: Error reading PBM image row #%d.\n", yc); |
1659 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
|
1660 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1661 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1662 } |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1663 |
1903 | 1664 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
|
1665 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
|
1666 return res; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1667 } |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1668 |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1669 |
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
|
1670 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
|
1671 { |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1672 DMIFFChunk chunk; |
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1673 DMIFF iff; |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
1674 Uint32 idsig; |
1903 | 1675 BOOL parsed = FALSE; |
1627 | 1676 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
|
1677 |
1167 | 1678 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
|
1679 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1680 // Read IFF FORM header |
1654
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1681 if ((res = dmReadIFFChunkHdr(fp, &chunk)) != DMERR_OK) |
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1682 return res; |
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1683 |
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1684 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
|
1685 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1686 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
|
1687 "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
|
1688 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
|
1689 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1690 |
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
|
1691 // Check IFF ILBM/PBM signature |
1810 | 1692 if (!dmf_read_be32(fp, &idsig) || |
1693 (idsig != IFF_ID_ILBM && idsig != IFF_ID_PBM)) | |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1694 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1695 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
|
1696 "IFF: Not a IFF ILBM/PBM file.\n"); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1697 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1698 |
1903 | 1699 iff.planar = (idsig == IFF_ID_ILBM); |
464 | 1700 |
1907
571109a14967
Add some more informative messages in IFF loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1906
diff
changeset
|
1701 dmMsg(3, "IFF: FORM data size %d\n", |
571109a14967
Add some more informative messages in IFF loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1906
diff
changeset
|
1702 chunk.size); |
571109a14967
Add some more informative messages in IFF loader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1906
diff
changeset
|
1703 |
1609
c29adf5ce240
Convert libgfx file format routines to use DMResource instead of stdio FILE.
Matti Hamalainen <ccr@tnsp.org>
parents:
1583
diff
changeset
|
1704 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
|
1705 { |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
1706 // Read chunk header |
1654
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1707 if ((res = dmReadIFFChunkHdr(fp, &chunk)) != DMERR_OK) |
92656ad7f706
Improve IFF reader error handling.
Matti Hamalainen <ccr@tnsp.org>
parents:
1641
diff
changeset
|
1708 return res; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1709 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1710 switch (chunk.id) |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1711 { |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1712 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
|
1713 // 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
|
1714 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
|
1715 return res; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1716 |
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
|
1717 // 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
|
1718 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
|
1719 !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
|
1720 !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
|
1721 !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
|
1722 !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
|
1723 !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
|
1724 !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
|
1725 !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
|
1726 !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
|
1727 !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
|
1728 !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
|
1729 !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
|
1730 !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
|
1731 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1732 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
|
1733 "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
|
1734 } |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1735 |
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
|
1736 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
|
1737 iff.bmhd.w, iff.bmhd.h, iff.bmhd.x, iff.bmhd.y, |
1655 | 1738 iff.bmhd.nplanes, iff.bmhd.compression, iff.bmhd.masking, |
1739 iff.bmhd.transp); | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1740 |
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
|
1741 // 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
|
1742 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
|
1743 (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
|
1744 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
|
1745 (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
|
1746 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
|
1747 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
|
1748 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1749 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
|
1750 "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
|
1751 } |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1752 break; |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1753 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1754 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1755 case IFF_ID_CMAP: |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1756 // 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
|
1757 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
|
1758 return res; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1759 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1760 // Check for sanity |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1761 if (chunk.size % 3 != 0) |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1762 { |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1763 // Non-fatal |
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1764 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
|
1765 "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
|
1766 } |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1767 |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1768 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
|
1769 dmMsg(2, "IFF: CMAP %d entries (%d bytes)\n", |
1624
9a8395b56d1a
Remove unused message argument.
Matti Hamalainen <ccr@tnsp.org>
parents:
1623
diff
changeset
|
1770 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
|
1771 |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1772 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
|
1773 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
|
1774 |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1775 // Read palette |
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1776 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
|
1777 { |
461
c7a3aacbd55e
Implement transparent color in IFF ILBM reader and ctransp setting in PNG reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
460
diff
changeset
|
1778 if (!dmPaletteAlloc(&iff.pal, iff.ncolors, |
c7a3aacbd55e
Implement transparent color in IFF ILBM reader and ctransp setting in PNG reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
460
diff
changeset
|
1779 (iff.bmhd.masking == IFF_MASK_TRANSP) ? iff.bmhd.transp : -1)) |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1780 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1781 return dmError(DMERR_MALLOC, |
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
|
1782 "IFF: Could not allocate palette data.\n"); |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1783 } |
1655 | 1784 if (!dmPaletteReadData(fp, iff.pal, iff.ncolors)) |
451
fdc91f2a0d27
Modularize palette reading and handling code.
Matti Hamalainen <ccr@tnsp.org>
parents:
449
diff
changeset
|
1785 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1786 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
|
1787 "IFF: Error reading CMAP.\n"); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1788 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1789 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1790 |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1791 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
|
1792 parsed = TRUE; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1793 break; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1794 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1795 case IFF_ID_BODY: |
1621 | 1796 // 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
|
1797 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
|
1798 return res; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1799 |
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
|
1800 // Check for sanity |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1801 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
|
1802 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1803 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
|
1804 "IFF: BODY chunk before BMHD?\n"); |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1805 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1806 |
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
|
1807 dmMsg(2, "IFF: BODY chunk size %d bytes\n", chunk.size); |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1808 |
1626
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
1809 // Allocate image |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
1810 if ((*pimg = dmImageAlloc(iff.bmhd.w, iff.bmhd.h, |
1801 | 1811 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
|
1812 // 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
|
1813 //iff->bmhd.nplanes <= 8 ? iff->bmhd.nplanes : -1 |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
1814 -1 |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
1815 )) == NULL) |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
1816 return DMERR_MALLOC; |
1793fc1496da
Remove some code duplication.
Matti Hamalainen <ccr@tnsp.org>
parents:
1625
diff
changeset
|
1817 |
1628
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1818 // Set image aspect ratio |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1819 if (iff.bmhd.xasp > 0 && iff.bmhd.yasp > 0) |
a549d33d543a
Add image aspect ratio information.
Matti Hamalainen <ccr@tnsp.org>
parents:
1627
diff
changeset
|
1820 (*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
|
1821 |
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
|
1822 // Decode the body |
1903 | 1823 if ((res = dmDecodeIFFBody(fp, &iff, *pimg)) != DMERR_OK) |
1824 return res; | |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1825 |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
1826 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
|
1827 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
|
1828 |
444
7d588807f91d
Clean up the IFF parser a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
443
diff
changeset
|
1829 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
|
1830 parsed = TRUE; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1831 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
|
1832 |
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
|
1833 |
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
|
1834 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
|
1835 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
|
1836 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
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: 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
|
1839 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1840 |
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
|
1841 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
|
1842 |
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
|
1843 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
|
1844 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1845 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
|
1846 "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
|
1847 } |
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
|
1848 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
|
1849 |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1850 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1851 default: |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1852 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
|
1853 chunk.idStr, chunk.size); |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1854 |
1901
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1855 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
|
1856 { |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1857 return dmError(DMERR_FSEEK, |
636d3c8bcd35
Fix uneven chunk size handling in IFF reader.
Matti Hamalainen <ccr@tnsp.org>
parents:
1900
diff
changeset
|
1858 "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
|
1859 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1860 break; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1861 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1862 |
1895
eb03869a10d3
Clean up the IFF reader and make it more robust.
Matti Hamalainen <ccr@tnsp.org>
parents:
1894
diff
changeset
|
1863 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
|
1864 return res; |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1865 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1866 |
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
|
1867 // Set colormap after finishing |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1868 if (iff.pal != NULL && iff.ncolors > 0 && *pimg != NULL) |
0e27860ddcfe
Finish initial implementation of IFF ILBM loader. And whoa .. it seems to be working.
Matti Hamalainen <ccr@tnsp.org>
parents:
445
diff
changeset
|
1869 { |
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
|
1870 // 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
|
1871 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
|
1872 { |
834 | 1873 void *ptmp; |
1903 | 1874 if (!iff.planar) |
1625
c8afa3e6c413
Print an error/warning about PBM files that have half-brite set.
Matti Hamalainen <ccr@tnsp.org>
parents:
1624
diff
changeset
|
1875 { |
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
|
1876 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
|
1877 } |
834 | 1878 |
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
|
1879 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
|
1880 { |
958
985225a93aeb
Add error code parameter to dmError() and dmErrorVA().
Matti Hamalainen <ccr@tnsp.org>
parents:
930
diff
changeset
|
1881 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
|
1882 "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
|
1883 } |
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
|
1884 |
834 | 1885 if ((ptmp = dmRealloc(iff.pal, sizeof(DMColor) * iff.ncolors * 2)) == NULL) |
1886 { | |
1887 dmFree(iff.pal); | |
1888 iff.pal = NULL; | |
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
|
1889 return DMERR_MALLOC; |
834 | 1890 } |
1891 else | |
1892 iff.pal = ptmp; | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1893 |
1627 | 1894 for (int i = 0; i < iff.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
|
1895 { |
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
|
1896 int i2 = iff.ncolors + i; |
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
|
1897 iff.pal[i2].r = iff.pal[i].r / 2; |
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
|
1898 iff.pal[i2].g = iff.pal[i].g / 2; |
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
|
1899 iff.pal[i2].b = iff.pal[i].b / 2; |
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
|
1900 } |
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
|
1901 } |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
958
diff
changeset
|
1902 |
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
|
1903 (*pimg)->ncolors = iff.ncolors; |
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 (*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
|
1905 } |
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 |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1907 return res; |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1908 } |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1909 |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
1910 |
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
|
1911 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
|
1912 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1913 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
|
1914 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
|
1915 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
|
1916 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1917 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
|
1918 !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
|
1919 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1920 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
|
1921 "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
|
1922 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
|
1923 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1924 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
|
1925 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
|
1926 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1927 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1928 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1929 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
|
1930 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1931 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
|
1932 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
|
1933 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
|
1934 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1935 chunk->size = curr - chunk->offs - (sizeof(Uint32) * 2); |
1900 | 1936 if (chunk->size & 1) |
1937 { | |
1938 if (!dmf_write_byte(fp, 0)) | |
1939 return dmferror(fp); | |
1940 | |
1941 chunk->size++; | |
1942 } | |
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
|
1943 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1944 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
|
1945 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
|
1946 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1947 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
|
1948 !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
|
1949 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1950 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
|
1951 "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
|
1952 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
|
1953 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1954 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1955 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
|
1956 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
|
1957 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1958 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
|
1959 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1960 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1961 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1962 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
|
1963 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1964 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
|
1965 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
|
1966 }; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1967 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1968 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1969 BOOL dmIFFEncodeByteRun1Flush( |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1970 DMResource *fp, const int mode, const BOOL flush, |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1971 size_t *l_offs, const size_t offs, const Uint8 *buf, |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1972 const Uint8 data, unsigned int *r_count) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1973 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1974 if (mode == 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
|
1975 { |
1902 | 1976 size_t l_count = offs - *l_offs; |
1977 if (l_count > *r_count || flush) | |
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
|
1978 { |
1902 | 1979 size_t count = l_count - *r_count; |
1908
2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1907
diff
changeset
|
1980 Uint8 tmp = count - 1; |
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
|
1981 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1982 if (!dmf_write_byte(fp, tmp) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1983 !dmf_write_str(fp, buf + *l_offs, count)) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1984 return FALSE; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1985 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1986 (*r_count)++; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1987 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
1988 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
|
1989 { |
1908
2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1907
diff
changeset
|
1990 if (*r_count > 0) |
2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1907
diff
changeset
|
1991 { |
2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1907
diff
changeset
|
1992 unsigned int count = *r_count; |
2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1907
diff
changeset
|
1993 Uint8 tmp = ((Uint8) count - 2) ^ 0xff; |
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
|
1994 |
1908
2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1907
diff
changeset
|
1995 if (!dmf_write_byte(fp, tmp) || |
2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1907
diff
changeset
|
1996 !dmf_write_byte(fp, data)) |
2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1907
diff
changeset
|
1997 return FALSE; |
2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1907
diff
changeset
|
1998 *r_count = 0; |
2977baab68db
Fix certain corner case in IFF ByteRun1 encoder.
Matti Hamalainen <ccr@tnsp.org>
parents:
1907
diff
changeset
|
1999 } |
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
|
2000 *l_offs = offs; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2001 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2002 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2003 return TRUE; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2004 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2005 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2006 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2007 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
|
2008 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2009 unsigned int r_count = 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
|
2010 int prev = -1, mode = DMODE_LIT; |
1899 | 2011 size_t offs, l_offs = 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
|
2012 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2013 for (offs = 0; offs < bufLen; offs++) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2014 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2015 Uint8 data = buf[offs]; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2016 int next_mode; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2017 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2018 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
|
2019 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2020 r_count++; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2021 next_mode = 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
|
2022 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2023 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
|
2024 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2025 next_mode = 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
|
2026 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2027 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2028 BOOL flush = offs - l_offs >= 126 || r_count >= 126; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2029 if ((next_mode != mode || flush) && |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2030 !dmIFFEncodeByteRun1Flush(fp, mode, flush, &l_offs, offs, buf, prev, &r_count)) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2031 return FALSE; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2032 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2033 mode = next_mode; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2034 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
|
2035 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2036 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2037 if (!dmIFFEncodeByteRun1Flush(fp, mode, TRUE, &l_offs, offs, buf, prev, &r_count)) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2038 return FALSE; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2039 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2040 return TRUE; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2041 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2042 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2043 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2044 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
|
2045 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2046 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
|
2047 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
|
2048 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
|
2049 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
|
2050 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2051 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2052 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2053 int dmWriteIFFImage(DMResource *fp, const DMImage *img, const DMImageConvSpec *spec) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2054 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2055 Uint32 idsig; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2056 DMIFF iff; |
1904 | 2057 Uint8 *buf = NULL; |
2058 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
|
2059 int res = 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
|
2060 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2061 // XXX: Non-paletted ILBM 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
|
2062 if (!spec->paletted) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2063 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2064 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
|
2065 "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
|
2066 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2067 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2068 // 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
|
2069 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
|
2070 iff.bmhd.y = 0; |
1904 | 2071 iff.bmhd.w = img->width * spec->scaleX; |
2072 iff.bmhd.h = img->height * spec->scaleY; | |
2073 iff.bmhd.pagew = img->width * spec->scaleX; | |
2074 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
|
2075 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
|
2076 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
|
2077 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
|
2078 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2079 iff.camg = 0; // XXX TODO: when/if HAM support |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2080 iff.bmhd.masking = (img->ctransp < 0) ? IFF_MASK_NONE : spec->mask; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2081 iff.bmhd.compression = spec->compression ? IFF_COMP_BYTERUN1 : IFF_COMP_NONE; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2082 iff.bmhd.transp = (img->ctransp >= 0 && spec->mask == IFF_MASK_TRANSP) ? img->ctransp : 0xffff; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2083 iff.bmhd.nplanes = spec->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
|
2084 idsig = spec->planar ? IFF_ID_ILBM : IFF_ID_PBM; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2085 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2086 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
|
2087 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
|
2088 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2089 // 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
|
2090 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
|
2091 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
|
2092 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2093 // Write IFF ILBM/PBM signature |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2094 if (!dmf_write_be32(fp, idsig)) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2095 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2096 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
|
2097 "IFF: Error writing %s signature.\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
|
2098 spec->planar ? "ILBM" : "PBM"); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2099 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
|
2100 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2101 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2102 // 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
|
2103 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
|
2104 !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
|
2105 !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
|
2106 !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
|
2107 !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
|
2108 !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
|
2109 !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
|
2110 !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
|
2111 !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
|
2112 !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
|
2113 !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
|
2114 !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
|
2115 !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
|
2116 !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
|
2117 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2118 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
|
2119 "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
|
2120 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
|
2121 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2122 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2123 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
|
2124 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
|
2125 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2126 // |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2127 // 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
|
2128 // |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2129 if (img->ncolors > 0 && spec->paletted) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2130 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2131 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
|
2132 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
|
2133 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2134 for (int i = 0; i < img->ncolors; i++) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2135 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2136 DMColor *col = &img->pal[i]; |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2137 if (!dmf_write_byte(fp, col->r) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2138 !dmf_write_byte(fp, col->g) || |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2139 !dmf_write_byte(fp, col->b)) |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2140 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2141 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
|
2142 "IFF: Could not write CMAP palette entry #%d.\n", i); |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2143 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
|
2144 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2145 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2146 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2147 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
|
2148 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
|
2149 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2150 dmMsg(2, "IFF: CMAP %d entries (%d bytes)\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
|
2151 img->ncolors, iff.chCMAP.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
|
2152 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2153 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2154 // |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2155 // 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
|
2156 // |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2157 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
|
2158 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
|
2159 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2160 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
|
2161 { |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2162 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
|
2163 "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
|
2164 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2165 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2166 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
|
2167 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
|
2168 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2169 // |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2170 // 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
|
2171 // |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2172 if ((res = dmWriteIFFChunkHdr(fp, &iff.chBODY, IFF_ID_BODY)) != 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
|
2173 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
|
2174 |
1904 | 2175 |
2176 // Allocate encoding buffer | |
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
|
2177 if (spec->planar) |
1904 | 2178 bufLen = (((img->width * spec->scaleX) + 15) / 16) * 2; |
2179 else | |
2180 bufLen = img->width * spec->scaleX; | |
2181 | |
2182 dmMsg(2, "IFF: Line/plane row size %d bytes.\n", bufLen); | |
2183 | |
2184 if ((buf = dmMalloc(bufLen)) == NULL) | |
2185 return DMERR_MALLOC; | |
2186 | |
2187 // Encode the body | |
2188 for (int yc = 0; yc < img->height; yc++) | |
2189 for (int yscale = 0; yscale < spec->scaleY; yscale++) | |
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
|
2190 { |
1904 | 2191 const Uint8 *sp = img->data + (yc * img->pitch); |
2192 | |
2193 if (spec->planar) | |
2194 { | |
2195 for (int plane = 0; plane < spec->nplanes; plane++) | |
2196 { | |
2197 // Encode bitplane | |
2198 dmMemset(buf, 0, bufLen); | |
2199 | |
2200 for (int xc = 0; xc < img->width * spec->scaleX; xc++) | |
2201 buf[xc / 8] |= ((sp[xc / spec->scaleX] >> plane) & 1) << (7 - (xc & 7)); | |
2202 | |
2203 // Compress / write data | |
2204 if (!dmIFFWriteOneRow(fp, &iff, buf, bufLen)) | |
2205 { | |
2206 res = dmError(DMERR_FWRITE, | |
2207 "IFF: Error writing image plane #%d @ %d.\n", | |
2208 plane, yc); | |
2209 goto out; | |
2210 } | |
2211 } | |
2212 | |
2213 // Write mask data, if any | |
2214 if (iff.bmhd.masking == IFF_MASK_HAS_MASK) | |
2215 { | |
2216 dmMemset(buf, 0, bufLen); | |
2217 | |
2218 for (int xc = 0; xc < img->width * spec->scaleX; xc++) | |
2219 buf[xc / 8] |= (sp[xc / spec->scaleX] == img->ctransp) << (7 - (xc & 7)); | |
2220 | |
2221 if (!dmIFFWriteOneRow(fp, &iff, buf, bufLen)) | |
2222 { | |
2223 res = dmError(DMERR_FWRITE, | |
2224 "IFF: Error writing mask plane %d.\n", yc); | |
2225 goto out; | |
2226 } | |
2227 } | |
2228 } | |
2229 else | |
2230 { | |
2231 for (int xc = 0; xc < img->width * spec->scaleX; xc++) | |
2232 buf[xc] = sp[xc / spec->scaleX]; | |
2233 | |
2234 if (!dmIFFWriteOneRow(fp, &iff, buf, bufLen)) | |
2235 { | |
2236 res = dmError(DMERR_FWRITE, | |
2237 "IFF: Error writing PBM image row #%d.\n", yc); | |
2238 goto out; | |
2239 } | |
2240 } | |
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
|
2241 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2242 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2243 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
|
2244 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
|
2245 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2246 // 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
|
2247 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
|
2248 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
|
2249 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2250 out: |
1904 | 2251 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
|
2252 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
|
2253 } |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2254 |
f80b2dc77c30
Work begins on IFF ILBM/PBM image writer. It is pretty broken, some things
Matti Hamalainen <ccr@tnsp.org>
parents:
1895
diff
changeset
|
2255 |
1613
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2256 // |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2257 // List of formats |
70b04c16aa40
Move format probe functions near to their other functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
1609
diff
changeset
|
2258 // |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2259 const DMImageFormat dmImageFormatList[] = |
435 | 2260 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2261 #ifdef DM_USE_LIBPNG |
435 | 2262 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2263 "png", "Portable Network Graphics", |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2264 DM_IMGFMT_PNG, DM_FMT_RDWR, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
2265 fmtProbePNG, dmReadPNGImage, dmWritePNGImage, |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2266 }, |
435 | 2267 #endif |
2268 { | |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2269 "ppm", "Portable PixMap", |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2270 DM_IMGFMT_PPM, DM_FMT_WR, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
2271 NULL, NULL, dmWritePPMImage, |
435 | 2272 }, |
2273 { | |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2274 "pcx", "Z-Soft Paintbrush", |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2275 DM_IMGFMT_PCX, DM_FMT_RDWR, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
2276 fmtProbePCX, dmReadPCXImage, dmWritePCXImage, |
435 | 2277 }, |
2278 { | |
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
|
2279 "iff", "IFF ILBM / PBM", |
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
|
2280 DM_IMGFMT_IFF, DM_FMT_RDWR, |
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
|
2281 fmtProbeIFF, dmReadIFFImage, dmWriteIFFImage, |
443
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2282 }, |
f7c9d1619c74
Beginnings of IFF ILBM reader. Not functional, only chunk parsing,
Matti Hamalainen <ccr@tnsp.org>
parents:
442
diff
changeset
|
2283 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2284 "raw", "Plain bitplaned (planar or non-planar) RAW", |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2285 DM_IMGFMT_RAW, DM_FMT_WR, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
2286 NULL, NULL, dmWriteRAWImage, |
566
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
487
diff
changeset
|
2287 }, |
d400e32b62d9
Add a slightly different raw output format.
Matti Hamalainen <ccr@tnsp.org>
parents:
487
diff
changeset
|
2288 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2289 "araw", "IFFMaster Amiga RAW", |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2290 DM_IMGFMT_ARAW, DM_FMT_WR, |
1886
1af79412f249
Remove the stdio FILE support from libgfx API, now only DMResource is supported.
Matti Hamalainen <ccr@tnsp.org>
parents:
1881
diff
changeset
|
2291 NULL, NULL, dmWriteRAWImage, |
435 | 2292 } |
2293 }; | |
2294 | |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2295 const int ndmImageFormatList = sizeof(dmImageFormatList) / sizeof(dmImageFormatList[0]); |
435 | 2296 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2297 |
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2298 int dmImageProbeGeneric(const Uint8 *buf, const size_t len, const DMImageFormat **pfmt, int *index) |
435 | 2299 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2300 int scoreMax = DM_PROBE_SCORE_FALSE, scoreIndex = -1; |
435 | 2301 |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2302 for (int i = 0; i < ndmImageFormatList; i++) |
435 | 2303 { |
1616
36d073c45327
Refactor the format handling a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1615
diff
changeset
|
2304 const DMImageFormat *fmt = &dmImageFormatList[i]; |
442
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2305 if (fmt->probe != NULL) |
435 | 2306 { |
442
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2307 int score = fmt->probe(buf, len); |
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2308 if (score > scoreMax) |
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2309 { |
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2310 scoreMax = score; |
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2311 scoreIndex = i; |
a67600e186d0
Fix probing to handle NULL probe functions.
Matti Hamalainen <ccr@tnsp.org>
parents:
440
diff
changeset
|
2312 } |
435 | 2313 } |
2314 } | |
2315 | |
2316 if (scoreIndex >= 0) | |
2317 { | |
2318 *pfmt = &dmImageFormatList[scoreIndex]; | |
2319 *index = scoreIndex; | |
2320 return scoreMax; | |
2321 } | |
2322 else | |
2323 return DM_PROBE_SCORE_FALSE; | |
2324 } |