Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp173965imj; Thu, 14 Feb 2019 17:57:43 -0800 (PST) X-Google-Smtp-Source: AHgI3IYQF5zwoGkzmmO92abp44m8PRxRaICbBRPV/zwRKARr+AMAnEVcA+0e9kijMfVGRCRseSAq X-Received: by 2002:a62:3a92:: with SMTP id v18mr7346027pfj.43.1550195863385; Thu, 14 Feb 2019 17:57:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550195863; cv=none; d=google.com; s=arc-20160816; b=wRlSLpUoqK6P4zALAODk/jtpDt9n4qfDL6kuGZGOtC9cwQhrxMnKji6JaCZ88bAmCs /j+K+cYSv/wuUBD4wdt7yE0c8n1IQLNrPlPj1RyFEsCbCjo5HNVfgIsMkhPZ+SQH1Jln jobKDc4yMjaThBM4Vy9hvPcAhI73WrInUEc39dWQzHzxorvhGd6PnsJcJEACrpOL4GbF Q/Sowk99N9QrGWh5P494/QFBqIi2LpLKJz3ETPr9+LJ+zTMwGG6Jwn0gG4+Xg4PCZtlt q6+jllVx1NbwOyejybPGGdq13qpnbKS8r1eoGl4JYV7TQDcmipB1wMmeUBbjatFhG/Ez mYMQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-language :content-transfer-encoding:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:subject:from:dkim-signature; bh=N9eJJVG9XGs4TaN74QOpQZCPONKwYIz2B722eHcHttE=; b=LaoT8G8l1/dMmNw2QsgEMc1zwdxVNPB5SztqI3r4cYlj/TMvYfXAb5uOzrED50c8lx 35YzIpPAfcFJ1w+oE9PzJplnfw4SG0nKvjvXl0FsyIUZYQQu7ga4k+l+WdLZlMYXGEjk 76OrFhFkhpRn/OG0/0SGacUPPA6GesA0xypCCxpBe0uguEBnyoVleFfvj7DwKrNsNRq6 LSkPTfltkvy6p4qAzJvhiIklO1wF8atpxy/IVGCDLd/JKrULE+3NuK+WGny+WYXz62FA fEhz1Ab+K+7oyQngOIAs5AyffAZGY9aUoP79lVSDlsL+otkS7ku23lNI4API3VH/ePcg 3qzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UqSPKNky; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id u27si4123790pfa.103.2019.02.14.17.57.27; Thu, 14 Feb 2019 17:57:43 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=UqSPKNky; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389313AbfBNSy1 (ORCPT + 99 others); Thu, 14 Feb 2019 13:54:27 -0500 Received: from mail-wm1-f68.google.com ([209.85.128.68]:50874 "EHLO mail-wm1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727717AbfBNSy0 (ORCPT ); Thu, 14 Feb 2019 13:54:26 -0500 Received: by mail-wm1-f68.google.com with SMTP id x7so7421041wmj.0; Thu, 14 Feb 2019 10:54:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:subject:to:cc:references:message-id:date:user-agent :mime-version:in-reply-to:content-transfer-encoding:content-language; bh=N9eJJVG9XGs4TaN74QOpQZCPONKwYIz2B722eHcHttE=; b=UqSPKNkyoJxNYYWFVTemRARDhJD8QPg3kY+ugEchqehm2frEaLoArmiby04EL518I+ kqTjY5s3sqnefl5VSZ8ISlE/ZjirPJPULWZ13CH+5BA5OfMDDOPVBZl+p5i1Awj+ixoJ W41gJhijrljbko7KPyBlFhMX4VkwRwJi5hSNUd+JY9vTHyGVyyNyQR9hFAIt9Wm21c2L IUfG+t0uEOO4yFTCHomHORR3s4l+Y7EWs6xLgzsmp5+UTMzfWuSNqYLxfGO0qji5p3xM MJlFK77Nkjbl/4s5TjndNTLqVZJa9CSq4vdRHPbQ7dW6KPktkqD4CJ0KYanR5xFAwNvg /4/w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:subject:to:cc:references:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=N9eJJVG9XGs4TaN74QOpQZCPONKwYIz2B722eHcHttE=; b=RspIbw+2kh1dAtEQgt/5QtV1zCqQnI6KurM3SFbY1gdyOeMkT98UmnEwtuTbPEyLdR wWPaynMCGMoihE5ySqUYx5PjnVLrWDChWOGM/MlnsMlnWl0BLvs35BlyXi1EZGlJWS8y 67an+Wi1AtGEQYuhtDTOJqtQi4x2FnXZSQSywnpKjyt68zZoZHjklJbwzezRzSNwWOrZ r3JqdJWK2kFdykr8Elc1q6rsudGRsKagStfQny3KeOaCC4LOvDBsu+Mi3ESoSmt3XlIV unNbavhLlYyZho61mtOWe1P3qitMnHaUKA9LN7xmswcsdsUU+x1di+w2LhN3fz31V1Ln EihQ== X-Gm-Message-State: AHQUAuaZHxrmiVU+H6ke7RxGk30v279+PLKHV2XE5drfoYx5KLRpXd/V jDhGbIW2q6svTg23bSV2+IfXWaL9 X-Received: by 2002:a1c:81c2:: with SMTP id c185mr3558479wmd.58.1550170463538; Thu, 14 Feb 2019 10:54:23 -0800 (PST) Received: from [172.30.88.202] (sjewanfw1-nat.mentorg.com. [139.181.7.34]) by smtp.gmail.com with ESMTPSA id u134sm2047373wmf.21.2019.02.14.10.54.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 14 Feb 2019 10:54:22 -0800 (PST) From: Steve Longerbeam Subject: Re: [PATCH v4 1/4] gpu: ipu-v3: ipu-ic: Rename yuv2rgb encoding matrices To: Philipp Zabel , linux-media@vger.kernel.org Cc: Tim Harvey , "open list:DRM DRIVERS FOR FREESCALE IMX" , open list References: <20190209014748.10427-1-slongerbeam@gmail.com> <20190209014748.10427-2-slongerbeam@gmail.com> <1549879117.7687.2.camel@pengutronix.de> <0f987e19-e6e9-a56e-00ec-61e7e300a92e@gmail.com> <1549966666.4800.3.camel@pengutronix.de> <7d4c5935-ffa1-2320-1632-136e1ce89350@gmail.com> <1550054109.3937.1.camel@pengutronix.de> Message-ID: <58bf1e34-8b9d-7fec-6ba5-5db1d5c5457d@gmail.com> Date: Thu, 14 Feb 2019 10:54:19 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <1550054109.3937.1.camel@pengutronix.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/13/19 2:35 AM, Philipp Zabel wrote: > On Tue, 2019-02-12 at 09:42 -0800, Steve Longerbeam wrote: > [...] >>>> But what about this "SAT_MODE" field in the IC task parameter memory? >>> That just controls the saturation. The result after the matrix >>> multiplication is either saturated to [0..255] or to [16..235]/[16..240] >>> when converting from the internal representation to the 8 bit output. >> By saturation I think you mean clipped to those ranges? > Yes, thanks. I didn't realize it sounds weird to use saturated this way. > See:https://en.wikipedia.org/wiki/Saturation_arithmetic Ok, saturation can mean the same thing as clipping/clamping. Thanks for the article. I tested a RGB->YUV pipeline with the .sat bit set in the BT.601 rgb2yuv table, with the following pipeline on the SabreSD: 'ov5640 1-003c':0         [fmt:RGB565_2X8_LE/1024x768@1/30 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:full-range] 'imx6-mipi-csi2':0         [fmt:RGB565_2X8_LE/1024x768 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:full-range] 'imx6-mipi-csi2':2         [fmt:RGB565_2X8_LE/1024x768 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:full-range] 'ipu1_csi1':0         [fmt:RGB565_2X8_LE/1024x768@1/30 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:full-range          crop.bounds:(0,0)/1024x768          crop:(0,0)/1024x768          compose.bounds:(0,0)/1024x768          compose:(0,0)/1024x768] 'ipu1_csi1':1         [fmt:ARGB8888_1X32/1024x768@1/30 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:full-range] 'ipu1_ic_prp':0         [fmt:ARGB8888_1X32/1024x768@1/30 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:full-range] 'ipu1_ic_prp':1         [fmt:ARGB8888_1X32/1024x768@1/30 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:full-range] 'ipu1_ic_prpenc':0         [fmt:ARGB8888_1X32/1024x768@1/30 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:full-range] 'ipu1_ic_prpenc':1         [fmt:AYUV8_1X32/800x600@1/30 field:none colorspace:srgb xfer:srgb ycbcr:601 quantization:lim-range] /dev/video0:0 Format Video Capture:     Width/Height      : 800/600     Pixel Format      : 'YV12'     Field             : None     Bytes per Line    : 800     Size Image        : 720000     Colorspace        : sRGB     Transfer Function : sRGB     YCbCr/HSV Encoding: ITU-R 601     Quantization      : Limited Range     Flags             : The result being that the captured image colors are all off (there's a bright pink shade to the images). But I discovered the init_csc() function was not setting the saturation bit at the correct bit offset within the TPMEM. The saturation bit is bit 42, or bit 10 of the second 32-bit word. But the code was writing to bit 9 of the second word. After correcting this, saturation is working fine. I have added another patch that fixes this for v5 series. > >>> SAT_MODE should be set for conversions to YUV limited range so that the >>> coefficients can be rounded to the closest value. >> Well, we have already rounded the coefficients to the nearest int in the >> tables. Do you mean the final result (coeff * color component + offset) >> is rounded? > The manual says so: "The final calculation result is limited according > to the SAT_MODE parameter and rounded to 8 bits", but that's not what I > meant. Still, I might have been mistaken. > > I think due to the fact that the coefficients are multiplied by up to > 255 (max pixel value) and then effectively divided by 256 when > converting to 8 bit, the only way to overflow limited range is if two > coefficients are rounded away from zero in the calculation of a single > component. This doesn't seem to happen in practice. > > A constructed example, conversion to YUV limited range with carefully > chosen coefficients. > > Y = R * .1817 + G * .6153 + B * .0618 + 16; > > Note that .1817 + .6153 + .0618 < 219/255. > With rounded coefficients though: > > Y = (R * 47 + G * 158 + B * 16 + (64 << 6)) / 256 = 236.136 Yes, for a rec.709 conversion and max/worst-case RGB signal = (255,255,255). But the rec.709 coefficients for Y are actually Y = (R * 47 + G * 157 + B * 16 + (16 << 8)) / 256 which for RGB = (255,255,255), Y = 235.14, which doesn't overflow limited range. Steve