Mercurial > hg > dmlib
comparison tools/lib64fmts.c @ 1573:86373ac0861a
Implement another RLE variant, with different ordering of marker, count and data bytes.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 13 May 2018 09:08:18 +0300 |
parents | fa4fa9a6e78f |
children | 0b0870a216e9 |
comparison
equal
deleted
inserted
replaced
1572:4643cd757c0b | 1573:86373ac0861a |
---|---|
52 { | 52 { |
53 int res; | 53 int res; |
54 DMGrowBuf mem; | 54 DMGrowBuf mem; |
55 DMCompParams cfg; | 55 DMCompParams cfg; |
56 | 56 |
57 cfg.type = DM_COMP_RLE_MARKER; | 57 cfg.type = DM_COMP_RLE_MARKER1; |
58 cfg.rleMarker = *(buf + 0x0d); | 58 cfg.rleMarker = *(buf + 0x0d); |
59 | 59 |
60 if ((res = dmDecodeGenericRLEAlloc(&mem, buf + 0x0e, buf + len, &cfg)) != DMERR_OK) | 60 if ((res = dmDecodeGenericRLEAlloc(&mem, buf + 0x0e, buf + len, &cfg)) != DMERR_OK) |
61 goto out; | 61 goto out; |
62 | 62 |
78 // Encode the data to temp buffer | 78 // Encode the data to temp buffer |
79 if ((res = dmC64EncodeGenericBMP(TRUE, &tmp, img, fmt)) != DMERR_OK) | 79 if ((res = dmC64EncodeGenericBMP(TRUE, &tmp, img, fmt)) != DMERR_OK) |
80 goto out; | 80 goto out; |
81 | 81 |
82 // Analyze the data .. | 82 // Analyze the data .. |
83 dmGenericRLEAnalyze(&tmp, &cfg.rleMarker, DM_COMP_RLE_MARKER); | 83 dmGenericRLEAnalyze(&tmp, &cfg.rleMarker, DM_COMP_RLE_MARKER1); |
84 | 84 |
85 // Add the header bits | 85 // Add the header bits |
86 if (!dmGrowBufPut(buf, magicID, strlen(magicID)) || | 86 if (!dmGrowBufPut(buf, magicID, strlen(magicID)) || |
87 !dmGrowBufPutU8(buf, cfg.rleMarker)) | 87 !dmGrowBufPutU8(buf, cfg.rleMarker)) |
88 { | 88 { |
89 res = DMERR_MALLOC; | 89 res = DMERR_MALLOC; |
90 goto out; | 90 goto out; |
91 } | 91 } |
92 | 92 |
93 // And now RLE compress the data to the existing buffer | 93 // And now RLE compress the data to the existing buffer |
94 cfg.type = DM_COMP_RLE_MARKER; | 94 cfg.type = DM_COMP_RLE_MARKER1; |
95 cfg.rleMinCount = 3; | 95 cfg.rleMinCount = 3; |
96 cfg.rleMaxCount = 255; | 96 cfg.rleMaxCount = 255; |
97 res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg); | 97 res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg); |
98 | 98 |
99 out: | 99 out: |
182 | 182 |
183 memcpy(tmp.data, buf, len); | 183 memcpy(tmp.data, buf, len); |
184 tmp.len = len + 1; | 184 tmp.len = len + 1; |
185 | 185 |
186 // Now do an RLE decode on the enlarged buffer | 186 // Now do an RLE decode on the enlarged buffer |
187 cfg.type = DM_COMP_RLE_MARKER; | 187 cfg.type = DM_COMP_RLE_MARKER1; |
188 cfg.rleMarker = 0xC2; | 188 cfg.rleMarker = 0xC2; |
189 if ((res = dmDecodeGenericRLEAlloc(&mem, tmp.data, tmp.data + tmp.len, &cfg)) != DMERR_OK) | 189 if ((res = dmDecodeGenericRLEAlloc(&mem, tmp.data, tmp.data + tmp.len, &cfg)) != DMERR_OK) |
190 goto out; | 190 goto out; |
191 | 191 |
192 // And finally decode to bitmap struct | 192 // And finally decode to bitmap struct |
208 // Encode the data to temp buffer | 208 // Encode the data to temp buffer |
209 if ((res = dmC64EncodeGenericBMP(TRUE, &tmp, img, fmt)) != DMERR_OK) | 209 if ((res = dmC64EncodeGenericBMP(TRUE, &tmp, img, fmt)) != DMERR_OK) |
210 goto out; | 210 goto out; |
211 | 211 |
212 // And now RLE compress the data to the existing buffer | 212 // And now RLE compress the data to the existing buffer |
213 cfg.type = DM_COMP_RLE_MARKER; | 213 cfg.type = DM_COMP_RLE_MARKER1; |
214 cfg.rleMarker = 0xC2; | 214 cfg.rleMarker = 0xC2; |
215 cfg.rleMinCount = 3; | 215 cfg.rleMinCount = 3; |
216 cfg.rleMaxCount = 255; | 216 cfg.rleMaxCount = 255; |
217 res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg); | 217 res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg); |
218 | 218 |
328 { | 328 { |
329 int res; | 329 int res; |
330 DMGrowBuf mem; | 330 DMGrowBuf mem; |
331 DMCompParams cfg; | 331 DMCompParams cfg; |
332 | 332 |
333 cfg.type = DM_COMP_RLE_MARKER; | 333 cfg.type = DM_COMP_RLE_MARKER1; |
334 cfg.rleMarker = *(buf + 15); | 334 cfg.rleMarker = *(buf + 15); |
335 if ((res = dmDecodeGenericRLEAlloc(&mem, buf + FUNPAINT2_HEADER_SIZE, buf + len, &cfg)) != DMERR_OK) | 335 if ((res = dmDecodeGenericRLEAlloc(&mem, buf + FUNPAINT2_HEADER_SIZE, buf + len, &cfg)) != DMERR_OK) |
336 goto out; | 336 goto out; |
337 | 337 |
338 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); | 338 res = dmC64DecodeGenericBMP(img, mem.data, mem.len, fmt); |
363 // Encode the data to temp buffer | 363 // Encode the data to temp buffer |
364 if ((res = dmC64EncodeGenericBMP(TRUE, &tmp, img, fmt)) != DMERR_OK) | 364 if ((res = dmC64EncodeGenericBMP(TRUE, &tmp, img, fmt)) != DMERR_OK) |
365 goto out; | 365 goto out; |
366 | 366 |
367 // Analyze the data .. | 367 // Analyze the data .. |
368 dmGenericRLEAnalyze(&tmp, &cfg.rleMarker, DM_COMP_RLE_MARKER); | 368 dmGenericRLEAnalyze(&tmp, &cfg.rleMarker, DM_COMP_RLE_MARKER1); |
369 | 369 |
370 // Add the header bits | 370 // Add the header bits |
371 if (!dmGrowBufPut(buf, fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) || | 371 if (!dmGrowBufPut(buf, fmtFunPaint2MagicID, strlen(fmtFunPaint2MagicID)) || |
372 !dmGrowBufPutU8(buf, cfg.rleMarker)) | 372 !dmGrowBufPutU8(buf, cfg.rleMarker)) |
373 { | 373 { |
374 res = DMERR_MALLOC; | 374 res = DMERR_MALLOC; |
375 goto out; | 375 goto out; |
376 } | 376 } |
377 | 377 |
378 // And now RLE compress the data to the existing buffer | 378 // And now RLE compress the data to the existing buffer |
379 cfg.type = DM_COMP_RLE_MARKER; | 379 cfg.type = DM_COMP_RLE_MARKER1; |
380 cfg.rleMinCount = 3; | 380 cfg.rleMinCount = 3; |
381 cfg.rleMaxCount = 255; | 381 cfg.rleMaxCount = 255; |
382 res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg); | 382 res = dmEncodeGenericRLE(buf, tmp.data, tmp.data + tmp.len, &cfg); |
383 | 383 |
384 out: | 384 out: |