From patchwork Fri Dec 22 15:04:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Shankar, Uma" X-Patchwork-Id: 10130579 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 940B360318 for ; Fri, 22 Dec 2017 14:33:05 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8B73329FA9 for ; Fri, 22 Dec 2017 14:33:05 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8085929FE9; Fri, 22 Dec 2017 14:33:05 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2381129FA9 for ; Fri, 22 Dec 2017 14:33:04 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9450B6E14C; Fri, 22 Dec 2017 14:33:04 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by gabe.freedesktop.org (Postfix) with ESMTPS id 280736E14C for ; Fri, 22 Dec 2017 14:33:03 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga104.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Dec 2017 06:33:03 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.45,441,1508828400"; d="scan'208";a="189023942" Received: from ubuntu-tc11.iind.intel.com ([10.223.25.173]) by fmsmga005.fm.intel.com with ESMTP; 22 Dec 2017 06:33:01 -0800 From: Uma Shankar To: intel-gfx@lists.freedesktop.org Date: Fri, 22 Dec 2017 20:34:47 +0530 Message-Id: <1513955087-17598-1-git-send-email-uma.shankar@intel.com> X-Mailer: git-send-email 1.7.9.5 Cc: Johnson Lin , ville.syrjala@intel.com, maarten.lankhorst@intel.com Subject: [Intel-gfx] [PATCH] drm/i915: Fix Limited Range Color Handling X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Johnson Lin Some panels support limited range output (16-235) compared to full range RGB values (0-255). Also userspace can control the RGB range using "Broadcast RGB" property. Currently the code to handle full range to limited range is broken. This patch fixes the same by properly scaling down all the full range co-efficients with limited range scaling factor. Signed-off-by: Johnson Lin Signed-off-by: Uma Shankar --- drivers/gpu/drm/i915/intel_color.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_color.c b/drivers/gpu/drm/i915/intel_color.c index aa66e95..777ce26 100644 --- a/drivers/gpu/drm/i915/intel_color.c +++ b/drivers/gpu/drm/i915/intel_color.c @@ -94,16 +94,24 @@ static void ctm_mult_by_limited(uint64_t *result, int64_t *input) for (i = 0; i < 9; i++) result[i] = 0; - for (i = 0; i < 3; i++) { - int64_t user_coeff = input[i * 3 + i]; + for (i = 0; i < 9; i++) { + int64_t user_coeff = input[i]; uint64_t limited_coeff = CTM_COEFF_LIMITED_RANGE >> 2; uint64_t abs_coeff = clamp_val(CTM_COEFF_ABS(user_coeff), 0, CTM_COEFF_4_0 - 1) >> 2; - result[i * 3 + i] = (limited_coeff * abs_coeff) >> 27; + /* + * By scaling every co-efficient with limited range (235-16) + * vs full range (0-255) the final o/p will be scaled down to + * fit in the limited range supported by the panel. + * Need to shift the multiplication result by 28 as the floating + * count expected is of 32bits, multiplication here is done in + * U2.30 so result need to be right shifted by 60-32 = 28 + */ + result[i] = (limited_coeff * abs_coeff) >> 28; if (CTM_COEFF_NEGATIVE(user_coeff)) - result[i * 3 + i] |= CTM_COEFF_SIGN; + result[i] |= CTM_COEFF_SIGN; } }