annotate libmpcodecs/vf_ass.c @ 35520:ecbaf301748f

Don't unnecessarily use global MPlayer variable filename in Win32 GUI. Use a local variable instead. (This has been forgotten in r35613.)
author ib
date Wed, 05 Dec 2012 23:12:53 +0000
parents d3b0d3f62d6f
children 715e7aa1ffdb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
2 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
3 * Copyright (C) 2012 Xidorn Quan <quanxunzhen@gmail.com>
26727
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
4 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
5 * This file is part of MPlayer.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
6 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
7 * MPlayer is free software; you can redistribute it and/or modify
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
8 * it under the terms of the GNU General Public License as published by
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
9 * the Free Software Foundation; either version 2 of the License, or
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
10 * (at your option) any later version.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
11 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
12 * MPlayer is distributed in the hope that it will be useful,
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
15 * GNU General Public License for more details.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
16 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
17 * You should have received a copy of the GNU General Public License along
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
18 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
20 */
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19563
diff changeset
21
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
22 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
24 #include <stdio.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
25 #include <stdlib.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
28 #include <assert.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
29
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
30 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
31 #include "mp_msg.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
32 #include "help_mp.h"
31489
dc26022e9c27 Clean up sub-related extern declarations.
diego
parents: 31488
diff changeset
33 #include "mpcommon.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
34 #include "img_format.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
37 #include "vf.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
38
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
fbe5c829c69b Move libvo/sub.[ch] from libvo to sub.
cigaes
parents: 32461
diff changeset
41 #include "sub/sub.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
42 #include "m_option.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
43 #include "m_struct.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
44
32461
bc43cf7638e6 Move ass_mp.[ch] to the sub directory.
cigaes
parents: 32460
diff changeset
45 #include "sub/ass_mp.h"
32460
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents: 32391
diff changeset
46 #include "sub/eosd.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
47
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
48 #define _r(c) ((c)>>24)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
49 #define _g(c) (((c)>>16)&0xFF)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
50 #define _b(c) (((c)>>8)&0xFF)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
51 #define _a(c) ((c)&0xFF)
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
52 #define rgba2y(c) ( (( 263*_r(c) + 516*_g(c) + 100*_b(c)) >> 10) + 16 )
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
53 #define rgba2u(c) ( ((-152*_r(c) - 298*_g(c) + 450*_b(c)) >> 10) + 128 )
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
54 #define rgba2v(c) ( (( 450*_r(c) - 376*_g(c) - 73*_b(c)) >> 10) + 128 )
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
55
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
56 /* map 0 - 0xFF -> 0 - 0x101 */
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
57 #define MAP_16BIT(v) RSHIFT(0x102 * (v), 8)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
58 /* map 0 - 0xFF -> 0 - 0x10101 */
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
59 #define MAP_24BIT(v) RSHIFT(0x10203 * (v), 8)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
62 int outh, outw;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
63
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
64 int is_planar;
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
65 unsigned int outfmt;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
66
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
67 // 1 = auto-added filter: insert only if chain does not support EOSD already
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
68 // 0 = insert always
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
69 int auto_insert;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
70
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
71 // planar data to be directly rendered on frames
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
72 uint8_t *planes[MP_MAX_PLANES];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
73 // alpha here is actually transparency, not opacity
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
74 uint8_t *alphas[MP_MAX_PLANES];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
75 struct dirty_rows_extent {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
76 int xmin, xmax;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
77 } *dirty_rows;
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
78
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
79 // called for every eosd image when subtitle is changed
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
80 void (*draw_image)(vf_instance_t *, struct mp_eosd_image *);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
81 // called for every time subtitle is changed
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
82 void (*prepare_buffer)(vf_instance_t *);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
83 // called for every frame
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
86
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
87 static void draw_image_yuv(vf_instance_t *vf, struct mp_eosd_image *img)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
88 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
89 uint32_t color = img->color;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
90 uint32_t opacity = 0xFF - _a(color);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
91 uint8_t y = rgba2y(color),
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
92 u = rgba2u(color),
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
93 v = rgba2v(color);
35268
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
94 int outw = vf->priv->outw;
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
95 uint8_t *alpha = vf->priv->alphas[0],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
96 *dst_y = vf->priv->planes[0],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
97 *dst_u = vf->priv->planes[1],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
98 *dst_v = vf->priv->planes[2];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
99 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
100 int src_x = img->dst_x, src_w = img->w,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
101 src_y = img->dst_y, src_h = img->h,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
102 stride = img->stride;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
103 uint8_t *src = img->bitmap;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
104 int i, j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
105
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
106 opacity = MAP_24BIT(opacity);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
107 for (i = 0; i < src_h; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
108 struct dirty_rows_extent *dirty_row = &dirty_rows[src_y + i];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
109 dirty_row->xmin = FFMIN(dirty_row->xmin, src_x);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
110 dirty_row->xmax = FFMAX(dirty_row->xmax, src_x + src_w);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
111
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
112 for (j = 0; j < src_w; j++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
113 uint32_t k = src[i * stride + j];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
114 if (k) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
115 size_t p = (src_y + i) * outw + src_x + j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
116 k *= opacity;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
117 alpha[p] = RSHIFT((0xFFFFFF - k) * alpha[p], 24);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
118 dst_y[p] = RSHIFT((0xFFFFFF - k) * dst_y[p] + k * y, 24);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
119 dst_u[p] = RSHIFT((0xFFFFFF - k) * dst_u[p] + k * u, 24);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
120 dst_v[p] = RSHIFT((0xFFFFFF - k) * dst_v[p] + k * v, 24);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
121 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
122 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
123 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
124 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
125
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
126 static void prepare_buffer_422(vf_instance_t *vf)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
127 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
128 uint8_t *dst_u = vf->priv->planes[1],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
129 *dst_v = vf->priv->planes[2];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
130 int outw = vf->priv->outw,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
131 outh = vf->priv->outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
132 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
133 int i, j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
134
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
135 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
136 int xmin = dirty_rows[i].xmin & ~1,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
137 xmax = dirty_rows[i].xmax;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
138 for (j = xmin; j < xmax; j += 2) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
139 size_t p = i * outw + j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
140 dst_u[p] = (dst_u[p] + dst_u[p + 1]) / 2;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
141 dst_v[p] = (dst_v[p] + dst_v[p + 1]) / 2;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
142 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
143 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
144 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
145
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
146 static void render_frame_yuv422(vf_instance_t *vf)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
147 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
148 uint8_t *alpha = vf->priv->alphas[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
149 uint8_t *src_y = vf->priv->planes[0],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
150 *src_u = vf->priv->planes[1],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
151 *src_v = vf->priv->planes[2];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
152 int outw = vf->priv->outw,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
153 outh = vf->priv->outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
154 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
155 uint8_t *dest = vf->dmpi->planes[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
156 int stride = vf->dmpi->stride[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
157 int is_uyvy = vf->priv->outfmt == IMGFMT_UYVY;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
158 int i, j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
159
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
160 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
161 int xmin = dirty_rows[i].xmin & ~1,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
162 xmax = dirty_rows[i].xmax;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
163 for (j = xmin; j < xmax; j += 2) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
164 size_t src = i * outw + j,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
165 dst = i * stride + j * 2;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
166 uint_fast16_t a0 = alpha[src],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
167 a1 = alpha[src + 1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
168 uint8_t y0, y1, u, v;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
169
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
170 if (a0 == 0xFF && a1 == 0xFF)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
171 continue;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
172
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
173 y0 = dest[dst + is_uyvy + 0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
174 y1 = dest[dst + is_uyvy + 2];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
175 u = dest[dst - is_uyvy + 1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
176 v = dest[dst - is_uyvy + 3];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
177
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
178 a0 = MAP_16BIT(a0);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
179 a1 = MAP_16BIT(a1);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
180 y0 = ((a0 * y0) >> 8) + src_y[src];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
181 y1 = ((a1 * y1) >> 8) + src_y[src + 1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
182
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
183 a0 = (a0 + a1) / 2;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
184 u = ((a0 * u) >> 8) + src_u[src];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
185 v = ((a0 * v) >> 8) + src_v[src];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
186
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
187 dest[dst + is_uyvy + 0] = y0;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
188 dest[dst + is_uyvy + 2] = y1;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
189 dest[dst - is_uyvy + 1] = u;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
190 dest[dst - is_uyvy + 3] = v;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
191 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
192 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
193 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
194
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
195 static void prepare_buffer_420p(vf_instance_t *vf)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
196 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
197 int outw = vf->priv->outw,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
198 outh = vf->priv->outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
199 uint8_t *dst_u = vf->priv->planes[1],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
200 *dst_v = vf->priv->planes[2];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
201 uint8_t *src_a = vf->priv->alphas[0],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
202 *dst_a = vf->priv->alphas[1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
203 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
204 int i, j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
205
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
206 for (i = 0; i < outh; i += 2) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
207 int xmin = FFMIN(dirty_rows[i].xmin, dirty_rows[i + 1].xmin) & ~1,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
208 xmax = FFMAX(dirty_rows[i].xmax, dirty_rows[i + 1].xmax);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
209 for (j = xmin; j < xmax; j += 2) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
210 size_t p = i * outw / 4 + j / 2,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
211 q1 = i * outw + j,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
212 q2 = q1 + outw;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
213 dst_a[p] = (src_a[q1] + src_a[q1 + 1] +
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
214 src_a[q2] + src_a[q2 + 1] + 2) / 4;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
215 dst_u[p] = (dst_u[q1] + dst_u[q1 + 1] +
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
216 dst_u[q2] + dst_u[q2 + 1] + 2) / 4;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
217 dst_v[p] = (dst_v[q1] + dst_v[q1 + 1] +
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
218 dst_v[q2] + dst_v[q2 + 1] + 2) / 4;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
219 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
220 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
221 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
222
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
223 static void render_frame_yuv420p(vf_instance_t *vf)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
224 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
225 uint8_t **planes = vf->priv->planes;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
226 uint8_t **dest = vf->dmpi->planes;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
227 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
228 uint8_t *alpha;
35268
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
229 uint8_t *src_y = planes[0],
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
230 *src_u = planes[1],
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
231 *src_v = planes[2];
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
232 uint8_t *dst_y = dest[0],
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
233 *dst_u = dest[1],
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
234 *dst_v = dest[2];
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
235 int stride;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
236 int outw = vf->priv->outw,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
237 outh = vf->priv->outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
238 int i, j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
239
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
240 // y
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
241 alpha = vf->priv->alphas[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
242 stride = vf->dmpi->stride[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
243 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
244 int xmin = dirty_rows[i].xmin,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
245 xmax = dirty_rows[i].xmax;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
246 for (j = xmin; j < xmax; j++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
247 size_t s = i * outw + j,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
248 d = i * stride + j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
249 if (alpha[s] != 0xFF)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
250 dst_y[d] = ((MAP_16BIT(alpha[s]) * dst_y[d]) >> 8) + src_y[s];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
251 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
252 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
253
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
254 // u & v
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
255 alpha = vf->priv->alphas[1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
256 stride = vf->dmpi->stride[1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
257 for (i = 0; i < outh / 2; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
258 int xmin = FFMIN(dirty_rows[i * 2].xmin, dirty_rows[i * 2 + 1].xmin),
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
259 xmax = FFMAX(dirty_rows[i * 2].xmax, dirty_rows[i * 2 + 1].xmax);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
260 for (j = xmin / 2; j < (xmax + 1) / 2; j++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
261 size_t s = i * outw / 2 + j,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
262 d = i * stride + j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
263 if (alpha[s] != 0xFF) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
264 uint_fast16_t a = MAP_16BIT(alpha[s]);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
265 dst_u[d] = ((a * dst_u[d]) >> 8) + src_u[s];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
266 dst_v[d] = ((a * dst_v[d]) >> 8) + src_v[s];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
267 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
268 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
269 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
270 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
271
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
272 static void clean_buffer(vf_instance_t *vf)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
273 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
274 int outw = vf->priv->outw,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
275 outh = vf->priv->outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
276 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
277 uint8_t **planes = vf->priv->planes;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
278 uint8_t *alpha = vf->priv->alphas[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
279 int i, j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
280
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
281 for (i = 0; i < MP_MAX_PLANES; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
282 uint8_t *plane = planes[i];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
283 if (!plane)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
284 break;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
285 for (j = 0; j < outh; j++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
286 int xmin = dirty_rows[j].xmin;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
287 int width = dirty_rows[j].xmax - xmin;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
288 if (width > 0)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
289 memset(plane + j * outw + xmin, 0, width);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
290 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
291 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
292 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
293 int xmin = dirty_rows[i].xmin;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
294 int width = dirty_rows[i].xmax - xmin;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
295 if (width > 0)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
296 memset(alpha + i * outw + xmin, -1, width);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
297 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
298 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
299 dirty_rows[i].xmin = outw;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
300 dirty_rows[i].xmax = 0;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
301 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
302 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
305 int width, int height, int d_width, int d_height,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
306 unsigned int flags, unsigned int outfmt)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
309 struct dirty_rows_extent *dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
310 int outw, outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
311 int planes, alphas;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
312 int i;
31927
6e0b5a97e00f EOSD/ASS code factorization
cigaes
parents: 31792
diff changeset
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
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
319 planes = 3;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
320 alphas = 2;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
321 vf->priv->draw_image = draw_image_yuv;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
322 vf->priv->render_frame = render_frame_yuv420p;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
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
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
328 planes = 3;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
329 alphas = 1;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
330 vf->priv->draw_image = draw_image_yuv;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
331 vf->priv->render_frame = render_frame_yuv422;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
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
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
335 return 0;
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
336 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
337
35033
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
338 vf->priv->outfmt = outfmt;
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
339 vf->priv->outh = outh = height + ass_top_margin + ass_bottom_margin;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
340 vf->priv->outw = outw = width;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
341
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
342 if (!opt_screen_size_x && !opt_screen_size_y) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
343 d_width = d_width * vf->priv->outw / width;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
344 d_height = d_height * vf->priv->outh / height;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
345 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
346
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
347 for (i = 0; i < planes; i++)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
348 vf->priv->planes[i] = av_malloc(outw * outh);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
349 for (i = 0; i < alphas; i++)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
350 vf->priv->alphas[i] = av_malloc(outw * outh);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
351 dirty_rows = av_malloc(outh * sizeof(*dirty_rows));
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
352 // mark all rows dirty here
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
353 // so that they can be properly cleaned in clear_buffer()
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
354 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
355 dirty_rows[i].xmin = 0;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
356 dirty_rows[i].xmax = outw;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
357 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
358 vf->priv->dirty_rows = dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
359 clean_buffer(vf);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
360
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
361 res.w = vf->priv->outw;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
362 res.h = vf->priv->outh;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
363 res.srcw = width;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
364 res.srch = height;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
365 res.mt = ass_top_margin;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
368
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
369 return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
370 d_height, flags, outfmt);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
371 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
374 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
375 if (mpi->type == MP_IMGTYPE_IPB)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
376 return;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
377 if (mpi->flags & MP_IMGFLAG_PRESERVE)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
378 return;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
379 if (mpi->imgfmt != vf->priv->outfmt)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
380 return; // colorspace differ
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
381
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
382 // width never changes, always try full DR
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
383 mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt, mpi->type,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
387
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
388 if ( (vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) &&
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
389 !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
390 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_MPCODECS_FullDRNotPossible);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
391 return;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
392 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
393 // set up mpi as a cropped-down image of dmpi:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
394 if (mpi->flags & MP_IMGFLAG_PLANAR) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
395 mpi->planes[0] = vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
396 mpi->planes[1] = vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
397 mpi->planes[2] = vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
398 mpi->stride[1] = vf->dmpi->stride[1];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
399 mpi->stride[2] = vf->dmpi->stride[2];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
400 } else {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
401 mpi->planes[0] = vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
402 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
403 mpi->stride[0] = vf->dmpi->stride[0];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
404 mpi->width = vf->dmpi->width;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
405 mpi->flags |= MP_IMGFLAG_DIRECT;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
406 mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
407 // vf->dmpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
408 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
409
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
410 static void blank(mp_image_t *mpi, int y1, int y2)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
411 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
412 int color[3] = { 16, 128, 128 }; // black (YUV)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
413 int y;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
414 unsigned char *dst;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
415 int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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) {
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
418 dst = mpi->planes[0] + y1 * mpi->stride[0];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
419 for (y = 0; y < y2 - y1; ++y) {
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
420 memset(dst, color[0], mpi->w);
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
421 dst += mpi->stride[0];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
422 }
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
423 dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
424 for (y = 0; y < chroma_rows; ++y) {
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
425 memset(dst, color[1], mpi->chroma_width);
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
426 dst += mpi->stride[1];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
427 }
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
428 dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
429 for (y = 0; y < chroma_rows; ++y) {
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
430 memset(dst, color[2], mpi->chroma_width);
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
431 dst += mpi->stride[2];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
454 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
457 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
458 if (mpi->flags & MP_IMGFLAG_DIRECT ||
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
459 mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
460 vf->dmpi = mpi->priv;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
461 if (!vf->dmpi) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
462 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_MPCODECS_FunWhydowegetNULL);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
463 return 0;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
464 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
465 mpi->priv = NULL;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
466 // we've used DR, so we're ready...
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
467 if (ass_top_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
468 blank(vf->dmpi, 0, ass_top_margin);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
469 if (ass_bottom_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
470 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
471 if (!(mpi->flags & MP_IMGFLAG_PLANAR))
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
472 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
473 return 0;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
474 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
475 // hope we'll get DR buffer:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
476 vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt, MP_IMGTYPE_TEMP,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
477 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
478 vf->priv->outw, vf->priv->outh);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
479
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
480 // copy mpi->dmpi...
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
481 if (mpi->flags & MP_IMGFLAG_PLANAR) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
482 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
483 mpi->planes[0],
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
484 mpi->w,
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
485 mpi->h,
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
486 vf->dmpi->stride[0],
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
487 mpi->stride[0]);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
488 memcpy_pic(vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1],
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
489 mpi->planes[1],
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
490 mpi->w >> mpi->chroma_x_shift,
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
491 mpi->h >> mpi->chroma_y_shift,
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
492 vf->dmpi->stride[1],
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
493 mpi->stride[1]);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
494 memcpy_pic(vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2],
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
495 mpi->planes[2],
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
496 mpi->w >> mpi->chroma_x_shift,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
497 mpi->h >> mpi->chroma_y_shift,
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
498 vf->dmpi->stride[2],
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
499 mpi->stride[2]);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
500 } else {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
501 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
502 mpi->planes[0],
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
503 mpi->w * (vf->dmpi->bpp / 8),
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
504 mpi->h,
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
505 vf->dmpi->stride[0],
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
506 mpi->stride[0]);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
507 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
508 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
509 if (ass_top_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
510 blank(vf->dmpi, 0, ass_top_margin);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
511 if (ass_bottom_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
512 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
513 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
514 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
515
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
516 static void prepare_eosd(vf_instance_t *vf, struct mp_eosd_image_list *imgs)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
517 {
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
518 struct mp_eosd_image *img = eosd_image_first(imgs);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
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
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
521 clean_buffer(vf);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
522 draw_image = vf->priv->draw_image;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
523 for (; img; img = eosd_image_next(imgs))
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
524 draw_image(vf, img);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
525 vf->priv->prepare_buffer(vf);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
526 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
532 prepare_image(vf, mpi);
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
533 if (images.changed)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
534 prepare_eosd(vf, &images);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
535 vf->priv->render_frame(vf);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
536 return vf_next_put_image(vf, vf->dmpi, pts);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
537 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
540 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
541 switch (fmt) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
542 case IMGFMT_YV12:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
543 case IMGFMT_I420:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
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
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
547 return vf_next_query_format(vf, fmt) | VFCAP_EOSD;
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
548 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
549 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
550 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
551
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
552 static int control(vf_instance_t *vf, int request, void *data)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
553 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
554 switch (request) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
555 case VFCTRL_INIT_EOSD:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
556 return CONTROL_TRUE;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
557 case VFCTRL_DRAW_EOSD:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
558 return CONTROL_TRUE;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
559 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
560 return vf_next_control(vf, request, data);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
561 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
564 {
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
565 int i;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
566 for (i = 0; i < MP_MAX_PLANES; i++)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
567 av_free(vf->priv->planes[i]);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
568 for (i = 0; i < MP_MAX_PLANES; i++)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
569 av_free(vf->priv->alphas[i]);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
570 av_free(vf->priv->dirty_rows);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
571 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
572
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
573 static const unsigned int fmt_list[] = {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
574 IMGFMT_YV12,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
575 IMGFMT_I420,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
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
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
579 0
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
580 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
583 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
584 int flags;
35033
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
585 unsigned outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12);
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
586 if (outfmt)
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
587 flags = vf_next_query_format(vf, outfmt);
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
588 if (!outfmt || (vf->priv->auto_insert && flags & VFCAP_EOSD)) {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
589 uninit(vf);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
590 return 0;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
591 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
592
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
593 if (vf->priv->auto_insert)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
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
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
596 vf->config = config;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
597 vf->query_format = query_format;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
598 vf->uninit = uninit;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
599 vf->control = control;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
600 vf->get_image = get_image;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
601 vf->put_image = put_image;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
602 vf->default_caps = VFCAP_EOSD;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
603 return 1;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
604 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
605
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
608 {"auto", ST_OFF(auto_insert), CONF_TYPE_FLAG, 0, 0, 1, NULL},
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
609 {NULL, NULL, 0, 0, 0, 0, NULL}
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
610 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
613 "ass",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
614 sizeof(struct vf_priv_s),
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
615 &vf_priv_dflt,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
616 vf_opts_fields
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
617 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
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
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
620 "Render ASS/SSA subtitles",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
621 "ass",
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
622 "Evgeniy Stepanov, Xidorn Quan",
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
623 "",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
624 vf_open,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
625 &vf_opts
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
626 };