annotate tools/libgfx.c @ 1450:61a486e25dc7

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