comparison libmpcodecs/vf_ass.c @ 32096:06519a2a9c77

cosmetics: Reformat in K&R style, prettyprinting.
author diego
date Sun, 12 Sep 2010 11:22:42 +0000
parents 6e0b5a97e00f
children 4c2bbab833d1
comparison
equal deleted inserted replaced
32095:96bdac8d878d 32096:06519a2a9c77
48 48
49 #define _r(c) ((c)>>24) 49 #define _r(c) ((c)>>24)
50 #define _g(c) (((c)>>16)&0xFF) 50 #define _g(c) (((c)>>16)&0xFF)
51 #define _b(c) (((c)>>8)&0xFF) 51 #define _b(c) (((c)>>8)&0xFF)
52 #define _a(c) ((c)&0xFF) 52 #define _a(c) ((c)&0xFF)
53 #define rgba2y(c) ( (( 263*_r(c) + 516*_g(c) + 100*_b(c)) >> 10) + 16 ) 53 #define rgba2y(c) ( (( 263*_r(c) + 516*_g(c) + 100*_b(c)) >> 10) + 16 )
54 #define rgba2u(c) ( ((-152*_r(c) - 298*_g(c) + 450*_b(c)) >> 10) + 128 ) 54 #define rgba2u(c) ( ((-152*_r(c) - 298*_g(c) + 450*_b(c)) >> 10) + 128 )
55 #define rgba2v(c) ( (( 450*_r(c) - 376*_g(c) - 73*_b(c)) >> 10) + 128 ) 55 #define rgba2v(c) ( (( 450*_r(c) - 376*_g(c) - 73*_b(c)) >> 10) + 128 )
56 56
57 57
58 static const struct vf_priv_s { 58 static const struct vf_priv_s {
59 int outh, outw; 59 int outh, outw;
60 60
61 unsigned int outfmt; 61 unsigned int outfmt;
62 62
63 // 1 = auto-added filter: insert only if chain does not support EOSD already 63 // 1 = auto-added filter: insert only if chain does not support EOSD already
64 // 0 = insert always 64 // 0 = insert always
65 int auto_insert; 65 int auto_insert;
66 66
67 unsigned char* planes[3]; 67 unsigned char *planes[3];
68 unsigned char* dirty_rows; 68 unsigned char *dirty_rows;
69 } vf_priv_dflt; 69 } vf_priv_dflt;
70 70
71 71
72 static int config(struct vf_instance *vf, 72 static int config(struct vf_instance *vf,
73 int width, int height, int d_width, int d_height, 73 int width, int height, int d_width, int d_height,
74 unsigned int flags, unsigned int outfmt) 74 unsigned int flags, unsigned int outfmt)
75 { 75 {
76 mp_eosd_res_t res = {0}; 76 mp_eosd_res_t res = { 0 };
77 77
78 if (outfmt == IMGFMT_IF09) return 0; 78 if (outfmt == IMGFMT_IF09)
79 79 return 0;
80 vf->priv->outh = height + ass_top_margin + ass_bottom_margin; 80
81 vf->priv->outw = width; 81 vf->priv->outh = height + ass_top_margin + ass_bottom_margin;
82 82 vf->priv->outw = width;
83 if(!opt_screen_size_x && !opt_screen_size_y){ 83
84 d_width = d_width * vf->priv->outw / width; 84 if (!opt_screen_size_x && !opt_screen_size_y) {
85 d_height = d_height * vf->priv->outh / height; 85 d_width = d_width * vf->priv->outw / width;
86 } 86 d_height = d_height * vf->priv->outh / height;
87 87 }
88 vf->priv->planes[1] = malloc(vf->priv->outw * vf->priv->outh); 88
89 vf->priv->planes[2] = malloc(vf->priv->outw * vf->priv->outh); 89 vf->priv->planes[1] = malloc(vf->priv->outw * vf->priv->outh);
90 vf->priv->dirty_rows = malloc(vf->priv->outh); 90 vf->priv->planes[2] = malloc(vf->priv->outw * vf->priv->outh);
91 91 vf->priv->dirty_rows = malloc(vf->priv->outh);
92 res.w = vf->priv->outw; 92
93 res.h = vf->priv->outh; 93 res.w = vf->priv->outw;
94 res.srcw = width; 94 res.h = vf->priv->outh;
95 res.srch = height; 95 res.srcw = width;
96 res.mt = ass_top_margin; 96 res.srch = height;
97 res.mb = ass_bottom_margin; 97 res.mt = ass_top_margin;
98 eosd_configure(&res, 0); 98 res.mb = ass_bottom_margin;
99 99 eosd_configure(&res, 0);
100 return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width, d_height, flags, outfmt); 100
101 return vf_next_config(vf, vf->priv->outw, vf->priv->outh, d_width,
102 d_height, flags, outfmt);
101 } 103 }
102 104
103 static void get_image(struct vf_instance *vf, mp_image_t *mpi) 105 static void get_image(struct vf_instance *vf, mp_image_t *mpi)
104 { 106 {
105 if(mpi->type == MP_IMGTYPE_IPB) return; 107 if (mpi->type == MP_IMGTYPE_IPB)
106 if(mpi->flags & MP_IMGFLAG_PRESERVE) return; 108 return;
107 if(mpi->imgfmt != vf->priv->outfmt) return; // colorspace differ 109 if (mpi->flags & MP_IMGFLAG_PRESERVE)
108 110 return;
109 // width never changes, always try full DR 111 if (mpi->imgfmt != vf->priv->outfmt)
110 mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt, 112 return; // colorspace differ
111 mpi->type, mpi->flags | MP_IMGFLAG_READABLE, 113
112 vf->priv->outw, 114 // width never changes, always try full DR
113 vf->priv->outh); 115 mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt, mpi->type,
114 116 mpi->flags | MP_IMGFLAG_READABLE,
115 if((vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) && 117 vf->priv->outw, vf->priv->outh);
116 !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)){ 118
117 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_MPCODECS_FullDRNotPossible); 119 if ( (vf->dmpi->flags & MP_IMGFLAG_DRAW_CALLBACK) &&
118 return; 120 !(vf->dmpi->flags & MP_IMGFLAG_DIRECT)) {
119 } 121 mp_msg(MSGT_ASS, MSGL_INFO, MSGTR_MPCODECS_FullDRNotPossible);
120 122 return;
121 // set up mpi as a cropped-down image of dmpi: 123 }
122 if(mpi->flags&MP_IMGFLAG_PLANAR){ 124 // set up mpi as a cropped-down image of dmpi:
123 mpi->planes[0]=vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0]; 125 if (mpi->flags & MP_IMGFLAG_PLANAR) {
124 mpi->planes[1]=vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1]; 126 mpi->planes[0] = vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0];
125 mpi->planes[2]=vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2]; 127 mpi->planes[1] = vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1];
126 mpi->stride[1]=vf->dmpi->stride[1]; 128 mpi->planes[2] = vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2];
127 mpi->stride[2]=vf->dmpi->stride[2]; 129 mpi->stride[1] = vf->dmpi->stride[1];
128 } else { 130 mpi->stride[2] = vf->dmpi->stride[2];
129 mpi->planes[0]=vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0]; 131 } else {
130 } 132 mpi->planes[0] = vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0];
131 mpi->stride[0]=vf->dmpi->stride[0]; 133 }
132 mpi->width=vf->dmpi->width; 134 mpi->stride[0] = vf->dmpi->stride[0];
133 mpi->flags|=MP_IMGFLAG_DIRECT; 135 mpi->width = vf->dmpi->width;
134 mpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK; 136 mpi->flags |= MP_IMGFLAG_DIRECT;
135 // vf->dmpi->flags&=~MP_IMGFLAG_DRAW_CALLBACK; 137 mpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
138 // vf->dmpi->flags &= ~MP_IMGFLAG_DRAW_CALLBACK;
136 } 139 }
137 140
138 static void blank(mp_image_t *mpi, int y1, int y2) 141 static void blank(mp_image_t *mpi, int y1, int y2)
139 { 142 {
140 int color[3] = {16, 128, 128}; // black (YUV) 143 int color[3] = { 16, 128, 128 }; // black (YUV)
141 int y; 144 int y;
142 unsigned char* dst; 145 unsigned char *dst;
143 int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift; 146 int chroma_rows = (y2 - y1) >> mpi->chroma_y_shift;
144 147
145 dst = mpi->planes[0] + y1 * mpi->stride[0]; 148 dst = mpi->planes[0] + y1 * mpi->stride[0];
146 for (y = 0; y < y2 - y1; ++y) { 149 for (y = 0; y < y2 - y1; ++y) {
147 memset(dst, color[0], mpi->w); 150 memset(dst, color[0], mpi->w);
148 dst += mpi->stride[0]; 151 dst += mpi->stride[0];
149 } 152 }
150 dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1]; 153 dst = mpi->planes[1] + (y1 >> mpi->chroma_y_shift) * mpi->stride[1];
151 for (y = 0; y < chroma_rows ; ++y) { 154 for (y = 0; y < chroma_rows; ++y) {
152 memset(dst, color[1], mpi->chroma_width); 155 memset(dst, color[1], mpi->chroma_width);
153 dst += mpi->stride[1]; 156 dst += mpi->stride[1];
154 } 157 }
155 dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2]; 158 dst = mpi->planes[2] + (y1 >> mpi->chroma_y_shift) * mpi->stride[2];
156 for (y = 0; y < chroma_rows ; ++y) { 159 for (y = 0; y < chroma_rows; ++y) {
157 memset(dst, color[2], mpi->chroma_width); 160 memset(dst, color[2], mpi->chroma_width);
158 dst += mpi->stride[2]; 161 dst += mpi->stride[2];
159 } 162 }
160 } 163 }
161 164
162 static int prepare_image(struct vf_instance *vf, mp_image_t *mpi) 165 static int prepare_image(struct vf_instance *vf, mp_image_t *mpi)
163 { 166 {
164 if(mpi->flags&MP_IMGFLAG_DIRECT || mpi->flags&MP_IMGFLAG_DRAW_CALLBACK){ 167 if (mpi->flags & MP_IMGFLAG_DIRECT ||
165 vf->dmpi = mpi->priv; 168 mpi->flags & MP_IMGFLAG_DRAW_CALLBACK) {
166 if (!vf->dmpi) { mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_MPCODECS_FunWhydowegetNULL); return 0; } 169 vf->dmpi = mpi->priv;
167 mpi->priv = NULL; 170 if (!vf->dmpi) {
168 // we've used DR, so we're ready... 171 mp_msg(MSGT_ASS, MSGL_WARN, MSGTR_MPCODECS_FunWhydowegetNULL);
169 if (ass_top_margin) 172 return 0;
170 blank(vf->dmpi, 0, ass_top_margin); 173 }
171 if (ass_bottom_margin) 174 mpi->priv = NULL;
172 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh); 175 // we've used DR, so we're ready...
173 if(!(mpi->flags&MP_IMGFLAG_PLANAR)) 176 if (ass_top_margin)
174 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette 177 blank(vf->dmpi, 0, ass_top_margin);
175 return 0; 178 if (ass_bottom_margin)
176 } 179 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh);
177 180 if (!(mpi->flags & MP_IMGFLAG_PLANAR))
178 // hope we'll get DR buffer: 181 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
179 vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt, 182 return 0;
180 MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE, 183 }
181 vf->priv->outw, vf->priv->outh); 184 // hope we'll get DR buffer:
182 185 vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt, MP_IMGTYPE_TEMP,
183 // copy mpi->dmpi... 186 MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE,
184 if(mpi->flags&MP_IMGFLAG_PLANAR){ 187 vf->priv->outw, vf->priv->outh);
185 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0], 188
186 mpi->planes[0], mpi->w, mpi->h, 189 // copy mpi->dmpi...
187 vf->dmpi->stride[0], mpi->stride[0]); 190 if (mpi->flags & MP_IMGFLAG_PLANAR) {
188 memcpy_pic(vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1], 191 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
189 mpi->planes[1], mpi->w >> mpi->chroma_x_shift, mpi->h >> mpi->chroma_y_shift, 192 mpi->planes[0],
190 vf->dmpi->stride[1], mpi->stride[1]); 193 mpi->w,
191 memcpy_pic(vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2], 194 mpi->h,
192 mpi->planes[2], mpi->w >> mpi->chroma_x_shift, mpi->h >> mpi->chroma_y_shift, 195 vf->dmpi->stride[0],
193 vf->dmpi->stride[2], mpi->stride[2]); 196 mpi->stride[0]);
194 } else { 197 memcpy_pic(vf->dmpi->planes[1] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[1],
195 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0], 198 mpi->planes[1],
196 mpi->planes[0], mpi->w*(vf->dmpi->bpp/8), mpi->h, 199 mpi->w >> mpi->chroma_x_shift,
197 vf->dmpi->stride[0], mpi->stride[0]); 200 mpi->h >> mpi->chroma_y_shift,
198 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette 201 vf->dmpi->stride[1],
199 } 202 mpi->stride[1]);
200 if (ass_top_margin) 203 memcpy_pic(vf->dmpi->planes[2] + (ass_top_margin >> mpi->chroma_y_shift) * vf->dmpi->stride[2],
201 blank(vf->dmpi, 0, ass_top_margin); 204 mpi->planes[2],
202 if (ass_bottom_margin) 205 mpi->w >> mpi->chroma_x_shift,
203 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh); 206 mpi->h >> mpi->chroma_y_shift,
204 return 0; 207 vf->dmpi->stride[2],
208 mpi->stride[2]);
209 } else {
210 memcpy_pic(vf->dmpi->planes[0] + ass_top_margin * vf->dmpi->stride[0],
211 mpi->planes[0],
212 mpi->w * (vf->dmpi->bpp / 8),
213 mpi->h,
214 vf->dmpi->stride[0],
215 mpi->stride[0]);
216 vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette
217 }
218 if (ass_top_margin)
219 blank(vf->dmpi, 0, ass_top_margin);
220 if (ass_bottom_margin)
221 blank(vf->dmpi, vf->priv->outh - ass_bottom_margin, vf->priv->outh);
222 return 0;
205 } 223 }
206 224
207 /** 225 /**
208 * \brief Copy specified rows from render_context.dmpi to render_context.planes, upsampling to 4:4:4 226 * \brief Copy specified rows from render_context.dmpi to render_context.planes, upsampling to 4:4:4
209 */ 227 */
210 static void copy_from_image(struct vf_instance *vf, int first_row, int last_row) 228 static void copy_from_image(struct vf_instance *vf, int first_row,
211 { 229 int last_row)
212 int pl; 230 {
213 int i, j, k; 231 int pl;
214 unsigned char val; 232 int i, j, k;
215 int chroma_rows; 233 unsigned char val;
216 234 int chroma_rows;
217 first_row -= (first_row % 2); 235
218 last_row += (last_row % 2); 236 first_row -= (first_row % 2);
219 chroma_rows = (last_row - first_row) / 2; 237 last_row += (last_row % 2);
220 238 chroma_rows = (last_row - first_row) / 2;
221 assert(first_row >= 0); 239
222 assert(first_row <= last_row); 240 assert(first_row >= 0);
223 assert(last_row <= vf->priv->outh); 241 assert(first_row <= last_row);
224 242 assert(last_row <= vf->priv->outh);
225 for (pl = 1; pl < 3; ++pl) { 243
226 int dst_stride = vf->priv->outw; 244 for (pl = 1; pl < 3; ++pl) {
227 int src_stride = vf->dmpi->stride[pl]; 245 int dst_stride = vf->priv->outw;
228 246 int src_stride = vf->dmpi->stride[pl];
229 unsigned char* src = vf->dmpi->planes[pl] + (first_row/2) * src_stride; 247
230 unsigned char* dst = vf->priv->planes[pl] + first_row * dst_stride; 248 unsigned char *src = vf->dmpi->planes[pl] + (first_row / 2) * src_stride;
231 unsigned char* dst_next = dst + dst_stride; 249 unsigned char *dst = vf->priv->planes[pl] + first_row * dst_stride;
232 for(i = 0; i < chroma_rows; ++i) 250 unsigned char *dst_next = dst + dst_stride;
233 { 251 for (i = 0; i < chroma_rows; ++i) {
234 if ((vf->priv->dirty_rows[first_row + i*2] == 0) || 252 if ((vf->priv->dirty_rows[first_row + i * 2 ] == 0) ||
235 (vf->priv->dirty_rows[first_row + i*2 + 1] == 0)) { 253 (vf->priv->dirty_rows[first_row + i * 2 + 1] == 0)) {
236 for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k+=2) { 254 for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k += 2) {
237 val = *(src + j); 255 val = *(src + j);
238 *(dst + k) = val; 256 *(dst + k ) = val;
239 *(dst + k + 1) = val; 257 *(dst + k + 1) = val;
240 *(dst_next + k) = val; 258 *(dst_next + k ) = val;
241 *(dst_next + k + 1) = val; 259 *(dst_next + k + 1) = val;
242 } 260 }
243 } 261 }
244 src += src_stride; 262 src += src_stride;
245 dst = dst_next + dst_stride; 263 dst = dst_next + dst_stride;
246 dst_next = dst + dst_stride; 264 dst_next = dst + dst_stride;
247 } 265 }
248 } 266 }
249 for (i = first_row; i < last_row; ++i) 267 for (i = first_row; i < last_row; ++i)
250 vf->priv->dirty_rows[i] = 1; 268 vf->priv->dirty_rows[i] = 1;
251 } 269 }
252 270
253 /** 271 /**
254 * \brief Copy all previously copied rows back to render_context.dmpi 272 * \brief Copy all previously copied rows back to render_context.dmpi
255 */ 273 */
256 static void copy_to_image(struct vf_instance *vf) 274 static void copy_to_image(struct vf_instance *vf)
257 { 275 {
258 int pl; 276 int pl;
259 int i, j, k; 277 int i, j, k;
260 for (pl = 1; pl < 3; ++pl) { 278 for (pl = 1; pl < 3; ++pl) {
261 int dst_stride = vf->dmpi->stride[pl]; 279 int dst_stride = vf->dmpi->stride[pl];
262 int src_stride = vf->priv->outw; 280 int src_stride = vf->priv->outw;
263 281
264 unsigned char* dst = vf->dmpi->planes[pl]; 282 unsigned char *dst = vf->dmpi->planes[pl];
265 unsigned char* src = vf->priv->planes[pl]; 283 unsigned char *src = vf->priv->planes[pl];
266 unsigned char* src_next = vf->priv->planes[pl] + src_stride; 284 unsigned char *src_next = vf->priv->planes[pl] + src_stride;
267 for(i = 0; i < vf->dmpi->chroma_height; ++i) 285 for (i = 0; i < vf->dmpi->chroma_height; ++i) {
268 { 286 if ((vf->priv->dirty_rows[i * 2] == 1)) {
269 if ((vf->priv->dirty_rows[i*2] == 1)) { 287 assert(vf->priv->dirty_rows[i * 2 + 1] == 1);
270 assert(vf->priv->dirty_rows[i*2 + 1] == 1); 288 for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k += 2) {
271 for (j = 0, k = 0; j < vf->dmpi->chroma_width; ++j, k+=2) { 289 unsigned val = 0;
272 unsigned val = 0; 290 val += *(src + k);
273 val += *(src + k); 291 val += *(src + k + 1);
274 val += *(src + k + 1); 292 val += *(src_next + k);
275 val += *(src_next + k); 293 val += *(src_next + k + 1);
276 val += *(src_next + k + 1); 294 *(dst + j) = val >> 2;
277 *(dst + j) = val >> 2; 295 }
278 } 296 }
279 } 297 dst += dst_stride;
280 dst += dst_stride; 298 src = src_next + src_stride;
281 src = src_next + src_stride; 299 src_next = src + src_stride;
282 src_next = src + src_stride; 300 }
283 } 301 }
284 } 302 }
285 } 303
286 304 static void my_draw_bitmap(struct vf_instance *vf, unsigned char *bitmap,
287 static void my_draw_bitmap(struct vf_instance *vf, unsigned char* bitmap, int bitmap_w, int bitmap_h, int stride, int dst_x, int dst_y, unsigned color) 305 int bitmap_w, int bitmap_h, int stride,
288 { 306 int dst_x, int dst_y, unsigned color)
289 unsigned char y = rgba2y(color); 307 {
290 unsigned char u = rgba2u(color); 308 unsigned char y = rgba2y(color);
291 unsigned char v = rgba2v(color); 309 unsigned char u = rgba2u(color);
292 unsigned char opacity = 255 - _a(color); 310 unsigned char v = rgba2v(color);
293 unsigned char *src, *dsty, *dstu, *dstv; 311 unsigned char opacity = 255 - _a(color);
294 int i, j; 312 unsigned char *src, *dsty, *dstu, *dstv;
295 mp_image_t* dmpi = vf->dmpi; 313 int i, j;
296 314 mp_image_t *dmpi = vf->dmpi;
297 src = bitmap; 315
298 dsty = dmpi->planes[0] + dst_x + dst_y * dmpi->stride[0]; 316 src = bitmap;
299 dstu = vf->priv->planes[1] + dst_x + dst_y * vf->priv->outw; 317 dsty = dmpi->planes[0] + dst_x + dst_y * dmpi->stride[0];
300 dstv = vf->priv->planes[2] + dst_x + dst_y * vf->priv->outw; 318 dstu = vf->priv->planes[1] + dst_x + dst_y * vf->priv->outw;
301 for (i = 0; i < bitmap_h; ++i) { 319 dstv = vf->priv->planes[2] + dst_x + dst_y * vf->priv->outw;
302 for (j = 0; j < bitmap_w; ++j) { 320 for (i = 0; i < bitmap_h; ++i) {
303 unsigned k = ((unsigned)src[j]) * opacity / 255; 321 for (j = 0; j < bitmap_w; ++j) {
304 dsty[j] = (k*y + (255-k)*dsty[j]) / 255; 322 unsigned k = ((unsigned) src[j]) * opacity / 255;
305 dstu[j] = (k*u + (255-k)*dstu[j]) / 255; 323 dsty[j] = (k * y + (255 - k) * dsty[j]) / 255;
306 dstv[j] = (k*v + (255-k)*dstv[j]) / 255; 324 dstu[j] = (k * u + (255 - k) * dstu[j]) / 255;
307 } 325 dstv[j] = (k * v + (255 - k) * dstv[j]) / 255;
308 src += stride; 326 }
309 dsty += dmpi->stride[0]; 327 src += stride;
310 dstu += vf->priv->outw; 328 dsty += dmpi->stride[0];
311 dstv += vf->priv->outw; 329 dstu += vf->priv->outw;
312 } 330 dstv += vf->priv->outw;
313 } 331 }
314 332 }
315 static int render_frame(struct vf_instance *vf, mp_image_t *mpi, const ASS_Image* img) 333
316 { 334 static int render_frame(struct vf_instance *vf, mp_image_t *mpi,
317 if (img) { 335 const ASS_Image *img)
318 memset(vf->priv->dirty_rows, 0, vf->priv->outh); // reset dirty rows 336 {
319 while (img) { 337 if (img) {
320 copy_from_image(vf, img->dst_y, img->dst_y + img->h); 338 memset(vf->priv->dirty_rows, 0, vf->priv->outh); // reset dirty rows
321 my_draw_bitmap(vf, img->bitmap, img->w, img->h, img->stride, 339 while (img) {
322 img->dst_x, img->dst_y, img->color); 340 copy_from_image(vf, img->dst_y, img->dst_y + img->h);
323 img = img->next; 341 my_draw_bitmap(vf, img->bitmap, img->w, img->h, img->stride,
324 } 342 img->dst_x, img->dst_y, img->color);
325 copy_to_image(vf); 343 img = img->next;
326 } 344 }
327 return 0; 345 copy_to_image(vf);
346 }
347 return 0;
328 } 348 }
329 349
330 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) 350 static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts)
331 { 351 {
332 ASS_Image* images = eosd_render_frame(pts, NULL); 352 ASS_Image *images = eosd_render_frame(pts, NULL);
333 prepare_image(vf, mpi); 353 prepare_image(vf, mpi);
334 if (images) render_frame(vf, mpi, images); 354 if (images)
335 355 render_frame(vf, mpi, images);
336 return vf_next_put_image(vf, vf->dmpi, pts); 356
357 return vf_next_put_image(vf, vf->dmpi, pts);
337 } 358 }
338 359
339 static int query_format(struct vf_instance *vf, unsigned int fmt) 360 static int query_format(struct vf_instance *vf, unsigned int fmt)
340 { 361 {
341 switch(fmt){ 362 switch (fmt) {
342 case IMGFMT_YV12: 363 case IMGFMT_YV12:
343 case IMGFMT_I420: 364 case IMGFMT_I420:
344 case IMGFMT_IYUV: 365 case IMGFMT_IYUV:
345 return vf_next_query_format(vf, vf->priv->outfmt); 366 return vf_next_query_format(vf, vf->priv->outfmt);
346 } 367 }
347 return 0; 368 return 0;
348 } 369 }
349 370
350 static int control(vf_instance_t *vf, int request, void *data) 371 static int control(vf_instance_t *vf, int request, void *data)
351 { 372 {
352 switch (request) { 373 switch (request) {
353 case VFCTRL_INIT_EOSD: 374 case VFCTRL_INIT_EOSD:
354 return CONTROL_TRUE; 375 return CONTROL_TRUE;
355 case VFCTRL_DRAW_EOSD: 376 case VFCTRL_DRAW_EOSD:
356 return CONTROL_TRUE; 377 return CONTROL_TRUE;
357 } 378 }
358 return vf_next_control(vf, request, data); 379 return vf_next_control(vf, request, data);
359 } 380 }
360 381
361 static void uninit(struct vf_instance *vf) 382 static void uninit(struct vf_instance *vf)
362 { 383 {
363 if (vf->priv->planes[1]) 384 if (vf->priv->planes[1])
364 free(vf->priv->planes[1]); 385 free(vf->priv->planes[1]);
365 if (vf->priv->planes[2]) 386 if (vf->priv->planes[2])
366 free(vf->priv->planes[2]); 387 free(vf->priv->planes[2]);
367 if (vf->priv->dirty_rows) 388 if (vf->priv->dirty_rows)
368 free(vf->priv->dirty_rows); 389 free(vf->priv->dirty_rows);
369 } 390 }
370 391
371 static const unsigned int fmt_list[]={ 392 static const unsigned int fmt_list[] = {
372 IMGFMT_YV12, 393 IMGFMT_YV12,
373 IMGFMT_I420, 394 IMGFMT_I420,
374 IMGFMT_IYUV, 395 IMGFMT_IYUV,
375 0 396 0
376 }; 397 };
377 398
378 static int vf_open(vf_instance_t *vf, char *args) 399 static int vf_open(vf_instance_t *vf, char *args)
379 { 400 {
380 int flags; 401 int flags;
381 vf->priv->outfmt = vf_match_csp(&vf->next,fmt_list,IMGFMT_YV12); 402 vf->priv->outfmt = vf_match_csp(&vf->next, fmt_list, IMGFMT_YV12);
382 if (vf->priv->outfmt) 403 if (vf->priv->outfmt)
383 flags = vf_next_query_format(vf, vf->priv->outfmt); 404 flags = vf_next_query_format(vf, vf->priv->outfmt);
384 if (!vf->priv->outfmt || (vf->priv->auto_insert && flags&VFCAP_EOSD)) 405 if (!vf->priv->outfmt || (vf->priv->auto_insert && flags & VFCAP_EOSD)) {
385 { 406 uninit(vf);
386 uninit(vf); 407 return 0;
387 return 0; 408 }
388 } 409
389 410 if (vf->priv->auto_insert)
390 if (vf->priv->auto_insert) 411 mp_msg(MSGT_ASS, MSGL_INFO, "[ass] auto-open\n");
391 mp_msg(MSGT_ASS, MSGL_INFO, "[ass] auto-open\n"); 412
392 413 vf->config = config;
393 vf->config = config; 414 vf->query_format = query_format;
394 vf->query_format = query_format; 415 vf->uninit = uninit;
395 vf->uninit = uninit; 416 vf->control = control;
396 vf->control = control; 417 vf->get_image = get_image;
397 vf->get_image = get_image; 418 vf->put_image = put_image;
398 vf->put_image = put_image; 419 vf->default_caps = VFCAP_EOSD;
399 vf->default_caps=VFCAP_EOSD; 420 return 1;
400 return 1;
401 } 421 }
402 422
403 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f) 423 #define ST_OFF(f) M_ST_OFF(struct vf_priv_s,f)
404 static const m_option_t vf_opts_fields[] = { 424 static const m_option_t vf_opts_fields[] = {
405 {"auto", ST_OFF(auto_insert), CONF_TYPE_FLAG, 0 , 0, 1, NULL}, 425 {"auto", ST_OFF(auto_insert), CONF_TYPE_FLAG, 0, 0, 1, NULL},
406 { NULL, NULL, 0, 0, 0, 0, NULL } 426 {NULL, NULL, 0, 0, 0, 0, NULL}
407 }; 427 };
408 428
409 static const m_struct_t vf_opts = { 429 static const m_struct_t vf_opts = {
410 "ass", 430 "ass",
411 sizeof(struct vf_priv_s), 431 sizeof(struct vf_priv_s),
412 &vf_priv_dflt, 432 &vf_priv_dflt,
413 vf_opts_fields 433 vf_opts_fields
414 }; 434 };
415 435
416 const vf_info_t vf_info_ass = { 436 const vf_info_t vf_info_ass = {
417 "Render ASS/SSA subtitles", 437 "Render ASS/SSA subtitles",
418 "ass", 438 "ass",
419 "Evgeniy Stepanov", 439 "Evgeniy Stepanov",
420 "", 440 "",
421 vf_open, 441 vf_open,
422 &vf_opts 442 &vf_opts
423 }; 443 };