summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean-Philippe Andre <jp.andre@samsung.com>2014-12-09 11:00:38 +0900
committerJean-Philippe Andre <jp.andre@samsung.com>2014-12-09 11:02:01 +0900
commit624787c42a4edb1f900051cc2124f9f055d01ce2 (patch)
treeccd87a93b2fa48a5416db12eb0beef978e916372
parent9dbd2db21bc813a86a95baad91f3605e99ebfeaa (diff)
Evas font: Improve RLE rounding alpha8 to alpha44
This should ensure that the difference between the original pixel value and the rle4 encoded one is <= 8. The previous fix was a bit stupid as it was not taking into account the conversion a4 to a8 (which is a8 = (a4 << 4) | a4).
-rw-r--r--src/lib/evas/common/evas_font_compress.c24
1 files changed, 15 insertions, 9 deletions
diff --git a/src/lib/evas/common/evas_font_compress.c b/src/lib/evas/common/evas_font_compress.c
index 66c8511..1cbd090 100644
--- a/src/lib/evas/common/evas_font_compress.c
+++ b/src/lib/evas/common/evas_font_compress.c
@@ -54,6 +54,17 @@ expand_bitmap(DATA8 *src, int pitch, int w, int h, DATA8 *dst)
54 } 54 }
55} 55}
56 56
57static inline DATA8
58alpha8to4(int a8)
59{
60 // a4 values are 0x00, 0x11, 0x22, 0x33, ... 0xee, 0xff
61 // increments by 0x11 = 17
62 int a4 = (a8 >> 4) & 0x0f;
63 int v = (a4 << 4) | a4;
64 if ((a8 - v) > 8) a4++;
65 else if ((v - a8) > 8) a4--;
66 return a4; // v = (a4 << 4) | a4;
67}
57 68
58 69
59 70
@@ -149,11 +160,8 @@ compress_rle4(DATA8 *src, int pitch, int w, int h, int *size_ret)
149 spanval = spanlen = spannum = 0; 160 spanval = spanlen = spannum = 0;
150 for (x = 0; x < w; x++) 161 for (x = 0; x < w; x++)
151 { 162 {
152 // we only need upper 4 bits of value for span creation 163 // round value from a8 to a44
153 DATA8 v = pix[x] >> 4; 164 DATA8 v = alpha8to4(pix[x]);
154 // round-up if closer to upper value
155 if ((pix[x] & 0x8) && (v != 0xF))
156 v++;
157 // if the current pixel value (in 4bit) is not the same as the 165 // if the current pixel value (in 4bit) is not the same as the
158 // span value (n 4 bit) OR... if the span now exceeds 16 pixels 166 // span value (n 4 bit) OR... if the span now exceeds 16 pixels
159 // then add/write out the span to our RLE span blob 167 // then add/write out the span to our RLE span blob
@@ -347,10 +355,8 @@ compress_bpp4(DATA8 *src, int pitch, int w, int h, int *size_ret)
347 // 4 bits only needed) and pack 355 // 4 bits only needed) and pack
348 for (x = 0; x < (w - 1); x += 2) 356 for (x = 0; x < (w - 1); x += 2)
349 { 357 {
350 DATA8 v1 = s[0] >> 4; 358 DATA8 v1 = alpha8to4(s[0]);
351 DATA8 v2 = s[1] >> 4; 359 DATA8 v2 = alpha8to4(s[1]);
352 if ((s[0] & 0x08) && (v1 != 0x0f)) v1++;
353 if ((s[1] & 0x08) && (v2 != 0x0f)) v2++;
354 *d = (v1 << 4) | v2; 360 *d = (v1 << 4) | v2;
355 s += 2; 361 s += 2;
356 d++; 362 d++;