annotate libmpcodecs/vf_ass.c @ 36650:8b2c68d6fd89

Enable specifying a font file in the GUI preferences. This has been broken since the introduction of Fontconfig. Since Fontconfig is selecting fonts by font patterns and the GUI does so by selecting a font file, it is necessary to temporarily disable fontconfig font handling if there is a directory separator character found in the name (or pattern) of the font to be used, i.e. assume the font name to be a pattern if and only if it doesn't contain a directory separator character. Thus set option 'fontconfig' depending on font_name. Set it in guiInit() for the font possibly given in a configuration file or on the command line, and set it in mplayerLoadFont() whenever it is affected by GUI preferences settings. (Although the font selection dialog only allows files to be selected, it is possible to simply enter a fontconfig font pattern in the preferences' text entry field - or to enter it directly into the GUI configuration file or to specify on the command line, both of which always is possible.)
author ib
date Sun, 26 Jan 2014 16:40:49 +0000
parents b4ce15212bfc
children
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
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
48 #include "cpudetect.h"
35705
b4ce15212bfc Replace obsolete x86_cpu.h #includes by the correct header.
diego
parents: 35618
diff changeset
49 #include "libavutil/x86/asm.h"
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
50
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
51 #define _r(c) ((c)>>24)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
52 #define _g(c) (((c)>>16)&0xFF)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
53 #define _b(c) (((c)>>8)&0xFF)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
54 #define _a(c) ((c)&0xFF)
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
55 #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
56 #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
57 #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
58
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
59 /* map 0 - 0xFF -> 0 - 0x101 */
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
60 #define MAP_16BIT(v) RSHIFT(0x102 * (v), 8)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
61 /* map 0 - 0xFF -> 0 - 0x10101 */
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
62 #define MAP_24BIT(v) RSHIFT(0x10203 * (v), 8)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
63
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
64 #if HAVE_SSE4
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
65
35582
373c7154ec54 Rename consts & avoid using a GNU extension.
upsuper
parents: 35581
diff changeset
66 DECLARE_ASM_CONST(16, uint32_t, sse_int32_80h[4])
373c7154ec54 Rename consts & avoid using a GNU extension.
upsuper
parents: 35581
diff changeset
67 = { 0x80, 0x80, 0x80, 0x80 };
373c7154ec54 Rename consts & avoid using a GNU extension.
upsuper
parents: 35581
diff changeset
68 DECLARE_ASM_CONST(16, uint32_t, sse_int32_map_factor[4])
373c7154ec54 Rename consts & avoid using a GNU extension.
upsuper
parents: 35581
diff changeset
69 = { 0x102, 0x102, 0x102, 0x102 };
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
70
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
71 #endif // HAVE_SSE4
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
72
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
73 static const struct vf_priv_s {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
74 int outh, outw;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
75
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
76 int is_planar;
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
77 unsigned int outfmt;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
78
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
79 // 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
80 // 0 = insert always
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
81 int auto_insert;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
82
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
83 // planar data to be directly rendered on frames
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
84 uint8_t *planes[MP_MAX_PLANES];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
85 // alpha here is actually transparency, not opacity
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
86 uint8_t *alphas[MP_MAX_PLANES];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
87 struct dirty_rows_extent {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
88 int xmin, xmax;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
89 } *dirty_rows;
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
90
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
91 // called for every eosd image when subtitle is changed
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
92 void (*draw_image)(vf_instance_t *, struct mp_eosd_image *);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
93 // called for every time subtitle is changed
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
94 void (*prepare_buffer)(vf_instance_t *);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
95 // called for every frame
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
96 void (*render_frame)(vf_instance_t *);
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
97 } vf_priv_dflt;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
98
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
99 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
100 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
101 uint32_t color = img->color;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
102 uint32_t opacity = 0xFF - _a(color);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
103 uint8_t y = rgba2y(color),
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
104 u = rgba2u(color),
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
105 v = rgba2v(color);
35268
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
106 int outw = vf->priv->outw;
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
107 uint8_t *alpha = vf->priv->alphas[0],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
108 *dst_y = vf->priv->planes[0],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
109 *dst_u = vf->priv->planes[1],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
110 *dst_v = vf->priv->planes[2];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
111 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
112 int src_x = img->dst_x, src_w = img->w,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
113 src_y = img->dst_y, src_h = img->h,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
114 stride = img->stride;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
115 uint8_t *src = img->bitmap;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
116 int i, j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
117
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
118 opacity = MAP_24BIT(opacity);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
119 for (i = 0; i < src_h; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
120 struct dirty_rows_extent *dirty_row = &dirty_rows[src_y + i];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
121 dirty_row->xmin = FFMIN(dirty_row->xmin, src_x);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
122 dirty_row->xmax = FFMAX(dirty_row->xmax, src_x + src_w);
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 for (j = 0; j < src_w; j++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
125 uint32_t k = src[i * stride + j];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
126 if (k) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
127 size_t p = (src_y + i) * outw + src_x + j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
128 k *= opacity;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
129 alpha[p] = RSHIFT((0xFFFFFF - k) * alpha[p], 24);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
130 dst_y[p] = RSHIFT((0xFFFFFF - k) * dst_y[p] + k * y, 24);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
131 dst_u[p] = RSHIFT((0xFFFFFF - k) * dst_u[p] + k * u, 24);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
132 dst_v[p] = RSHIFT((0xFFFFFF - k) * dst_v[p] + k * v, 24);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
133 }
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 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
136 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
137
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
138 static void prepare_buffer_422(vf_instance_t *vf)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
139 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
140 uint8_t *dst_u = vf->priv->planes[1],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
141 *dst_v = vf->priv->planes[2];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
142 int outw = vf->priv->outw,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
143 outh = vf->priv->outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
144 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
145 int i, j;
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 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
148 int xmin = dirty_rows[i].xmin & ~1,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
149 xmax = dirty_rows[i].xmax;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
150 for (j = xmin; j < xmax; j += 2) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
151 size_t p = i * outw + j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
152 dst_u[p] = (dst_u[p] + dst_u[p + 1]) / 2;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
153 dst_v[p] = (dst_v[p] + dst_v[p + 1]) / 2;
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
154 dst_u[p + 1] = dst_v[p + 1] = 0;
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
155 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
156 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
157 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
158
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
159 static void render_frame_yuv422(vf_instance_t *vf)
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 uint8_t *alpha = vf->priv->alphas[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
162 uint8_t *src_y = vf->priv->planes[0],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
163 *src_u = vf->priv->planes[1],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
164 *src_v = vf->priv->planes[2];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
165 int outw = vf->priv->outw,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
166 outh = vf->priv->outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
167 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
168 uint8_t *dest = vf->dmpi->planes[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
169 int stride = vf->dmpi->stride[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
170 int is_uyvy = vf->priv->outfmt == IMGFMT_UYVY;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
171 int i, j;
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 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
174 int xmin = dirty_rows[i].xmin & ~1,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
175 xmax = dirty_rows[i].xmax;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
176 for (j = xmin; j < xmax; j += 2) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
177 size_t src = i * outw + j,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
178 dst = i * stride + j * 2;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
179 uint_fast16_t a0 = alpha[src],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
180 a1 = alpha[src + 1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
181 uint8_t y0, y1, u, v;
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 if (a0 == 0xFF && a1 == 0xFF)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
184 continue;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
185
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
186 y0 = dest[dst + is_uyvy + 0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
187 y1 = dest[dst + is_uyvy + 2];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
188 u = dest[dst - is_uyvy + 1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
189 v = dest[dst - is_uyvy + 3];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
190
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
191 a0 = MAP_16BIT(a0);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
192 a1 = MAP_16BIT(a1);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
193 y0 = ((a0 * y0) >> 8) + src_y[src];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
194 y1 = ((a1 * y1) >> 8) + src_y[src + 1];
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 a0 = (a0 + a1) / 2;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
197 u = ((a0 * u) >> 8) + src_u[src];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
198 v = ((a0 * v) >> 8) + src_v[src];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
199
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
200 dest[dst + is_uyvy + 0] = y0;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
201 dest[dst + is_uyvy + 2] = y1;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
202 dest[dst - is_uyvy + 1] = u;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
203 dest[dst - is_uyvy + 3] = v;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
204 }
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 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
207
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
208 #if HAVE_SSE4
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
209
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
210 static void render_frame_yuv422_sse4(vf_instance_t *vf)
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
211 {
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
212 uint8_t *alpha = vf->priv->alphas[0];
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
213 uint8_t *src_y = vf->priv->planes[0],
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
214 *src_u = vf->priv->planes[1],
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
215 *src_v = vf->priv->planes[2];
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
216 int outw = vf->priv->outw,
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
217 outh = vf->priv->outh;
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
218 struct dirty_rows_extent *dr = vf->priv->dirty_rows;
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
219 uint8_t *dst = vf->dmpi->planes[0];
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
220 int stride = vf->dmpi->stride[0];
35579
6b169870ae30 Reduce register usage to fix the compilation in x86.
upsuper
parents: 35576
diff changeset
221 int32_t is_uyvy = vf->priv->outfmt == IMGFMT_UYVY;
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
222 int i;
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
223
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
224 for (i = 0; i < outh; i++) {
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
225 size_t xmin = dr[i].xmin & ~7,
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
226 xmax = dr[i].xmax;
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
227 __asm__ volatile (
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
228 "pxor %%xmm7, %%xmm7 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
229 "jmp 4f \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
230 "1: \n\t"
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
231
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
232 "cmpl $-1, 0(%[alpha], %[j], 1) \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
233 "jne 2f \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
234 "cmpl $-1, 4(%[alpha], %[j], 1) \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
235 "jne 2f \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
236 "jmp 3f \n\t"
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
237
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
238 "2: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
239 "movq (%[alpha], %[j], 1), %%xmm0 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
240 "punpcklbw %%xmm7, %%xmm0 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
241 "movdqa %%xmm0, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
242 "punpcklwd %%xmm7, %%xmm0 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
243 "punpckhwd %%xmm7, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
244 "pmulld "MANGLE(sse_int32_map_factor)", %%xmm0 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
245 "pmulld "MANGLE(sse_int32_map_factor)", %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
246 "paddd "MANGLE(sse_int32_80h)", %%xmm0 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
247 "paddd "MANGLE(sse_int32_80h)", %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
248 "psrld $8, %%xmm0 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
249 "psrld $8, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
250 "movdqa %%xmm0, %%xmm2 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
251 "movdqa %%xmm1, %%xmm3 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
252 "packssdw %%xmm1, %%xmm0 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
253 "phaddd %%xmm3, %%xmm2 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
254 "psrld $1, %%xmm2 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
255 "packssdw %%xmm7, %%xmm2 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
256 "punpcklwd %%xmm2, %%xmm2 \n\t"
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
257
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
258 "movdqu (%[dst], %[j], 2), %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
259 "movdqa %%xmm1, %%xmm3 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
260 "cmpl $0, %[f] \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
261 "je 11f \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
262 "psrlw $8, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
263 "psllw $8, %%xmm3 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
264 "psrlw $8, %%xmm3 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
265 "jmp 12f \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
266 "11: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
267 "psllw $8, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
268 "psrlw $8, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
269 "psrlw $8, %%xmm3 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
270 "12: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
271 "pmullw %%xmm0, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
272 "pmullw %%xmm2, %%xmm3 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
273 "psrlw $8, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
274 "psrlw $8, %%xmm3 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
275 "packuswb %%xmm7, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
276 "packuswb %%xmm7, %%xmm3 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
277 "mov %[src_y], %%"REG_S" \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
278 "movq (%%"REG_S", %[j], 1), %%xmm4 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
279 "mov %[src_u], %%"REG_S" \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
280 "movq (%%"REG_S", %[j], 1), %%xmm5 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
281 "mov %[src_v], %%"REG_S" \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
282 "movq (%%"REG_S", %[j], 1), %%xmm6 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
283 "packuswb %%xmm7, %%xmm5 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
284 "packuswb %%xmm7, %%xmm6 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
285 "punpcklbw %%xmm6, %%xmm5 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
286 "cmpl $0, %[f] \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
287 "je 21f \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
288 "punpcklbw %%xmm1, %%xmm3 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
289 "punpcklbw %%xmm4, %%xmm5 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
290 "paddb %%xmm5, %%xmm3 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
291 "movdqu %%xmm3, (%[dst], %[j], 2) \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
292 "jmp 22f \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
293 "21: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
294 "punpcklbw %%xmm3, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
295 "punpcklbw %%xmm5, %%xmm4 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
296 "paddb %%xmm4, %%xmm1 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
297 "movdqu %%xmm1, (%[dst], %[j], 2) \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
298 "22: \n\t"
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
299
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
300 "3: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
301 "add $8, %[j] \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
302 "4: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
303 "cmp %[xmax], %[j] \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
304 "jl 1b \n\t"
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
305
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
306 : : [dst] "r" (dst + i * stride),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
307 [alpha] "r" (alpha + i * outw),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
308 [src_y] "g" (src_y + i * outw),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
309 [src_u] "g" (src_u + i * outw),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
310 [src_v] "g" (src_v + i * outw),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
311 [j] "r" (xmin),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
312 [xmax] "g" (xmax),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
313 [f] "g" (is_uyvy)
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
314 : REG_S
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
315 );
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
316 }
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
317 }
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
318
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
319 #endif // HAVE_SSE4
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
320
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
321 static void prepare_buffer_420p(vf_instance_t *vf)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
322 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
323 int outw = vf->priv->outw,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
324 outh = vf->priv->outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
325 uint8_t *dst_u = vf->priv->planes[1],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
326 *dst_v = vf->priv->planes[2];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
327 uint8_t *src_a = vf->priv->alphas[0],
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
328 *dst_a = vf->priv->alphas[1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
329 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
330 int i, j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
331
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
332 for (i = 0; i < outh; i += 2) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
333 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
334 xmax = FFMAX(dirty_rows[i].xmax, dirty_rows[i + 1].xmax);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
335 for (j = xmin; j < xmax; j += 2) {
35618
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
336 size_t p = i * outw / 2 + j / 2,
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
337 q1 = i * outw + j,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
338 q2 = q1 + outw;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
339 dst_a[p] = (src_a[q1] + src_a[q1 + 1] +
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
340 src_a[q2] + src_a[q2 + 1] + 2) / 4;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
341 dst_u[p] = (dst_u[q1] + dst_u[q1 + 1] +
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
342 dst_u[q2] + dst_u[q2 + 1] + 2) / 4;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
343 dst_v[p] = (dst_v[q1] + dst_v[q1 + 1] +
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
344 dst_v[q2] + dst_v[q2 + 1] + 2) / 4;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
345 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
346 }
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
347
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
348 #if HAVE_SSE4
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
349 // for render_frame_yuv420p_sse4
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
350 if (gCpuCaps.hasSSE4 && outw % 32 == 0) {
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
351 for (i = 0; i < outh; i += 2) {
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
352 int xmin = FFMIN(dirty_rows[i].xmin, dirty_rows[i + 1].xmin) & ~1,
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
353 xmax = FFMAX(dirty_rows[i].xmax, dirty_rows[i + 1].xmax);
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
354 if (xmin >= xmax)
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
355 continue;
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
356 for (j = xmin & ~31; j < xmin; j += 2) {
35618
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
357 size_t p = i * outw / 2 + j / 2;
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
358 dst_a[p] = 0xFF;
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
359 dst_u[p] = dst_v[p] = 0;
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
360 }
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
361 for (j = xmax; j < FFALIGN(xmax, 32); j += 2) {
35618
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
362 size_t p = i * outw / 2 + j / 2;
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
363 dst_a[p] = 0xFF;
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
364 dst_u[p] = dst_v[p] = 0;
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
365 }
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
366 }
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
367 }
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
368 #endif // HAVE_SSE4
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
369 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
370
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
371 static void render_frame_yuv420p(vf_instance_t *vf)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
372 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
373 uint8_t **planes = vf->priv->planes;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
374 uint8_t **dest = vf->dmpi->planes;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
375 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
376 uint8_t *alpha;
35268
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
377 uint8_t *src_y = planes[0],
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
378 *src_u = planes[1],
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
379 *src_v = planes[2];
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
380 uint8_t *dst_y = dest[0],
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
381 *dst_u = dest[1],
f16646c59e33 Avoid unused variable warnings.
reimar
parents: 35244
diff changeset
382 *dst_v = dest[2];
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
383 int stride;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
384 int outw = vf->priv->outw,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
385 outh = vf->priv->outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
386 int i, j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
387
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
388 // y
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
389 alpha = vf->priv->alphas[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
390 stride = vf->dmpi->stride[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
391 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
392 int xmin = dirty_rows[i].xmin,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
393 xmax = dirty_rows[i].xmax;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
394 for (j = xmin; j < xmax; j++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
395 size_t s = i * outw + j,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
396 d = i * stride + j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
397 if (alpha[s] != 0xFF)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
398 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
399 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
400 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
401
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
402 // u & v
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
403 alpha = vf->priv->alphas[1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
404 stride = vf->dmpi->stride[1];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
405 for (i = 0; i < outh / 2; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
406 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
407 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
408 for (j = xmin / 2; j < (xmax + 1) / 2; j++) {
35618
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
409 size_t s = i * outw + j,
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
410 d = i * stride + j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
411 if (alpha[s] != 0xFF) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
412 uint_fast16_t a = MAP_16BIT(alpha[s]);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
413 dst_u[d] = ((a * dst_u[d]) >> 8) + src_u[s];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
414 dst_v[d] = ((a * dst_v[d]) >> 8) + src_v[s];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
415 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
416 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
417 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
418 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
419
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
420 #if HAVE_SSE4
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
421
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
422 #define CHECK_16_ALPHA \
35602
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
423 "cmpl $-1, 0(%[alpha], %[j], 1) \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
424 "jne 2f \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
425 "cmpl $-1, 4(%[alpha], %[j], 1) \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
426 "jne 2f \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
427 "cmpl $-1, 8(%[alpha], %[j], 1) \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
428 "jne 2f \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
429 "cmpl $-1, 12(%[alpha], %[j], 1) \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
430 "jne 2f \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
431 "jmp 3f \n\t"
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
432
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
433 #define MAP_16_ALPHA \
35602
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
434 "movq 0(%[alpha], %[j], 1), %%xmm0 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
435 "movq 8(%[alpha], %[j], 1), %%xmm2 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
436 "punpcklbw %%xmm7, %%xmm0 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
437 "punpcklbw %%xmm7, %%xmm2 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
438 "movdqa %%xmm0, %%xmm1 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
439 "movdqa %%xmm2, %%xmm3 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
440 "punpcklwd %%xmm7, %%xmm0 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
441 "punpckhwd %%xmm7, %%xmm1 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
442 "punpcklwd %%xmm7, %%xmm2 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
443 "punpckhwd %%xmm7, %%xmm3 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
444 "pmulld "MANGLE(sse_int32_map_factor)", %%xmm0 \n\t"\
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
445 "pmulld "MANGLE(sse_int32_map_factor)", %%xmm1 \n\t"\
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
446 "pmulld "MANGLE(sse_int32_map_factor)", %%xmm2 \n\t"\
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
447 "pmulld "MANGLE(sse_int32_map_factor)", %%xmm3 \n\t"\
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
448 "paddd "MANGLE(sse_int32_80h)", %%xmm0 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
449 "paddd "MANGLE(sse_int32_80h)", %%xmm1 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
450 "paddd "MANGLE(sse_int32_80h)", %%xmm2 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
451 "paddd "MANGLE(sse_int32_80h)", %%xmm3 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
452 "psrld $8, %%xmm0 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
453 "psrld $8, %%xmm1 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
454 "psrld $8, %%xmm2 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
455 "psrld $8, %%xmm3 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
456 "packssdw %%xmm1, %%xmm0 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
457 "packssdw %%xmm3, %%xmm2 \n\t"
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
458
35584
fb92c6de7f70 Reduce register usage in an asm block.
upsuper
parents: 35582
diff changeset
459 #define DO_RENDER \
35602
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
460 "movq 0(%%"REG_D", %[j], 1), %%xmm1 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
461 "movq 8(%%"REG_D", %[j], 1), %%xmm3 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
462 "punpcklbw %%xmm7, %%xmm1 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
463 "punpcklbw %%xmm7, %%xmm3 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
464 "pmullw %%xmm0, %%xmm1 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
465 "pmullw %%xmm2, %%xmm3 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
466 "psrlw $8, %%xmm1 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
467 "psrlw $8, %%xmm3 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
468 "packuswb %%xmm3, %%xmm1 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
469 "movdqa (%%"REG_S", %[j], 1), %%xmm4 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
470 "paddb %%xmm4, %%xmm1 \n\t" \
80521cdbc272 Cosmetic: reindent.
upsuper
parents: 35597
diff changeset
471 "movdqu %%xmm1, (%%"REG_D", %[j], 1) \n\t"
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
472
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
473 static void render_frame_yuv420p_sse4(vf_instance_t *vf)
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
474 {
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
475 struct dirty_rows_extent *dr = vf->priv->dirty_rows;
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
476 uint8_t *alpha;
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
477 uint8_t *src_y = vf->priv->planes[0],
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
478 *src_u = vf->priv->planes[1],
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
479 *src_v = vf->priv->planes[2];
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
480 uint8_t *dst_y = vf->dmpi->planes[0],
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
481 *dst_u = vf->dmpi->planes[1],
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
482 *dst_v = vf->dmpi->planes[2];
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
483 int stride;
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
484 int outw = vf->priv->outw,
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
485 outh = vf->priv->outh;
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
486 int i;
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
487
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
488 // y
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
489 alpha = vf->priv->alphas[0];
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
490 stride = vf->dmpi->stride[0];
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
491 for (i = 0; i < outh; i++) {
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
492 size_t xmin = dr[i].xmin & ~15,
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
493 xmax = dr[i].xmax;
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
494 __asm__ volatile (
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
495 "pxor %%xmm7, %%xmm7 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
496 "jmp 4f \n\t"
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
497
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
498 "1: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
499 CHECK_16_ALPHA
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
500
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
501 "2: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
502 MAP_16_ALPHA
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
503 DO_RENDER
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
504
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
505 "3: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
506 "add $16, %[j] \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
507 "4: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
508 "cmp %[xmax], %[j] \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
509 "jl 1b \n\t"
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
510
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
511 : : [j] "r" (xmin),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
512 [xmax] "g" (xmax),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
513 [alpha] "r" (alpha + i * outw),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
514 [src] "S" (src_y + i * outw),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
515 [dst] "D" (dst_y + i * stride)
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
516 );
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
517 }
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
518
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
519 // u & v
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
520 alpha = vf->priv->alphas[1];
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
521 stride = vf->dmpi->stride[1];
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
522 for (i = 0; i < outh / 2; i++) {
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
523 size_t xmin = FFMIN(dr[i * 2].xmin, dr[i * 2 + 1].xmin) & ~31,
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
524 xmax = FFMAX(dr[i * 2].xmax, dr[i * 2 + 1].xmax);
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
525 __asm__ volatile (
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
526 "pxor %%xmm7, %%xmm7 \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
527 "jmp 4f \n\t"
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
528
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
529 "1: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
530 CHECK_16_ALPHA
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
531
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
532 "2: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
533 MAP_16_ALPHA
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
534 "mov %[src_u], %%"REG_S" \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
535 "mov %[dst_u], %%"REG_D" \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
536 DO_RENDER
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
537 "mov %[src_v], %%"REG_S" \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
538 "mov %[dst_v], %%"REG_D" \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
539 DO_RENDER
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
540
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
541 "3: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
542 "add $16, %[j] \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
543 "4: \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
544 "cmp %[xmax], %[j] \n\t"
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
545 "jl 1b \n\t"
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
546
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
547 : : [j] "r" (xmin / 2),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
548 [xmax] "g" ((xmax + 1) / 2),
35618
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
549 [alpha] "r" (alpha + i * outw),
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
550 [src_u] "g" (src_u + i * outw),
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
551 [src_v] "g" (src_v + i * outw),
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
552 [dst_u] "g" (dst_u + i * stride),
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
553 [dst_v] "g" (dst_v + i * stride)
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
554 : REG_S, REG_D
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
555 );
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
556 }
35597
6063e2930092 Cosmetic: reindent & move defines out of function
upsuper
parents: 35585
diff changeset
557 }
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
558
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
559 #undef CHECK_16_ALPHA
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
560 #undef MAP_16_ALPHA
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
561 #undef MUL_ALPHA
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
562
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
563 #endif // HAVE_SSE4
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
564
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
565 static void clean_buffer(vf_instance_t *vf)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
566 {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
567 int outw = vf->priv->outw,
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
568 outh = vf->priv->outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
569 struct dirty_rows_extent *dirty_rows = vf->priv->dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
570 uint8_t **planes = vf->priv->planes;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
571 uint8_t *alpha = vf->priv->alphas[0];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
572 int i, j;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
573
35618
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
574 if (vf->priv->prepare_buffer == prepare_buffer_420p) {
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
575 // HACK: prepare_buffer_420p touched u & v planes
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
576 // so we want to clean them here.
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
577 for (i = 0; i < outh; i += 2) {
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
578 int xmin = FFMIN(dirty_rows[i].xmin, dirty_rows[i + 1].xmin) & ~1,
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
579 xmax = FFMAX(dirty_rows[i].xmax, dirty_rows[i + 1].xmax);
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
580 dirty_rows[i / 2].xmin = FFMIN(dirty_rows[i / 2].xmin, xmin / 2);
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
581 dirty_rows[i / 2].xmax = FFMAX(dirty_rows[i / 2].xmax, xmax / 2);
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
582 }
2cf9f80c4023 Fix a rendering bug in vf_ass.
upsuper
parents: 35602
diff changeset
583 }
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
584 for (i = 0; i < MP_MAX_PLANES; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
585 uint8_t *plane = planes[i];
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
586 if (!plane)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
587 break;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
588 for (j = 0; j < outh; j++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
589 int xmin = dirty_rows[j].xmin;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
590 int width = dirty_rows[j].xmax - xmin;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
591 if (width > 0)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
592 memset(plane + j * outw + xmin, 0, width);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
593 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
594 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
595 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
596 int xmin = dirty_rows[i].xmin;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
597 int width = dirty_rows[i].xmax - xmin;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
598 if (width > 0)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
599 memset(alpha + i * outw + xmin, -1, width);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
600 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
601 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
602 dirty_rows[i].xmin = outw;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
603 dirty_rows[i].xmax = 0;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
604 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
605 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
606
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
607 static int config(struct vf_instance *vf,
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
608 int width, int height, int d_width, int d_height,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
609 unsigned int flags, unsigned int outfmt)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
610 {
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
611 struct mp_eosd_settings res = {0};
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
612 struct dirty_rows_extent *dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
613 int outw, outh;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
614 int planes, alphas;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
615 int i;
31927
6e0b5a97e00f EOSD/ASS code factorization
cigaes
parents: 31792
diff changeset
616
35574
715e7aa1ffdb Move some code up.
upsuper
parents: 35436
diff changeset
617 vf->priv->outfmt = outfmt;
715e7aa1ffdb Move some code up.
upsuper
parents: 35436
diff changeset
618 vf->priv->outh = outh = height + ass_top_margin + ass_bottom_margin;
715e7aa1ffdb Move some code up.
upsuper
parents: 35436
diff changeset
619 vf->priv->outw = outw = width;
715e7aa1ffdb Move some code up.
upsuper
parents: 35436
diff changeset
620
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
621 switch (outfmt) {
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
622 case IMGFMT_YV12:
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
623 case IMGFMT_I420:
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
624 case IMGFMT_IYUV:
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
625 vf->priv->is_planar = 1;
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
626 planes = 3;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
627 alphas = 2;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
628 vf->priv->draw_image = draw_image_yuv;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
629 vf->priv->render_frame = render_frame_yuv420p;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
630 vf->priv->prepare_buffer = prepare_buffer_420p;
35576
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
631 #if HAVE_SSE4
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
632 if (gCpuCaps.hasSSE4 && outw % 32 == 0)
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
633 vf->priv->render_frame = render_frame_yuv420p_sse4;
2508973357da Accelerate ass rendering by using SSE4 for yuv420p.
upsuper
parents: 35575
diff changeset
634 #endif
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
635 break;
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
636 case IMGFMT_UYVY:
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
637 case IMGFMT_YUY2:
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
638 vf->priv->is_planar = 0;
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
639 planes = 3;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
640 alphas = 1;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
641 vf->priv->draw_image = draw_image_yuv;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
642 vf->priv->render_frame = render_frame_yuv422;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
643 vf->priv->prepare_buffer = prepare_buffer_422;
35575
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
644 #if HAVE_SSE4
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
645 if (gCpuCaps.hasSSE4 && outw % 8 == 0)
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
646 vf->priv->render_frame = render_frame_yuv422_sse4;
db12239148e9 Accelerate ass rendering by using SSE4 for yuv422.
upsuper
parents: 35574
diff changeset
647 #endif
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
648 break;
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
649 default:
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
650 return 0;
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
651 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
652
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
653 if (!opt_screen_size_x && !opt_screen_size_y) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
654 d_width = d_width * vf->priv->outw / width;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
655 d_height = d_height * vf->priv->outh / height;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
656 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
657
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
658 for (i = 0; i < planes; i++)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
659 vf->priv->planes[i] = av_malloc(outw * outh);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
660 for (i = 0; i < alphas; i++)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
661 vf->priv->alphas[i] = av_malloc(outw * outh);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
662 dirty_rows = av_malloc(outh * sizeof(*dirty_rows));
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
663 // mark all rows dirty here
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
664 // so that they can be properly cleaned in clear_buffer()
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
665 for (i = 0; i < outh; i++) {
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
666 dirty_rows[i].xmin = 0;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
667 dirty_rows[i].xmax = outw;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
668 }
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
669 vf->priv->dirty_rows = dirty_rows;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
670 clean_buffer(vf);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
671
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
672 res.w = vf->priv->outw;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
673 res.h = vf->priv->outh;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
674 res.srcw = width;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
675 res.srch = height;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
676 res.mt = ass_top_margin;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
677 res.mb = ass_bottom_margin;
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
678 eosd_configure(&res);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
679
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
680 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
681 d_height, flags, outfmt);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
682 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
683
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
684 static void get_image(struct vf_instance *vf, mp_image_t *mpi)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
685 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
686 if (mpi->type == MP_IMGTYPE_IPB)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
687 return;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
688 if (mpi->flags & MP_IMGFLAG_PRESERVE)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
689 return;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
690 if (mpi->imgfmt != vf->priv->outfmt)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
691 return; // colorspace differ
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
692
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
693 // width never changes, always try full DR
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
694 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
695 mpi->flags | MP_IMGFLAG_READABLE,
34882
649d4cad4619 Request a sufficiently large image for direct rendering.
reimar
parents: 34863
diff changeset
696 FFMAX(mpi->width, vf->priv->outw),
649d4cad4619 Request a sufficiently large image for direct rendering.
reimar
parents: 34863
diff changeset
697 FFMAX(mpi->height, vf->priv->outh));
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
698
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
699 if ( (vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) &&
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
700 !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
701 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_MPCODECS_FullDRNotPossible);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
702 return;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
703 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
704 // set up mpi as a cropped-down image of dmpi:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
705 if (mpi->flags & MP_IMGFLAG_PLANAR) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
706 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
707 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
708 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
709 mpi->stride[1] = vf->dmpi->stride[1];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
710 mpi->stride[2] = vf->dmpi->stride[2];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
711 } else {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
712 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
713 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
714 mpi->stride[0] = vf->dmpi->stride[0];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
715 mpi->width = vf->dmpi->width;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
716 mpi->flags |= MP_IMGFLAG_DIRECT;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
717 mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
718 // vf->dmpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
719 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
720
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
721 static void blank(mp_image_t *mpi, int y1, int y2)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
722 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
723 int color[3] = { 16, 128, 128 }; // black (YUV)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
724 int y;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
725 unsigned char *dst;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
726 int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
727
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
728 if (mpi->flags & MP_IMGFLAG_PLANAR) {
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
729 dst = mpi->planes[0] + y1 * mpi->stride[0];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
730 for (y = 0; y < y2 - y1; ++y) {
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
731 memset(dst, color[0], mpi->w);
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
732 dst += mpi->stride[0];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
733 }
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
734 dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
735 for (y = 0; y < chroma_rows; ++y) {
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
736 memset(dst, color[1], mpi->chroma_width);
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
737 dst += mpi->stride[1];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
738 }
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
739 dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
740 for (y = 0; y < chroma_rows; ++y) {
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
741 memset(dst, color[2], mpi->chroma_width);
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
742 dst += mpi->stride[2];
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
743 }
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
744 } else {
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
745 unsigned char packed_color[4];
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
746 int x;
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
747 if (mpi->imgfmt == IMGFMT_UYVY) {
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
748 packed_color[0] = color[1];
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
749 packed_color[1] = color[0];
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
750 packed_color[2] = color[2];
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
751 packed_color[3] = color[0];
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
752 } else {
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
753 packed_color[0] = color[0];
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
754 packed_color[1] = color[1];
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
755 packed_color[2] = color[0];
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
756 packed_color[3] = color[2];
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
757 }
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
758 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
759 for (y = y1; y < y2; ++y) {
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
760 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
761 AV_COPY32(dst + 4 * x, packed_color);
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
762 dst += mpi->stride[0];
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
763 }
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
764 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
765 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
766
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
767 static int prepare_image(struct vf_instance *vf, mp_image_t *mpi)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
768 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
769 if (mpi->flags & MP_IMGFLAG_DIRECT ||
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
770 mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
771 vf->dmpi = mpi->priv;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
772 if (!vf->dmpi) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
773 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_MPCODECS_FunWhydowegetNULL);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
774 return 0;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
775 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
776 mpi->priv = NULL;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
777 // we've used DR, so we're ready...
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
778 if (ass_top_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
779 blank(vf->dmpi, 0, ass_top_margin);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
780 if (ass_bottom_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
781 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
782 if (!(mpi->flags & MP_IMGFLAG_PLANAR))
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
783 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
784 return 0;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
785 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
786 // hope we'll get DR buffer:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
787 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
788 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
789 vf->priv->outw, vf->priv->outh);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
790
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
791 // copy mpi->dmpi...
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
792 if (mpi->flags & MP_IMGFLAG_PLANAR) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
793 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
794 mpi->planes[0],
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
795 mpi->w,
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
796 mpi->h,
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
797 vf->dmpi->stride[0],
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
798 mpi->stride[0]);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
799 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
800 mpi->planes[1],
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
801 mpi->w >> mpi->chroma_x_shift,
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
802 mpi->h >> mpi->chroma_y_shift,
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
803 vf->dmpi->stride[1],
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
804 mpi->stride[1]);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
805 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
806 mpi->planes[2],
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
807 mpi->w >> mpi->chroma_x_shift,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
808 mpi->h >> mpi->chroma_y_shift,
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
809 vf->dmpi->stride[2],
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
810 mpi->stride[2]);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
811 } else {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
812 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
813 mpi->planes[0],
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
814 mpi->w * (vf->dmpi->bpp / 8),
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
815 mpi->h,
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
816 vf->dmpi->stride[0],
35436
d3b0d3f62d6f Cosmetic: Reindent.
upsuper
parents: 35268
diff changeset
817 mpi->stride[0]);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
818 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
819 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
820 if (ass_top_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
821 blank(vf->dmpi, 0, ass_top_margin);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
822 if (ass_bottom_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
823 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
824 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
825 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
826
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
827 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
828 {
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
829 struct mp_eosd_image *img = eosd_image_first(imgs);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
830 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
831
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
832 clean_buffer(vf);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
833 draw_image = vf->priv->draw_image;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
834 for (; img; img = eosd_image_next(imgs))
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
835 draw_image(vf, img);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
836 vf->priv->prepare_buffer(vf);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
837 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
838
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
839 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
840 {
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
841 struct mp_eosd_image_list images;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
842 eosd_render_frame(pts, &images);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
843 prepare_image(vf, mpi);
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
844 if (images.changed)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
845 prepare_eosd(vf, &images);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
846 vf->priv->render_frame(vf);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
847 return vf_next_put_image(vf, vf->dmpi, pts);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
848 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
849
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
850 static int query_format(struct vf_instance *vf, unsigned int fmt)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
851 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
852 switch (fmt) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
853 case IMGFMT_YV12:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
854 case IMGFMT_I420:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
855 case IMGFMT_IYUV:
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
856 case IMGFMT_UYVY:
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
857 case IMGFMT_YUY2:
35033
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
858 return vf_next_query_format(vf, fmt) | VFCAP_EOSD;
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
859 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
860 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
861 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
862
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
863 static int control(vf_instance_t *vf, int request, void *data)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
864 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
865 switch (request) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
866 case VFCTRL_INIT_EOSD:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
867 return CONTROL_TRUE;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
868 case VFCTRL_DRAW_EOSD:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
869 return CONTROL_TRUE;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
870 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
871 return vf_next_control(vf, request, data);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
872 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
873
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
874 static void uninit(struct vf_instance *vf)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
875 {
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
876 int i;
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
877 for (i = 0; i < MP_MAX_PLANES; i++)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
878 av_free(vf->priv->planes[i]);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
879 for (i = 0; i < MP_MAX_PLANES; i++)
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
880 av_free(vf->priv->alphas[i]);
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
881 av_free(vf->priv->dirty_rows);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
882 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
883
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
884 static const unsigned int fmt_list[] = {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
885 IMGFMT_YV12,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
886 IMGFMT_I420,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
887 IMGFMT_IYUV,
35039
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
888 IMGFMT_UYVY,
848835e1b053 vf_ass: add support for rendering on YUY2 and UYVY images.
reimar
parents: 35033
diff changeset
889 IMGFMT_YUY2,
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
890 0
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
891 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
892
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30633
diff changeset
893 static int vf_open(vf_instance_t *vf, char *args)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
894 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
895 int flags;
35033
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
896 unsigned outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12);
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
897 if (outfmt)
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
898 flags = vf_next_query_format(vf, outfmt);
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
899 if (!outfmt || (vf->priv->auto_insert && flags & VFCAP_EOSD)) {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
900 uninit(vf);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
901 return 0;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
902 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
903
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
904 if (vf->priv->auto_insert)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
905 mp_msg(MSGT_ASS, MSGL_INFO, "[ass] auto-open\n");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
906
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
907 vf->config = config;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
908 vf->query_format = query_format;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
909 vf->uninit = uninit;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
910 vf->control = control;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
911 vf->get_image = get_image;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
912 vf->put_image = put_image;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
913 vf->default_caps = VFCAP_EOSD;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
914 return 1;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
915 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
916
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
917 #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
918 static const m_option_t vf_opts_fields[] = {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
919 {"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
920 {NULL, NULL, 0, 0, 0, 0, NULL}
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
921 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
922
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
923 static const m_struct_t vf_opts = {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
924 "ass",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
925 sizeof(struct vf_priv_s),
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
926 &vf_priv_dflt,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
927 vf_opts_fields
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
928 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
929
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
930 const vf_info_t vf_info_ass = {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
931 "Render ASS/SSA subtitles",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
932 "ass",
35244
222713e4d79f a new implementation of vf_ass
upsuper
parents: 35039
diff changeset
933 "Evgeniy Stepanov, Xidorn Quan",
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
934 "",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
935 vf_open,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
936 &vf_opts
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
937 };