[FFmpeg-devel] [PATCH v12 03/14] lavc/tiff: Convert DNGs to sRGB color space

Michael Niedermayer michael at niedermayer.cc
Sat Aug 10 15:42:11 EEST 2019


On Fri, Aug 09, 2019 at 07:29:48PM +0300, Nick Renieris wrote:
> From: Nick Renieris <velocityra at gmail.com>
> 
> Signed-off-by: Nick Renieris <velocityra at gmail.com>
> ---
>  libavcodec/tiff.c | 34 +++++++++++++++++++++++-----------
>  1 file changed, 23 insertions(+), 11 deletions(-)
> 
> diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c
> index d5673abb19..a118c37c41 100644
> --- a/libavcodec/tiff.c
> +++ b/libavcodec/tiff.c
> @@ -731,14 +731,23 @@ static int tiff_unpack_strip(TiffContext *s, AVFrame *p, uint8_t *dst, int strid
>      return 0;
>  }
>  
> +static float av_always_inline linear_to_srgb(float value) {
> +    if (value <= 0.0031308)
> +        return value * 12.92;
> +    else
> +        return pow(value * 1.055, 1.0 / 2.4) - 0.055;
> +}
> +
>  /**
> - * Map stored raw sensor values into linear reference values.
> - * See: DNG Specification - Chapter 5
> + * Map stored raw sensor values into linear reference values (see: DNG Specification - Chapter 5)
> + * Then convert to sRGB color space.
>   */
> -static uint16_t av_always_inline dng_raw_to_linear16(uint16_t value,
> -                                                    const uint16_t *lut,
> -                                                    uint16_t black_level,
> -                                                    float scale_factor) {
> +static uint16_t av_always_inline dng_process_color16(uint16_t value,
> +                                                     const uint16_t *lut,
> +                                                     uint16_t black_level,
> +                                                     float scale_factor) {
> +    float value_norm;
> +
>      // Lookup table lookup
>      if (lut)
>          value = lut[value];
> @@ -747,16 +756,19 @@ static uint16_t av_always_inline dng_raw_to_linear16(uint16_t value,
>      value = av_clip_uint16_c((unsigned)value - black_level);
>  
>      // Color scaling
> -    value = av_clip_uint16_c((unsigned)(((float)value * scale_factor) * 0xFFFF));
> +    value_norm = (float)value * scale_factor;
> +
> +    // Color space conversion (sRGB)
> +    value = av_clip_uint16_c((uint16_t)(linear_to_srgb(value_norm) * 0xFFFF));
>  
>      return value;
>  }

Why do you put all this color space convertion code into the decoders ?

Colorspace and pixel format convertion is generally done outside decoders.

Thanks


[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

What does censorship reveal? It reveals fear. -- Julian Assange
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20190810/9f63cb55/attachment.sig>


More information about the ffmpeg-devel mailing list