Mercurial > mplayer.hg
annotate libmpcodecs/vf_ass.c @ 35262:49fc594fda43
Updated libass to 0.10.1
This closes #2099
author | SubJunk |
---|---|
date | Tue, 06 Nov 2012 05:41:14 +0000 |
parents | 222713e4d79f |
children | f16646c59e33 |
rev | line source |
---|---|
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19563
diff
changeset
|
1 /* |
26727 | 2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com> |
35244 | 3 * Copyright (C) 2012 Xidorn Quan <quanxunzhen@gmail.com> |
26727 | 4 * |
5 * This file is part of MPlayer. | |
6 * | |
7 * MPlayer is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * MPlayer is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License along | |
18 * with MPlayer; if not, write to the Free Software Foundation, Inc., | |
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | |
20 */ | |
20008
fa122b7c71c6
Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents:
19563
diff
changeset
|
21 |
18937 | 22 #include "config.h" |
23 | |
24 #include <stdio.h> | |
25 #include <stdlib.h> | |
26 #include <string.h> | |
24545
9e5126679d44
Replace stdint.h #include by functionally equivalent inttypes.h.
diego
parents:
23134
diff
changeset
|
27 #include <inttypes.h> |
18937 | 28 #include <assert.h> |
29 | |
30 #include "config.h" | |
31 #include "mp_msg.h" | |
32 #include "help_mp.h" | |
31489 | 33 #include "mpcommon.h" |
18937 | 34 #include "img_format.h" |
35 #include "mp_image.h" | |
30653
3d23e24c5c60
Declare externally used variables from vd.c as extern in vd.h.
diego
parents:
30642
diff
changeset
|
36 #include "vd.h" |
18937 | 37 #include "vf.h" |
38 | |
39 #include "libvo/fastmemcpy.h" | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
40 #include "libavutil/intreadwrite.h" |
32467 | 41 #include "sub/sub.h" |
18937 | 42 #include "m_option.h" |
43 #include "m_struct.h" | |
44 | |
32461 | 45 #include "sub/ass_mp.h" |
32460 | 46 #include "sub/eosd.h" |
18937 | 47 |
48 #define _r(c) ((c)>>24) | |
49 #define _g(c) (((c)>>16)&0xFF) | |
50 #define _b(c) (((c)>>8)&0xFF) | |
51 #define _a(c) ((c)&0xFF) | |
32096 | 52 #define rgba2y(c) ( (( 263*_r(c) + 516*_g(c) + 100*_b(c)) >> 10) + 16 ) |
18937 | 53 #define rgba2u(c) ( ((-152*_r(c) - 298*_g(c) + 450*_b(c)) >> 10) + 128 ) |
54 #define rgba2v(c) ( (( 450*_r(c) - 376*_g(c) - 73*_b(c)) >> 10) + 128 ) | |
55 | |
35244 | 56 /* map 0 - 0xFF -> 0 - 0x101 */ |
57 #define MAP_16BIT(v) RSHIFT(0x102 * (v), 8) | |
58 /* map 0 - 0xFF -> 0 - 0x10101 */ | |
59 #define MAP_24BIT(v) RSHIFT(0x10203 * (v), 8) | |
18937 | 60 |
24969
c2b7ba444ade
begin moving const filter data to .text/.rodata sections
rfelker
parents:
24545
diff
changeset
|
61 static const struct vf_priv_s { |
32096 | 62 int outh, outw; |
18937 | 63 |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
64 int is_planar; |
32096 | 65 unsigned int outfmt; |
18937 | 66 |
32096 | 67 // 1 = auto-added filter: insert only if chain does not support EOSD already |
68 // 0 = insert always | |
69 int auto_insert; | |
18937 | 70 |
35244 | 71 // planar data to be directly rendered on frames |
72 uint8_t *planes[MP_MAX_PLANES]; | |
73 // alpha here is actually transparency, not opacity | |
74 uint8_t *alphas[MP_MAX_PLANES]; | |
75 struct dirty_rows_extent { | |
76 int xmin, xmax; | |
77 } *dirty_rows; | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
78 |
35244 | 79 // called for every eosd image when subtitle is changed |
80 void (*draw_image)(vf_instance_t *, struct mp_eosd_image *); | |
81 // called for every time subtitle is changed | |
82 void (*prepare_buffer)(vf_instance_t *); | |
83 // called for every frame | |
84 void (*render_frame)(vf_instance_t *); | |
24969
c2b7ba444ade
begin moving const filter data to .text/.rodata sections
rfelker
parents:
24545
diff
changeset
|
85 } vf_priv_dflt; |
18937 | 86 |
35244 | 87 static void draw_image_yuv(vf_instance_t *vf, struct mp_eosd_image *img) |
88 { | |
89 uint32_t color = img->color; | |
90 uint32_t opacity = 0xFF - _a(color); | |
91 uint8_t y = rgba2y(color), | |
92 u = rgba2u(color), | |
93 v = rgba2v(color); | |
94 int outw = vf->priv->outw, | |
95 outh = vf->priv->outh; | |
96 uint8_t *alpha = vf->priv->alphas[0], | |
97 *dst_y = vf->priv->planes[0], | |
98 *dst_u = vf->priv->planes[1], | |
99 *dst_v = vf->priv->planes[2]; | |
100 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
101 int src_x = img->dst_x, src_w = img->w, | |
102 src_y = img->dst_y, src_h = img->h, | |
103 stride = img->stride; | |
104 uint8_t *src = img->bitmap; | |
105 int i, j; | |
106 | |
107 opacity = MAP_24BIT(opacity); | |
108 for (i = 0; i < src_h; i++) { | |
109 struct dirty_rows_extent *dirty_row = &dirty_rows[src_y + i]; | |
110 dirty_row->xmin = FFMIN(dirty_row->xmin, src_x); | |
111 dirty_row->xmax = FFMAX(dirty_row->xmax, src_x + src_w); | |
112 | |
113 for (j = 0; j < src_w; j++) { | |
114 uint32_t k = src[i * stride + j]; | |
115 if (k) { | |
116 size_t p = (src_y + i) * outw + src_x + j; | |
117 k *= opacity; | |
118 alpha[p] = RSHIFT((0xFFFFFF - k) * alpha[p], 24); | |
119 dst_y[p] = RSHIFT((0xFFFFFF - k) * dst_y[p] + k * y, 24); | |
120 dst_u[p] = RSHIFT((0xFFFFFF - k) * dst_u[p] + k * u, 24); | |
121 dst_v[p] = RSHIFT((0xFFFFFF - k) * dst_v[p] + k * v, 24); | |
122 } | |
123 } | |
124 } | |
125 } | |
126 | |
127 static void prepare_buffer_422(vf_instance_t *vf) | |
128 { | |
129 uint8_t *dst_u = vf->priv->planes[1], | |
130 *dst_v = vf->priv->planes[2]; | |
131 int outw = vf->priv->outw, | |
132 outh = vf->priv->outh; | |
133 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
134 int i, j; | |
135 | |
136 for (i = 0; i < outh; i++) { | |
137 int xmin = dirty_rows[i].xmin & ~1, | |
138 xmax = dirty_rows[i].xmax; | |
139 for (j = xmin; j < xmax; j += 2) { | |
140 size_t p = i * outw + j; | |
141 dst_u[p] = (dst_u[p] + dst_u[p + 1]) / 2; | |
142 dst_v[p] = (dst_v[p] + dst_v[p + 1]) / 2; | |
143 } | |
144 } | |
145 } | |
146 | |
147 static void render_frame_yuv422(vf_instance_t *vf) | |
148 { | |
149 uint8_t *alpha = vf->priv->alphas[0]; | |
150 uint8_t *src_y = vf->priv->planes[0], | |
151 *src_u = vf->priv->planes[1], | |
152 *src_v = vf->priv->planes[2]; | |
153 int outw = vf->priv->outw, | |
154 outh = vf->priv->outh; | |
155 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
156 uint8_t *dest = vf->dmpi->planes[0]; | |
157 int stride = vf->dmpi->stride[0]; | |
158 int is_uyvy = vf->priv->outfmt == IMGFMT_UYVY; | |
159 int i, j; | |
160 | |
161 for (i = 0; i < outh; i++) { | |
162 int xmin = dirty_rows[i].xmin & ~1, | |
163 xmax = dirty_rows[i].xmax; | |
164 for (j = xmin; j < xmax; j += 2) { | |
165 size_t src = i * outw + j, | |
166 dst = i * stride + j * 2; | |
167 uint_fast16_t a0 = alpha[src], | |
168 a1 = alpha[src + 1]; | |
169 uint8_t y0, y1, u, v; | |
170 | |
171 if (a0 == 0xFF && a1 == 0xFF) | |
172 continue; | |
173 | |
174 y0 = dest[dst + is_uyvy + 0]; | |
175 y1 = dest[dst + is_uyvy + 2]; | |
176 u = dest[dst - is_uyvy + 1]; | |
177 v = dest[dst - is_uyvy + 3]; | |
178 | |
179 a0 = MAP_16BIT(a0); | |
180 a1 = MAP_16BIT(a1); | |
181 y0 = ((a0 * y0) >> 8) + src_y[src]; | |
182 y1 = ((a1 * y1) >> 8) + src_y[src + 1]; | |
183 | |
184 a0 = (a0 + a1) / 2; | |
185 u = ((a0 * u) >> 8) + src_u[src]; | |
186 v = ((a0 * v) >> 8) + src_v[src]; | |
187 | |
188 dest[dst + is_uyvy + 0] = y0; | |
189 dest[dst + is_uyvy + 2] = y1; | |
190 dest[dst - is_uyvy + 1] = u; | |
191 dest[dst - is_uyvy + 3] = v; | |
192 } | |
193 } | |
194 } | |
195 | |
196 static void prepare_buffer_420p(vf_instance_t *vf) | |
197 { | |
198 int outw = vf->priv->outw, | |
199 outh = vf->priv->outh; | |
200 uint8_t *dst_u = vf->priv->planes[1], | |
201 *dst_v = vf->priv->planes[2]; | |
202 uint8_t *src_a = vf->priv->alphas[0], | |
203 *dst_a = vf->priv->alphas[1]; | |
204 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
205 int i, j; | |
206 | |
207 for (i = 0; i < outh; i += 2) { | |
208 int xmin = FFMIN(dirty_rows[i].xmin, dirty_rows[i + 1].xmin) & ~1, | |
209 xmax = FFMAX(dirty_rows[i].xmax, dirty_rows[i + 1].xmax); | |
210 for (j = xmin; j < xmax; j += 2) { | |
211 size_t p = i * outw / 4 + j / 2, | |
212 q1 = i * outw + j, | |
213 q2 = q1 + outw; | |
214 dst_a[p] = (src_a[q1] + src_a[q1 + 1] + | |
215 src_a[q2] + src_a[q2 + 1] + 2) / 4; | |
216 dst_u[p] = (dst_u[q1] + dst_u[q1 + 1] + | |
217 dst_u[q2] + dst_u[q2 + 1] + 2) / 4; | |
218 dst_v[p] = (dst_v[q1] + dst_v[q1 + 1] + | |
219 dst_v[q2] + dst_v[q2 + 1] + 2) / 4; | |
220 } | |
221 } | |
222 } | |
223 | |
224 static void render_frame_yuv420p(vf_instance_t *vf) | |
225 { | |
226 uint8_t **planes = vf->priv->planes; | |
227 uint8_t **dest = vf->dmpi->planes; | |
228 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
229 uint8_t *alpha; | |
230 uint8_t *src_y = vf->priv->planes[0], | |
231 *src_u = vf->priv->planes[1], | |
232 *src_v = vf->priv->planes[2]; | |
233 uint8_t *dst_y = vf->dmpi->planes[0], | |
234 *dst_u = vf->dmpi->planes[1], | |
235 *dst_v = vf->dmpi->planes[2]; | |
236 int stride; | |
237 int outw = vf->priv->outw, | |
238 outh = vf->priv->outh; | |
239 int i, j; | |
240 | |
241 // y | |
242 alpha = vf->priv->alphas[0]; | |
243 stride = vf->dmpi->stride[0]; | |
244 for (i = 0; i < outh; i++) { | |
245 int xmin = dirty_rows[i].xmin, | |
246 xmax = dirty_rows[i].xmax; | |
247 for (j = xmin; j < xmax; j++) { | |
248 size_t s = i * outw + j, | |
249 d = i * stride + j; | |
250 if (alpha[s] != 0xFF) | |
251 dst_y[d] = ((MAP_16BIT(alpha[s]) * dst_y[d]) >> 8) + src_y[s]; | |
252 } | |
253 } | |
254 | |
255 // u & v | |
256 alpha = vf->priv->alphas[1]; | |
257 stride = vf->dmpi->stride[1]; | |
258 for (i = 0; i < outh / 2; i++) { | |
259 int xmin = FFMIN(dirty_rows[i * 2].xmin, dirty_rows[i * 2 + 1].xmin), | |
260 xmax = FFMAX(dirty_rows[i * 2].xmax, dirty_rows[i * 2 + 1].xmax); | |
261 for (j = xmin / 2; j < (xmax + 1) / 2; j++) { | |
262 size_t s = i * outw / 2 + j, | |
263 d = i * stride + j; | |
264 if (alpha[s] != 0xFF) { | |
265 uint_fast16_t a = MAP_16BIT(alpha[s]); | |
266 dst_u[d] = ((a * dst_u[d]) >> 8) + src_u[s]; | |
267 dst_v[d] = ((a * dst_v[d]) >> 8) + src_v[s]; | |
268 } | |
269 } | |
270 } | |
271 } | |
272 | |
273 static void clean_buffer(vf_instance_t *vf) | |
274 { | |
275 int outw = vf->priv->outw, | |
276 outh = vf->priv->outh; | |
277 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
278 uint8_t **planes = vf->priv->planes; | |
279 uint8_t *alpha = vf->priv->alphas[0]; | |
280 int i, j; | |
281 | |
282 for (i = 0; i < MP_MAX_PLANES; i++) { | |
283 uint8_t *plane = planes[i]; | |
284 if (!plane) | |
285 break; | |
286 for (j = 0; j < outh; j++) { | |
287 int xmin = dirty_rows[j].xmin; | |
288 int width = dirty_rows[j].xmax - xmin; | |
289 if (width > 0) | |
290 memset(plane + j * outw + xmin, 0, width); | |
291 } | |
292 } | |
293 for (i = 0; i < outh; i++) { | |
294 int xmin = dirty_rows[i].xmin; | |
295 int width = dirty_rows[i].xmax - xmin; | |
296 if (width > 0) | |
297 memset(alpha + i * outw + xmin, -1, width); | |
298 } | |
299 for (i = 0; i < outh; i++) { | |
300 dirty_rows[i].xmin = outw; | |
301 dirty_rows[i].xmax = 0; | |
302 } | |
303 } | |
18937 | 304 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
305 static int config(struct vf_instance *vf, |
32096 | 306 int width, int height, int d_width, int d_height, |
307 unsigned int flags, unsigned int outfmt) | |
18937 | 308 { |
32391
b4c3659d16b1
Use a dynamic list for the sources of EOSD elements.
cigaes
parents:
32261
diff
changeset
|
309 struct mp_eosd_settings res = {0}; |
35244 | 310 struct dirty_rows_extent *dirty_rows; |
311 int outw, outh; | |
312 int planes, alphas; | |
313 int i; | |
31927 | 314 |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
315 switch (outfmt) { |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
316 case IMGFMT_YV12: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
317 case IMGFMT_I420: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
318 case IMGFMT_IYUV: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
319 vf->priv->is_planar = 1; |
35244 | 320 planes = 3; |
321 alphas = 2; | |
322 vf->priv->draw_image = draw_image_yuv; | |
323 vf->priv->render_frame = render_frame_yuv420p; | |
324 vf->priv->prepare_buffer = prepare_buffer_420p; | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
325 break; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
326 case IMGFMT_UYVY: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
327 case IMGFMT_YUY2: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
328 vf->priv->is_planar = 0; |
35244 | 329 planes = 3; |
330 alphas = 1; | |
331 vf->priv->draw_image = draw_image_yuv; | |
332 vf->priv->render_frame = render_frame_yuv422; | |
333 vf->priv->prepare_buffer = prepare_buffer_422; | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
334 break; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
335 default: |
32096 | 336 return 0; |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
337 } |
18937 | 338 |
35033 | 339 vf->priv->outfmt = outfmt; |
35244 | 340 vf->priv->outh = outh = height + ass_top_margin + ass_bottom_margin; |
341 vf->priv->outw = outw = width; | |
18937 | 342 |
32096 | 343 if (!opt_screen_size_x && !opt_screen_size_y) { |
344 d_width = d_width * vf->priv->outw / width; | |
345 d_height = d_height * vf->priv->outh / height; | |
346 } | |
18937 | 347 |
35244 | 348 for (i = 0; i < planes; i++) |
349 vf->priv->planes[i] = av_malloc(outw * outh); | |
350 for (i = 0; i < alphas; i++) | |
351 vf->priv->alphas[i] = av_malloc(outw * outh); | |
352 dirty_rows = av_malloc(outh * sizeof(*dirty_rows)); | |
353 // mark all rows dirty here | |
354 // so that they can be properly cleaned in clear_buffer() | |
355 for (i = 0; i < outh; i++) { | |
356 dirty_rows[i].xmin = 0; | |
357 dirty_rows[i].xmax = outw; | |
358 } | |
359 vf->priv->dirty_rows = dirty_rows; | |
360 clean_buffer(vf); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26727
diff
changeset
|
361 |
32096 | 362 res.w = vf->priv->outw; |
363 res.h = vf->priv->outh; | |
364 res.srcw = width; | |
365 res.srch = height; | |
366 res.mt = ass_top_margin; | |
367 res.mb = ass_bottom_margin; | |
32391
b4c3659d16b1
Use a dynamic list for the sources of EOSD elements.
cigaes
parents:
32261
diff
changeset
|
368 eosd_configure(&res); |
18937 | 369 |
32096 | 370 return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, |
371 d_height, flags, outfmt); | |
18937 | 372 } |
373 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
374 static void get_image(struct vf_instance *vf, mp_image_t *mpi) |
18937 | 375 { |
32096 | 376 if (mpi->type == MP_IMGTYPE_IPB) |
377 return; | |
378 if (mpi->flags & MP_IMGFLAG_PRESERVE) | |
379 return; | |
380 if (mpi->imgfmt != vf->priv->outfmt) | |
381 return; // colorspace differ | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26727
diff
changeset
|
382 |
32096 | 383 // width never changes, always try full DR |
384 mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt, mpi->type, | |
385 mpi->flags | MP_IMGFLAG_READABLE, | |
34882
649d4cad4619
Request a sufficiently large image for direct rendering.
reimar
parents:
34863
diff
changeset
|
386 FFMAX(mpi->width, vf->priv->outw), |
649d4cad4619
Request a sufficiently large image for direct rendering.
reimar
parents:
34863
diff
changeset
|
387 FFMAX(mpi->height, vf->priv->outh)); |
18937 | 388 |
32096 | 389 if ( (vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) && |
390 !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)) { | |
391 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_MPCODECS_FullDRNotPossible); | |
392 return; | |
393 } | |
394 // set up mpi as a cropped-down image of dmpi: | |
395 if (mpi->flags & MP_IMGFLAG_PLANAR) { | |
396 mpi->planes[0] = vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0]; | |
397 mpi->planes[1] = vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1]; | |
398 mpi->planes[2] = vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2]; | |
399 mpi->stride[1] = vf->dmpi->stride[1]; | |
400 mpi->stride[2] = vf->dmpi->stride[2]; | |
401 } else { | |
402 mpi->planes[0] = vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0]; | |
403 } | |
404 mpi->stride[0] = vf->dmpi->stride[0]; | |
405 mpi->width = vf->dmpi->width; | |
406 mpi->flags |= MP_IMGFLAG_DIRECT; | |
407 mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK; | |
408 // vf->dmpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK; | |
18937 | 409 } |
410 | |
411 static void blank(mp_image_t *mpi, int y1, int y2) | |
412 { | |
32096 | 413 int color[3] = { 16, 128, 128 }; // black (YUV) |
414 int y; | |
415 unsigned char *dst; | |
416 int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift; | |
18937 | 417 |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
418 if (mpi->flags & MP_IMGFLAG_PLANAR) { |
32096 | 419 dst = mpi->planes[0] + y1 * mpi->stride[0]; |
420 for (y = 0; y < y2 - y1; ++y) { | |
421 memset(dst, color[0], mpi->w); | |
422 dst += mpi->stride[0]; | |
423 } | |
424 dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1]; | |
425 for (y = 0; y < chroma_rows; ++y) { | |
426 memset(dst, color[1], mpi->chroma_width); | |
427 dst += mpi->stride[1]; | |
428 } | |
429 dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2]; | |
430 for (y = 0; y < chroma_rows; ++y) { | |
431 memset(dst, color[2], mpi->chroma_width); | |
432 dst += mpi->stride[2]; | |
433 } | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
434 } else { |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
435 unsigned char packed_color[4]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
436 int x; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
437 if (mpi->imgfmt == IMGFMT_UYVY) { |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
438 packed_color[0] = color[1]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
439 packed_color[1] = color[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
440 packed_color[2] = color[2]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
441 packed_color[3] = color[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
442 } else { |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
443 packed_color[0] = color[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
444 packed_color[1] = color[1]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
445 packed_color[2] = color[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
446 packed_color[3] = color[2]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
447 } |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
448 dst = mpi->planes[0] + y1 * mpi->stride[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
449 for (y = y1; y < y2; ++y) { |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
450 for (x = 0; x < mpi->w / 2; ++x) |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
451 AV_COPY32(dst + 4 * x, packed_color); |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
452 dst += mpi->stride[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
453 } |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
454 } |
18937 | 455 } |
456 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
457 static int prepare_image(struct vf_instance *vf, mp_image_t *mpi) |
18937 | 458 { |
32096 | 459 if (mpi->flags & MP_IMGFLAG_DIRECT || |
460 mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) { | |
461 vf->dmpi = mpi->priv; | |
462 if (!vf->dmpi) { | |
463 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_MPCODECS_FunWhydowegetNULL); | |
464 return 0; | |
465 } | |
466 mpi->priv = NULL; | |
467 // we've used DR, so we're ready... | |
468 if (ass_top_margin) | |
469 blank(vf->dmpi, 0, ass_top_margin); | |
470 if (ass_bottom_margin) | |
471 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh); | |
472 if (!(mpi->flags & MP_IMGFLAG_PLANAR)) | |
473 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette | |
474 return 0; | |
475 } | |
476 // hope we'll get DR buffer: | |
477 vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt, MP_IMGTYPE_TEMP, | |
478 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE, | |
479 vf->priv->outw, vf->priv->outh); | |
18937 | 480 |
32096 | 481 // copy mpi->dmpi... |
482 if (mpi->flags & MP_IMGFLAG_PLANAR) { | |
483 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0], | |
484 mpi->planes[0], | |
485 mpi->w, | |
486 mpi->h, | |
487 vf->dmpi->stride[0], | |
488 mpi->stride[0]); | |
489 memcpy_pic(vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1], | |
490 mpi->planes[1], | |
491 mpi->w >> mpi->chroma_x_shift, | |
492 mpi->h >> mpi->chroma_y_shift, | |
493 vf->dmpi->stride[1], | |
494 mpi->stride[1]); | |
495 memcpy_pic(vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2], | |
496 mpi->planes[2], | |
497 mpi->w >> mpi->chroma_x_shift, | |
498 mpi->h >> mpi->chroma_y_shift, | |
499 vf->dmpi->stride[2], | |
500 mpi->stride[2]); | |
501 } else { | |
502 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0], | |
503 mpi->planes[0], | |
504 mpi->w * (vf->dmpi->bpp / 8), | |
505 mpi->h, | |
506 vf->dmpi->stride[0], | |
507 mpi->stride[0]); | |
508 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette | |
509 } | |
510 if (ass_top_margin) | |
511 blank(vf->dmpi, 0, ass_top_margin); | |
512 if (ass_bottom_margin) | |
513 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh); | |
514 return 0; | |
18937 | 515 } |
516 | |
35244 | 517 static void prepare_eosd(vf_instance_t *vf, struct mp_eosd_image_list *imgs) |
18937 | 518 { |
35244 | 519 struct mp_eosd_image *img = eosd_image_first(imgs); |
520 void (*draw_image)(vf_instance_t *, struct mp_eosd_image *); | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
521 |
35244 | 522 clean_buffer(vf); |
523 draw_image = vf->priv->draw_image; | |
524 for (; img; img = eosd_image_next(imgs)) | |
525 draw_image(vf, img); | |
526 vf->priv->prepare_buffer(vf); | |
18937 | 527 } |
528 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
529 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) |
18937 | 530 { |
32391
b4c3659d16b1
Use a dynamic list for the sources of EOSD elements.
cigaes
parents:
32261
diff
changeset
|
531 struct mp_eosd_image_list images; |
b4c3659d16b1
Use a dynamic list for the sources of EOSD elements.
cigaes
parents:
32261
diff
changeset
|
532 eosd_render_frame(pts, &images); |
32096 | 533 prepare_image(vf, mpi); |
35244 | 534 if (images.changed) |
535 prepare_eosd(vf, &images); | |
536 vf->priv->render_frame(vf); | |
32096 | 537 return vf_next_put_image(vf, vf->dmpi, pts); |
18937 | 538 } |
539 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
540 static int query_format(struct vf_instance *vf, unsigned int fmt) |
18937 | 541 { |
32096 | 542 switch (fmt) { |
543 case IMGFMT_YV12: | |
544 case IMGFMT_I420: | |
545 case IMGFMT_IYUV: | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
546 case IMGFMT_UYVY: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
547 case IMGFMT_YUY2: |
35033 | 548 return vf_next_query_format(vf, fmt) | VFCAP_EOSD; |
32096 | 549 } |
550 return 0; | |
18937 | 551 } |
552 | |
553 static int control(vf_instance_t *vf, int request, void *data) | |
554 { | |
32096 | 555 switch (request) { |
556 case VFCTRL_INIT_EOSD: | |
557 return CONTROL_TRUE; | |
558 case VFCTRL_DRAW_EOSD: | |
559 return CONTROL_TRUE; | |
560 } | |
561 return vf_next_control(vf, request, data); | |
18937 | 562 } |
563 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
564 static void uninit(struct vf_instance *vf) |
18937 | 565 { |
35244 | 566 int i; |
567 for (i = 0; i < MP_MAX_PLANES; i++) | |
568 av_free(vf->priv->planes[i]); | |
569 for (i = 0; i < MP_MAX_PLANES; i++) | |
570 av_free(vf->priv->alphas[i]); | |
571 av_free(vf->priv->dirty_rows); | |
18937 | 572 } |
573 | |
32096 | 574 static const unsigned int fmt_list[] = { |
575 IMGFMT_YV12, | |
576 IMGFMT_I420, | |
577 IMGFMT_IYUV, | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
578 IMGFMT_UYVY, |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
579 IMGFMT_YUY2, |
32096 | 580 0 |
18937 | 581 }; |
582 | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30633
diff
changeset
|
583 static int vf_open(vf_instance_t *vf, char *args) |
18937 | 584 { |
32096 | 585 int flags; |
35033 | 586 unsigned outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12); |
587 if (outfmt) | |
588 flags = vf_next_query_format(vf, outfmt); | |
589 if (!outfmt || (vf->priv->auto_insert && flags & VFCAP_EOSD)) { | |
32096 | 590 uninit(vf); |
591 return 0; | |
592 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26727
diff
changeset
|
593 |
32096 | 594 if (vf->priv->auto_insert) |
595 mp_msg(MSGT_ASS, MSGL_INFO, "[ass] auto-open\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26727
diff
changeset
|
596 |
32096 | 597 vf->config = config; |
598 vf->query_format = query_format; | |
599 vf->uninit = uninit; | |
600 vf->control = control; | |
601 vf->get_image = get_image; | |
602 vf->put_image = put_image; | |
603 vf->default_caps = VFCAP_EOSD; | |
604 return 1; | |
18937 | 605 } |
606 | |
607 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f) | |
24969
c2b7ba444ade
begin moving const filter data to .text/.rodata sections
rfelker
parents:
24545
diff
changeset
|
608 static const m_option_t vf_opts_fields[] = { |
32096 | 609 {"auto", ST_OFF(auto_insert), CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
610 {NULL, NULL, 0, 0, 0, 0, NULL} | |
18937 | 611 }; |
612 | |
24969
c2b7ba444ade
begin moving const filter data to .text/.rodata sections
rfelker
parents:
24545
diff
changeset
|
613 static const m_struct_t vf_opts = { |
32096 | 614 "ass", |
615 sizeof(struct vf_priv_s), | |
616 &vf_priv_dflt, | |
617 vf_opts_fields | |
18937 | 618 }; |
619 | |
24969
c2b7ba444ade
begin moving const filter data to .text/.rodata sections
rfelker
parents:
24545
diff
changeset
|
620 const vf_info_t vf_info_ass = { |
32096 | 621 "Render ASS/SSA subtitles", |
622 "ass", | |
35244 | 623 "Evgeniy Stepanov, Xidorn Quan", |
32096 | 624 "", |
625 vf_open, | |
626 &vf_opts | |
18937 | 627 }; |