Mercurial > mplayer.hg
annotate libass/ass_bitmap.c @ 34272:4074457d5746
caca: for ordinary keys, send key events on press instead of release.
This is consistent with how other vos behave.
Patch by Paul B. Mahol [onemda gmail com].
author | reimar |
---|---|
date | Wed, 23 Nov 2011 23:59:01 +0000 |
parents | 88eebbbbd6a0 |
children | 6e7f60f6f9d4 |
rev | line source |
---|---|
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19966
diff
changeset
|
1 /* |
26723 | 2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> |
3 * | |
26738
588ce97b44f2
Speak of libass instead of MPlayer in the libass license headers.
diego
parents:
26723
diff
changeset
|
4 * This file is part of libass. |
26723 | 5 * |
34011 | 6 * Permission to use, copy, modify, and distribute this software for any |
7 * purpose with or without fee is hereby granted, provided that the above | |
8 * copyright notice and this permission notice appear in all copies. | |
26723 | 9 * |
34011 | 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
26723 | 17 */ |
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19966
diff
changeset
|
18 |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
19 #include <stdlib.h> |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
20 #include <string.h> |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
21 #include <math.h> |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
22 #include <assert.h> |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
23 #include <ft2build.h> |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
24 #include FT_GLYPH_H |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
25 |
30200 | 26 #include "ass_utils.h" |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
27 #include "ass_bitmap.h" |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
28 |
30200 | 29 struct ass_synth_priv { |
30 int tmp_w, tmp_h; | |
31 unsigned short *tmp; | |
19848 | 32 |
30200 | 33 int g_r; |
34 int g_w; | |
19848 | 35 |
30200 | 36 unsigned *g; |
37 unsigned *gt2; | |
28436
12e936031c36
Allow \be with arguments other than 0 or 1. Implement \blur.
eugeni
parents:
27409
diff
changeset
|
38 |
30200 | 39 double radius; |
19848 | 40 }; |
41 | |
42 static const unsigned int maxcolor = 255; | |
43 static const unsigned base = 256; | |
44 | |
30200 | 45 static int generate_tables(ASS_SynthPriv *priv, double radius) |
19848 | 46 { |
30200 | 47 double A = log(1.0 / base) / (radius * radius * 2); |
48 int mx, i; | |
49 double volume_diff, volume_factor = 0; | |
50 unsigned volume; | |
19848 | 51 |
30200 | 52 if (priv->radius == radius) |
53 return 0; | |
54 else | |
55 priv->radius = radius; | |
28436
12e936031c36
Allow \be with arguments other than 0 or 1. Implement \blur.
eugeni
parents:
27409
diff
changeset
|
56 |
30200 | 57 priv->g_r = ceil(radius); |
58 priv->g_w = 2 * priv->g_r + 1; | |
19955
2792de2ca069
Cosmetics. Change indentation of block of code to make it consistent with
eugeni
parents:
19941
diff
changeset
|
59 |
30200 | 60 if (priv->g_r) { |
61 priv->g = realloc(priv->g, priv->g_w * sizeof(unsigned)); | |
62 priv->gt2 = realloc(priv->gt2, 256 * priv->g_w * sizeof(unsigned)); | |
63 if (priv->g == NULL || priv->gt2 == NULL) { | |
64 return -1; | |
65 } | |
66 } | |
19848 | 67 |
30200 | 68 if (priv->g_r) { |
69 // gaussian curve with volume = 256 | |
70 for (volume_diff = 10000000; volume_diff > 0.0000001; | |
71 volume_diff *= 0.5) { | |
72 volume_factor += volume_diff; | |
73 volume = 0; | |
74 for (i = 0; i < priv->g_w; ++i) { | |
75 priv->g[i] = | |
76 (unsigned) (exp(A * (i - priv->g_r) * (i - priv->g_r)) * | |
77 volume_factor + .5); | |
78 volume += priv->g[i]; | |
79 } | |
80 if (volume > 256) | |
81 volume_factor -= volume_diff; | |
82 } | |
83 volume = 0; | |
84 for (i = 0; i < priv->g_w; ++i) { | |
85 priv->g[i] = | |
86 (unsigned) (exp(A * (i - priv->g_r) * (i - priv->g_r)) * | |
87 volume_factor + .5); | |
88 volume += priv->g[i]; | |
89 } | |
19955
2792de2ca069
Cosmetics. Change indentation of block of code to make it consistent with
eugeni
parents:
19941
diff
changeset
|
90 |
30200 | 91 // gauss table: |
92 for (mx = 0; mx < priv->g_w; mx++) { | |
93 for (i = 0; i < 256; i++) { | |
94 priv->gt2[mx + i * priv->g_w] = i * priv->g[mx]; | |
95 } | |
96 } | |
97 } | |
19955
2792de2ca069
Cosmetics. Change indentation of block of code to make it consistent with
eugeni
parents:
19941
diff
changeset
|
98 |
30200 | 99 return 0; |
19848 | 100 } |
101 | |
30200 | 102 static void resize_tmp(ASS_SynthPriv *priv, int w, int h) |
19848 | 103 { |
30200 | 104 if (priv->tmp_w >= w && priv->tmp_h >= h) |
105 return; | |
106 if (priv->tmp_w == 0) | |
107 priv->tmp_w = 64; | |
108 if (priv->tmp_h == 0) | |
109 priv->tmp_h = 64; | |
110 while (priv->tmp_w < w) | |
111 priv->tmp_w *= 2; | |
112 while (priv->tmp_h < h) | |
113 priv->tmp_h *= 2; | |
31875 | 114 free(priv->tmp); |
30200 | 115 priv->tmp = malloc((priv->tmp_w + 1) * priv->tmp_h * sizeof(short)); |
19848 | 116 } |
117 | |
30200 | 118 ASS_SynthPriv *ass_synth_init(double radius) |
19848 | 119 { |
30200 | 120 ASS_SynthPriv *priv = calloc(1, sizeof(ASS_SynthPriv)); |
121 generate_tables(priv, radius); | |
122 return priv; | |
19848 | 123 } |
124 | |
30200 | 125 void ass_synth_done(ASS_SynthPriv *priv) |
19848 | 126 { |
31875 | 127 free(priv->tmp); |
128 free(priv->g); | |
129 free(priv->gt2); | |
30200 | 130 free(priv); |
19848 | 131 } |
132 | |
30200 | 133 static Bitmap *alloc_bitmap(int w, int h) |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
134 { |
30200 | 135 Bitmap *bm; |
31853 | 136 bm = malloc(sizeof(Bitmap)); |
137 bm->buffer = calloc(w, h); | |
30200 | 138 bm->w = w; |
139 bm->h = h; | |
140 bm->left = bm->top = 0; | |
141 return bm; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
142 } |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
143 |
30200 | 144 void ass_free_bitmap(Bitmap *bm) |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
145 { |
31875 | 146 if (bm) |
147 free(bm->buffer); | |
148 free(bm); | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
149 } |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
150 |
30200 | 151 static Bitmap *copy_bitmap(const Bitmap *src) |
19965 | 152 { |
30200 | 153 Bitmap *dst = alloc_bitmap(src->w, src->h); |
154 dst->left = src->left; | |
155 dst->top = src->top; | |
156 memcpy(dst->buffer, src->buffer, src->w * src->h); | |
157 return dst; | |
19965 | 158 } |
159 | |
31853 | 160 int check_glyph_area(ASS_Library *library, FT_Glyph glyph) |
26035
501ea0b13962
Check glyph bounding box before rasterizing and complain if it is too large.
eugeni
parents:
22886
diff
changeset
|
161 { |
30200 | 162 FT_BBox bbox; |
163 long long dx, dy; | |
164 FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_TRUNCATE, &bbox); | |
165 dx = bbox.xMax - bbox.xMin; | |
166 dy = bbox.yMax - bbox.yMin; | |
167 if (dx * dy > 8000000) { | |
168 ass_msg(library, MSGL_WARN, "Glyph bounding box too large: %dx%dpx", | |
169 (int) dx, (int) dy); | |
170 return 1; | |
171 } else | |
172 return 0; | |
26035
501ea0b13962
Check glyph bounding box before rasterizing and complain if it is too large.
eugeni
parents:
22886
diff
changeset
|
173 } |
501ea0b13962
Check glyph bounding box before rasterizing and complain if it is too large.
eugeni
parents:
22886
diff
changeset
|
174 |
30200 | 175 static Bitmap *glyph_to_bitmap_internal(ASS_Library *library, |
176 FT_Glyph glyph, int bord) | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
177 { |
30200 | 178 FT_BitmapGlyph bg; |
179 FT_Bitmap *bit; | |
180 Bitmap *bm; | |
181 int w, h; | |
182 unsigned char *src; | |
183 unsigned char *dst; | |
184 int i; | |
185 int error; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
186 |
30200 | 187 if (check_glyph_area(library, glyph)) |
188 return 0; | |
189 error = FT_Glyph_To_Bitmap(&glyph, FT_RENDER_MODE_NORMAL, 0, 0); | |
190 if (error) { | |
191 ass_msg(library, MSGL_WARN, "FT_Glyph_To_Bitmap error %d", | |
192 error); | |
193 return 0; | |
194 } | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
195 |
30200 | 196 bg = (FT_BitmapGlyph) glyph; |
197 bit = &(bg->bitmap); | |
198 if (bit->pixel_mode != FT_PIXEL_MODE_GRAY) { | |
199 ass_msg(library, MSGL_WARN, "Unsupported pixel mode: %d", | |
200 (int) (bit->pixel_mode)); | |
201 FT_Done_Glyph(glyph); | |
202 return 0; | |
203 } | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
204 |
30200 | 205 w = bit->width; |
206 h = bit->rows; | |
207 bm = alloc_bitmap(w + 2 * bord, h + 2 * bord); | |
208 bm->left = bg->left - bord; | |
209 bm->top = -bg->top - bord; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
210 |
30200 | 211 src = bit->buffer; |
212 dst = bm->buffer + bord + bm->w * bord; | |
213 for (i = 0; i < h; ++i) { | |
214 memcpy(dst, src, w); | |
215 src += bit->pitch; | |
216 dst += bm->w; | |
217 } | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
218 |
30200 | 219 FT_Done_Glyph(glyph); |
220 return bm; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
221 } |
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
222 |
19966 | 223 /** |
30200 | 224 * \brief fix outline bitmap |
225 * | |
226 * The glyph bitmap is subtracted from outline bitmap. This way looks much | |
227 * better in some cases. | |
19966 | 228 */ |
30200 | 229 static void fix_outline(Bitmap *bm_g, Bitmap *bm_o) |
230 { | |
231 int x, y; | |
232 const int l = bm_o->left > bm_g->left ? bm_o->left : bm_g->left; | |
233 const int t = bm_o->top > bm_g->top ? bm_o->top : bm_g->top; | |
234 const int r = | |
235 bm_o->left + bm_o->w < | |
236 bm_g->left + bm_g->w ? bm_o->left + bm_o->w : bm_g->left + bm_g->w; | |
237 const int b = | |
238 bm_o->top + bm_o->h < | |
239 bm_g->top + bm_g->h ? bm_o->top + bm_o->h : bm_g->top + bm_g->h; | |
240 | |
241 unsigned char *g = | |
242 bm_g->buffer + (t - bm_g->top) * bm_g->w + (l - bm_g->left); | |
243 unsigned char *o = | |
244 bm_o->buffer + (t - bm_o->top) * bm_o->w + (l - bm_o->left); | |
245 | |
246 for (y = 0; y < b - t; ++y) { | |
247 for (x = 0; x < r - l; ++x) { | |
248 unsigned char c_g, c_o; | |
249 c_g = g[x]; | |
250 c_o = o[x]; | |
251 o[x] = (c_o > c_g) ? c_o - (c_g / 2) : 0; | |
252 } | |
253 g += bm_g->w; | |
254 o += bm_o->w; | |
255 } | |
256 } | |
257 | |
258 /** | |
259 * \brief Shift a bitmap by the fraction of a pixel in x and y direction | |
260 * expressed in 26.6 fixed point | |
261 */ | |
262 static void shift_bitmap(unsigned char *buf, int w, int h, int shift_x, | |
263 int shift_y) | |
19856 | 264 { |
30200 | 265 int x, y, b; |
266 | |
267 // Shift in x direction | |
268 if (shift_x > 0) { | |
269 for (y = 0; y < h; y++) { | |
270 for (x = w - 1; x > 0; x--) { | |
271 b = (buf[x + y * w - 1] * shift_x) >> 6; | |
272 buf[x + y * w - 1] -= b; | |
273 buf[x + y * w] += b; | |
274 } | |
275 } | |
276 } else if (shift_x < 0) { | |
277 shift_x = -shift_x; | |
278 for (y = 0; y < h; y++) { | |
279 for (x = 0; x < w - 1; x++) { | |
280 b = (buf[x + y * w + 1] * shift_x) >> 6; | |
281 buf[x + y * w + 1] -= b; | |
282 buf[x + y * w] += b; | |
283 } | |
284 } | |
285 } | |
19965 | 286 |
30200 | 287 // Shift in y direction |
288 if (shift_y > 0) { | |
289 for (x = 0; x < w; x++) { | |
290 for (y = h - 1; y > 0; y--) { | |
291 b = (buf[x + (y - 1) * w] * shift_y) >> 6; | |
292 buf[x + (y - 1) * w] -= b; | |
293 buf[x + y * w] += b; | |
294 } | |
295 } | |
296 } else if (shift_y < 0) { | |
297 shift_y = -shift_y; | |
298 for (x = 0; x < w; x++) { | |
299 for (y = 0; y < h - 1; y++) { | |
300 b = (buf[x + (y + 1) * w] * shift_y) >> 6; | |
301 buf[x + (y + 1) * w] -= b; | |
302 buf[x + y * w] += b; | |
303 } | |
304 } | |
305 } | |
306 } | |
307 | |
308 /* | |
309 * Gaussian blur. An fast pure C implementation from MPlayer. | |
310 */ | |
311 static void ass_gauss_blur(unsigned char *buffer, unsigned short *tmp2, | |
312 int width, int height, int stride, int *m2, | |
313 int r, int mwidth) | |
314 { | |
315 | |
316 int x, y; | |
317 | |
318 unsigned char *s = buffer; | |
319 unsigned short *t = tmp2 + 1; | |
320 for (y = 0; y < height; y++) { | |
321 memset(t - 1, 0, (width + 1) * sizeof(short)); | |
19965 | 322 |
30200 | 323 for (x = 0; x < r; x++) { |
324 const int src = s[x]; | |
325 if (src) { | |
326 register unsigned short *dstp = t + x - r; | |
327 int mx; | |
328 unsigned *m3 = (unsigned *) (m2 + src * mwidth); | |
329 for (mx = r - x; mx < mwidth; mx++) { | |
330 dstp[mx] += m3[mx]; | |
331 } | |
332 } | |
333 } | |
334 | |
335 for (; x < width - r; x++) { | |
336 const int src = s[x]; | |
337 if (src) { | |
338 register unsigned short *dstp = t + x - r; | |
339 int mx; | |
340 unsigned *m3 = (unsigned *) (m2 + src * mwidth); | |
341 for (mx = 0; mx < mwidth; mx++) { | |
342 dstp[mx] += m3[mx]; | |
343 } | |
344 } | |
345 } | |
346 | |
347 for (; x < width; x++) { | |
348 const int src = s[x]; | |
349 if (src) { | |
350 register unsigned short *dstp = t + x - r; | |
351 int mx; | |
352 const int x2 = r + width - x; | |
353 unsigned *m3 = (unsigned *) (m2 + src * mwidth); | |
354 for (mx = 0; mx < x2; mx++) { | |
355 dstp[mx] += m3[mx]; | |
356 } | |
357 } | |
358 } | |
359 | |
360 s += stride; | |
361 t += width + 1; | |
362 } | |
363 | |
364 t = tmp2; | |
365 for (x = 0; x < width; x++) { | |
366 for (y = 0; y < r; y++) { | |
367 unsigned short *srcp = t + y * (width + 1) + 1; | |
368 int src = *srcp; | |
369 if (src) { | |
370 register unsigned short *dstp = srcp - 1 + width + 1; | |
371 const int src2 = (src + 128) >> 8; | |
372 unsigned *m3 = (unsigned *) (m2 + src2 * mwidth); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28802
diff
changeset
|
373 |
30200 | 374 int mx; |
375 *srcp = 128; | |
376 for (mx = r - 1; mx < mwidth; mx++) { | |
377 *dstp += m3[mx]; | |
378 dstp += width + 1; | |
379 } | |
380 } | |
381 } | |
382 for (; y < height - r; y++) { | |
383 unsigned short *srcp = t + y * (width + 1) + 1; | |
384 int src = *srcp; | |
385 if (src) { | |
386 register unsigned short *dstp = srcp - 1 - r * (width + 1); | |
387 const int src2 = (src + 128) >> 8; | |
388 unsigned *m3 = (unsigned *) (m2 + src2 * mwidth); | |
19965 | 389 |
30200 | 390 int mx; |
391 *srcp = 128; | |
392 for (mx = 0; mx < mwidth; mx++) { | |
393 *dstp += m3[mx]; | |
394 dstp += width + 1; | |
395 } | |
396 } | |
397 } | |
398 for (; y < height; y++) { | |
399 unsigned short *srcp = t + y * (width + 1) + 1; | |
400 int src = *srcp; | |
401 if (src) { | |
402 const int y2 = r + height - y; | |
403 register unsigned short *dstp = srcp - 1 - r * (width + 1); | |
404 const int src2 = (src + 128) >> 8; | |
405 unsigned *m3 = (unsigned *) (m2 + src2 * mwidth); | |
406 | |
407 int mx; | |
408 *srcp = 128; | |
409 for (mx = 0; mx < y2; mx++) { | |
410 *dstp += m3[mx]; | |
411 dstp += width + 1; | |
412 } | |
413 } | |
414 } | |
415 t++; | |
416 } | |
417 | |
418 t = tmp2; | |
419 s = buffer; | |
420 for (y = 0; y < height; y++) { | |
421 for (x = 0; x < width; x++) { | |
422 s[x] = t[x] >> 8; | |
423 } | |
424 s += stride; | |
425 t += width + 1; | |
426 } | |
19856 | 427 } |
428 | |
28799
65b83aee82fb
Use blur with kernel [[1,2,1], [2,4,2], [1,2,1]] for \be.
greg
parents:
28781
diff
changeset
|
429 /** |
65b83aee82fb
Use blur with kernel [[1,2,1], [2,4,2], [1,2,1]] for \be.
greg
parents:
28781
diff
changeset
|
430 * \brief Blur with [[1,2,1]. [2,4,2], [1,2,1]] kernel |
65b83aee82fb
Use blur with kernel [[1,2,1], [2,4,2], [1,2,1]] for \be.
greg
parents:
28781
diff
changeset
|
431 * This blur is the same as the one employed by vsfilter. |
65b83aee82fb
Use blur with kernel [[1,2,1], [2,4,2], [1,2,1]] for \be.
greg
parents:
28781
diff
changeset
|
432 */ |
30200 | 433 static void be_blur(unsigned char *buf, int w, int h) |
434 { | |
435 unsigned int x, y; | |
436 unsigned int old_sum, new_sum; | |
28799
65b83aee82fb
Use blur with kernel [[1,2,1], [2,4,2], [1,2,1]] for \be.
greg
parents:
28781
diff
changeset
|
437 |
30200 | 438 for (y = 0; y < h; y++) { |
439 old_sum = 2 * buf[y * w]; | |
440 for (x = 0; x < w - 1; x++) { | |
441 new_sum = buf[y * w + x] + buf[y * w + x + 1]; | |
442 buf[y * w + x] = (old_sum + new_sum) >> 2; | |
443 old_sum = new_sum; | |
444 } | |
445 } | |
28799
65b83aee82fb
Use blur with kernel [[1,2,1], [2,4,2], [1,2,1]] for \be.
greg
parents:
28781
diff
changeset
|
446 |
30200 | 447 for (x = 0; x < w; x++) { |
448 old_sum = 2 * buf[x]; | |
449 for (y = 0; y < h - 1; y++) { | |
450 new_sum = buf[y * w + x] + buf[(y + 1) * w + x]; | |
451 buf[y * w + x] = (old_sum + new_sum) >> 2; | |
452 old_sum = new_sum; | |
453 } | |
454 } | |
28799
65b83aee82fb
Use blur with kernel [[1,2,1], [2,4,2], [1,2,1]] for \be.
greg
parents:
28781
diff
changeset
|
455 } |
65b83aee82fb
Use blur with kernel [[1,2,1], [2,4,2], [1,2,1]] for \be.
greg
parents:
28781
diff
changeset
|
456 |
30200 | 457 int glyph_to_bitmap(ASS_Library *library, ASS_SynthPriv *priv_blur, |
458 FT_Glyph glyph, FT_Glyph outline_glyph, | |
459 Bitmap **bm_g, Bitmap **bm_o, Bitmap **bm_s, | |
460 int be, double blur_radius, FT_Vector shadow_offset, | |
461 int border_style) | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
462 { |
30200 | 463 blur_radius *= 2; |
464 int bbord = be > 0 ? sqrt(2 * be) : 0; | |
465 int gbord = blur_radius > 0.0 ? blur_radius + 1 : 0; | |
466 int bord = FFMAX(bbord, gbord); | |
467 if (bord == 0 && (shadow_offset.x || shadow_offset.y)) | |
468 bord = 1; | |
19848 | 469 |
30200 | 470 assert(bm_g && bm_o && bm_s); |
19965 | 471 |
30200 | 472 *bm_g = *bm_o = *bm_s = 0; |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
473 |
30200 | 474 if (glyph) |
475 *bm_g = glyph_to_bitmap_internal(library, glyph, bord); | |
476 if (!*bm_g) | |
477 return 1; | |
478 | |
479 if (outline_glyph) { | |
480 *bm_o = glyph_to_bitmap_internal(library, outline_glyph, bord); | |
481 if (!*bm_o) { | |
482 return 1; | |
483 } | |
484 } | |
19965 | 485 |
30200 | 486 // Apply box blur (multiple passes, if requested) |
487 while (be--) { | |
488 if (*bm_o) | |
489 be_blur((*bm_o)->buffer, (*bm_o)->w, (*bm_o)->h); | |
490 else | |
491 be_blur((*bm_g)->buffer, (*bm_g)->w, (*bm_g)->h); | |
492 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
28802
diff
changeset
|
493 |
30200 | 494 // Apply gaussian blur |
495 if (blur_radius > 0.0) { | |
496 if (*bm_o) | |
497 resize_tmp(priv_blur, (*bm_o)->w, (*bm_o)->h); | |
498 else | |
499 resize_tmp(priv_blur, (*bm_g)->w, (*bm_g)->h); | |
500 generate_tables(priv_blur, blur_radius); | |
501 if (*bm_o) | |
502 ass_gauss_blur((*bm_o)->buffer, priv_blur->tmp, | |
503 (*bm_o)->w, (*bm_o)->h, (*bm_o)->w, | |
504 (int *) priv_blur->gt2, priv_blur->g_r, | |
505 priv_blur->g_w); | |
506 else | |
507 ass_gauss_blur((*bm_g)->buffer, priv_blur->tmp, | |
508 (*bm_g)->w, (*bm_g)->h, (*bm_g)->w, | |
509 (int *) priv_blur->gt2, priv_blur->g_r, | |
510 priv_blur->g_w); | |
511 } | |
19856 | 512 |
30200 | 513 // Create shadow and fix outline as needed |
514 if (*bm_o && border_style != 3) { | |
515 *bm_s = copy_bitmap(*bm_o); | |
516 fix_outline(*bm_g, *bm_o); | |
517 } else if (*bm_o) { | |
518 *bm_s = copy_bitmap(*bm_o); | |
519 } else | |
520 *bm_s = copy_bitmap(*bm_g); | |
521 | |
522 assert(bm_s); | |
523 | |
524 shift_bitmap((*bm_s)->buffer, (*bm_s)->w,(*bm_s)->h, | |
525 shadow_offset.x, shadow_offset.y); | |
526 | |
527 return 0; | |
19846
bcc792bfa431
Store bitmap glyphs in a separate struct, instead of FreeType's internal buffer.
eugeni
parents:
diff
changeset
|
528 } |