annotate libmpcodecs/vf_ass.c @ 35262:49fc594fda43

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