1 |
cardoe 08/12/30 17:11:10 |
2 |
|
3 |
Added: cairo-1.2.4-lcd-cleartype-like.diff |
4 |
Log: |
5 |
add ClearType-style sub-pixel hinting patch from Arch Linux |
6 |
(Portage version: 2.1.6.4/cvs/Linux 2.6.28-gentoo x86_64) |
7 |
|
8 |
Revision Changes Path |
9 |
1.1 x11-libs/cairo/files/cairo-1.2.4-lcd-cleartype-like.diff |
10 |
|
11 |
file : http://sources.gentoo.org/viewcvs.py/gentoo-x86/x11-libs/cairo/files/cairo-1.2.4-lcd-cleartype-like.diff?rev=1.1&view=markup |
12 |
plain: http://sources.gentoo.org/viewcvs.py/gentoo-x86/x11-libs/cairo/files/cairo-1.2.4-lcd-cleartype-like.diff?rev=1.1&content-type=text/plain |
13 |
|
14 |
Index: cairo-1.2.4-lcd-cleartype-like.diff |
15 |
=================================================================== |
16 |
diff -rup libcairo-1.2.4.orig/src/cairo-ft-font.c libcairo-1.2.4/src/cairo-ft-font.c |
17 |
--- libcairo-1.2.4.orig/src/cairo-ft-font.c 2006-08-22 21:40:02.802247352 +0800 |
18 |
+++ libcairo-1.2.4/src/cairo-ft-font.c 2006-08-22 21:40:39.443677008 +0800 |
19 |
@@ -53,6 +53,8 @@ |
20 |
#include FT_SYNTHESIS_H |
21 |
#endif |
22 |
|
23 |
+#define FIR_FILTER 1 |
24 |
+ |
25 |
#define DOUBLE_TO_26_6(d) ((FT_F26Dot6)((d) * 64.0)) |
26 |
#define DOUBLE_FROM_26_6(t) ((double)(t) / 64.0) |
27 |
#define DOUBLE_TO_16_16(d) ((FT_Fixed)((d) * 65536.0)) |
28 |
@@ -492,6 +494,8 @@ _cairo_ft_unscaled_font_destroy (void *a |
29 |
} |
30 |
} |
31 |
|
32 |
+static const int fir_filter[5] = { 0x1C, 0x38, 0x55, 0x38, 0x1C }; |
33 |
+ |
34 |
static cairo_bool_t |
35 |
_has_unlocked_face (void *entry) |
36 |
{ |
37 |
@@ -779,7 +783,220 @@ _get_bitmap_surface (FT_Bitmap *bi |
38 |
} |
39 |
format = CAIRO_FORMAT_A8; |
40 |
break; |
41 |
- case CAIRO_ANTIALIAS_SUBPIXEL: { |
42 |
+ case CAIRO_ANTIALIAS_SUBPIXEL: |
43 |
+#ifdef FIR_FILTER |
44 |
+ { |
45 |
+ unsigned char* line; |
46 |
+ unsigned char* bufBitmap; |
47 |
+ int pitch; |
48 |
+ unsigned char *data_rgba; |
49 |
+ unsigned int width_rgba, stride_rgba; |
50 |
+ int vmul = 1; |
51 |
+ int hmul = 1; |
52 |
+ |
53 |
+ switch (font_options->subpixel_order) { |
54 |
+ case CAIRO_SUBPIXEL_ORDER_DEFAULT: |
55 |
+ case CAIRO_SUBPIXEL_ORDER_RGB: |
56 |
+ case CAIRO_SUBPIXEL_ORDER_BGR: |
57 |
+ default: |
58 |
+ width /= 3; |
59 |
+ hmul = 3; |
60 |
+ break; |
61 |
+ case CAIRO_SUBPIXEL_ORDER_VRGB: |
62 |
+ case CAIRO_SUBPIXEL_ORDER_VBGR: |
63 |
+ vmul = 3; |
64 |
+ height /= 3; |
65 |
+ break; |
66 |
+ } |
67 |
+ /* |
68 |
+ * Filter the glyph to soften the color fringes |
69 |
+ */ |
70 |
+ width_rgba = width; |
71 |
+ stride = bitmap->pitch; |
72 |
+ stride_rgba = (width_rgba * 4 + 3) & ~3; |
73 |
+ data_rgba = calloc (1, stride_rgba * height); |
74 |
+ |
75 |
+ /* perform in-place FIR filtering in either the horizontal or |
76 |
+ * vertical direction. We're going to modify the RGB graymap, |
77 |
+ * but that's ok, because we either own it, or its part of |
78 |
+ * the FreeType glyph slot, which will not be used anymore. |
79 |
+ */ |
80 |
+ pitch = bitmap->pitch; |
81 |
+ line = (unsigned char*)bitmap->buffer; |
82 |
+ if ( pitch < 0 ) |
83 |
+ line -= pitch*(height-1); |
84 |
+ |
85 |
+ bufBitmap = line; |
86 |
+ |
87 |
+ switch (font_options->subpixel_order) { |
88 |
+ case CAIRO_SUBPIXEL_ORDER_DEFAULT: |
89 |
+ case CAIRO_SUBPIXEL_ORDER_RGB: |
90 |
+ case CAIRO_SUBPIXEL_ORDER_BGR: |
91 |
+ { |
92 |
+ int h; |
93 |
+ |
94 |
+ for ( h = height; h > 0; h--, line += pitch ) { |
95 |
+ int pix[6] = { 0, 0, 0, 0, 0, 0 }; |
96 |
+ unsigned char* p = line; |
97 |
+ unsigned char* limit = line + width*3; |
98 |
+ int nn, val, val2; |
99 |
+ |
100 |
+ val = p[0]; |
101 |
+ for (nn = 0; nn < 3; nn++) |
102 |
+ pix[2 + nn] += val * fir_filter[nn]; |
103 |
+ |
104 |
+ val = p[1]; |
105 |
+ for (nn = 0; nn < 4; nn++) |
106 |
+ pix[1 + nn] += val * fir_filter[nn]; |
107 |
+ |
108 |
+ p += 2; |
109 |
+ |
110 |
+ for ( ; p < limit; p++ ) { |
111 |
+ val = p[0]; |
112 |
+ for (nn = 0; nn < 5; nn++) |
113 |
+ pix[nn] += val * fir_filter[nn]; |
114 |
+ |
115 |
+ val2 = pix[0] / 256; |
116 |
+ val2 |= -(val2 >> 8); |
117 |
+ p[-2] = (unsigned char)val2; |
118 |
+ |
119 |
+ for (nn = 0; nn < 5; nn++) |
120 |
+ pix[nn] = pix[nn + 1]; |
121 |
+ } |
122 |
+ for (nn = 0; nn < 2; nn++ ) { |
123 |
+ val2 = pix[nn] / 256; |
124 |
+ val2 |= -(val2 >> 8); |
125 |
+ p[nn - 2] = (unsigned char)val2; |
126 |
+ } |
127 |
+ } |
128 |
+ } |
129 |
+ break; |
130 |
+ case CAIRO_SUBPIXEL_ORDER_VRGB: |
131 |
+ case CAIRO_SUBPIXEL_ORDER_VBGR: |
132 |
+ { |
133 |
+ int w; |
134 |
+ |
135 |
+ for (w = 0; w < width; w++ ) { |
136 |
+ int pix[6] = { 0, 0, 0, 0, 0, 0 }; |
137 |
+ unsigned char* p = bufBitmap + w; |
138 |
+ unsigned char* limit = bufBitmap + w + height*3*pitch; |
139 |
+ int nn, val, val2; |
140 |
+ |
141 |
+ val = p[0]; |
142 |
+ for (nn = 0; nn < 3; nn++) |
143 |
+ pix[2 + nn] += val*fir_filter[nn]; |
144 |
+ |
145 |
+ val = p[pitch]; |
146 |
+ for (nn = 0; nn < 4; nn++ ) |
147 |
+ pix[1 + nn] += val * fir_filter[nn]; |
148 |
+ |
149 |
+ p += 2*pitch; |
150 |
+ for ( ; p < limit; p += pitch ) { |
151 |
+ val = p[0]; |
152 |
+ for (nn = 0; nn < 5; nn++ ) |
153 |
+ pix[nn] += val * fir_filter[nn]; |
154 |
+ |
155 |
+ val2 = pix[0] / 256; |
156 |
+ val2 |= -(val2 >> 8); |
157 |
+ p[-2 * pitch] = (unsigned char)val2; |
158 |
+ |
159 |
+ for (nn = 0; nn < 5; nn++) |
160 |
+ pix[nn] = pix[nn+1]; |
161 |
+ } |
162 |
+ |
163 |
+ for (nn = 0; nn < 2; nn++) { |
164 |
+ val2 = pix[nn] / 256; |
165 |
+ val2 |= -(val2 >> 8); |
166 |
+ p[(nn - 2) * pitch] = (unsigned char)val2; |
167 |
+ } |
168 |
+ } |
169 |
+ } |
170 |
+ break; |
171 |
+ default: /* shouldn't happen */ |
172 |
+ break; |
173 |
+ } |
174 |
+ |
175 |
+ /* now copy the resulting graymap into an ARGB32 image */ |
176 |
+ { |
177 |
+ unsigned char* in_line = bufBitmap; |
178 |
+ unsigned char* out_line = data_rgba; |
179 |
+ int h = height; |
180 |
+ |
181 |
+ switch (font_options->subpixel_order) { |
182 |
+ case CAIRO_SUBPIXEL_ORDER_DEFAULT: |
183 |
+ case CAIRO_SUBPIXEL_ORDER_RGB: |
184 |
+ for ( ; h > 0; h--, in_line += pitch, out_line += stride_rgba) { |
185 |
+ unsigned char* in = in_line; |
186 |
+ int* out = (int*)out_line; |
187 |
+ int w; |
188 |
+ |
189 |
+ for (w = width; w > 0; w--, in += 3, out += 1) { |
190 |
+ int r = in[0]; |
191 |
+ int g = in[1]; |
192 |
+ int b = in[2]; |
193 |
+ |
194 |
+ out[0] = (g << 24) | (r << 16) | (g << 8) | b; |
195 |
+ } |
196 |
+ } |
197 |
+ break; |
198 |
+ case CAIRO_SUBPIXEL_ORDER_BGR: |
199 |
+ for ( ; h > 0; h--, in_line += pitch, out_line += stride_rgba) { |
200 |
+ unsigned char* in = in_line; |
201 |
+ int* out = (int*)out_line; |
202 |
+ int w; |
203 |
+ |
204 |
+ for (w = width; w > 0; w--, in += 3, out += 1) { |
205 |
+ int r = in[2]; |
206 |
+ int g = in[1]; |
207 |
+ int b = in[0]; |
208 |
+ |
209 |
+ out[0] = (g << 24) | (r << 16) | (g << 8) | b; |
210 |
+ } |
211 |
+ } |
212 |
+ break; |
213 |
+ case CAIRO_SUBPIXEL_ORDER_VRGB: |
214 |
+ for ( ; h > 0; h--, in_line += pitch*3, out_line += stride_rgba) { |
215 |
+ unsigned char* in = in_line; |
216 |
+ int* out = (int*)out_line; |
217 |
+ int w; |
218 |
+ |
219 |
+ for (w = width; w > 0; w--, in += 1, out += 1) { |
220 |
+ int r = in[0]; |
221 |
+ int g = in[pitch]; |
222 |
+ int b = in[pitch*2]; |
223 |
+ |
224 |
+ out[0] = (g << 24) | (r << 16) | (g << 8) | b; |
225 |
+ } |
226 |
+ } |
227 |
+ break; |
228 |
+ case CAIRO_SUBPIXEL_ORDER_VBGR: |
229 |
+ for ( ; h > 0; h--, in_line += pitch*3, out_line += stride_rgba) { |
230 |
+ unsigned char* in = in_line; |
231 |
+ int* out = (int*)out_line; |
232 |
+ int w; |
233 |
+ |
234 |
+ for (w = width; w > 0; w--, in += 1, out += 1) { |
235 |
+ int r = in[2*pitch]; |
236 |
+ int g = in[pitch]; |
237 |
+ int b = in[0]; |
238 |
+ |
239 |
+ out[0] = (g << 24) | (r << 16) | (g << 8) | b; |
240 |
+ } |
241 |
+ } |
242 |
+ break; |
243 |
+ } |
244 |
+ } |
245 |
+ |
246 |
+ if (own_buffer) |
247 |
+ free (bitmap->buffer); |
248 |
+ data = data_rgba; |
249 |
+ stride = stride_rgba; |
250 |
+ format = CAIRO_FORMAT_ARGB32; |
251 |
+ subpixel = TRUE; |
252 |
+ break; |
253 |
+ } |
254 |
+#else /* !FIR_FILTER */ |
255 |
+ { |
256 |
int x, y; |
257 |
unsigned char *in_line, *out_line, *in; |
258 |
unsigned int *out; |
259 |
@@ -871,6 +1088,7 @@ _get_bitmap_surface (FT_Bitmap *bi |
260 |
subpixel = TRUE; |
261 |
break; |
262 |
} |
263 |
+#endif /* !FIR_FILTER */ |
264 |
} |
265 |
break; |
266 |
case FT_PIXEL_MODE_GRAY2: |
267 |
@@ -986,12 +1204,22 @@ _render_glyph_outline (FT_Face |
268 |
matrix.xx *= 3; |
269 |
hmul = 3; |
270 |
subpixel = TRUE; |
271 |
+#ifdef FIR_FILTER |
272 |
+ cbox.xMin -= 64; |
273 |
+ cbox.xMax += 64; |
274 |
+ width += 2; |
275 |
+#endif |
276 |
break; |
277 |
case CAIRO_SUBPIXEL_ORDER_VRGB: |
278 |
case CAIRO_SUBPIXEL_ORDER_VBGR: |
279 |
matrix.yy *= 3; |
280 |
vmul = 3; |
281 |
subpixel = TRUE; |
282 |
+#ifdef FIR_FILTER |
283 |
+ cbox.yMin -= 64; |
284 |
+ cbox.yMax += 64; |
285 |
+ height += 2; |
286 |
+#endif |
287 |
break; |
288 |
} |
289 |
FT_Outline_Transform (outline, &matrix); |
290 |
Only in libcairo-1.2.4/src: cairo-ft-font.c.orig |