comparison lib64gfx.c @ 523:d0c0c6baeb57

Split the RLE decoding from DrazPaint/Lace and Amica paint decoders to a generic function.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 21 Nov 2012 23:04:00 +0200
parents feaaf0e2ecbe
children 78edb9710ab7
comparison
equal deleted inserted replaced
522:2a70f5902b70 523:d0c0c6baeb57
140 140
141 return DM_PROBE_SCORE_FALSE; 141 return DM_PROBE_SCORE_FALSE;
142 } 142 }
143 143
144 144
145 static int fmtDecodeDrazPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) 145 static int dmDecodeGenericRLE(Uint8 **mem, Uint8 **pdstEnd, const Uint8 *src, const Uint8 *srcEnd, const Uint8 rleMarker)
146 { 146 {
147 int res; 147 Uint8 *dst, *dstEnd;
148 Uint8 rleMarker; 148
149 Uint8 *mem, *dst, *dstEnd; 149 if ((*mem = dmMalloc(C64_RAM_SIZE)) == NULL)
150 const Uint8 *src, *srcEnd; 150 return DMERR_MALLOC;
151 151
152 if ((mem = dmMalloc(C64_RAM_SIZE)) == NULL) 152 dst = *mem;
153 return -1; 153 dstEnd = *mem + C64_RAM_SIZE;
154
155 rleMarker = *(buf + 0x0d);
156 src = buf + 0x0e;
157 srcEnd = buf + len;
158 dst = mem;
159 dstEnd = mem + C64_RAM_SIZE;
160 154
161 while (src <= srcEnd && dst <= dstEnd) 155 while (src <= srcEnd && dst <= dstEnd)
162 { 156 {
163 int c = *src++; 157 int c = *src++;
164 if (c == rleMarker && src + 2 <= srcEnd) 158 if (c == rleMarker && src + 2 <= srcEnd)
169 *dst++ = c; 163 *dst++ = c;
170 } 164 }
171 else 165 else
172 *dst++ = c; 166 *dst++ = c;
173 } 167 }
174 168
175 res = dmC64DecodeGenericBMP(img, mem, dst - mem + 1, fmt); 169 *pdstEnd = dst;
176 170
171 return DMERR_OK;
172 }
173
174
175 static int fmtDecodeDrazPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
176 {
177 int res;
178 Uint8 *mem = NULL, *dstEnd;
179
180 if ((res = dmDecodeGenericRLE(&mem, &dstEnd, buf + 0x0e, buf + len, *(buf + 0x0d))) != DMERR_OK)
181 goto out;
182
183 res = dmC64DecodeGenericBMP(img, mem, dstEnd - mem + 1, fmt);
184
185 out:
177 dmFree(mem); 186 dmFree(mem);
178 return res; 187 return res;
179 } 188 }
180 189
181 190
225 234
226 235
227 static int fmtDecodeAmicaPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) 236 static int fmtDecodeAmicaPaintPacked(DMC64Image *img, const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
228 { 237 {
229 int res; 238 int res;
230 Uint8 *mem, *dst, *dstEnd; 239 Uint8 *mem = NULL, *dstEnd;
231 const Uint8 *src, *srcEnd; 240
232 241 if ((res = dmDecodeGenericRLE(&mem, &dstEnd, buf, buf + len, 0xC2)) != DMERR_OK)
233 if ((mem = dmMalloc(C64_RAM_SIZE)) == NULL) 242 goto out;
234 return -1; 243
235 244 res = dmC64DecodeGenericBMP(img, mem, dstEnd - mem + 1, fmt);
236 src = buf; 245
237 srcEnd = buf + len; 246 out:
238 dst = mem;
239 dstEnd = mem + C64_RAM_SIZE;
240
241 while (src <= srcEnd && dst <= dstEnd)
242 {
243 int c = *src++;
244 if (c == 0xC2 && src + 2 <= srcEnd)
245 {
246 int cnt = *src++;
247 c = *src++;
248 while (cnt-- && dst <= dstEnd)
249 *dst++ = c;
250 }
251 else
252 *dst++ = c;
253 }
254
255 res = dmC64DecodeGenericBMP(img, mem, dst - mem + 1, fmt);
256
257 dmFree(mem); 247 dmFree(mem);
258
259 return res; 248 return res;
260 } 249 }
261 250
262 251
263 static BOOL fmtTruePaintSetLaceType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len) 252 static BOOL fmtTruePaintSetLaceType(DMC64Image *img, const struct _DMC64EncDecOp *op, const Uint8 *buf, const size_t len)