annotate libmpcodecs/vf_ass.c @ 30101:c5b6cd54fa0a

Make the ffmpeg decoders for DTS and AC3 the default.
author reimar
date Wed, 30 Dec 2009 19:30:06 +0000
parents d5d20b8256b7
children 595410bd114e
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 // -*- c-basic-offset: 8; indent-tabs-mode: t -*-
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19563
diff changeset
2 // vim:ts=8:sw=8:noet:ai:
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19563
diff changeset
3 /*
26727
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
4 * Copyright (C) 2006 Evgeniy Stepanov <eugeni.stepanov@gmail.com>
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
5 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
6 * This file is part of MPlayer.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
7 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
8 * MPlayer is free software; you can redistribute it and/or modify
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
9 * it under the terms of the GNU General Public License as published by
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
11 * (at your option) any later version.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
12 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
13 * MPlayer is distributed in the hope that it will be useful,
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
16 * GNU General Public License for more details.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
17 *
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
18 * You should have received a copy of the GNU General Public License along
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
19 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
82601a38e2a7 Use standard license headers.
diego
parents: 25813
diff changeset
21 */
20008
fa122b7c71c6 Add copyright notice and vim/emacs comments to libass and vf_ass.c.
eugeni
parents: 19563
diff changeset
22
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
24
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
25 #include <stdio.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
26 #include <stdlib.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
27 #include <string.h>
24545
9e5126679d44 Replace stdint.h #include by functionally equivalent inttypes.h.
diego
parents: 23134
diff changeset
28 #include <inttypes.h>
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
29 #include <assert.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
30
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
31 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
32 #include "mp_msg.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
33 #include "help_mp.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
34
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
35 #include "img_format.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
36 #include "mp_image.h"
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"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
40
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
41 #include "m_option.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
42 #include "m_struct.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
43
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
44 #include "libass/ass_mp.h"
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)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
50 #define rgba2y(c) ( (( 263*_r(c) + 516*_g(c) + 100*_b(c)) >> 10) + 16 )
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 {
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
56 int outh, outw;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
57
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
58 unsigned int outfmt;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
59
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
60 // 1 = auto-added filter: insert only if chain does not support EOSD already
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
61 // 0 = insert always
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
62 int auto_insert;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
63
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents: 20446
diff changeset
64 ass_renderer_t* ass_priv;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
65
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
66 unsigned char* planes[3];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
67 unsigned char* dirty_rows;
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
68 } vf_priv_dflt;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
69
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
70 extern int opt_screen_size_x;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
71 extern int opt_screen_size_y;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
72
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
73 extern ass_track_t* ass_track;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
74 extern float sub_delay;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
75 extern int sub_visibility;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
76
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
77 static int config(struct vf_instance_s* vf,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
78 int width, int height, int d_width, int d_height,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
79 unsigned int flags, unsigned int outfmt)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
80 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
81 if (outfmt == IMGFMT_IF09) return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
82
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
83 vf->priv->outh = height + ass_top_margin + ass_bottom_margin;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
84 vf->priv->outw = width;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
85
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
86 if(!opt_screen_size_x && !opt_screen_size_y){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
87 d_width = d_width * vf->priv->outw / width;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
88 d_height = d_height * vf->priv->outh / height;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
89 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
90
19065
26ed3fcd5cd4 drops casts from void * on malloc/calloc, leftover on libmpcodecs
reynaldo
parents: 18937
diff changeset
91 vf->priv->planes[1] = malloc(vf->priv->outw * vf->priv->outh);
26ed3fcd5cd4 drops casts from void * on malloc/calloc, leftover on libmpcodecs
reynaldo
parents: 18937
diff changeset
92 vf->priv->planes[2] = malloc(vf->priv->outw * vf->priv->outh);
26ed3fcd5cd4 drops casts from void * on malloc/calloc, leftover on libmpcodecs
reynaldo
parents: 18937
diff changeset
93 vf->priv->dirty_rows = malloc(vf->priv->outh);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
94
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
95 if (vf->priv->ass_priv) {
23134
1de2a46a0987 Add -ass-hinting option for setting font hinting method.
eugeni
parents: 22027
diff changeset
96 ass_configure(vf->priv->ass_priv, vf->priv->outw, vf->priv->outh, 0);
30065
d5d20b8256b7 Some ugly hacks to make compiling against a newer external version of libass work.
reimar
parents: 30063
diff changeset
97 #if defined(LIBASS_VERSION) && LIBASS_VERSION >= 0x00908000
d5d20b8256b7 Some ugly hacks to make compiling against a newer external version of libass work.
reimar
parents: 30063
diff changeset
98 ass_set_aspect_ratio(vf->priv->ass_priv, ((double)d_width) / d_height, ((double)width) / height);
d5d20b8256b7 Some ugly hacks to make compiling against a newer external version of libass work.
reimar
parents: 30063
diff changeset
99 #else
20446
e8adc3778348 Split ass_configure() into several smaller functions.
eugeni
parents: 20012
diff changeset
100 ass_set_aspect_ratio(vf->priv->ass_priv, ((double)d_width) / d_height);
30065
d5d20b8256b7 Some ugly hacks to make compiling against a newer external version of libass work.
reimar
parents: 30063
diff changeset
101 #endif
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
102 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
103
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
104 return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, d_height, flags, outfmt);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
105 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
106
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
107 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
108 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
109 if(mpi->type == MP_IMGTYPE_IPB) return;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
110 if(mpi->flags & MP_IMGFLAG_PRESERVE) return;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
111 if(mpi->imgfmt != vf->priv->outfmt) return; // colorspace differ
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
112
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
113 // width never changes, always try full DR
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
114 mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt,
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
115 mpi->type, mpi->flags | MP_IMGFLAG_READABLE,
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
116 vf->priv->outw,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
117 vf->priv->outh);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
118
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
119 if((vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) &&
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
120 !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)){
20629
e8885ec63928 Introduce MSGT_ASS, use it for all libass messages.
eugeni
parents: 20477
diff changeset
121 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_MPCODECS_FullDRNotPossible);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
122 return;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
123 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
124
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
125 // set up mpi as a cropped-down image of dmpi:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
126 if(mpi->flags&MP_IMGFLAG_PLANAR){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
127 mpi->planes[0]=vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
128 mpi->planes[1]=vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
129 mpi->planes[2]=vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
130 mpi->stride[1]=vf->dmpi->stride[1];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
131 mpi->stride[2]=vf->dmpi->stride[2];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
132 } else {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
133 mpi->planes[0]=vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
134 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
135 mpi->stride[0]=vf->dmpi->stride[0];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
136 mpi->width=vf->dmpi->width;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
137 mpi->flags|=MP_IMGFLAG_DIRECT;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
138 mpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
139 // vf->dmpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
140 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
141
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
142 static void blank(mp_image_t *mpi, int y1, int y2)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
143 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
144 int color[3] = {16, 128, 128}; // black (YUV)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
145 int y;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
146 unsigned char* dst;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
147 int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
148
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
149 dst = mpi->planes[0] + y1 * mpi->stride[0];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
150 for (y = 0; y < y2 - y1; ++y) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
151 memset(dst, color[0], mpi->w);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
152 dst += mpi->stride[0];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
153 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
154 dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
155 for (y = 0; y < chroma_rows ; ++y) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
156 memset(dst, color[1], mpi->chroma_width);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
157 dst += mpi->stride[1];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
158 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
159 dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
160 for (y = 0; y < chroma_rows ; ++y) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
161 memset(dst, color[2], mpi->chroma_width);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
162 dst += mpi->stride[2];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
163 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
164 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
165
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
166 static int prepare_image(struct vf_instance_s* vf, mp_image_t *mpi)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
167 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
168 if(mpi->flags&MP_IMGFLAG_DIRECT || mpi->flags&MP_IMGFLAG_DRAW_CALLBACK){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
169 vf->dmpi = mpi->priv;
20629
e8885ec63928 Introduce MSGT_ASS, use it for all libass messages.
eugeni
parents: 20477
diff changeset
170 if (!vf->dmpi) { mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_MPCODECS_FunWhydowegetNULL); return 0; }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
171 mpi->priv = NULL;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
172 // we've used DR, so we're ready...
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
173 if (ass_top_margin)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
174 blank(vf->dmpi, 0, ass_top_margin);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
175 if (ass_bottom_margin)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
176 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
177 if(!(mpi->flags&MP_IMGFLAG_PLANAR))
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
178 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
179 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
180 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
181
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
182 // hope we'll get DR buffer:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
183 vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt,
20656
839c48c35ce8 ass renderer absolutely needs readable target mpi.
reimar
parents: 20629
diff changeset
184 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE,
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
185 vf->priv->outw, vf->priv->outh);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
186
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
187 // copy mpi->dmpi...
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
188 if(mpi->flags&MP_IMGFLAG_PLANAR){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
189 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
190 mpi->planes[0], mpi->w, mpi->h,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
191 vf->dmpi->stride[0], mpi->stride[0]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
192 memcpy_pic(vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1],
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
193 mpi->planes[1], mpi->w >> mpi->chroma_x_shift, mpi->h >> mpi->chroma_y_shift,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
194 vf->dmpi->stride[1], mpi->stride[1]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
195 memcpy_pic(vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2],
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
196 mpi->planes[2], mpi->w >> mpi->chroma_x_shift, mpi->h >> mpi->chroma_y_shift,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
197 vf->dmpi->stride[2], mpi->stride[2]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
198 } else {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
199 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
200 mpi->planes[0], mpi->w*(vf->dmpi->bpp/8), mpi->h,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
201 vf->dmpi->stride[0], mpi->stride[0]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
202 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
203 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
204 if (ass_top_margin)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
205 blank(vf->dmpi, 0, ass_top_margin);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
206 if (ass_bottom_margin)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
207 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
208 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
209 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
210
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
211 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
212 * \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
213 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
214 static void copy_from_image(struct vf_instance_s* vf, int first_row, int last_row)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
215 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
216 int pl;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
217 int i, j, k;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
218 unsigned char val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
219 int chroma_rows;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
220
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
221 first_row -= (first_row % 2);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
222 last_row += (last_row % 2);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
223 chroma_rows = (last_row - first_row) / 2;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
224
29383
e9cab9f6ed62 Make sure clip coordinates are inside the screen area.
eugeni
parents: 29263
diff changeset
225 assert(first_row >= 0);
e9cab9f6ed62 Make sure clip coordinates are inside the screen area.
eugeni
parents: 29263
diff changeset
226 assert(first_row <= last_row);
29406
e1c1e13cb646 Fix stupid, off-by-one, mistakes in assert() expressions.
eugeni
parents: 29383
diff changeset
227 assert(last_row <= vf->priv->outh);
29383
e9cab9f6ed62 Make sure clip coordinates are inside the screen area.
eugeni
parents: 29263
diff changeset
228
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
229 for (pl = 1; pl < 3; ++pl) {
21154
1ac5087585f6 Fix incorrect stride used in vf_ass.
eugeni
parents: 20706
diff changeset
230 int dst_stride = vf->priv->outw;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
231 int src_stride = vf->dmpi->stride[pl];
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
232
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
233 unsigned char* src = vf->dmpi->planes[pl] + (first_row/2) * src_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
234 unsigned char* dst = vf->priv->planes[pl] + first_row * dst_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
235 unsigned char* dst_next = dst + dst_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
236 for(i = 0; i < chroma_rows; ++i)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
237 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
238 if ((vf->priv->dirty_rows[first_row + i*2] == 0) ||
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
239 (vf->priv->dirty_rows[first_row + i*2 + 1] == 0)) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
240 for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k+=2) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
241 val = *(src + j);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
242 *(dst + k) = val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
243 *(dst + k + 1) = val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
244 *(dst_next + k) = val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
245 *(dst_next + k + 1) = val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
246 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
247 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
248 src += src_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
249 dst = dst_next + dst_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
250 dst_next = dst + dst_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
251 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
252 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
253 for (i = first_row; i < last_row; ++i)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
254 vf->priv->dirty_rows[i] = 1;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
255 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
256
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
257 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
258 * \brief Copy all previously copied rows back to render_context.dmpi
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
259 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
260 static void copy_to_image(struct vf_instance_s* vf)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
261 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
262 int pl;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
263 int i, j, k;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
264 for (pl = 1; pl < 3; ++pl) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
265 int dst_stride = vf->dmpi->stride[pl];
21154
1ac5087585f6 Fix incorrect stride used in vf_ass.
eugeni
parents: 20706
diff changeset
266 int src_stride = vf->priv->outw;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
267
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
268 unsigned char* dst = vf->dmpi->planes[pl];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
269 unsigned char* src = vf->priv->planes[pl];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
270 unsigned char* src_next = vf->priv->planes[pl] + src_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
271 for(i = 0; i < vf->dmpi->chroma_height; ++i)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
272 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
273 if ((vf->priv->dirty_rows[i*2] == 1)) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
274 assert(vf->priv->dirty_rows[i*2 + 1] == 1);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
275 for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k+=2) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
276 unsigned val = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
277 val += *(src + k);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
278 val += *(src + k + 1);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
279 val += *(src_next + k);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
280 val += *(src_next + k + 1);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
281 *(dst + j) = val >> 2;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
282 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
283 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
284 dst += dst_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
285 src = src_next + src_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
286 src_next = src + src_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
287 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
288 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
289 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
290
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
291 static void my_draw_bitmap(struct vf_instance_s* vf, unsigned char* bitmap, int bitmap_w, int bitmap_h, int stride, int dst_x, int dst_y, unsigned color)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
292 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
293 unsigned char y = rgba2y(color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
294 unsigned char u = rgba2u(color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
295 unsigned char v = rgba2v(color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
296 unsigned char opacity = 255 - _a(color);
20012
9a2462925e07 Simplify and optimize bitmap blending.
eugeni
parents: 20008
diff changeset
297 unsigned char *src, *dsty, *dstu, *dstv;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
298 int i, j;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
299 mp_image_t* dmpi = vf->dmpi;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
300
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
301 src = bitmap;
20012
9a2462925e07 Simplify and optimize bitmap blending.
eugeni
parents: 20008
diff changeset
302 dsty = dmpi->planes[0] + dst_x + dst_y * dmpi->stride[0];
21154
1ac5087585f6 Fix incorrect stride used in vf_ass.
eugeni
parents: 20706
diff changeset
303 dstu = vf->priv->planes[1] + dst_x + dst_y * vf->priv->outw;
1ac5087585f6 Fix incorrect stride used in vf_ass.
eugeni
parents: 20706
diff changeset
304 dstv = vf->priv->planes[2] + dst_x + dst_y * vf->priv->outw;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
305 for (i = 0; i < bitmap_h; ++i) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
306 for (j = 0; j < bitmap_w; ++j) {
20012
9a2462925e07 Simplify and optimize bitmap blending.
eugeni
parents: 20008
diff changeset
307 unsigned k = ((unsigned)src[j]) * opacity / 255;
9a2462925e07 Simplify and optimize bitmap blending.
eugeni
parents: 20008
diff changeset
308 dsty[j] = (k*y + (255-k)*dsty[j]) / 255;
9a2462925e07 Simplify and optimize bitmap blending.
eugeni
parents: 20008
diff changeset
309 dstu[j] = (k*u + (255-k)*dstu[j]) / 255;
9a2462925e07 Simplify and optimize bitmap blending.
eugeni
parents: 20008
diff changeset
310 dstv[j] = (k*v + (255-k)*dstv[j]) / 255;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
311 }
20012
9a2462925e07 Simplify and optimize bitmap blending.
eugeni
parents: 20008
diff changeset
312 src += stride;
9a2462925e07 Simplify and optimize bitmap blending.
eugeni
parents: 20008
diff changeset
313 dsty += dmpi->stride[0];
21154
1ac5087585f6 Fix incorrect stride used in vf_ass.
eugeni
parents: 20706
diff changeset
314 dstu += vf->priv->outw;
1ac5087585f6 Fix incorrect stride used in vf_ass.
eugeni
parents: 20706
diff changeset
315 dstv += vf->priv->outw;
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
316 }
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
317 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
318
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
319 static int render_frame(struct vf_instance_s* vf, mp_image_t *mpi, const ass_image_t* img)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
320 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
321 if (img) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
322 memset(vf->priv->dirty_rows, 0, vf->priv->outh); // reset dirty rows
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
323 while (img) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
324 copy_from_image(vf, img->dst_y, img->dst_y + img->h);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
325 my_draw_bitmap(vf, img->bitmap, img->w, img->h, img->stride,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
326 img->dst_x, img->dst_y, img->color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
327 img = img->next;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
328 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
329 copy_to_image(vf);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
330 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
331 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
332 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
333
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
334 static int put_image(struct vf_instance_s* vf, mp_image_t *mpi, double pts)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
335 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
336 ass_image_t* images = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
337 if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE))
25813
ba7bd4f7e322 Add global ass_force_reload flag.
eugeni
parents: 24969
diff changeset
338 images = ass_mp_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5, NULL);
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
339
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
340 prepare_image(vf, mpi);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
341 if (images) render_frame(vf, mpi, images);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
342
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
343 return vf_next_put_image(vf, vf->dmpi, pts);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
344 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
345
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
346 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
347 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
348 switch(fmt){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
349 case IMGFMT_YV12:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
350 case IMGFMT_I420:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
351 case IMGFMT_IYUV:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
352 return vf_next_query_format(vf, vf->priv->outfmt);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
353 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
354 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
355 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
356
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
357 static int control(vf_instance_t *vf, int request, void *data)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
358 {
19521
0be2d3583f4f Add VFCTRL_DRAW_EOSD.
eugeni
parents: 19517
diff changeset
359 switch (request) {
0be2d3583f4f Add VFCTRL_DRAW_EOSD.
eugeni
parents: 19517
diff changeset
360 case VFCTRL_INIT_EOSD:
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents: 20446
diff changeset
361 vf->priv->ass_priv = ass_renderer_init((ass_library_t*)data);
20706
6ae01628975f Initialize fontconfig in VFCTRL_INIT_EOSD handler.
eugeni
parents: 20656
diff changeset
362 if (!vf->priv->ass_priv) return CONTROL_FALSE;
6ae01628975f Initialize fontconfig in VFCTRL_INIT_EOSD handler.
eugeni
parents: 20656
diff changeset
363 ass_configure_fonts(vf->priv->ass_priv);
6ae01628975f Initialize fontconfig in VFCTRL_INIT_EOSD handler.
eugeni
parents: 20656
diff changeset
364 return CONTROL_TRUE;
19521
0be2d3583f4f Add VFCTRL_DRAW_EOSD.
eugeni
parents: 19517
diff changeset
365 case VFCTRL_DRAW_EOSD:
0be2d3583f4f Add VFCTRL_DRAW_EOSD.
eugeni
parents: 19517
diff changeset
366 if (vf->priv->ass_priv) return CONTROL_TRUE;
0be2d3583f4f Add VFCTRL_DRAW_EOSD.
eugeni
parents: 19517
diff changeset
367 break;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
368 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
369 return vf_next_control(vf, request, data);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
370 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
371
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
372 static void uninit(struct vf_instance_s* vf)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
373 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
374 if (vf->priv->ass_priv)
20477
de4a66d99f41 Libass interface reworked:
eugeni
parents: 20446
diff changeset
375 ass_renderer_done(vf->priv->ass_priv);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
376 if (vf->priv->planes[1])
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
377 free(vf->priv->planes[1]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
378 if (vf->priv->planes[2])
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
379 free(vf->priv->planes[2]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
380 if (vf->priv->dirty_rows)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
381 free(vf->priv->dirty_rows);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
382 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
383
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
384 static const unsigned int fmt_list[]={
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
385 IMGFMT_YV12,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
386 IMGFMT_I420,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
387 IMGFMT_IYUV,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
388 0
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
389 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
390
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
391 static int open(vf_instance_t *vf, char* args)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
392 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
393 int flags;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
394 vf->priv->outfmt = vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
395 if (vf->priv->outfmt)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
396 flags = vf_next_query_format(vf, vf->priv->outfmt);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
397 if (!vf->priv->outfmt || (vf->priv->auto_insert && flags&VFCAP_EOSD))
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
398 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
399 uninit(vf);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
400 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
401 }
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
402
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
403 if (vf->priv->auto_insert)
20629
e8885ec63928 Introduce MSGT_ASS, use it for all libass messages.
eugeni
parents: 20477
diff changeset
404 mp_msg(MSGT_ASS, MSGL_INFO, "[ass] auto-open\n");
29263
0f1b5b68af32 whitespace cosmetics: Remove all trailing whitespace.
diego
parents: 26727
diff changeset
405
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
406 vf->config = config;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
407 vf->query_format = query_format;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
408 vf->uninit = uninit;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
409 vf->control = control;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
410 vf->get_image = get_image;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
411 vf->put_image = put_image;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
412 vf->default_caps=VFCAP_EOSD;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
413 return 1;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
414 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
415
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
416 #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
417 static const m_option_t vf_opts_fields[] = {
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
418 {"auto", ST_OFF(auto_insert), CONF_TYPE_FLAG, 0 , 0, 1, NULL},
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
419 { NULL, NULL, 0, 0, 0, 0, NULL }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
420 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
421
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
422 static const m_struct_t vf_opts = {
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
423 "ass",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
424 sizeof(struct vf_priv_s),
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
425 &vf_priv_dflt,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
426 vf_opts_fields
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
427 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
428
24969
c2b7ba444ade begin moving const filter data to .text/.rodata sections
rfelker
parents: 24545
diff changeset
429 const vf_info_t vf_info_ass = {
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
430 "Render ASS/SSA subtitles",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
431 "ass",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
432 "Evgeniy Stepanov",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
433 "",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
434 open,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
435 &vf_opts
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
436 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
437