[FFmpeg-cvslog] avfilter/drawutils: add support for full range
Paul B Mahol
git at videolan.org
Thu May 3 22:58:55 EEST 2018
ffmpeg | branch: master | Paul B Mahol <onemda at gmail.com> | Wed May 2 13:10:10 2018 +0200| [f43fd68f28079c49e9237894a294968d841babc7] | committer: Paul B Mahol
avfilter/drawutils: add support for full range
Signed-off-by: Paul B Mahol <onemda at gmail.com>
> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=f43fd68f28079c49e9237894a294968d841babc7
---
libavfilter/drawutils.c | 11 ++++++++---
libavfilter/drawutils.h | 1 +
libavutil/colorspace.h | 12 ++++++++++++
tests/ref/fate/filter-pixfmts-pad | 10 +++++-----
4 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/libavfilter/drawutils.c b/libavfilter/drawutils.c
index db8c7a6226..650ef25aba 100644
--- a/libavfilter/drawutils.c
+++ b/libavfilter/drawutils.c
@@ -181,6 +181,7 @@ int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
const AVComponentDescriptor *c;
unsigned i, nb_planes = 0;
int pixelstep[MAX_PLANES] = { 0 };
+ int full_range = 0;
if (!desc || !desc->name)
return AVERROR(EINVAL);
@@ -188,6 +189,9 @@ int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
return AVERROR(ENOSYS);
if (format == AV_PIX_FMT_P010LE || format == AV_PIX_FMT_P010BE || format == AV_PIX_FMT_P016LE || format == AV_PIX_FMT_P016BE)
return AVERROR(ENOSYS);
+ if (format == AV_PIX_FMT_YUVJ420P || format == AV_PIX_FMT_YUVJ422P || format == AV_PIX_FMT_YUVJ444P ||
+ format == AV_PIX_FMT_YUVJ411P || format == AV_PIX_FMT_YUVJ440P)
+ full_range = 1;
for (i = 0; i < desc->nb_components; i++) {
c = &desc->comp[i];
/* for now, only 8-16 bits formats */
@@ -214,6 +218,7 @@ int ff_draw_init(FFDrawContext *draw, enum AVPixelFormat format, unsigned flags)
draw->format = format;
draw->nb_planes = nb_planes;
draw->flags = flags;
+ draw->full_range = full_range;
memcpy(draw->pixelstep, pixelstep, sizeof(draw->pixelstep));
draw->hsub[1] = draw->hsub[2] = draw->hsub_max = desc->log2_chroma_w;
draw->vsub[1] = draw->vsub[2] = draw->vsub_max = desc->log2_chroma_h;
@@ -249,9 +254,9 @@ void ff_draw_color(FFDrawContext *draw, FFDrawColor *color, const uint8_t rgba[4
} else if (draw->nb_planes >= 2) {
/* assume YUV */
const AVPixFmtDescriptor *desc = draw->desc;
- color->comp[desc->comp[0].plane].u8[desc->comp[0].offset] = RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
- color->comp[desc->comp[1].plane].u8[desc->comp[1].offset] = RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
- color->comp[desc->comp[2].plane].u8[desc->comp[2].offset] = RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
+ color->comp[desc->comp[0].plane].u8[desc->comp[0].offset] = draw->full_range ? RGB_TO_Y_JPEG(rgba[0], rgba[1], rgba[2]) : RGB_TO_Y_CCIR(rgba[0], rgba[1], rgba[2]);
+ color->comp[desc->comp[1].plane].u8[desc->comp[1].offset] = draw->full_range ? RGB_TO_U_JPEG(rgba[0], rgba[1], rgba[2]) : RGB_TO_U_CCIR(rgba[0], rgba[1], rgba[2], 0);
+ color->comp[desc->comp[2].plane].u8[desc->comp[2].offset] = draw->full_range ? RGB_TO_V_JPEG(rgba[0], rgba[1], rgba[2]) : RGB_TO_V_CCIR(rgba[0], rgba[1], rgba[2], 0);
color->comp[3].u8[0] = rgba[3];
#define EXPAND(compn) \
if (desc->comp[compn].depth > 8) \
diff --git a/libavfilter/drawutils.h b/libavfilter/drawutils.h
index cf53635456..b999d70e55 100644
--- a/libavfilter/drawutils.h
+++ b/libavfilter/drawutils.h
@@ -55,6 +55,7 @@ typedef struct FFDrawContext {
uint8_t vsub[MAX_PLANES]; /*< vertical subsampling */
uint8_t hsub_max;
uint8_t vsub_max;
+ int full_range;
unsigned flags;
} FFDrawContext;
diff --git a/libavutil/colorspace.h b/libavutil/colorspace.h
index b6dba2c95f..d0be8cb99a 100644
--- a/libavutil/colorspace.h
+++ b/libavutil/colorspace.h
@@ -107,4 +107,16 @@ static inline int C_JPEG_TO_CCIR(int y) {
(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.41869*224.0/255.0) * g1 - \
FIX(0.08131*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128)
+#define RGB_TO_Y_JPEG(r, g, b) \
+(FFMIN((FIX(0.29900) * (r) + FIX(0.58700) * (g) + \
+ FIX(0.11400) * (b) + (ONE_HALF)) >> SCALEBITS, 255))
+
+#define RGB_TO_U_JPEG(r1, g1, b1)\
+(((- FIX(0.16874) * r1 - FIX(0.33126) * g1 + \
+ FIX(0.50000) * b1 + (ONE_HALF) - 1) >> (SCALEBITS)) + 128)
+
+#define RGB_TO_V_JPEG(r1, g1, b1)\
+(((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \
+ FIX(0.08131) * b1 + (ONE_HALF) - 1) >> (SCALEBITS)) + 128)
+
#endif /* AVUTIL_COLORSPACE_H */
diff --git a/tests/ref/fate/filter-pixfmts-pad b/tests/ref/fate/filter-pixfmts-pad
index e777211cd9..68b83e7a61 100644
--- a/tests/ref/fate/filter-pixfmts-pad
+++ b/tests/ref/fate/filter-pixfmts-pad
@@ -62,8 +62,8 @@ yuva444p fb60941a57596b277417a3c7c00aa194
yuva444p10le 251ea4ead8300d752eb355a08cbb0352
yuva444p16le 5b65287e1862d2d9f1ad2cfdcde94661
yuva444p9le e6946c10b94c271e7ea24b3bcff314e1
-yuvj411p ca967e68759a4956729dd366adc7e7fa
-yuvj420p c00611cd5f1558047d579d8a7d30e381
-yuvj422p b3acdf07147a7598836065836ad8420b
-yuvj440p 3446ba4b1d7fdf536c926cee643c2b35
-yuvj444p 3b0f1a185af048b9e0b202d003fc7e62
+yuvj411p 87dbac57b211ab4823c1abbd702f1516
+yuvj420p 1abef62bce65131ca4913eb2006fd860
+yuvj422p 198c57b519e2be14b150889bd7f94898
+yuvj440p e6533260d197ad15e39319117c57473e
+yuvj444p 26a44748960513783ea676eff409d89a
More information about the ffmpeg-cvslog
mailing list