Message ID | c0b4aca9-4939-ccf4-541e-6d22147d8533@gyani.pro |
---|---|
State | Accepted |
Commit | 3bef1dab6e881bf593037f831e66ed87c6167e3c |
Headers | show |
On 19-04-2019 01:04 AM, Gyan wrote: > > > On 17-04-2019 11:30 PM, Gyan wrote: >> >> >> On 17-04-2019 11:11 PM, Vittorio Giovara wrote: >>> On Wed, Apr 17, 2019 at 12:26 AM Gyan <ffmpeg@gyani.pro> wrote: >>> >>>> >>>> On 13-04-2019 05:23 PM, Gyan wrote: >>>>> Will be helpful for correct result in filters that paint like >>>>> fillborders/drawbox or those using drawutils. >>>> Ping. >>>> >>> these seem to only work for 8 bit content, is that their only intended >>> usecase? >>> if so, could there be at least a comment mentioning that please? >> Yes, the existing macros use Rec.601 co-efficients, but most data is >> 709 now. >> Will add a note. > > With note. Will apply soon. Gyan
On 19-04-2019 09:57 AM, Gyan wrote: > > > On 19-04-2019 01:04 AM, Gyan wrote: >> >> >> On 17-04-2019 11:30 PM, Gyan wrote: >>> >>> >>> On 17-04-2019 11:11 PM, Vittorio Giovara wrote: >>>> On Wed, Apr 17, 2019 at 12:26 AM Gyan <ffmpeg@gyani.pro> wrote: >>>> >>>>> >>>>> On 13-04-2019 05:23 PM, Gyan wrote: >>>>>> Will be helpful for correct result in filters that paint like >>>>>> fillborders/drawbox or those using drawutils. >>>>> Ping. >>>>> >>>> these seem to only work for 8 bit content, is that their only intended >>>> usecase? >>>> if so, could there be at least a comment mentioning that please? >>> Yes, the existing macros use Rec.601 co-efficients, but most data is >>> 709 now. >>> Will add a note. >> >> With note. > > Will apply soon. Pushed as 3bef1dab6e881bf593037f831e66ed87c6167e3c Gyan
diff --git a/libavutil/colorspace.h b/libavutil/colorspace.h index d0be8cb99a..ef6f6107d6 100644 --- a/libavutil/colorspace.h +++ b/libavutil/colorspace.h @@ -119,4 +119,32 @@ static inline int C_JPEG_TO_CCIR(int y) { (((FIX(0.50000) * r1 - FIX(0.41869) * g1 - \ FIX(0.08131) * b1 + (ONE_HALF) - 1) >> (SCALEBITS)) + 128) +// Conversion macros for 8-bit RGB to YUV +// Derived from ITU-R BT.709-6 (06/2015) Item 3.5 +// https://www.itu.int/rec/R-REC-BT.709-6-201506-I/en + +#define RGB_TO_Y_BT709(r, g, b) \ +((FIX(0.21260*219.0/255.0) * (r) + FIX(0.71520*219.0/255.0) * (g) + \ + FIX(0.07220*219.0/255.0) * (b) + (ONE_HALF + (16 << SCALEBITS))) >> SCALEBITS) + +#define RGB_TO_U_BT709(r1, g1, b1, shift)\ +(((- FIX(0.11457*224.0/255.0) * r1 - FIX(0.38543*224.0/255.0) * g1 + \ + FIX(0.50000*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) + +#define RGB_TO_V_BT709(r1, g1, b1, shift)\ +(((FIX(0.50000*224.0/255.0) * r1 - FIX(0.45415*224.0/255.0) * g1 - \ + FIX(0.04585*224.0/255.0) * b1 + (ONE_HALF << shift) - 1) >> (SCALEBITS + shift)) + 128) + +#define RGB_TO_Y_BT709_FULL(r, g, b) \ +(FFMIN((FIX(0.21260) * (r) + FIX(0.71520) * (g) + \ + FIX(0.07220) * (b) + (ONE_HALF)) >> SCALEBITS, 255)) + +#define RGB_TO_U_BT709_FULL(r1, g1, b1)\ +(((- FIX(0.11457) * r1 - FIX(0.38543) * g1 + \ + FIX(0.50000) * b1 + (ONE_HALF) - 1) >> (SCALEBITS)) + 128) + +#define RGB_TO_V_BT709_FULL(r1, g1, b1)\ +(((FIX(0.50000) * r1 - FIX(0.45415) * g1 - \ + FIX(0.04585) * b1 + (ONE_HALF) - 1) >> (SCALEBITS)) + 128) + #endif /* AVUTIL_COLORSPACE_H */