summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2012-10-27 18:01:51 +0200
committerwm4 <wm4@nowhere>2012-10-28 15:31:32 +0100
commitd9839fe8623c855b6b335df3a5b9783e3ed22266 (patch)
treeb074361fef63d1a00b473e1859d373acb8c1e0e0
parent1ba8090df7e64885f717133d769f59808c3c8807 (diff)
downloadmpv-d9839fe8623c855b6b335df3a5b9783e3ed22266.tar.bz2
mpv-d9839fe8623c855b6b335df3a5b9783e3ed22266.tar.xz
mp_image: add fields to pass colorspace down the filter chain
Note that this also adds a RGB colorspace for general symmetry. The frontend (colormatrix property and options) and mp_get_yuv2rgb_coeffs() don't support this.
-rw-r--r--libmpcodecs/mp_image.c29
-rw-r--r--libmpcodecs/mp_image.h10
-rw-r--r--libmpcodecs/vd_ffmpeg.c2
-rw-r--r--libmpcodecs/vf.c4
-rw-r--r--libvo/csputils.c5
-rw-r--r--libvo/csputils.h2
6 files changed, 51 insertions, 1 deletions
diff --git a/libmpcodecs/mp_image.c b/libmpcodecs/mp_image.c
index b7c9017188..c0227e4b1d 100644
--- a/libmpcodecs/mp_image.c
+++ b/libmpcodecs/mp_image.c
@@ -249,3 +249,32 @@ void free_mp_image(mp_image_t* mpi){
talloc_free(mpi);
}
+enum mp_csp mp_image_csp(struct mp_image *img)
+{
+ if (img->colorspace != MP_CSP_AUTO)
+ return img->colorspace;
+ return (img->flags & MP_IMGFLAG_YUV) ? MP_CSP_BT_601 : MP_CSP_RGB;
+}
+
+enum mp_csp_levels mp_image_levels(struct mp_image *img)
+{
+ if (img->levels != MP_CSP_LEVELS_AUTO)
+ return img->levels;
+ return (img->flags & MP_IMGFLAG_YUV) ? MP_CSP_LEVELS_TV : MP_CSP_LEVELS_PC;
+}
+
+void mp_image_set_colorspace_details(struct mp_image *image,
+ struct mp_csp_details *csp)
+{
+ if (image->flags & MP_IMGFLAG_YUV) {
+ image->colorspace = csp->format;
+ if (image->colorspace == MP_CSP_AUTO)
+ image->colorspace = MP_CSP_BT_601;
+ image->levels = csp->levels_in;
+ if (image->levels == MP_CSP_LEVELS_AUTO)
+ image->levels = MP_CSP_LEVELS_TV;
+ } else {
+ image->colorspace = MP_CSP_RGB;
+ image->levels = MP_CSP_LEVELS_PC;
+ }
+}
diff --git a/libmpcodecs/mp_image.h b/libmpcodecs/mp_image.h
index 91a725f9d6..fa5e7032f9 100644
--- a/libmpcodecs/mp_image.h
+++ b/libmpcodecs/mp_image.h
@@ -24,6 +24,7 @@
#include <string.h>
#include <inttypes.h>
#include "mp_msg.h"
+#include "libvo/csputils.h"
//--------- codec's requirements (filled by the codec/vf) ---------
@@ -118,6 +119,8 @@ typedef struct mp_image {
int chroma_height;
int chroma_x_shift; // horizontal
int chroma_y_shift; // vertical
+ enum mp_csp colorspace;
+ enum mp_csp_levels levels;
int usage_count;
/* for private use by filter or vo driver (to store buffer id or dmpi) */
void* priv;
@@ -131,6 +134,13 @@ mp_image_t* alloc_mpi(int w, int h, unsigned long int fmt);
void mp_image_alloc_planes(mp_image_t *mpi);
void copy_mpi(mp_image_t *dmpi, mp_image_t *mpi);
+enum mp_csp mp_image_csp(struct mp_image *img);
+enum mp_csp_levels mp_image_levels(struct mp_image *img);
+
+struct mp_csp_details;
+void mp_image_set_colorspace_details(struct mp_image *image,
+ struct mp_csp_details *csp);
+
// this macro requires img_format.h to be included too:
#define MP_IMAGE_PLANAR_BITS_PER_PIXEL_ON_PLANE(mpi, p) \
(IMGFMT_IS_YUVP16((mpi)->imgfmt) ? 16 : 8)
diff --git a/libmpcodecs/vd_ffmpeg.c b/libmpcodecs/vd_ffmpeg.c
index 343a26d8d3..941aae7175 100644
--- a/libmpcodecs/vd_ffmpeg.c
+++ b/libmpcodecs/vd_ffmpeg.c
@@ -768,6 +768,8 @@ static struct mp_image *decode(struct sh_video *sh, struct demux_packet *packet,
swap_palette(mpi->planes[1]);
#endif
+ mpi->colorspace = sh->colorspace;
+ mpi->levels = sh->color_range;
mpi->qscale = pic->qscale_table;
mpi->qstride = pic->qstride;
mpi->pict_type = pic->pict_type;
diff --git a/libmpcodecs/vf.c b/libmpcodecs/vf.c
index 39a720a893..5f4da28dee 100644
--- a/libmpcodecs/vf.c
+++ b/libmpcodecs/vf.c
@@ -538,6 +538,10 @@ void vf_clone_mpi_attributes(mp_image_t *dst, mp_image_t *src)
dst->qstride = src->qstride;
dst->qscale = src->qscale;
}
+ if ((dst->flags & MP_IMGFLAG_YUV) == (src->flags & MP_IMGFLAG_YUV)) {
+ dst->colorspace = src->colorspace;
+ dst->levels = src->levels;
+ }
}
void vf_queue_frame(vf_instance_t *vf, int (*func)(vf_instance_t *))
diff --git a/libvo/csputils.c b/libvo/csputils.c
index 5d2711b1ce..23eb099f69 100644
--- a/libvo/csputils.c
+++ b/libvo/csputils.c
@@ -39,6 +39,7 @@ char * const mp_csp_names[MP_CSP_COUNT] = {
"BT.601 (SD)",
"BT.709 (HD)",
"SMPTE-240M",
+ "RGB",
};
char * const mp_csp_equalizer_names[MP_CSP_EQ_COUNT] = {
@@ -56,6 +57,7 @@ enum mp_csp avcol_spc_to_mp_csp(enum AVColorSpace colorspace)
case AVCOL_SPC_BT470BG: return MP_CSP_BT_601;
case AVCOL_SPC_SMPTE170M: return MP_CSP_BT_601;
case AVCOL_SPC_SMPTE240M: return MP_CSP_SMPTE_240M;
+ case AVCOL_SPC_RGB: return MP_CSP_RGB;
default: return MP_CSP_AUTO;
}
}
@@ -75,7 +77,8 @@ enum AVColorSpace mp_csp_to_avcol_spc(enum mp_csp colorspace)
case MP_CSP_BT_709: return AVCOL_SPC_BT709;
case MP_CSP_BT_601: return AVCOL_SPC_BT470BG;
case MP_CSP_SMPTE_240M: return AVCOL_SPC_SMPTE240M;
- default: return AVCOL_SPC_RGB;
+ case MP_CSP_RGB: return AVCOL_SPC_RGB;
+ default: return AVCOL_SPC_UNSPECIFIED;
}
}
diff --git a/libvo/csputils.h b/libvo/csputils.h
index fc6b492441..d66bb86fa3 100644
--- a/libvo/csputils.h
+++ b/libvo/csputils.h
@@ -24,6 +24,7 @@
#ifndef MPLAYER_CSPUTILS_H
#define MPLAYER_CSPUTILS_H
+#include <stdbool.h>
#include <stdint.h>
#include "libavcodec/avcodec.h"
@@ -38,6 +39,7 @@ enum mp_csp {
MP_CSP_BT_601,
MP_CSP_BT_709,
MP_CSP_SMPTE_240M,
+ MP_CSP_RGB,
MP_CSP_COUNT
};