comparison tools/lib64fmts.c @ 1663:8ae32df3c184

Add support for BDP5 format encoding.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 30 May 2018 17:22:27 +0300
parents 34d7c708649e
children 0022e1a428ca
comparison
equal deleted inserted replaced
1662:34d7c708649e 1663:8ae32df3c184
225 dmGrowBufFree(&mem); 225 dmGrowBufFree(&mem);
226 return res; 226 return res;
227 } 227 }
228 228
229 229
230 static int fmtEncodeBDP5Packed(DMGrowBuf *buf, const DMC64Image *img, const DMC64ImageFormat *fmt)
231 {
232 int res;
233 DMGrowBuf tmp;
234 DMCompParams cfg;
235
236 // Encode the data to temp buffer
237 if ((res = dmC64EncodeGenericBMP(TRUE, &tmp, img, fmt)) != DMERR_OK)
238 goto out;
239
240 // Analyze and setup RLE
241 cfg.type = DM_COMP_RLE_MARKER;
242 cfg.flags = DM_RLE_BYTE_RUNS | DM_RLE_WORD_RUNS | DM_RLE_ORDER_1;
243 cfg.rleMinCountB = 3;
244 cfg.rleMaxCountB = 255;
245 cfg.rleMinCountW = 256;
246 cfg.rleMaxCountW = 1024;
247
248 dmGenericRLEAnalyze(tmp.data, tmp.len, &cfg);
249
250 // Add the header bits
251 if (!dmGrowBufPut(buf, fmtBDP5MagicID, strlen(fmtBDP5MagicID)) ||
252 !dmGrowBufPutU8(buf, cfg.rleMarkerB) ||
253 !dmGrowBufPutU8(buf, cfg.rleMarkerW))
254 {
255 res = DMERR_MALLOC;
256 goto out;
257 }
258
259 // And now RLE compress the data to the existing buffer
260 res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg);
261
262 out:
263 dmGrowBufFree(&tmp);
264 return res;
265 }
266
267
230 static int fmtProbeGunPaint(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt) 268 static int fmtProbeGunPaint(const Uint8 *buf, const size_t len, const DMC64ImageFormat *fmt)
231 { 269 {
232 if (len > 0x400 && 270 if (len > 0x400 &&
233 dmCompareAddr16(buf, 0, fmt->addr) && 271 dmCompareAddr16(buf, 0, fmt->addr) &&
234 memcmp(buf + 0x3ea, "GUNPAINT (JZ) ", 14) == 0) 272 memcmp(buf + 0x3ea, "GUNPAINT (JZ) ", 14) == 0)