Mercurial > mplayer.hg
annotate libmpcodecs/vf_ass.c @ 35369:dac86d3464e2
Also free the noauth_url entry in the URL struct.
author | reimar |
---|---|
date | Fri, 23 Nov 2012 19:26:01 +0000 |
parents | f16646c59e33 |
children | d3b0d3f62d6f |
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); | |
35268 | 94 int outw = vf->priv->outw; |
35244 | 95 uint8_t *alpha = vf->priv->alphas[0], |
96 *dst_y = vf->priv->planes[0], | |
97 *dst_u = vf->priv->planes[1], | |
98 *dst_v = vf->priv->planes[2]; | |
99 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
100 int src_x = img->dst_x, src_w = img->w, | |
101 src_y = img->dst_y, src_h = img->h, | |
102 stride = img->stride; | |
103 uint8_t *src = img->bitmap; | |
104 int i, j; | |
105 | |
106 opacity = MAP_24BIT(opacity); | |
107 for (i = 0; i < src_h; i++) { | |
108 struct dirty_rows_extent *dirty_row = &dirty_rows[src_y + i]; | |
109 dirty_row->xmin = FFMIN(dirty_row->xmin, src_x); | |
110 dirty_row->xmax = FFMAX(dirty_row->xmax, src_x + src_w); | |
111 | |
112 for (j = 0; j < src_w; j++) { | |
113 uint32_t k = src[i * stride + j]; | |
114 if (k) { | |
115 size_t p = (src_y + i) * outw + src_x + j; | |
116 k *= opacity; | |
117 alpha[p] = RSHIFT((0xFFFFFF - k) * alpha[p], 24); | |
118 dst_y[p] = RSHIFT((0xFFFFFF - k) * dst_y[p] + k * y, 24); | |
119 dst_u[p] = RSHIFT((0xFFFFFF - k) * dst_u[p] + k * u, 24); | |
120 dst_v[p] = RSHIFT((0xFFFFFF - k) * dst_v[p] + k * v, 24); | |
121 } | |
122 } | |
123 } | |
124 } | |
125 | |
126 static void prepare_buffer_422(vf_instance_t *vf) | |
127 { | |
128 uint8_t *dst_u = vf->priv->planes[1], | |
129 *dst_v = vf->priv->planes[2]; | |
130 int outw = vf->priv->outw, | |
131 outh = vf->priv->outh; | |
132 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
133 int i, j; | |
134 | |
135 for (i = 0; i < outh; i++) { | |
136 int xmin = dirty_rows[i].xmin & ~1, | |
137 xmax = dirty_rows[i].xmax; | |
138 for (j = xmin; j < xmax; j += 2) { | |
139 size_t p = i * outw + j; | |
140 dst_u[p] = (dst_u[p] + dst_u[p + 1]) / 2; | |
141 dst_v[p] = (dst_v[p] + dst_v[p + 1]) / 2; | |
142 } | |
143 } | |
144 } | |
145 | |
146 static void render_frame_yuv422(vf_instance_t *vf) | |
147 { | |
148 uint8_t *alpha = vf->priv->alphas[0]; | |
149 uint8_t *src_y = vf->priv->planes[0], | |
150 *src_u = vf->priv->planes[1], | |
151 *src_v = vf->priv->planes[2]; | |
152 int outw = vf->priv->outw, | |
153 outh = vf->priv->outh; | |
154 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
155 uint8_t *dest = vf->dmpi->planes[0]; | |
156 int stride = vf->dmpi->stride[0]; | |
157 int is_uyvy = vf->priv->outfmt == IMGFMT_UYVY; | |
158 int i, j; | |
159 | |
160 for (i = 0; i < outh; i++) { | |
161 int xmin = dirty_rows[i].xmin & ~1, | |
162 xmax = dirty_rows[i].xmax; | |
163 for (j = xmin; j < xmax; j += 2) { | |
164 size_t src = i * outw + j, | |
165 dst = i * stride + j * 2; | |
166 uint_fast16_t a0 = alpha[src], | |
167 a1 = alpha[src + 1]; | |
168 uint8_t y0, y1, u, v; | |
169 | |
170 if (a0 == 0xFF && a1 == 0xFF) | |
171 continue; | |
172 | |
173 y0 = dest[dst + is_uyvy + 0]; | |
174 y1 = dest[dst + is_uyvy + 2]; | |
175 u = dest[dst - is_uyvy + 1]; | |
176 v = dest[dst - is_uyvy + 3]; | |
177 | |
178 a0 = MAP_16BIT(a0); | |
179 a1 = MAP_16BIT(a1); | |
180 y0 = ((a0 * y0) >> 8) + src_y[src]; | |
181 y1 = ((a1 * y1) >> 8) + src_y[src + 1]; | |
182 | |
183 a0 = (a0 + a1) / 2; | |
184 u = ((a0 * u) >> 8) + src_u[src]; | |
185 v = ((a0 * v) >> 8) + src_v[src]; | |
186 | |
187 dest[dst + is_uyvy + 0] = y0; | |
188 dest[dst + is_uyvy + 2] = y1; | |
189 dest[dst - is_uyvy + 1] = u; | |
190 dest[dst - is_uyvy + 3] = v; | |
191 } | |
192 } | |
193 } | |
194 | |
195 static void prepare_buffer_420p(vf_instance_t *vf) | |
196 { | |
197 int outw = vf->priv->outw, | |
198 outh = vf->priv->outh; | |
199 uint8_t *dst_u = vf->priv->planes[1], | |
200 *dst_v = vf->priv->planes[2]; | |
201 uint8_t *src_a = vf->priv->alphas[0], | |
202 *dst_a = vf->priv->alphas[1]; | |
203 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
204 int i, j; | |
205 | |
206 for (i = 0; i < outh; i += 2) { | |
207 int xmin = FFMIN(dirty_rows[i].xmin, dirty_rows[i + 1].xmin) & ~1, | |
208 xmax = FFMAX(dirty_rows[i].xmax, dirty_rows[i + 1].xmax); | |
209 for (j = xmin; j < xmax; j += 2) { | |
210 size_t p = i * outw / 4 + j / 2, | |
211 q1 = i * outw + j, | |
212 q2 = q1 + outw; | |
213 dst_a[p] = (src_a[q1] + src_a[q1 + 1] + | |
214 src_a[q2] + src_a[q2 + 1] + 2) / 4; | |
215 dst_u[p] = (dst_u[q1] + dst_u[q1 + 1] + | |
216 dst_u[q2] + dst_u[q2 + 1] + 2) / 4; | |
217 dst_v[p] = (dst_v[q1] + dst_v[q1 + 1] + | |
218 dst_v[q2] + dst_v[q2 + 1] + 2) / 4; | |
219 } | |
220 } | |
221 } | |
222 | |
223 static void render_frame_yuv420p(vf_instance_t *vf) | |
224 { | |
225 uint8_t **planes = vf->priv->planes; | |
226 uint8_t **dest = vf->dmpi->planes; | |
227 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
228 uint8_t *alpha; | |
35268 | 229 uint8_t *src_y = planes[0], |
230 *src_u = planes[1], | |
231 *src_v = planes[2]; | |
232 uint8_t *dst_y = dest[0], | |
233 *dst_u = dest[1], | |
234 *dst_v = dest[2]; | |
35244 | 235 int stride; |
236 int outw = vf->priv->outw, | |
237 outh = vf->priv->outh; | |
238 int i, j; | |
239 | |
240 // y | |
241 alpha = vf->priv->alphas[0]; | |
242 stride = vf->dmpi->stride[0]; | |
243 for (i = 0; i < outh; i++) { | |
244 int xmin = dirty_rows[i].xmin, | |
245 xmax = dirty_rows[i].xmax; | |
246 for (j = xmin; j < xmax; j++) { | |
247 size_t s = i * outw + j, | |
248 d = i * stride + j; | |
249 if (alpha[s] != 0xFF) | |
250 dst_y[d] = ((MAP_16BIT(alpha[s]) * dst_y[d]) >> 8) + src_y[s]; | |
251 } | |
252 } | |
253 | |
254 // u & v | |
255 alpha = vf->priv->alphas[1]; | |
256 stride = vf->dmpi->stride[1]; | |
257 for (i = 0; i < outh / 2; i++) { | |
258 int xmin = FFMIN(dirty_rows[i * 2].xmin, dirty_rows[i * 2 + 1].xmin), | |
259 xmax = FFMAX(dirty_rows[i * 2].xmax, dirty_rows[i * 2 + 1].xmax); | |
260 for (j = xmin / 2; j < (xmax + 1) / 2; j++) { | |
261 size_t s = i * outw / 2 + j, | |
262 d = i * stride + j; | |
263 if (alpha[s] != 0xFF) { | |
264 uint_fast16_t a = MAP_16BIT(alpha[s]); | |
265 dst_u[d] = ((a * dst_u[d]) >> 8) + src_u[s]; | |
266 dst_v[d] = ((a * dst_v[d]) >> 8) + src_v[s]; | |
267 } | |
268 } | |
269 } | |
270 } | |
271 | |
272 static void clean_buffer(vf_instance_t *vf) | |
273 { | |
274 int outw = vf->priv->outw, | |
275 outh = vf->priv->outh; | |
276 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows; | |
277 uint8_t **planes = vf->priv->planes; | |
278 uint8_t *alpha = vf->priv->alphas[0]; | |
279 int i, j; | |
280 | |
281 for (i = 0; i < MP_MAX_PLANES; i++) { | |
282 uint8_t *plane = planes[i]; | |
283 if (!plane) | |
284 break; | |
285 for (j = 0; j < outh; j++) { | |
286 int xmin = dirty_rows[j].xmin; | |
287 int width = dirty_rows[j].xmax - xmin; | |
288 if (width > 0) | |
289 memset(plane + j * outw + xmin, 0, width); | |
290 } | |
291 } | |
292 for (i = 0; i < outh; i++) { | |
293 int xmin = dirty_rows[i].xmin; | |
294 int width = dirty_rows[i].xmax - xmin; | |
295 if (width > 0) | |
296 memset(alpha + i * outw + xmin, -1, width); | |
297 } | |
298 for (i = 0; i < outh; i++) { | |
299 dirty_rows[i].xmin = outw; | |
300 dirty_rows[i].xmax = 0; | |
301 } | |
302 } | |
18937 | 303 |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
304 static int config(struct vf_instance *vf, |
32096 | 305 int width, int height, int d_width, int d_height, |
306 unsigned int flags, unsigned int outfmt) | |
18937 | 307 { |
32391
b4c3659d16b1
Use a dynamic list for the sources of EOSD elements.
cigaes
parents:
32261
diff
changeset
|
308 struct mp_eosd_settings res = {0}; |
35244 | 309 struct dirty_rows_extent *dirty_rows; |
310 int outw, outh; | |
311 int planes, alphas; | |
312 int i; | |
31927 | 313 |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
314 switch (outfmt) { |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
315 case IMGFMT_YV12: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
316 case IMGFMT_I420: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
317 case IMGFMT_IYUV: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
318 vf->priv->is_planar = 1; |
35244 | 319 planes = 3; |
320 alphas = 2; | |
321 vf->priv->draw_image = draw_image_yuv; | |
322 vf->priv->render_frame = render_frame_yuv420p; | |
323 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
|
324 break; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
325 case IMGFMT_UYVY: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
326 case IMGFMT_YUY2: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
327 vf->priv->is_planar = 0; |
35244 | 328 planes = 3; |
329 alphas = 1; | |
330 vf->priv->draw_image = draw_image_yuv; | |
331 vf->priv->render_frame = render_frame_yuv422; | |
332 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
|
333 break; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
334 default: |
32096 | 335 return 0; |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
336 } |
18937 | 337 |
35033 | 338 vf->priv->outfmt = outfmt; |
35244 | 339 vf->priv->outh = outh = height + ass_top_margin + ass_bottom_margin; |
340 vf->priv->outw = outw = width; | |
18937 | 341 |
32096 | 342 if (!opt_screen_size_x && !opt_screen_size_y) { |
343 d_width = d_width * vf->priv->outw / width; | |
344 d_height = d_height * vf->priv->outh / height; | |
345 } | |
18937 | 346 |
35244 | 347 for (i = 0; i < planes; i++) |
348 vf->priv->planes[i] = av_malloc(outw * outh); | |
349 for (i = 0; i < alphas; i++) | |
350 vf->priv->alphas[i] = av_malloc(outw * outh); | |
351 dirty_rows = av_malloc(outh * sizeof(*dirty_rows)); | |
352 // mark all rows dirty here | |
353 // so that they can be properly cleaned in clear_buffer() | |
354 for (i = 0; i < outh; i++) { | |
355 dirty_rows[i].xmin = 0; | |
356 dirty_rows[i].xmax = outw; | |
357 } | |
358 vf->priv->dirty_rows = dirty_rows; | |
359 clean_buffer(vf); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26727
diff
changeset
|
360 |
32096 | 361 res.w = vf->priv->outw; |
362 res.h = vf->priv->outh; | |
363 res.srcw = width; | |
364 res.srch = height; | |
365 res.mt = ass_top_margin; | |
366 res.mb = ass_bottom_margin; | |
32391
b4c3659d16b1
Use a dynamic list for the sources of EOSD elements.
cigaes
parents:
32261
diff
changeset
|
367 eosd_configure(&res); |
18937 | 368 |
32096 | 369 return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, |
370 d_height, flags, outfmt); | |
18937 | 371 } |
372 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
373 static void get_image(struct vf_instance *vf, mp_image_t *mpi) |
18937 | 374 { |
32096 | 375 if (mpi->type == MP_IMGTYPE_IPB) |
376 return; | |
377 if (mpi->flags & MP_IMGFLAG_PRESERVE) | |
378 return; | |
379 if (mpi->imgfmt != vf->priv->outfmt) | |
380 return; // colorspace differ | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26727
diff
changeset
|
381 |
32096 | 382 // width never changes, always try full DR |
383 mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt, mpi->type, | |
384 mpi->flags | MP_IMGFLAG_READABLE, | |
34882
649d4cad4619
Request a sufficiently large image for direct rendering.
reimar
parents:
34863
diff
changeset
|
385 FFMAX(mpi->width, vf->priv->outw), |
649d4cad4619
Request a sufficiently large image for direct rendering.
reimar
parents:
34863
diff
changeset
|
386 FFMAX(mpi->height, vf->priv->outh)); |
18937 | 387 |
32096 | 388 if ( (vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) && |
389 !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)) { | |
390 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_MPCODECS_FullDRNotPossible); | |
391 return; | |
392 } | |
393 // set up mpi as a cropped-down image of dmpi: | |
394 if (mpi->flags & MP_IMGFLAG_PLANAR) { | |
395 mpi->planes[0] = vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0]; | |
396 mpi->planes[1] = vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1]; | |
397 mpi->planes[2] = vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2]; | |
398 mpi->stride[1] = vf->dmpi->stride[1]; | |
399 mpi->stride[2] = vf->dmpi->stride[2]; | |
400 } else { | |
401 mpi->planes[0] = vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0]; | |
402 } | |
403 mpi->stride[0] = vf->dmpi->stride[0]; | |
404 mpi->width = vf->dmpi->width; | |
405 mpi->flags |= MP_IMGFLAG_DIRECT; | |
406 mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK; | |
407 // vf->dmpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK; | |
18937 | 408 } |
409 | |
410 static void blank(mp_image_t *mpi, int y1, int y2) | |
411 { | |
32096 | 412 int color[3] = { 16, 128, 128 }; // black (YUV) |
413 int y; | |
414 unsigned char *dst; | |
415 int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift; | |
18937 | 416 |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
417 if (mpi->flags & MP_IMGFLAG_PLANAR) { |
32096 | 418 dst = mpi->planes[0] + y1 * mpi->stride[0]; |
419 for (y = 0; y < y2 - y1; ++y) { | |
420 memset(dst, color[0], mpi->w); | |
421 dst += mpi->stride[0]; | |
422 } | |
423 dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1]; | |
424 for (y = 0; y < chroma_rows; ++y) { | |
425 memset(dst, color[1], mpi->chroma_width); | |
426 dst += mpi->stride[1]; | |
427 } | |
428 dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2]; | |
429 for (y = 0; y < chroma_rows; ++y) { | |
430 memset(dst, color[2], mpi->chroma_width); | |
431 dst += mpi->stride[2]; | |
432 } | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
433 } else { |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
434 unsigned char packed_color[4]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
435 int x; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
436 if (mpi->imgfmt == IMGFMT_UYVY) { |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
437 packed_color[0] = color[1]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
438 packed_color[1] = color[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
439 packed_color[2] = color[2]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
440 packed_color[3] = color[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
441 } else { |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
442 packed_color[0] = color[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
443 packed_color[1] = color[1]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
444 packed_color[2] = color[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
445 packed_color[3] = color[2]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
446 } |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
447 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
|
448 for (y = y1; y < y2; ++y) { |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
449 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
|
450 AV_COPY32(dst + 4 * x, packed_color); |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
451 dst += mpi->stride[0]; |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
452 } |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
453 } |
18937 | 454 } |
455 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
456 static int prepare_image(struct vf_instance *vf, mp_image_t *mpi) |
18937 | 457 { |
32096 | 458 if (mpi->flags & MP_IMGFLAG_DIRECT || |
459 mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) { | |
460 vf->dmpi = mpi->priv; | |
461 if (!vf->dmpi) { | |
462 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_MPCODECS_FunWhydowegetNULL); | |
463 return 0; | |
464 } | |
465 mpi->priv = NULL; | |
466 // we've used DR, so we're ready... | |
467 if (ass_top_margin) | |
468 blank(vf->dmpi, 0, ass_top_margin); | |
469 if (ass_bottom_margin) | |
470 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh); | |
471 if (!(mpi->flags & MP_IMGFLAG_PLANAR)) | |
472 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette | |
473 return 0; | |
474 } | |
475 // hope we'll get DR buffer: | |
476 vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt, MP_IMGTYPE_TEMP, | |
477 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE, | |
478 vf->priv->outw, vf->priv->outh); | |
18937 | 479 |
32096 | 480 // copy mpi->dmpi... |
481 if (mpi->flags & MP_IMGFLAG_PLANAR) { | |
482 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0], | |
483 mpi->planes[0], | |
484 mpi->w, | |
485 mpi->h, | |
486 vf->dmpi->stride[0], | |
487 mpi->stride[0]); | |
488 memcpy_pic(vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1], | |
489 mpi->planes[1], | |
490 mpi->w >> mpi->chroma_x_shift, | |
491 mpi->h >> mpi->chroma_y_shift, | |
492 vf->dmpi->stride[1], | |
493 mpi->stride[1]); | |
494 memcpy_pic(vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2], | |
495 mpi->planes[2], | |
496 mpi->w >> mpi->chroma_x_shift, | |
497 mpi->h >> mpi->chroma_y_shift, | |
498 vf->dmpi->stride[2], | |
499 mpi->stride[2]); | |
500 } else { | |
501 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0], | |
502 mpi->planes[0], | |
503 mpi->w * (vf->dmpi->bpp / 8), | |
504 mpi->h, | |
505 vf->dmpi->stride[0], | |
506 mpi->stride[0]); | |
507 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette | |
508 } | |
509 if (ass_top_margin) | |
510 blank(vf->dmpi, 0, ass_top_margin); | |
511 if (ass_bottom_margin) | |
512 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh); | |
513 return 0; | |
18937 | 514 } |
515 | |
35244 | 516 static void prepare_eosd(vf_instance_t *vf, struct mp_eosd_image_list *imgs) |
18937 | 517 { |
35244 | 518 struct mp_eosd_image *img = eosd_image_first(imgs); |
519 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
|
520 |
35244 | 521 clean_buffer(vf); |
522 draw_image = vf->priv->draw_image; | |
523 for (; img; img = eosd_image_next(imgs)) | |
524 draw_image(vf, img); | |
525 vf->priv->prepare_buffer(vf); | |
18937 | 526 } |
527 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
528 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) |
18937 | 529 { |
32391
b4c3659d16b1
Use a dynamic list for the sources of EOSD elements.
cigaes
parents:
32261
diff
changeset
|
530 struct mp_eosd_image_list images; |
b4c3659d16b1
Use a dynamic list for the sources of EOSD elements.
cigaes
parents:
32261
diff
changeset
|
531 eosd_render_frame(pts, &images); |
32096 | 532 prepare_image(vf, mpi); |
35244 | 533 if (images.changed) |
534 prepare_eosd(vf, &images); | |
535 vf->priv->render_frame(vf); | |
32096 | 536 return vf_next_put_image(vf, vf->dmpi, pts); |
18937 | 537 } |
538 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
539 static int query_format(struct vf_instance *vf, unsigned int fmt) |
18937 | 540 { |
32096 | 541 switch (fmt) { |
542 case IMGFMT_YV12: | |
543 case IMGFMT_I420: | |
544 case IMGFMT_IYUV: | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
545 case IMGFMT_UYVY: |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
546 case IMGFMT_YUY2: |
35033 | 547 return vf_next_query_format(vf, fmt) | VFCAP_EOSD; |
32096 | 548 } |
549 return 0; | |
18937 | 550 } |
551 | |
552 static int control(vf_instance_t *vf, int request, void *data) | |
553 { | |
32096 | 554 switch (request) { |
555 case VFCTRL_INIT_EOSD: | |
556 return CONTROL_TRUE; | |
557 case VFCTRL_DRAW_EOSD: | |
558 return CONTROL_TRUE; | |
559 } | |
560 return vf_next_control(vf, request, data); | |
18937 | 561 } |
562 | |
30642
a972c1a4a012
cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents:
30638
diff
changeset
|
563 static void uninit(struct vf_instance *vf) |
18937 | 564 { |
35244 | 565 int i; |
566 for (i = 0; i < MP_MAX_PLANES; i++) | |
567 av_free(vf->priv->planes[i]); | |
568 for (i = 0; i < MP_MAX_PLANES; i++) | |
569 av_free(vf->priv->alphas[i]); | |
570 av_free(vf->priv->dirty_rows); | |
18937 | 571 } |
572 | |
32096 | 573 static const unsigned int fmt_list[] = { |
574 IMGFMT_YV12, | |
575 IMGFMT_I420, | |
576 IMGFMT_IYUV, | |
35039
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
577 IMGFMT_UYVY, |
848835e1b053
vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents:
35033
diff
changeset
|
578 IMGFMT_YUY2, |
32096 | 579 0 |
18937 | 580 }; |
581 | |
30638
a7b908875c14
Rename open() vf initialization function to vf_open().
diego
parents:
30633
diff
changeset
|
582 static int vf_open(vf_instance_t *vf, char *args) |
18937 | 583 { |
32096 | 584 int flags; |
35033 | 585 unsigned outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12); |
586 if (outfmt) | |
587 flags = vf_next_query_format(vf, outfmt); | |
588 if (!outfmt || (vf->priv->auto_insert && flags & VFCAP_EOSD)) { | |
32096 | 589 uninit(vf); |
590 return 0; | |
591 } | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26727
diff
changeset
|
592 |
32096 | 593 if (vf->priv->auto_insert) |
594 mp_msg(MSGT_ASS, MSGL_INFO, "[ass] auto-open\n"); | |
29263
0f1b5b68af32
whitespace cosmetics: Remove all trailing whitespace.
diego
parents:
26727
diff
changeset
|
595 |
32096 | 596 vf->config = config; |
597 vf->query_format = query_format; | |
598 vf->uninit = uninit; | |
599 vf->control = control; | |
600 vf->get_image = get_image; | |
601 vf->put_image = put_image; | |
602 vf->default_caps = VFCAP_EOSD; | |
603 return 1; | |
18937 | 604 } |
605 | |
606 #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
|
607 static const m_option_t vf_opts_fields[] = { |
32096 | 608 {"auto", ST_OFF(auto_insert), CONF_TYPE_FLAG, 0, 0, 1, NULL}, |
609 {NULL, NULL, 0, 0, 0, 0, NULL} | |
18937 | 610 }; |
611 | |
24969
c2b7ba444ade
begin moving const filter data to .text/.rodata sections
rfelker
parents:
24545
diff
changeset
|
612 static const m_struct_t vf_opts = { |
32096 | 613 "ass", |
614 sizeof(struct vf_priv_s), | |
615 &vf_priv_dflt, | |
616 vf_opts_fields | |
18937 | 617 }; |
618 | |
24969
c2b7ba444ade
begin moving const filter data to .text/.rodata sections
rfelker
parents:
24545
diff
changeset
|
619 const vf_info_t vf_info_ass = { |
32096 | 620 "Render ASS/SSA subtitles", |
621 "ass", | |
35244 | 622 "Evgeniy Stepanov, Xidorn Quan", |
32096 | 623 "", |
624 vf_open, | |
625 &vf_opts | |
18937 | 626 }; |