annotate tools/libgfx.c @ 2202:455a3849b8ac

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