Mercurial > hg > dmlib
comparison tools/lib64gfx.c @ 1542:69fa95707e65
Implement dmGenericRLEAnalyze() and use it where appropriate.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sat, 12 May 2018 05:31:40 +0300 |
parents | 776aa43b2c57 |
children | 20cd589366d7 |
comparison
equal
deleted
inserted
replaced
1541:203e00a4dfc0 | 1542:69fa95707e65 |
---|---|
242 } | 242 } |
243 | 243 |
244 | 244 |
245 void dmGenericRLEAnalyze(const DMGrowBuf *buf, Uint8 *rleMarker, const int rleType) | 245 void dmGenericRLEAnalyze(const DMGrowBuf *buf, Uint8 *rleMarker, const int rleType) |
246 { | 246 { |
247 | 247 #define DM_STAT_MAX 256 |
248 size_t *stats; | |
249 | |
250 // Allocate statistics counts buffer | |
251 if ((stats = dmMalloc0(DM_STAT_MAX * sizeof(size_t))) == NULL) | |
252 return; | |
253 | |
254 // Get statistics on the data | |
255 for (size_t offs = 0; offs < buf->len; offs++) | |
256 stats[buf->data[offs]]++; | |
257 | |
258 // According to compression type .. | |
259 if (rleType == DM_COMP_RLE_MARKER) | |
260 { | |
261 size_t selected = 0, | |
262 smallest = buf->len; | |
263 | |
264 // Find least used byte value | |
265 for (size_t n = 0; n < DM_STAT_MAX; n++) | |
266 { | |
267 if (stats[n] < smallest) | |
268 { | |
269 selected = n; | |
270 smallest = stats[n]; | |
271 } | |
272 } | |
273 | |
274 *rleMarker = selected; | |
275 } | |
276 else | |
277 *rleMarker = 0xC0; | |
278 | |
279 dmFree(stats); | |
248 } | 280 } |
249 | 281 |
250 | 282 |
251 int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg) | 283 int dmDecodeGenericRLE(DMGrowBuf *dst, const Uint8 *src, const Uint8 *srcEnd, const DMCompParams *cfg) |
252 { | 284 { |