annotate libmpcodecs/vf_ass.c @ 35033:387485e3956a

vf_ass: Improve format query. The output format should always match the input format for this filter, and we should set the EOSD capability. This also simplifies adding support for more formats. Patch by Xidorn Quan [quanxunzhen gmail com].
author reimar
date Wed, 29 Aug 2012 16:06:26 +0000
parents e8af23854aa1
children 848835e1b053
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>
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
3 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
4 * This file is part of MPlayer.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
5 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
6 * MPlayer is free software; you can redistribute it and/or modify
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
7 * it under the terms of the GNU General Public License as published by
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
9 * (at your option) any later version.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
10 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
11 * MPlayer is distributed in the hope that it will be useful,
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
14 * GNU General Public License for more details.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
15 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
16 * You should have received a copy of the GNU General Public License along
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
17 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
19 */
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19563
diff changeset
20
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
21 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
22
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23 #include <stdio.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
24 #include <stdlib.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
25 #include <string.h>
24545
9e5126679d44 Replace stdint.h #include by functionally equivalent inttypes.h.
diego
parents: 23134
diff changeset
26 #include <inttypes.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
27 #include <assert.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
28
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
29 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
30 #include "mp_msg.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
31 #include "help_mp.h"
31489
dc26022e9c27 Clean up sub-related extern declarations.
diego
parents: 31488
diff changeset
32 #include "mpcommon.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
33 #include "img_format.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
34 #include "mp_image.h"
30653
3d23e24c5c60 Declare externally used variables from vd.c as extern in vd.h.
diego
parents: 30642
diff changeset
35 #include "vd.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
36 #include "vf.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
37
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
38 #include "libvo/fastmemcpy.h"
32467
fbe5c829c69b Move libvo/sub.[ch] from libvo to sub.
cigaes
parents: 32461
diff changeset
39 #include "sub/sub.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
40 #include "m_option.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
41 #include "m_struct.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
42
32461
bc43cf7638e6 Move ass_mp.[ch] to the sub directory.
cigaes
parents: 32460
diff changeset
43 #include "sub/ass_mp.h"
32460
d80bbc5868de Move eosd.[ch] to the sub directory.
cigaes
parents: 32391
diff changeset
44 #include "sub/eosd.h"
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
45
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
46 #define _r(c) ((c)>>24)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
47 #define _g(c) (((c)>>16)&0xFF)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
48 #define _b(c) (((c)>>8)&0xFF)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
49 #define _a(c) ((c)&0xFF)
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
50 #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
51 #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
52 #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
53
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
54
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
55 static const struct vf_priv_s {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
56 int outh, outw;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
57
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
58 unsigned int outfmt;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
59
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
60 // 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
61 // 0 = insert always
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
62 int auto_insert;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
63
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
64 unsigned char *planes[3];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
65 unsigned char *dirty_rows;
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
66 } vf_priv_dflt;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
67
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
68
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
69 static int config(struct vf_instance *vf,
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
70 int width, int height, int d_width, int d_height,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
71 unsigned int flags, unsigned int outfmt)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
72 {
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
73 struct mp_eosd_settings res = {0};
31927
6e0b5a97e00f EOSD/ASS code factorization
cigaes
parents: 31792
diff changeset
74
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
75 if (outfmt == IMGFMT_IF09)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
76 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
77
35033
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
78 vf->priv->outfmt = outfmt;
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
79 vf->priv->outh = height + ass_top_margin + ass_bottom_margin;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
80 vf->priv->outw = width;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
81
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
82 if (!opt_screen_size_x && !opt_screen_size_y) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
83 d_width = d_width * vf->priv->outw / width;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
84 d_height = d_height * vf->priv->outh / height;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
85 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
86
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
87 vf->priv->planes[1] = malloc(vf->priv->outw * vf->priv->outh);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
88 vf->priv->planes[2] = malloc(vf->priv->outw * vf->priv->outh);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
89 vf->priv->dirty_rows = malloc(vf->priv->outh);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
90
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
91 res.w = vf->priv->outw;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
92 res.h = vf->priv->outh;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
93 res.srcw = width;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
94 res.srch = height;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
95 res.mt = ass_top_margin;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
96 res.mb = ass_bottom_margin;
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
97 eosd_configure(&res);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
98
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
99 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
100 d_height, flags, outfmt);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
101 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
102
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
103 static void get_image(struct vf_instance *vf, mp_image_t *mpi)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
104 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
105 if (mpi->type == MP_IMGTYPE_IPB)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
106 return;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
107 if (mpi->flags & MP_IMGFLAG_PRESERVE)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
108 return;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
109 if (mpi->imgfmt != vf->priv->outfmt)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
110 return; // colorspace differ
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
111
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
112 // width never changes, always try full DR
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
113 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
114 mpi->flags | MP_IMGFLAG_READABLE,
34882
649d4cad4619 Request a sufficiently large image for direct rendering.
reimar
parents: 34863
diff changeset
115 FFMAX(mpi->width, vf->priv->outw),
649d4cad4619 Request a sufficiently large image for direct rendering.
reimar
parents: 34863
diff changeset
116 FFMAX(mpi->height, vf->priv->outh));
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
117
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
118 if ( (vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) &&
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
119 !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
120 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_MPCODECS_FullDRNotPossible);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
121 return;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
122 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
123 // set up mpi as a cropped-down image of dmpi:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
124 if (mpi->flags & MP_IMGFLAG_PLANAR) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
125 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
126 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
127 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
128 mpi->stride[1] = vf->dmpi->stride[1];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
129 mpi->stride[2] = vf->dmpi->stride[2];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
130 } else {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
131 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
132 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
133 mpi->stride[0] = vf->dmpi->stride[0];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
134 mpi->width = vf->dmpi->width;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
135 mpi->flags |= MP_IMGFLAG_DIRECT;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
136 mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
137 // vf->dmpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
138 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
139
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
140 static void blank(mp_image_t *mpi, int y1, int y2)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
141 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
142 int color[3] = { 16, 128, 128 }; // black (YUV)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
143 int y;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
144 unsigned char *dst;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
145 int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
146
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
147 dst = mpi->planes[0] + y1 * mpi->stride[0];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
148 for (y = 0; y < y2 - y1; ++y) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
149 memset(dst, color[0], mpi->w);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
150 dst += mpi->stride[0];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
151 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
152 dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
153 for (y = 0; y < chroma_rows; ++y) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
154 memset(dst, color[1], mpi->chroma_width);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
155 dst += mpi->stride[1];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
156 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
157 dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
158 for (y = 0; y < chroma_rows; ++y) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
159 memset(dst, color[2], mpi->chroma_width);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
160 dst += mpi->stride[2];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
161 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
162 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
163
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
164 static int prepare_image(struct vf_instance *vf, mp_image_t *mpi)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
165 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
166 if (mpi->flags & MP_IMGFLAG_DIRECT ||
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
167 mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
168 vf->dmpi = mpi->priv;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
169 if (!vf->dmpi) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
170 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_MPCODECS_FunWhydowegetNULL);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
171 return 0;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
172 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
173 mpi->priv = NULL;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
174 // we've used DR, so we're ready...
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
175 if (ass_top_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
176 blank(vf->dmpi, 0, ass_top_margin);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
177 if (ass_bottom_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
178 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
179 if (!(mpi->flags & MP_IMGFLAG_PLANAR))
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
180 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
181 return 0;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
182 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
183 // hope we'll get DR buffer:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
184 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
185 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
186 vf->priv->outw, vf->priv->outh);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
187
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
188 // copy mpi->dmpi...
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
189 if (mpi->flags & MP_IMGFLAG_PLANAR) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
190 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
191 mpi->planes[0],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
192 mpi->w,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
193 mpi->h,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
194 vf->dmpi->stride[0],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
195 mpi->stride[0]);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
196 memcpy_pic(vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
197 mpi->planes[1],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
198 mpi->w >> mpi->chroma_x_shift,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
199 mpi->h >> mpi->chroma_y_shift,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
200 vf->dmpi->stride[1],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
201 mpi->stride[1]);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
202 memcpy_pic(vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
203 mpi->planes[2],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
204 mpi->w >> mpi->chroma_x_shift,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
205 mpi->h >> mpi->chroma_y_shift,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
206 vf->dmpi->stride[2],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
207 mpi->stride[2]);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
208 } else {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
209 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
210 mpi->planes[0],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
211 mpi->w * (vf->dmpi->bpp / 8),
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
212 mpi->h,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
213 vf->dmpi->stride[0],
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
214 mpi->stride[0]);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
215 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
216 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
217 if (ass_top_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
218 blank(vf->dmpi, 0, ass_top_margin);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
219 if (ass_bottom_margin)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
220 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
221 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
222 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
223
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
224 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
225 * \brief Copy specified rows from render_context.dmpi to render_context.planes, upsampling to 4:4:4
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
226 */
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
227 static void copy_from_image(struct vf_instance *vf, int first_row,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
228 int last_row)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
229 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
230 int pl;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
231 int i, j, k;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
232 unsigned char val;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
233 int chroma_rows;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
234
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
235 first_row -= (first_row % 2);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
236 last_row += (last_row % 2);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
237 chroma_rows = (last_row - first_row) / 2;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
238
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
239 assert(first_row >= 0);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
240 assert(first_row <= last_row);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
241 assert(last_row <= vf->priv->outh);
29383
e9cab9f6ed62 Make sure clip coordinates are inside the screen area.
eugeni
parents: 29263
diff changeset
242
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
243 for (pl = 1; pl < 3; ++pl) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
244 int dst_stride = vf->priv->outw;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
245 int src_stride = vf->dmpi->stride[pl];
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
246
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
247 unsigned char *src = vf->dmpi->planes[pl] + (first_row / 2) * src_stride;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
248 unsigned char *dst = vf->priv->planes[pl] + first_row * dst_stride;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
249 unsigned char *dst_next = dst + dst_stride;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
250 for (i = 0; i < chroma_rows; ++i) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
251 if ((vf->priv->dirty_rows[first_row + i * 2 ] == 0) ||
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
252 (vf->priv->dirty_rows[first_row + i * 2 + 1] == 0)) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
253 for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k += 2) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
254 val = *(src + j);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
255 *(dst + k ) = val;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
256 *(dst + k + 1) = val;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
257 *(dst_next + k ) = val;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
258 *(dst_next + k + 1) = val;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
259 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
260 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
261 src += src_stride;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
262 dst = dst_next + dst_stride;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
263 dst_next = dst + dst_stride;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
264 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
265 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
266 for (i = first_row; i < last_row; ++i)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
267 vf->priv->dirty_rows[i] = 1;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
268 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
269
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
270 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
271 * \brief Copy all previously copied rows back to render_context.dmpi
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
272 */
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
273 static void copy_to_image(struct vf_instance *vf)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
274 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
275 int pl;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
276 int i, j, k;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
277 for (pl = 1; pl < 3; ++pl) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
278 int dst_stride = vf->dmpi->stride[pl];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
279 int src_stride = vf->priv->outw;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
280
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
281 unsigned char *dst = vf->dmpi->planes[pl];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
282 unsigned char *src = vf->priv->planes[pl];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
283 unsigned char *src_next = vf->priv->planes[pl] + src_stride;
34885
e8af23854aa1 Use correct variable for height.
reimar
parents: 34883
diff changeset
284 for (i = 0; i < vf->priv->outh / 2; ++i) {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
285 if ((vf->priv->dirty_rows[i * 2] == 1)) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
286 assert(vf->priv->dirty_rows[i * 2 + 1] == 1);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
287 for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k += 2) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
288 unsigned val = 0;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
289 val += *(src + k);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
290 val += *(src + k + 1);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
291 val += *(src_next + k);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
292 val += *(src_next + k + 1);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
293 *(dst + j) = val >> 2;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
294 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
295 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
296 dst += dst_stride;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
297 src = src_next + src_stride;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
298 src_next = src + src_stride;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
299 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
300 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
301 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
302
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
303 static void my_draw_bitmap(struct vf_instance *vf, unsigned char *bitmap,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
304 int bitmap_w, int bitmap_h, int stride,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
305 int dst_x, int dst_y, unsigned color)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
306 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
307 unsigned char y = rgba2y(color);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
308 unsigned char u = rgba2u(color);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
309 unsigned char v = rgba2v(color);
32261
0dd2b27940b5 vf_ass: avoid divisions in alpha blending.
cigaes
parents: 32226
diff changeset
310 unsigned opacity = 255 - _a(color);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
311 unsigned char *src, *dsty, *dstu, *dstv;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
312 int i, j;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
313 mp_image_t *dmpi = vf->dmpi;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
314
32261
0dd2b27940b5 vf_ass: avoid divisions in alpha blending.
cigaes
parents: 32226
diff changeset
315 opacity = (0x10203 * opacity + 0x80) >> 8; /* 0x10203 = (1<<32)/(255*255) */
0dd2b27940b5 vf_ass: avoid divisions in alpha blending.
cigaes
parents: 32226
diff changeset
316 /* 0 <= opacity <= 0x10101 */
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
317 src = bitmap;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
318 dsty = dmpi->planes[0] + dst_x + dst_y * dmpi->stride[0];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
319 dstu = vf->priv->planes[1] + dst_x + dst_y * vf->priv->outw;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
320 dstv = vf->priv->planes[2] + dst_x + dst_y * vf->priv->outw;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
321 for (i = 0; i < bitmap_h; ++i) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
322 for (j = 0; j < bitmap_w; ++j) {
32226
808e9d7eef5d vf_ass: skip alpha blending for pixels where alpha is zero.
cigaes
parents: 32209
diff changeset
323 unsigned k = src[j];
808e9d7eef5d vf_ass: skip alpha blending for pixels where alpha is zero.
cigaes
parents: 32209
diff changeset
324 if (!k)
808e9d7eef5d vf_ass: skip alpha blending for pixels where alpha is zero.
cigaes
parents: 32209
diff changeset
325 continue;
32261
0dd2b27940b5 vf_ass: avoid divisions in alpha blending.
cigaes
parents: 32226
diff changeset
326 k *= opacity; /* 0 <= k <= 0xFFFFFF */
0dd2b27940b5 vf_ass: avoid divisions in alpha blending.
cigaes
parents: 32226
diff changeset
327 dsty[j] = (k * y + (0xFFFFFF - k) * dsty[j] + 0x800000) >> 24;
0dd2b27940b5 vf_ass: avoid divisions in alpha blending.
cigaes
parents: 32226
diff changeset
328 dstu[j] = (k * u + (0xFFFFFF - k) * dstu[j] + 0x800000) >> 24;
0dd2b27940b5 vf_ass: avoid divisions in alpha blending.
cigaes
parents: 32226
diff changeset
329 dstv[j] = (k * v + (0xFFFFFF - k) * dstv[j] + 0x800000) >> 24;
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
330 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
331 src += stride;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
332 dsty += dmpi->stride[0];
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
333 dstu += vf->priv->outw;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
334 dstv += vf->priv->outw;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
335 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
336 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
337
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
338 static void render_frame(struct vf_instance *vf, mp_image_t *mpi,
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
339 struct mp_eosd_image_list *images)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
340 {
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
341 struct mp_eosd_image *img;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
342 img = eosd_image_first(images);
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
343 if (!img)
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
344 return;
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
345 memset(vf->priv->dirty_rows, 0, vf->priv->outh); // reset dirty rows
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
346 while (img) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
347 copy_from_image(vf, img->dst_y, img->dst_y + img->h);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
348 my_draw_bitmap(vf, img->bitmap, img->w, img->h, img->stride,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
349 img->dst_x, img->dst_y, img->color);
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
350 img = eosd_image_next(images);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
351 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
352 copy_to_image(vf);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
353 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
354
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
355 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
356 {
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
357 struct mp_eosd_image_list images;
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
358 eosd_render_frame(pts, &images);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
359 prepare_image(vf, mpi);
32391
b4c3659d16b1 Use a dynamic list for the sources of EOSD elements.
cigaes
parents: 32261
diff changeset
360 render_frame(vf, mpi, &images);
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
361 return vf_next_put_image(vf, vf->dmpi, pts);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
362 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
363
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
364 static int query_format(struct vf_instance *vf, unsigned int fmt)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
365 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
366 switch (fmt) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
367 case IMGFMT_YV12:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
368 case IMGFMT_I420:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
369 case IMGFMT_IYUV:
35033
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
370 return vf_next_query_format(vf, fmt) | VFCAP_EOSD;
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
371 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
372 return 0;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
373 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
374
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
375 static int control(vf_instance_t *vf, int request, void *data)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
376 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
377 switch (request) {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
378 case VFCTRL_INIT_EOSD:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
379 return CONTROL_TRUE;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
380 case VFCTRL_DRAW_EOSD:
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
381 return CONTROL_TRUE;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
382 }
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
383 return vf_next_control(vf, request, data);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
384 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
385
30642
a972c1a4a012 cosmetics: Rename struct vf_instance_s --> vf_instance.
diego
parents: 30638
diff changeset
386 static void uninit(struct vf_instance *vf)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
387 {
32537
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 32467
diff changeset
388 free(vf->priv->planes[1]);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 32467
diff changeset
389 free(vf->priv->planes[2]);
8fa2f43cb760 Remove most of the NULL pointer check before free all over the code
cboesch
parents: 32467
diff changeset
390 free(vf->priv->dirty_rows);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
391 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
392
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
393 static const unsigned int fmt_list[] = {
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
394 IMGFMT_YV12,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
395 IMGFMT_I420,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
396 IMGFMT_IYUV,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
397 0
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
398 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
399
30638
a7b908875c14 Rename open() vf initialization function to vf_open().
diego
parents: 30633
diff changeset
400 static int vf_open(vf_instance_t *vf, char *args)
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
401 {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
402 int flags;
35033
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
403 unsigned outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12);
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
404 if (outfmt)
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
405 flags = vf_next_query_format(vf, outfmt);
387485e3956a vf_ass: Improve format query.
reimar
parents: 34885
diff changeset
406 if (!outfmt || (vf->priv->auto_insert && flags & VFCAP_EOSD)) {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
407 uninit(vf);
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
408 return 0;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
409 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
410
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
411 if (vf->priv->auto_insert)
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
412 mp_msg(MSGT_ASS, MSGL_INFO, "[ass] auto-open\n");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
413
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
414 vf->config = config;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
415 vf->query_format = query_format;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
416 vf->uninit = uninit;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
417 vf->control = control;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
418 vf->get_image = get_image;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
419 vf->put_image = put_image;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
420 vf->default_caps = VFCAP_EOSD;
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
421 return 1;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
422 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
423
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
424 #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
425 static const m_option_t vf_opts_fields[] = {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
426 {"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
427 {NULL, NULL, 0, 0, 0, 0, NULL}
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
428 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
429
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
430 static const m_struct_t vf_opts = {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
431 "ass",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
432 sizeof(struct vf_priv_s),
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
433 &vf_priv_dflt,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
434 vf_opts_fields
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
435 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
436
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
437 const vf_info_t vf_info_ass = {
32096
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
438 "Render ASS/SSA subtitles",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
439 "ass",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
440 "Evgeniy Stepanov",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
441 "",
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
442 vf_open,
06519a2a9c77 cosmetics: Reformat in K&R style, prettyprinting.
diego
parents: 31927
diff changeset
443 &vf_opts
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
444 };