summaryrefslogtreecommitdiffstats
path: root/video/mp_image.c
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-12-19 12:04:57 +0100
committerwm4 <wm4@nowhere>2013-01-13 20:04:11 +0100
commit15c7f7a33968edebe305e2845b32eb2383457d46 (patch)
treed9ac4532c4b2ceb2e7a08f16399dcbfda3eefa7f /video/mp_image.c
parentaa6ba6372c627bc602647d225bdfb076f93bd291 (diff)
downloadmpv-15c7f7a33968edebe305e2845b32eb2383457d46.tar.bz2
mpv-15c7f7a33968edebe305e2845b32eb2383457d46.tar.xz
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.
Diffstat (limited to 'video/mp_image.c')
-rw-r--r--video/mp_image.c76
1 files changed, 70 insertions, 6 deletions
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)