diff options
Diffstat (limited to 'video/filter/vf_sub.c')
-rw-r--r-- | video/filter/vf_sub.c | 104 |
1 files changed, 29 insertions, 75 deletions
diff --git a/video/filter/vf_sub.c b/video/filter/vf_sub.c index 3307af0c90..10fcdbfc5b 100644 --- a/video/filter/vf_sub.c +++ b/video/filter/vf_sub.c @@ -89,37 +89,6 @@ static int config(struct vf_instance *vf, d_height, flags, outfmt); } -static void get_image(struct vf_instance *vf, mp_image_t *mpi) -{ - if (mpi->type == MP_IMGTYPE_IPB) - return; - if (mpi->flags & MP_IMGFLAG_PRESERVE) - return; - if (mpi->imgfmt != vf->priv->outfmt) - return; // colorspace differ - - // width never changes, always try full DR - mpi->priv = vf->dmpi = vf_get_image(vf->next, mpi->imgfmt, mpi->type, - mpi->flags | MP_IMGFLAG_READABLE, - FFMAX(mpi->width, vf->priv->outw), - FFMAX(mpi->height, vf->priv->outh)); - - int tmargin = vf->priv->opt_top_margin; - // set up mpi as a cropped-down image of dmpi: - if (mpi->flags & MP_IMGFLAG_PLANAR) { - mpi->planes[0] = vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0]; - mpi->planes[1] = vf->dmpi->planes[1] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[1]; - mpi->planes[2] = vf->dmpi->planes[2] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[2]; - mpi->stride[1] = vf->dmpi->stride[1]; - mpi->stride[2] = vf->dmpi->stride[2]; - } else { - mpi->planes[0] = vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0]; - } - mpi->stride[0] = vf->dmpi->stride[0]; - mpi->width = vf->dmpi->width; - mpi->flags |= MP_IMGFLAG_DIRECT; -} - static void blank(mp_image_t *mpi, int y1, int y2) { int color[3] = {16, 128, 128}; // black (YUV) @@ -144,81 +113,67 @@ static void blank(mp_image_t *mpi, int y1, int y2) } } -static int prepare_image(struct vf_instance *vf, mp_image_t *mpi) +static void prepare_image(struct vf_instance *vf, struct mp_image *dmpi, + struct mp_image *mpi) { int tmargin = vf->priv->opt_top_margin; - if (mpi->flags & MP_IMGFLAG_DIRECT) { - vf->dmpi = mpi->priv; - if (!vf->dmpi) { - mp_tmsg(MSGT_ASS, MSGL_WARN, "Why do we get NULL??\n"); - return 0; - } - mpi->priv = NULL; - // we've used DR, so we're ready... - if (tmargin) - blank(vf->dmpi, 0, tmargin); - if (vf->priv->opt_bottom_margin) - blank(vf->dmpi, vf->priv->outh - vf->priv->opt_bottom_margin, - vf->priv->outh); - if (!(mpi->flags & MP_IMGFLAG_PLANAR)) - vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette - return 0; - } - - // hope we'll get DR buffer: - vf->dmpi = vf_get_image(vf->next, vf->priv->outfmt, MP_IMGTYPE_TEMP, - MP_IMGFLAG_ACCEPT_STRIDE | MP_IMGFLAG_READABLE, - vf->priv->outw, vf->priv->outh); - // copy mpi->dmpi... if (mpi->flags & MP_IMGFLAG_PLANAR) { - memcpy_pic(vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0], + memcpy_pic(dmpi->planes[0] + tmargin * dmpi->stride[0], mpi->planes[0], mpi->w, mpi->h, - vf->dmpi->stride[0], + dmpi->stride[0], mpi->stride[0]); - memcpy_pic(vf->dmpi->planes[1] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[1], + memcpy_pic(dmpi->planes[1] + (tmargin >> mpi->chroma_y_shift) * dmpi->stride[1], mpi->planes[1], mpi->w >> mpi->chroma_x_shift, mpi->h >> mpi->chroma_y_shift, - vf->dmpi->stride[1], + dmpi->stride[1], mpi->stride[1]); - memcpy_pic(vf->dmpi->planes[2] + (tmargin >> mpi->chroma_y_shift) * vf->dmpi->stride[2], + memcpy_pic(dmpi->planes[2] + (tmargin >> mpi->chroma_y_shift) * dmpi->stride[2], mpi->planes[2], mpi->w >> mpi->chroma_x_shift, mpi->h >> mpi->chroma_y_shift, - vf->dmpi->stride[2], + dmpi->stride[2], mpi->stride[2]); } else { - memcpy_pic(vf->dmpi->planes[0] + tmargin * vf->dmpi->stride[0], + memcpy_pic(dmpi->planes[0] + tmargin * dmpi->stride[0], mpi->planes[0], - mpi->w * (vf->dmpi->bpp / 8), + mpi->w * (dmpi->bpp / 8), mpi->h, - vf->dmpi->stride[0], + dmpi->stride[0], mpi->stride[0]); - vf->dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette + dmpi->planes[1] = mpi->planes[1]; // passthrough rgb8 palette } if (tmargin) - blank(vf->dmpi, 0, tmargin); + blank(dmpi, 0, tmargin); if (vf->priv->opt_bottom_margin) - blank(vf->dmpi, vf->priv->outh - vf->priv->opt_bottom_margin, + blank(dmpi, vf->priv->outh - vf->priv->opt_bottom_margin, vf->priv->outh); - return 0; } -static int put_image(struct vf_instance *vf, mp_image_t *mpi, double pts) +static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) { struct vf_priv_s *priv = vf->priv; struct osd_state *osd = priv->osd; - prepare_image(vf, mpi); + if (vf->priv->opt_top_margin || vf->priv->opt_bottom_margin || + !mp_image_is_writeable(mpi)) + { + struct mp_image *dmpi = vf_alloc_out_image(vf); + mp_image_copy_attributes(dmpi, mpi); + prepare_image(vf, dmpi, mpi); + talloc_free(mpi); + mpi = dmpi; + } + mp_image_set_colorspace_details(mpi, &priv->csp); - if (pts != MP_NOPTS_VALUE) - osd_draw_on_image(osd, priv->dim, pts, OSD_DRAW_SUB_FILTER, vf->dmpi); + if (mpi->pts != MP_NOPTS_VALUE) + osd_draw_on_image(osd, priv->dim, mpi->pts, OSD_DRAW_SUB_FILTER, mpi); - return vf_next_put_image(vf, vf->dmpi, pts); + return mpi; } static int query_format(struct vf_instance *vf, unsigned int fmt) @@ -273,8 +228,7 @@ static int vf_open(vf_instance_t *vf, char *args) vf->query_format = query_format; vf->uninit = uninit; vf->control = control; - vf->get_image = get_image; - vf->put_image = put_image; + vf->filter = filter; vf->default_caps = VFCAP_OSD; return 1; } |