From patchwork Tue Nov 15 12:05:57 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ricardo Ribalda Delgado X-Patchwork-Id: 9429537 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 7640C6047D for ; Tue, 15 Nov 2016 12:06:11 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62FE128BAD for ; Tue, 15 Nov 2016 12:06:11 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 57D8828BB6; Tue, 15 Nov 2016 12:06:11 +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=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 14E3428BAD for ; Tue, 15 Nov 2016 12:06:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932110AbcKOMGF (ORCPT ); Tue, 15 Nov 2016 07:06:05 -0500 Received: from mail-wm0-f67.google.com ([74.125.82.67]:32797 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752269AbcKOMGE (ORCPT ); Tue, 15 Nov 2016 07:06:04 -0500 Received: by mail-wm0-f67.google.com with SMTP id u144so25073787wmu.0 for ; Tue, 15 Nov 2016 04:06:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b4WAFsNm9v7qNk38P0/IiD4k9oeLLC9miSDleVKtZVo=; b=IIfMTxTutRHzcf5A5MyCgHa6QrnHsaroJnCZ3qbX3WEFSZzG13xl31MsfYzltm0xIP 2BL9vdDD354ijdKLNatOth1kcYq3+RbjqoZUtxaU3Al0eFd8bQpkCIXjEEOI8o410Sk7 nlfpvpBXo1820HmuV+vR6DvxMeT0MpyuJD8EHCPMXMuPSQIQIJXakioQEbuhoAhxicrC Y2rqUMogg+l/+cxyLol+9iJ3sp9rQXh8tY3rgqCTq+K6z5+7x4Jg7pPAhoKlTjt4gSjq hA+QdJwdnmwmbO+omiR1oOI/ilmJvmjnuK0r7TcGgZNxPlaDMjAmC96K1NwV3ny60/lE M2DQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b4WAFsNm9v7qNk38P0/IiD4k9oeLLC9miSDleVKtZVo=; b=ZNxkA/6XAFMfr78lH+KjLTYKhs+D1NGkx46V75bY8JkbPlRsaaFR0RvWC3nmG+sa2L tKcmc7x3+Q9+V4Ex3wfrSF5BeWMSdvEu5MjDlxlw/bMxb4keFmfZ1sG4eZF15hCINDZI xI+amVPDDnaKIAIewoRMJ3lNnjxOi/KAWFZ37xaaseuqE+sE+IPPFDpyLrrPts5aBCI4 4U4QDC7SvrtcbVDyr+0kWntD0Ib3lCd8v5iJm02ujPfvLeB805iDmc85zVXDMUlSOAYP HqKdCM9+RikALRUpMwMag8mf3TZ463XfOpWRiVYYt4oRpYiLtTuF7hGc0bOq+Rrv1p+x K5JQ== X-Gm-Message-State: ABUngvc1Xt2QKCUtvaVhNCyAxO15gBDJjT1ET2ZZKM6+0+JWxmEBBR5vVCVRVb/F+w4Ftw== X-Received: by 10.25.28.143 with SMTP id c137mr10456989lfc.149.1479211562889; Tue, 15 Nov 2016 04:06:02 -0800 (PST) Received: from neopili.qtec.com (cpe.xe-3-0-1-778.vbrnqe10.dk.customer.tdc.net. [80.197.57.18]) by smtp.gmail.com with ESMTPSA id v26sm5746263lja.30.2016.11.15.04.06.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 15 Nov 2016 04:06:01 -0800 (PST) From: Ricardo Ribalda Delgado To: Hans Verkuil , Hans de Goede , linux-media@vger.kernel.org Cc: Ricardo Ribalda Delgado Subject: [PATCH 2/3] qv4l: support for HSV formats via OpenGL. Date: Tue, 15 Nov 2016 13:05:57 +0100 Message-Id: <20161115120558.2872-2-ricardo.ribalda@gmail.com> X-Mailer: git-send-email 2.10.2 In-Reply-To: <20161115120558.2872-1-ricardo.ribalda@gmail.com> References: <20161115120558.2872-1-ricardo.ribalda@gmail.com> Sender: linux-media-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Support for HSV32 and HSV24. Signed-off-by: Ricardo Ribalda Delgado --- utils/qv4l2/capture-win-gl.cpp | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/utils/qv4l2/capture-win-gl.cpp b/utils/qv4l2/capture-win-gl.cpp index af1909c936c5..df10d6863402 100644 --- a/utils/qv4l2/capture-win-gl.cpp +++ b/utils/qv4l2/capture-win-gl.cpp @@ -185,6 +185,8 @@ void CaptureWinGLEngine::setColorspace(unsigned colorspace, unsigned xfer_func, case V4L2_PIX_FMT_YUV555: case V4L2_PIX_FMT_YUV565: case V4L2_PIX_FMT_YUV32: + case V4L2_PIX_FMT_HSV24: + case V4L2_PIX_FMT_HSV32: is_rgb = false; break; } @@ -396,6 +398,8 @@ bool CaptureWinGLEngine::hasNativeFormat(__u32 format) V4L2_PIX_FMT_GREY, V4L2_PIX_FMT_Y16, V4L2_PIX_FMT_Y16_BE, + V4L2_PIX_FMT_HSV24, + V4L2_PIX_FMT_HSV32, 0 }; @@ -505,6 +509,8 @@ void CaptureWinGLEngine::changeShader() case V4L2_PIX_FMT_GREY: case V4L2_PIX_FMT_Y16: case V4L2_PIX_FMT_Y16_BE: + case V4L2_PIX_FMT_HSV24: + case V4L2_PIX_FMT_HSV32: default: shader_RGB(m_frameFormat); break; @@ -647,6 +653,8 @@ void CaptureWinGLEngine::paintGL() case V4L2_PIX_FMT_XBGR32: case V4L2_PIX_FMT_ARGB32: case V4L2_PIX_FMT_ABGR32: + case V4L2_PIX_FMT_HSV24: + case V4L2_PIX_FMT_HSV32: default: render_RGB(m_frameFormat); break; @@ -1537,7 +1545,9 @@ void CaptureWinGLEngine::shader_RGB(__u32 format) format == V4L2_PIX_FMT_BGR666 || format == V4L2_PIX_FMT_GREY || format == V4L2_PIX_FMT_Y16 || - format == V4L2_PIX_FMT_Y16_BE; + format == V4L2_PIX_FMT_Y16_BE || + format == V4L2_PIX_FMT_HSV24 || + format == V4L2_PIX_FMT_HSV32; GLint internalFmt = manualTransform ? GL_RGBA8 : GL_SRGB8_ALPHA8; switch (format) { @@ -1588,6 +1598,7 @@ void CaptureWinGLEngine::shader_RGB(__u32 format) /* fall-through */ case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_XRGB32: + case V4L2_PIX_FMT_HSV32: glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_frameWidth, m_frameHeight, 0, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, NULL); break; @@ -1610,6 +1621,7 @@ void CaptureWinGLEngine::shader_RGB(__u32 format) break; case V4L2_PIX_FMT_RGB24: case V4L2_PIX_FMT_BGR24: + case V4L2_PIX_FMT_HSV24: default: glTexImage2D(GL_TEXTURE_2D, 0, internalFmt, m_frameWidth, m_frameHeight, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL); @@ -1657,6 +1669,22 @@ void CaptureWinGLEngine::shader_RGB(__u32 format) " float g = r;" " float b = r;"; break; + case V4L2_PIX_FMT_HSV24: + case V4L2_PIX_FMT_HSV32: + /* From http://lolengine.net/blog/2013/07/27/rgb-to-hsv-in-glsl */ + if (m_ycbcr_enc == V4L2_HSV_ENC_256) + codeHead += " float hue = color.r;"; + else + codeHead += " float hue = (color.r * 256.0) / 180.0;"; + + codeHead += " vec3 c = vec3(hue, color.g, color.b);" + " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);" + " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);" + " vec3 ret = c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);" + " float r = ret.x;" + " float g = ret.y;" + " float b = ret.z;"; + break; default: codeHead += " float r = color.r;" " float g = color.g;" @@ -1759,6 +1787,7 @@ void CaptureWinGLEngine::render_RGB(__u32 format) case V4L2_PIX_FMT_RGB32: case V4L2_PIX_FMT_XRGB32: case V4L2_PIX_FMT_ARGB32: + case V4L2_PIX_FMT_HSV32: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8, m_frameData); break; @@ -1771,6 +1800,7 @@ void CaptureWinGLEngine::render_RGB(__u32 format) break; case V4L2_PIX_FMT_RGB24: case V4L2_PIX_FMT_BGR24: + case V4L2_PIX_FMT_HSV24: default: glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_frameWidth, m_frameHeight, GL_RGB, GL_UNSIGNED_BYTE, m_frameData);