annotate libmpcodecs/vf_ass.c @ 19689:b187da3ed321

fix charset issues and a little wording
author kraymer
date Tue, 05 Sep 2006 16:09:49 +0000
parents 661d6c8a4adb
children fa122b7c71c6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
1 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
2
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
3 #include <stdio.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
4 #include <stdlib.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
5 #include <string.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
6 #include <stdint.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
7 #include <assert.h>
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
8
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
9 #include "config.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
10 #include "mp_msg.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
11 #include "help_mp.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
12
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
13 #include "img_format.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
14 #include "mp_image.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
15 #include "vf.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
16
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
17 #include "libvo/fastmemcpy.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
18
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
19 #include "m_option.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
20 #include "m_struct.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
21
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
22 #include "libass/ass.h"
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
23 #include "libass/ass_mp.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 #define _r(c) ((c)>>24)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
26 #define _g(c) (((c)>>16)&0xFF)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
27 #define _b(c) (((c)>>8)&0xFF)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
28 #define _a(c) ((c)&0xFF)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
29 #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
30 #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
31 #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
32
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
33
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
34 static struct vf_priv_s {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
35 int outh, outw;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
36
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
37 unsigned int outfmt;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
38
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
39 // 1 = auto-added filter: insert only if chain does not support EOSD already
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
40 // 0 = insert always
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
41 int auto_insert;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
42
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
43 ass_instance_t* ass_priv;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
44
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
45 unsigned char* planes[3];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
46 unsigned char* dirty_rows;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
47 } vf_priv_dflt;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
48
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
49 extern int opt_screen_size_x;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
50 extern int opt_screen_size_y;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
51
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
52 extern ass_track_t* ass_track;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
53 extern float sub_delay;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
54 extern int sub_visibility;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
55
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
56 static int config(struct vf_instance_s* vf,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
57 int width, int height, int d_width, int d_height,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
58 unsigned int flags, 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 ass_settings_t settings;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
61
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
62 if (outfmt == IMGFMT_IF09) return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
63
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
64 vf->priv->outh = height + ass_top_margin + ass_bottom_margin;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
65 vf->priv->outw = width;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
66
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
67 if(!opt_screen_size_x && !opt_screen_size_y){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
68 d_width = d_width * vf->priv->outw / width;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
69 d_height = d_height * vf->priv->outh / height;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
70 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
71
19065
26ed3fcd5cd4 drops casts from void * on malloc/calloc, leftover on libmpcodecs
reynaldo
parents: 18937
diff changeset
72 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
73 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
74 vf->priv->dirty_rows = malloc(vf->priv->outh);
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
75
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
76 if (vf->priv->ass_priv) {
19550
ec7090509b38 Zero fill ass_settings_t before use.
eugeni
parents: 19521
diff changeset
77 memset(&settings, 0, sizeof(ass_settings_t));
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
78 settings.frame_width = vf->priv->outw;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
79 settings.frame_height = vf->priv->outh;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
80 settings.font_size_coeff = ass_font_scale;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
81 settings.line_spacing = ass_line_spacing;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
82 settings.top_margin = ass_top_margin;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
83 settings.bottom_margin = ass_bottom_margin;
19563
661d6c8a4adb Add -(no)ass-use-margins option.
eugeni
parents: 19550
diff changeset
84 settings.use_margins = ass_use_margins;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
85 settings.aspect = ((double)d_width) / d_height;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
86
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
87 ass_configure(vf->priv->ass_priv, &settings);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
88 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
89
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
90 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
91 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
92
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
93 static void get_image(struct vf_instance_s* vf, mp_image_t *mpi)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
94 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
95 if(mpi->type == MP_IMGTYPE_IPB) return;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
96 if(mpi->flags & MP_IMGFLAG_PRESERVE) return;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
97 if(mpi->imgfmt != vf->priv->outfmt) return; // colorspace differ
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
98
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
99 // width never changes, always try full DR
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
100 mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
101 mpi->type, mpi->flags,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
102 vf->priv->outw,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
103 vf->priv->outh);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
104
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
105 if((vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) &&
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
106 !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
107 mp_msg(MSGT_VFILTER, MSGL_INFO, MSGTR_MPCODECS_FullDRNotPossible);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
108 return;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
109 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
110
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
111 // set up mpi as a cropped-down image of dmpi:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
112 if(mpi->flags&MP_IMGFLAG_PLANAR){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
113 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
114 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
115 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
116 mpi->stride[1]=vf->dmpi->stride[1];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
117 mpi->stride[2]=vf->dmpi->stride[2];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
118 } else {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
119 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
120 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
121 mpi->stride[0]=vf->dmpi->stride[0];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
122 mpi->width=vf->dmpi->width;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
123 mpi->flags|=MP_IMGFLAG_DIRECT;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
124 mpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
125 // vf->dmpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
126 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
127
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
128 static void blank(mp_image_t *mpi, int y1, int y2)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
129 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
130 int color[3] = {16, 128, 128}; // black (YUV)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
131 int y;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
132 unsigned char* dst;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
133 int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
134
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
135 dst = mpi->planes[0] + y1 * mpi->stride[0];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
136 for (y = 0; y < y2 - y1; ++y) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
137 memset(dst, color[0], mpi->w);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
138 dst += mpi->stride[0];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
139 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
140 dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
141 for (y = 0; y < chroma_rows ; ++y) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
142 memset(dst, color[1], mpi->chroma_width);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
143 dst += mpi->stride[1];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
144 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
145 dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
146 for (y = 0; y < chroma_rows ; ++y) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
147 memset(dst, color[2], mpi->chroma_width);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
148 dst += mpi->stride[2];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
149 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
150 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
151
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
152 static int prepare_image(struct vf_instance_s* vf, mp_image_t *mpi)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
153 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
154 if(mpi->flags&MP_IMGFLAG_DIRECT || mpi->flags&MP_IMGFLAG_DRAW_CALLBACK){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
155 vf->dmpi = mpi->priv;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
156 if (!vf->dmpi) { mp_msg(MSGT_VFILTER, MSGL_WARN, MSGTR_MPCODECS_FunWhydowegetNULL); return 0; }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
157 mpi->priv = NULL;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
158 // we've used DR, so we're ready...
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
159 if (ass_top_margin)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
160 blank(vf->dmpi, 0, ass_top_margin);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
161 if (ass_bottom_margin)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
162 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
163 if(!(mpi->flags&MP_IMGFLAG_PLANAR))
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
164 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
165 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
166 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
167
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
168 // hope we'll get DR buffer:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
169 vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
170 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
171 vf->priv->outw, vf->priv->outh);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
172
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
173 // copy mpi->dmpi...
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
174 if(mpi->flags&MP_IMGFLAG_PLANAR){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
175 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
176 mpi->planes[0], mpi->w, mpi->h,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
177 vf->dmpi->stride[0], mpi->stride[0]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
178 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
179 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
180 vf->dmpi->stride[1], mpi->stride[1]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
181 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
182 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
183 vf->dmpi->stride[2], mpi->stride[2]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
184 } else {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
185 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
186 mpi->planes[0], mpi->w*(vf->dmpi->bpp/8), mpi->h,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
187 vf->dmpi->stride[0], mpi->stride[0]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
188 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
189 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
190 if (ass_top_margin)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
191 blank(vf->dmpi, 0, ass_top_margin);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
192 if (ass_bottom_margin)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
193 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
194 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
195 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
196
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
197 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
198 * \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
199 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
200 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
201 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
202 int pl;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
203 int i, j, k;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
204 unsigned char val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
205 int chroma_rows;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
206
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
207 first_row -= (first_row % 2);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
208 last_row += (last_row % 2);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
209 chroma_rows = (last_row - first_row) / 2;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
210
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
211 for (pl = 1; pl < 3; ++pl) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
212 int dst_stride = vf->dmpi->stride[pl] * 2;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
213 int src_stride = vf->dmpi->stride[pl];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
214
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
215 unsigned char* src = vf->dmpi->planes[pl] + (first_row/2) * src_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
216 unsigned char* dst = vf->priv->planes[pl] + first_row * dst_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
217 unsigned char* dst_next = dst + dst_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
218 for(i = 0; i < chroma_rows; ++i)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
219 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
220 if ((vf->priv->dirty_rows[first_row + i*2] == 0) ||
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
221 (vf->priv->dirty_rows[first_row + i*2 + 1] == 0)) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
222 for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k+=2) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
223 val = *(src + j);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
224 *(dst + k) = val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
225 *(dst + k + 1) = val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
226 *(dst_next + k) = val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
227 *(dst_next + k + 1) = val;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
228 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
229 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
230 src += src_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
231 dst = dst_next + dst_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
232 dst_next = dst + dst_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
233 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
234 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
235 for (i = first_row; i < last_row; ++i)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
236 vf->priv->dirty_rows[i] = 1;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
237 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
238
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
239 /**
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
240 * \brief Copy all previously copied rows back to render_context.dmpi
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
241 */
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
242 static void copy_to_image(struct vf_instance_s* vf)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
243 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
244 int pl;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
245 int i, j, k;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
246 for (pl = 1; pl < 3; ++pl) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
247 int dst_stride = vf->dmpi->stride[pl];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
248 int src_stride = vf->dmpi->stride[pl] * 2;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
249
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
250 unsigned char* dst = vf->dmpi->planes[pl];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
251 unsigned char* src = vf->priv->planes[pl];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
252 unsigned char* src_next = vf->priv->planes[pl] + src_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
253 for(i = 0; i < vf->dmpi->chroma_height; ++i)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
254 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
255 if ((vf->priv->dirty_rows[i*2] == 1)) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
256 assert(vf->priv->dirty_rows[i*2 + 1] == 1);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
257 for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k+=2) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
258 unsigned val = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
259 val += *(src + k);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
260 val += *(src + k + 1);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
261 val += *(src_next + k);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
262 val += *(src_next + k + 1);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
263 *(dst + j) = val >> 2;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
264 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
265 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
266 dst += dst_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
267 src = src_next + src_stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
268 src_next = src + src_stride;
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 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
272
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
273 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
274 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
275 unsigned char y = rgba2y(color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
276 unsigned char u = rgba2u(color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
277 unsigned char v = rgba2v(color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
278 unsigned char opacity = 255 - _a(color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
279 unsigned char* src;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
280 unsigned char* dst;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
281 int i, j;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
282 mp_image_t* dmpi = vf->dmpi;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
283
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
284
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
285 src = bitmap;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
286 dst = dmpi->planes[0] + dst_x + dst_y * dmpi->stride[0];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
287 for(i = 0; i < bitmap_h; ++i)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
288 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
289 for (j = 0; j < bitmap_w; ++j) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
290 // unsigned k = *(src+j);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
291 unsigned k = ((unsigned)*(bitmap + stride * i + j)) * opacity / 255;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
292 unsigned char orig_color = *(dst+j);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
293 *(dst+j) = (k*y + (255-k)*orig_color) / 255;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
294 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
295 src += stride;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
296 dst += dmpi->stride[0];
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
297 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
298
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
299 for (i = 0; i < bitmap_h; ++i) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
300 for (j = 0; j < bitmap_w; ++j) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
301 int x = dst_x + j;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
302 int y = dst_y + i;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
303 unsigned k;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
304 unsigned char orig_u, orig_v;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
305 unsigned char new_u, new_v;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
306
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
307 k = ((unsigned)*(bitmap + stride * i + j)) * opacity / 255;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
308
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
309 orig_u = *(vf->priv->planes[1] + x + y * 2 * dmpi->chroma_width);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
310 new_u = (k*u + (255-k)*orig_u) / 255;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
311 *(vf->priv->planes[1] + x + y * 2 * dmpi->chroma_width) = new_u;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
312
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
313 orig_v = *(vf->priv->planes[2] + x + y * 2 * dmpi->chroma_width);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
314 new_v = (k*v + (255-k)*orig_v) / 255;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
315 *(vf->priv->planes[2] + x + y * 2 * dmpi->chroma_width) = new_v;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
316 }
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
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
320 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
321 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
322 if (img) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
323 memset(vf->priv->dirty_rows, 0, vf->priv->outh); // reset dirty rows
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
324 while (img) {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
325 copy_from_image(vf, img->dst_y, img->dst_y + img->h);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
326 my_draw_bitmap(vf, img->bitmap, img->w, img->h, img->stride,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
327 img->dst_x, img->dst_y, img->color);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
328 img = img->next;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
329 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
330 copy_to_image(vf);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
331 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
332 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
333 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
334
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
335 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
336 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
337 ass_image_t* images = 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
338 if (sub_visibility && vf->priv->ass_priv && ass_track && (pts != MP_NOPTS_VALUE))
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
339 images = ass_render_frame(vf->priv->ass_priv, ass_track, (pts+sub_delay) * 1000 + .5);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
340
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
341 prepare_image(vf, mpi);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
342 if (images) render_frame(vf, mpi, images);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
343
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
344 return vf_next_put_image(vf, vf->dmpi, pts);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
345 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
346
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
347 static int query_format(struct vf_instance_s* vf, unsigned int fmt)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
348 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
349 switch(fmt){
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
350 case IMGFMT_YV12:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
351 case IMGFMT_I420:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
352 case IMGFMT_IYUV:
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
353 return vf_next_query_format(vf, vf->priv->outfmt);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
354 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
355 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
356 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
357
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
358 static int control(vf_instance_t *vf, int request, void *data)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
359 {
19521
0be2d3583f4f Add VFCTRL_DRAW_EOSD.
eugeni
parents: 19517
diff changeset
360 switch (request) {
0be2d3583f4f Add VFCTRL_DRAW_EOSD.
eugeni
parents: 19517
diff changeset
361 case VFCTRL_INIT_EOSD:
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
362 vf->priv->ass_priv = ass_init();
19517
2f5e66e7bdcc Simplify vf_ass initialization.
eugeni
parents: 19341
diff changeset
363 return vf->priv->ass_priv ? CONTROL_TRUE : CONTROL_FALSE;
19521
0be2d3583f4f Add VFCTRL_DRAW_EOSD.
eugeni
parents: 19517
diff changeset
364 case VFCTRL_DRAW_EOSD:
0be2d3583f4f Add VFCTRL_DRAW_EOSD.
eugeni
parents: 19517
diff changeset
365 if (vf->priv->ass_priv) return CONTROL_TRUE;
0be2d3583f4f Add VFCTRL_DRAW_EOSD.
eugeni
parents: 19517
diff changeset
366 break;
18937
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
367 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
368 return vf_next_control(vf, request, data);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
369 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
370
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
371 static void uninit(struct vf_instance_s* vf)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
372 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
373 if (vf->priv->ass_priv)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
374 ass_done(vf->priv->ass_priv);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
375 if (vf->priv->planes[1])
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
376 free(vf->priv->planes[1]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
377 if (vf->priv->planes[2])
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
378 free(vf->priv->planes[2]);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
379 if (vf->priv->dirty_rows)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
380 free(vf->priv->dirty_rows);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
381 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
382
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
383 static unsigned int fmt_list[]={
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
384 IMGFMT_YV12,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
385 IMGFMT_I420,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
386 IMGFMT_IYUV,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
387 0
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
388 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
389
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
390 static int open(vf_instance_t *vf, char* args)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
391 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
392 int flags;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
393 vf->priv->outfmt = vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
394 if (vf->priv->outfmt)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
395 flags = vf_next_query_format(vf, vf->priv->outfmt);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
396 if (!vf->priv->outfmt || (vf->priv->auto_insert && flags&VFCAP_EOSD))
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
397 {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
398 uninit(vf);
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
399 return 0;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
400 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
401
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
402 if (vf->priv->auto_insert)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
403 mp_msg(MSGT_VFILTER, MSGL_INFO, "[ass] auto-open\n");
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
404
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
405 vf->config = config;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
406 vf->query_format = query_format;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
407 vf->uninit = uninit;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
408 vf->control = control;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
409 vf->get_image = get_image;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
410 vf->put_image = put_image;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
411 vf->default_caps=VFCAP_EOSD;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
412 return 1;
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
413 }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
414
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
415 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
416 static m_option_t vf_opts_fields[] = {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
417 {"auto", ST_OFF(auto_insert), CONF_TYPE_FLAG, 0 , 0, 1, NULL},
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
418 { NULL, NULL, 0, 0, 0, 0, NULL }
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
419 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
420
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
421 static m_struct_t vf_opts = {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
422 "ass",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
423 sizeof(struct vf_priv_s),
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
424 &vf_priv_dflt,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
425 vf_opts_fields
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
426 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
427
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
428 vf_info_t vf_info_ass = {
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
429 "Render ASS/SSA subtitles",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
430 "ass",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
431 "Evgeniy Stepanov",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
432 "",
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
433 open,
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
434 &vf_opts
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
435 };
9e95ac641e77 Initial libass release (without mencoder support).
eugeni
parents:
diff changeset
436