From patchwork Tue Aug 20 13:37:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: velocityra@gmail.com X-Patchwork-Id: 14624 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 3CA57447FAE for ; Tue, 20 Aug 2019 16:46:14 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 279D268AA1F; Tue, 20 Aug 2019 16:46:14 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C2A54688391 for ; Tue, 20 Aug 2019 16:46:08 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id k1so2399118wmi.1 for ; Tue, 20 Aug 2019 06:46:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=4B6V9oHUwk0PTlUrpZ2ItwPqM2tEd1DF1UK2BGn6yXc=; b=nEtRKYqtvQHc5AALzPui0kNx1P4gQA85qrzLtAL4gccWM6WlcIQlr/VytpwLUcqyfh SeQgWRVhI4miL3E72aTxGS8s8GxHtznPBUMj5BAV5puXDVrgbTEzuuTCSNCXJnF/5VkQ nkxq/iqQzaAu50irZa5ZwsnBkfOPO93eSFhUCyxSqnZqBDjGzGGlZfouDoqd3uLemGJL ne5ytlieb4nfndm9iY7W2kLkOXGfpjbj43lf4A1GSNKXchReOCEd1fnytgkDZ1QPyAjU rnpNg5/1O+gYz0OVbDc/ZttG5TypUiP+sA9ks392VtDB6DqFGTtLlkyUcdf7iNNLsjG9 u6kQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=4B6V9oHUwk0PTlUrpZ2ItwPqM2tEd1DF1UK2BGn6yXc=; b=rbfROQrwxByHMba1OYOaTMUFmWh+GF8K1uhZZoyEYCMEPBEvs8r3KoEfZPccwPnK89 0OWVgubhZUOOVkfhC5HVwI3DOstRX4isMu4zowRVdZ2czrtv2PzWmU2SCtzbM3KQ6QoS Xu+dLy6o5kf8wm+PTzGYsz4GyGe1f3ufF1snrRcwoxYyqowdNQEcqLBT9UU37ZysOdur xgAkteRCOPHXqGLE++8hOVEOQjm2b4A5sgkOt7U91EsihJzKPT5NUj2ma7KkMKQWe3MU yLaQHYea1Nqg+CSPu4Yc5JRddxJ60Fxq2LndLnhjO1y8f6MBl+rtH7MaFOJnGgTN2O8a D5jQ== X-Gm-Message-State: APjAAAU3R4UxMqvIP+INFNNpIu/mKys49eXmUZb2HkX00QoNAcE4m2+p AIKo6NZOl/vkZ3Rs4wAbbOqYdrC/ X-Google-Smtp-Source: APXvYqzXhMHohQ8lyq+2DCv1QIIjZXACRK1gxx3STMENSdQGVYJ5VRTg1WfUhMLlLBPzFdwHAVlJNA== X-Received: by 2002:a7b:c415:: with SMTP id k21mr12635wmi.135.1566308295495; Tue, 20 Aug 2019 06:38:15 -0700 (PDT) Received: from localhost.localdomain (ppp-94-66-223-133.home.otenet.gr. [94.66.223.133]) by smtp.gmail.com with ESMTPSA id t14sm11545882wrs.58.2019.08.20.06.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 20 Aug 2019 06:38:14 -0700 (PDT) From: Nick Renieris To: ffmpeg-devel@ffmpeg.org Date: Tue, 20 Aug 2019 16:37:35 +0300 Message-Id: <20190820133747.30983-3-velocityra@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190820133747.30983-1-velocityra@gmail.com> References: <20190811144542.11704-13-velocityra@gmail.com> <20190820133747.30983-1-velocityra@gmail.com> Subject: [FFmpeg-devel] [PATCH v15 03/15] lavc/tiff: Convert DNGs to sRGB color space X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Nick Renieris MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: Nick Renieris --- libavcodec/tiff.c | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/libavcodec/tiff.c b/libavcodec/tiff.c index 4c6b835afe..a2102f32b5 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; } -static uint16_t av_always_inline dng_raw_to_linear8(uint16_t value, +static uint16_t av_always_inline dng_process_color8(uint16_t value, const uint16_t *lut, uint16_t black_level, float scale_factor) { - return dng_raw_to_linear16(value, lut, black_level, scale_factor) >> 8; + return dng_process_color16(value, lut, black_level, scale_factor) >> 8; } static void dng_blit(TiffContext *s, uint8_t *dst, int dst_stride, @@ -774,7 +786,7 @@ static void dng_blit(TiffContext *s, uint8_t *dst, int dst_stride, uint16_t *src_u16 = (uint16_t *)src; for (col = 0; col < width; col++) - *dst_u16++ = dng_raw_to_linear16(*src_u16++, s->dng_lut, s->black_level, scale_factor); + *dst_u16++ = dng_process_color16(*src_u16++, s->dng_lut, s->black_level, scale_factor); dst += dst_stride * sizeof(uint16_t); src += src_stride * sizeof(uint16_t); @@ -782,7 +794,7 @@ static void dng_blit(TiffContext *s, uint8_t *dst, int dst_stride, } else { for (line = 0; line < height; line++) { for (col = 0; col < width; col++) - *dst++ = dng_raw_to_linear8(*src++, s->dng_lut, s->black_level, scale_factor); + *dst++ = dng_process_color8(*src++, s->dng_lut, s->black_level, scale_factor); dst += dst_stride; src += src_stride;