From 15c7f7a33968edebe305e2845b32eb2383457d46 Mon Sep 17 00:00:00 2001 From: wm4 Date: Wed, 19 Dec 2012 12:04:57 +0100 Subject: video: cleanup: move and rename vf_mpi_clear and vf_clone_attributes These functions weren't specific to video filters and were misplaced in vf.c. Move them to mp_image.c. Fix the big endian test in vf_mpi_clear/mp_image_clear, which has been messed up in 74df1d. --- video/filter/vf.c | 73 ---------------------------------------------- video/filter/vf.h | 3 -- video/filter/vf_expand.c | 12 ++++---- video/image_writer.c | 4 +-- video/mp_image.c | 76 ++++++++++++++++++++++++++++++++++++++++++++---- video/mp_image.h | 1 + video/out/vo_xv.c | 7 ++--- 7 files changed, 80 insertions(+), 96 deletions(-) (limited to 'video') diff --git a/video/filter/vf.c b/video/filter/vf.c index 1d21413787..f286da8a4f 100644 --- a/video/filter/vf.c +++ b/video/filter/vf.c @@ -118,58 +118,6 @@ const m_obj_list_t vf_obj_list = { M_ST_OFF(vf_info_t, opts) }; -//============================================================================ -// mpi stuff: - -void vf_mpi_clear(mp_image_t *mpi, int x0, int y0, int w, int h) -{ - int y; - if (mpi->flags & MP_IMGFLAG_PLANAR) { - y0 &= ~1; - h += h & 1; - for (y = y0; y < y0 + h; y += 2) { - memset(mpi->planes[0] + x0 + mpi->stride[0] * y, 0, w); - memset(mpi->planes[0] + x0 + mpi->stride[0] * (y + 1), 0, w); - memset(mpi->planes[1] + (x0 >> mpi->chroma_x_shift) + - mpi->stride[1] * (y >> mpi->chroma_y_shift), - 128, (w >> mpi->chroma_x_shift)); - memset(mpi->planes[2] + (x0 >> mpi->chroma_x_shift) + - mpi->stride[2] * (y >> mpi->chroma_y_shift), - 128, (w >> mpi->chroma_x_shift)); - } - return; - } - // packed: - for (y = y0; y < y0 + h; y++) { - unsigned char *dst = mpi->planes[0] + mpi->stride[0] * y + - (mpi->bpp >> 3) * x0; - if (mpi->flags & MP_IMGFLAG_YUV) { - unsigned int *p = (unsigned int *) dst; - int size = (mpi->bpp >> 3) * w / 4; - int i; -#ifdef BIG_ENDIAN -#define CLEAR_PACKEDYUV_PATTERN 0x00800080 -#define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x80008000 -#else -#define CLEAR_PACKEDYUV_PATTERN 0x80008000 -#define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x00800080 -#endif - if (mpi->flags & MP_IMGFLAG_SWAPPED) { - for (i = 0; i < size - 3; i += 4) - p[i] = p[i + 1] = p[i + 2] = p[i + 3] = CLEAR_PACKEDYUV_PATTERN_SWAPPED; - for (; i < size; i++) - p[i] = CLEAR_PACKEDYUV_PATTERN_SWAPPED; - } else { - for (i = 0; i < size - 3; i += 4) - p[i] = p[i + 1] = p[i + 2] = p[i + 3] = CLEAR_PACKEDYUV_PATTERN; - for (; i < size; i++) - p[i] = CLEAR_PACKEDYUV_PATTERN; - } - } else - memset(dst, 0, (mpi->bpp >> 3) * w); - } -} - // Get a new image for filter output, with size and pixel format according to // the last vf_config call. struct mp_image *vf_alloc_out_image(struct vf_instance *vf) @@ -364,27 +312,6 @@ unsigned int vf_match_csp(vf_instance_t **vfp, const unsigned int *list, return best; } -void vf_clone_mpi_attributes(mp_image_t *dst, mp_image_t *src) -{ - dst->pict_type = src->pict_type; - dst->fields = src->fields; - dst->qscale_type = src->qscale_type; - dst->pts = src->pts; - if (dst->w == src->w && dst->h == src->h) { - dst->qstride = src->qstride; - dst->qscale = src->qscale; - dst->display_w = src->display_w; - dst->display_h = src->display_h; - } - if ((dst->flags & MP_IMGFLAG_YUV) == (src->flags & MP_IMGFLAG_YUV)) { - dst->colorspace = src->colorspace; - dst->levels = src->levels; - } - if (dst->imgfmt == IMGFMT_PAL8 && src->imgfmt == IMGFMT_PAL8) { - memcpy(dst->planes[1], src->planes[1], MP_PALETTE_SIZE); - } -} - // Used by filters to add a filtered frame to the output queue. // Ownership of img is transferred from caller to the filter chain. void vf_add_output_frame(struct vf_instance *vf, struct mp_image *img) diff --git a/video/filter/vf.h b/video/filter/vf.h index 187af302ad..358b8135f5 100644 --- a/video/filter/vf.h +++ b/video/filter/vf.h @@ -102,8 +102,6 @@ typedef struct vf_seteq { #define VFCTRL_SET_YUV_COLORSPACE 22 // arg is struct mp_csp_details* #define VFCTRL_GET_YUV_COLORSPACE 23 // arg is struct mp_csp_details* -// functions: -void vf_mpi_clear(mp_image_t *mpi, int x0, int y0, int w, int h); struct mp_image *vf_alloc_out_image(struct vf_instance *vf); void vf_make_out_image_writeable(struct vf_instance *vf, struct mp_image *img); @@ -124,7 +122,6 @@ vf_instance_t *vf_add_before_vo(vf_instance_t **vf, char *name, char **args); unsigned int vf_match_csp(vf_instance_t **vfp, const unsigned int *list, unsigned int preferred); -void vf_clone_mpi_attributes(mp_image_t *dst, mp_image_t *src); // default wrappers: int vf_next_config(struct vf_instance *vf, diff --git a/video/filter/vf_expand.c b/video/filter/vf_expand.c index 5f5ffcae7f..5ce5db16bd 100644 --- a/video/filter/vf_expand.c +++ b/video/filter/vf_expand.c @@ -129,15 +129,15 @@ static void clear_borders(struct vf_instance *vf, struct mp_image *dmpi, int w, int h) { // upper border (over the full width) - vf_mpi_clear(dmpi, 0, 0, vf->priv->exp_w, vf->priv->exp_y); + mp_image_clear(dmpi, 0, 0, vf->priv->exp_w, vf->priv->exp_y); // lower border - vf_mpi_clear(dmpi, 0, vf->priv->exp_y + h, vf->priv->exp_w, - vf->priv->exp_h - (vf->priv->exp_y + h)); + mp_image_clear(dmpi, 0, vf->priv->exp_y + h, vf->priv->exp_w, + vf->priv->exp_h - (vf->priv->exp_y + h)); // left - vf_mpi_clear(dmpi, 0, vf->priv->exp_y, vf->priv->exp_x, h); + mp_image_clear(dmpi, 0, vf->priv->exp_y, vf->priv->exp_x, h); // right - vf_mpi_clear(dmpi, vf->priv->exp_x + w, vf->priv->exp_y, - vf->priv->exp_w - (vf->priv->exp_x + w), h); + mp_image_clear(dmpi, vf->priv->exp_x + w, vf->priv->exp_y, + vf->priv->exp_w - (vf->priv->exp_x + w), h); } static struct mp_image *filter(struct vf_instance *vf, struct mp_image *mpi) diff --git a/video/image_writer.c b/video/image_writer.c index 570db961ca..b730f40bf6 100644 --- a/video/image_writer.c +++ b/video/image_writer.c @@ -39,9 +39,7 @@ #include "video/img_format.h" #include "video/mp_image.h" #include "video/fmt-conversion.h" - #include "video/sws_utils.h" -#include "video/filter/vf.h" #include "core/m_option.h" @@ -288,7 +286,7 @@ int write_image(struct mp_image *image, const struct image_writer_opts *opts, // - color levels broken in various ways thanks to libswscale if (image->imgfmt != destfmt || is_anamorphic) { struct mp_image *dst = alloc_mpi(d_w, d_h, destfmt); - vf_clone_mpi_attributes(dst, image); + mp_image_copy_attributes(dst, image); int flags = SWS_LANCZOS | SWS_FULL_CHR_H_INT | SWS_FULL_CHR_H_INP | SWS_ACCURATE_RND | SWS_BITEXACT; diff --git a/video/mp_image.c b/video/mp_image.c index 00f8cb2c28..751949a3d4 100644 --- a/video/mp_image.c +++ b/video/mp_image.c @@ -31,7 +31,6 @@ #include "video/img_format.h" #include "video/mp_image.h" #include "video/sws_utils.h" -#include "video/filter/vf.h" #include "video/memcpy_pic.h" struct m_refcount { @@ -122,11 +121,6 @@ static void mp_image_alloc_planes(struct mp_image *mpi) } } -void mp_image_copy_attributes(struct mp_image *dmpi, struct mp_image *mpi) -{ - vf_clone_mpi_attributes(dmpi, mpi); -} - void mp_image_setfmt(struct mp_image *mpi, unsigned int out_fmt) { mpi->flags &= ~MP_IMGFLAG_FMT_MASK; @@ -320,6 +314,76 @@ void mp_image_copy(struct mp_image *dst, struct mp_image *src) memcpy(dst->planes[1], src->planes[1], MP_PALETTE_SIZE); } +void mp_image_copy_attributes(struct mp_image *dst, struct mp_image *src) +{ + dst->pict_type = src->pict_type; + dst->fields = src->fields; + dst->qscale_type = src->qscale_type; + dst->pts = src->pts; + if (dst->w == src->w && dst->h == src->h) { + dst->qstride = src->qstride; + dst->qscale = src->qscale; + dst->display_w = src->display_w; + dst->display_h = src->display_h; + } + if ((dst->flags & MP_IMGFLAG_YUV) == (src->flags & MP_IMGFLAG_YUV)) { + dst->colorspace = src->colorspace; + dst->levels = src->levels; + } + if (dst->imgfmt == IMGFMT_PAL8 && src->imgfmt == IMGFMT_PAL8) { + memcpy(dst->planes[1], src->planes[1], MP_PALETTE_SIZE); + } +} + +void mp_image_clear(struct mp_image *mpi, int x0, int y0, int w, int h) +{ + int y; + if (mpi->flags & MP_IMGFLAG_PLANAR) { + y0 &= ~1; + h += h & 1; + for (y = y0; y < y0 + h; y += 2) { + memset(mpi->planes[0] + x0 + mpi->stride[0] * y, 0, w); + memset(mpi->planes[0] + x0 + mpi->stride[0] * (y + 1), 0, w); + memset(mpi->planes[1] + (x0 >> mpi->chroma_x_shift) + + mpi->stride[1] * (y >> mpi->chroma_y_shift), + 128, (w >> mpi->chroma_x_shift)); + memset(mpi->planes[2] + (x0 >> mpi->chroma_x_shift) + + mpi->stride[2] * (y >> mpi->chroma_y_shift), + 128, (w >> mpi->chroma_x_shift)); + } + return; + } + // packed: + for (y = y0; y < y0 + h; y++) { + unsigned char *dst = mpi->planes[0] + mpi->stride[0] * y + + (mpi->bpp >> 3) * x0; + if (mpi->flags & MP_IMGFLAG_YUV) { + unsigned int *p = (unsigned int *) dst; + int size = (mpi->bpp >> 3) * w / 4; + int i; +#if BYTE_ORDER == BIG_ENDIAN +#define CLEAR_PACKEDYUV_PATTERN 0x00800080 +#define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x80008000 +#else +#define CLEAR_PACKEDYUV_PATTERN 0x80008000 +#define CLEAR_PACKEDYUV_PATTERN_SWAPPED 0x00800080 +#endif + if (mpi->flags & MP_IMGFLAG_SWAPPED) { + for (i = 0; i < size - 3; i += 4) + p[i] = p[i + 1] = p[i + 2] = p[i + 3] = CLEAR_PACKEDYUV_PATTERN_SWAPPED; + for (; i < size; i++) + p[i] = CLEAR_PACKEDYUV_PATTERN_SWAPPED; + } else { + for (i = 0; i < size - 3; i += 4) + p[i] = p[i + 1] = p[i + 2] = p[i + 3] = CLEAR_PACKEDYUV_PATTERN; + for (; i < size; i++) + p[i] = CLEAR_PACKEDYUV_PATTERN; + } + } else + memset(dst, 0, (mpi->bpp >> 3) * w); + } +} + enum mp_csp mp_image_csp(struct mp_image *img) { if (img->colorspace != MP_CSP_AUTO) diff --git a/video/mp_image.h b/video/mp_image.h index cfc839c1cc..05502c49b4 100644 --- a/video/mp_image.h +++ b/video/mp_image.h @@ -97,6 +97,7 @@ typedef struct mp_image { #define copy_mpi mp_image_copy struct mp_image *mp_image_alloc(unsigned int fmt, int w, int h); +void mp_image_clear(struct mp_image *mpi, int x0, int y0, int w, int h); void mp_image_copy(struct mp_image *dmpi, struct mp_image *mpi); void mp_image_copy_attributes(struct mp_image *dmpi, struct mp_image *mpi); struct mp_image *mp_image_new_copy(struct mp_image *img); diff --git a/video/out/vo_xv.c b/video/out/vo_xv.c index 4f26f195c6..8bfe3e1777 100644 --- a/video/out/vo_xv.c +++ b/video/out/vo_xv.c @@ -47,7 +47,6 @@ #include "vo.h" #include "video/vfcap.h" #include "video/mp_image.h" -#include "video/filter/vf.h" #include "x11_common.h" #include "video/memcpy_pic.h" #include "sub/sub.h" @@ -267,7 +266,7 @@ static void allocate_xvimage(struct vo *vo, int foo) XSync(x11->display, False); } struct mp_image img = get_xv_buffer(vo, foo); - vf_mpi_clear(&img, 0, 0, img.w, img.h); + mp_image_clear(&img, 0, 0, img.w, img.h); return; } @@ -394,9 +393,7 @@ static mp_image_t *get_screenshot(struct vo *vo) struct xvctx *ctx = vo->priv; struct mp_image img = get_xv_buffer(vo, ctx->visible_buf); - struct mp_image *res = alloc_mpi(img.w, img.h, img.imgfmt); - copy_mpi(res, &img); - vf_clone_mpi_attributes(res, &img); + struct mp_image *res = mp_image_new_copy(&img); mp_image_set_display_size(res, vo->aspdat.prew, vo->aspdat.preh); // try to get an image without OSD mp_draw_sub_backup_restore(ctx->osd_backup, res); -- cgit v1.2.3