| 239 | } |
| 240 | |
| 241 | static hb_buffer_t * scale_subtitle(hb_filter_private_t *pv, |
| 242 | hb_buffer_t *sub, hb_buffer_t *buf) |
| 243 | { |
| 244 | hb_buffer_t *scaled; |
| 245 | double xfactor = 1., yfactor = 1.; |
| 246 | |
| 247 | // Do we need to rescale subtitles? |
| 248 | if (sub->f.window_width > 0 && sub->f.window_height > 0) |
| 249 | { |
| 250 | // TODO: Factor aspect ratio |
| 251 | // For now, assume subtitle and video PAR is the same. |
| 252 | xfactor = (double)buf->f.width / sub->f.window_width; |
| 253 | yfactor = (double)buf->f.height / sub->f.window_height; |
| 254 | // The video may have been cropped. This will make xfactor != yfactor |
| 255 | // even though video and subtitles are the same PAR. So use the |
| 256 | // larger of as the scale factor. |
| 257 | if (xfactor > yfactor) |
| 258 | { |
| 259 | yfactor = xfactor; |
| 260 | } |
| 261 | else |
| 262 | { |
| 263 | xfactor = yfactor; |
| 264 | } |
| 265 | } |
| 266 | if (ABS(xfactor - 1) > 0.01 || ABS(yfactor - 1) > 0.01) |
| 267 | { |
| 268 | uint8_t *in_data[4], *out_data[4]; |
| 269 | int in_stride[4], out_stride[4]; |
| 270 | int width, height; |
| 271 | |
| 272 | width = sub->f.width * xfactor; |
| 273 | height = sub->f.height * yfactor; |
| 274 | // Note that subtitle frame buffer has alpha and should always be 444P |
| 275 | scaled = hb_frame_buffer_init(sub->f.fmt, width, height); |
| 276 | if (scaled == NULL) |
| 277 | { |
| 278 | return NULL; |
| 279 | } |
| 280 | |
| 281 | scaled->f.x = sub->f.x * xfactor; |
| 282 | scaled->f.y = sub->f.y * yfactor; |
| 283 | |
| 284 | hb_picture_fill(in_data, in_stride, sub); |
| 285 | hb_picture_fill(out_data, out_stride, scaled); |
| 286 | |
| 287 | if (pv->sws == NULL || |
| 288 | pv->sws_width != width || |
| 289 | pv->sws_height != height) |
| 290 | { |
| 291 | if (pv->sws!= NULL) |
| 292 | { |
| 293 | sws_freeContext(pv->sws); |
| 294 | } |
| 295 | pv->sws = hb_sws_get_context( |
| 296 | sub->f.width, sub->f.height, sub->f.fmt, AVCOL_RANGE_MPEG, |
| 297 | scaled->f.width, scaled->f.height, sub->f.fmt, AVCOL_RANGE_MPEG, |
| 298 | SWS_LANCZOS|SWS_ACCURATE_RND, SWS_CS_DEFAULT); |
no test coverage detected