{"id":9544,"url":"https://patchwork.libcamera.org/api/1.1/patches/9544/?format=json","web_url":"https://patchwork.libcamera.org/patch/9544/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20200908150739.1552-2-andrey.konovalov@linaro.org>","date":"2020-09-08T15:07:38","name":"[libcamera-devel,RFC,v2,1/2] qcam: format_converter: put parameters of different formats into union","commit_ref":null,"pull_url":null,"state":"superseded","archived":false,"hash":"c50ebfdc4c6532461198ed00987619c9871e0910","submitter":{"id":25,"url":"https://patchwork.libcamera.org/api/1.1/people/25/?format=json","name":"Andrey Konovalov","email":"andrey.konovalov@linaro.org"},"delegate":{"id":14,"url":"https://patchwork.libcamera.org/api/1.1/users/14/?format=json","username":"pinchartl","first_name":"Laurent","last_name":"Pinchart","email":"laurent.pinchart@ideasonboard.com"},"mbox":"https://patchwork.libcamera.org/patch/9544/mbox/","series":[{"id":1275,"url":"https://patchwork.libcamera.org/api/1.1/series/1275/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=1275","date":"2020-09-08T15:07:37","name":"qcam: format_converter: add 10 and 12 bit packed raw Bayer formats","version":2,"mbox":"https://patchwork.libcamera.org/series/1275/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/9544/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/9544/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 0ABEDBDB1C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  8 Sep 2020 15:08:12 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C9CD362C30;\n\tTue,  8 Sep 2020 17:08:11 +0200 (CEST)","from mail-lf1-x142.google.com (mail-lf1-x142.google.com\n\t[IPv6:2a00:1450:4864:20::142])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 40D6A6056C\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Sep 2020 17:08:10 +0200 (CEST)","by mail-lf1-x142.google.com with SMTP id u8so3834227lff.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 08 Sep 2020 08:08:10 -0700 (PDT)","from localhost.localdomain (37-144-159-139.broadband.corbina.ru.\n\t[37.144.159.139]) by smtp.googlemail.com with ESMTPSA id\n\tf19sm10614121lfs.85.2020.09.08.08.08.08\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tTue, 08 Sep 2020 08:08:08 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=linaro.org header.i=@linaro.org\n\theader.b=\"KRbd+D+x\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=jtE0KsyuA8WbherHcyBIpGQCxZtUBIpqvnIW7vCbHPw=;\n\tb=KRbd+D+xJMuxvi6r1yFdJskxc0IBSlkqDXWq12KlQkMQQBrkXKiO2/fCfGuN70KAdC\n\tMdWw8kSjbuYH6q6/QntvmaF9kFWHY7QlEX3KvpQgBpoe6J4DFEPuVWL7CX1kzuRt/RCa\n\tysjRKTF+ppwhfkLfpcD89hsnLk/9FIreVFYWQfBgrMdm6uxQzrXwOSaMtfcHzRlDREtK\n\tv1z6DvZH+d3/xT0Hc2ifhbsq+WX6uVh0BNJ47K6JjBr4+s90y/DTT+z25N40s8KRsUVk\n\tElILLD6MFIpI8iptx3fwunsNScAVpwE1wh3eCBzvWaa0xfaTqH4FN+qK9oLidh5IYOyb\n\t4sJg==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=jtE0KsyuA8WbherHcyBIpGQCxZtUBIpqvnIW7vCbHPw=;\n\tb=pNeS1ZzOyd76cHWVJOPdDlWoOJr1ir8bGPHQFUr443p/z6oT+m0s6e/3XaiXTKfVUO\n\tdAN5f3+aqLlvU4ENBBL8ho+oKg9UuU1ocfaXg8U3bOLmA2EmVs8eBQNV1+2AKiAoPab5\n\tdmv1EQAz7wWEgWeGmE59SQ/uwWez2oCvKdsNb7Agb9SHP9XR+fLMDKmO1k337qAxQ1Mq\n\tEA3zjMGeRsaS1pUK4RWRnZAEPdOcmzEnAl/PHoF4ldp1zcjFgHlAATYPav4TNKUeHweV\n\t42cGAoh4WFs5x9ENLv2p7xg+W4Tp4rAxr6+yLkoFBgkapttMgOKjy/kaVRQqZdXEueNI\n\tROYA==","X-Gm-Message-State":"AOAM530MrvGqstlyElRBwirOGTqWIt3HMNyK5jZnuzlQ5fz6zfFN4DZd\n\tJjH02WnxL0x+7FG89nG1Ce6I8/6Wy9Jdyw==","X-Google-Smtp-Source":"ABdhPJwWa74NrKwieKk1Ydj5/JY9X3+tCixDa5kvP1oPf3DR6+opQgbiRd8bZlmv9WBDXu4NAPBirA==","X-Received":"by 2002:a19:d11:: with SMTP id 17mr12889863lfn.0.1599577689084; \n\tTue, 08 Sep 2020 08:08:09 -0700 (PDT)","From":"Andrey Konovalov <andrey.konovalov@linaro.org>","To":"libcamera-devel@lists.libcamera.org","Date":"Tue,  8 Sep 2020 18:07:38 +0300","Message-Id":"<20200908150739.1552-2-andrey.konovalov@linaro.org>","X-Mailer":"git-send-email 2.17.1","In-Reply-To":"<20200908150739.1552-1-andrey.konovalov@linaro.org>","References":"<20200908150739.1552-1-andrey.konovalov@linaro.org>","Subject":"[libcamera-devel] [RFC PATCH v2 1/2] qcam: format_converter: put\n\tparameters of different formats into union","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"As the number of supported formats in the converter grows, having the\nformat-specific parameters in a union makes the code cleaner, and save\nsome amount of memory.\n\nSigned-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>\n---\n src/qcam/format_converter.cpp | 133 ++++++++++++++++++----------------\n src/qcam/format_converter.h   |  37 ++++++----\n 2 files changed, 92 insertions(+), 78 deletions(-)","diff":"diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp\nindex 4b9722d..3481330 100644\n--- a/src/qcam/format_converter.cpp\n+++ b/src/qcam/format_converter.cpp\n@@ -33,103 +33,103 @@ int FormatConverter::configure(const libcamera::PixelFormat &format,\n \tswitch (format) {\n \tcase libcamera::formats::NV12:\n \t\tformatFamily_ = NV;\n-\t\thorzSubSample_ = 2;\n-\t\tvertSubSample_ = 2;\n-\t\tnvSwap_ = false;\n+\t\tparams_.nv.horzSubSample = 2;\n+\t\tparams_.nv.vertSubSample = 2;\n+\t\tparams_.nv.nvSwap = false;\n \t\tbreak;\n \tcase libcamera::formats::NV21:\n \t\tformatFamily_ = NV;\n-\t\thorzSubSample_ = 2;\n-\t\tvertSubSample_ = 2;\n-\t\tnvSwap_ = true;\n+\t\tparams_.nv.horzSubSample = 2;\n+\t\tparams_.nv.vertSubSample = 2;\n+\t\tparams_.nv.nvSwap = true;\n \t\tbreak;\n \tcase libcamera::formats::NV16:\n \t\tformatFamily_ = NV;\n-\t\thorzSubSample_ = 2;\n-\t\tvertSubSample_ = 1;\n-\t\tnvSwap_ = false;\n+\t\tparams_.nv.horzSubSample = 2;\n+\t\tparams_.nv.vertSubSample = 1;\n+\t\tparams_.nv.nvSwap = false;\n \t\tbreak;\n \tcase libcamera::formats::NV61:\n \t\tformatFamily_ = NV;\n-\t\thorzSubSample_ = 2;\n-\t\tvertSubSample_ = 1;\n-\t\tnvSwap_ = true;\n+\t\tparams_.nv.horzSubSample = 2;\n+\t\tparams_.nv.vertSubSample = 1;\n+\t\tparams_.nv.nvSwap = true;\n \t\tbreak;\n \tcase libcamera::formats::NV24:\n \t\tformatFamily_ = NV;\n-\t\thorzSubSample_ = 1;\n-\t\tvertSubSample_ = 1;\n-\t\tnvSwap_ = false;\n+\t\tparams_.nv.horzSubSample = 1;\n+\t\tparams_.nv.vertSubSample = 1;\n+\t\tparams_.nv.nvSwap = false;\n \t\tbreak;\n \tcase libcamera::formats::NV42:\n \t\tformatFamily_ = NV;\n-\t\thorzSubSample_ = 1;\n-\t\tvertSubSample_ = 1;\n-\t\tnvSwap_ = true;\n+\t\tparams_.nv.horzSubSample = 1;\n+\t\tparams_.nv.vertSubSample = 1;\n+\t\tparams_.nv.nvSwap = true;\n \t\tbreak;\n \n \tcase libcamera::formats::RGB888:\n \t\tformatFamily_ = RGB;\n-\t\tr_pos_ = 2;\n-\t\tg_pos_ = 1;\n-\t\tb_pos_ = 0;\n-\t\tbpp_ = 3;\n+\t\tparams_.rgb.r_pos = 2;\n+\t\tparams_.rgb.g_pos = 1;\n+\t\tparams_.rgb.b_pos = 0;\n+\t\tparams_.rgb.bpp = 3;\n \t\tbreak;\n \tcase libcamera::formats::BGR888:\n \t\tformatFamily_ = RGB;\n-\t\tr_pos_ = 0;\n-\t\tg_pos_ = 1;\n-\t\tb_pos_ = 2;\n-\t\tbpp_ = 3;\n+\t\tparams_.rgb.r_pos = 0;\n+\t\tparams_.rgb.g_pos = 1;\n+\t\tparams_.rgb.b_pos = 2;\n+\t\tparams_.rgb.bpp = 3;\n \t\tbreak;\n \tcase libcamera::formats::ARGB8888:\n \t\tformatFamily_ = RGB;\n-\t\tr_pos_ = 2;\n-\t\tg_pos_ = 1;\n-\t\tb_pos_ = 0;\n-\t\tbpp_ = 4;\n+\t\tparams_.rgb.r_pos = 2;\n+\t\tparams_.rgb.g_pos = 1;\n+\t\tparams_.rgb.b_pos = 0;\n+\t\tparams_.rgb.bpp = 4;\n \t\tbreak;\n \tcase libcamera::formats::RGBA8888:\n \t\tformatFamily_ = RGB;\n-\t\tr_pos_ = 3;\n-\t\tg_pos_ = 2;\n-\t\tb_pos_ = 1;\n-\t\tbpp_ = 4;\n+\t\tparams_.rgb.r_pos = 3;\n+\t\tparams_.rgb.g_pos = 2;\n+\t\tparams_.rgb.b_pos = 1;\n+\t\tparams_.rgb.bpp = 4;\n \t\tbreak;\n \tcase libcamera::formats::ABGR8888:\n \t\tformatFamily_ = RGB;\n-\t\tr_pos_ = 0;\n-\t\tg_pos_ = 1;\n-\t\tb_pos_ = 2;\n-\t\tbpp_ = 4;\n+\t\tparams_.rgb.r_pos = 0;\n+\t\tparams_.rgb.g_pos = 1;\n+\t\tparams_.rgb.b_pos = 2;\n+\t\tparams_.rgb.bpp = 4;\n \t\tbreak;\n \tcase libcamera::formats::BGRA8888:\n \t\tformatFamily_ = RGB;\n-\t\tr_pos_ = 1;\n-\t\tg_pos_ = 2;\n-\t\tb_pos_ = 3;\n-\t\tbpp_ = 4;\n+\t\tparams_.rgb.r_pos = 1;\n+\t\tparams_.rgb.g_pos = 2;\n+\t\tparams_.rgb.b_pos = 3;\n+\t\tparams_.rgb.bpp = 4;\n \t\tbreak;\n \n \tcase libcamera::formats::VYUY:\n \t\tformatFamily_ = YUV;\n-\t\ty_pos_ = 1;\n-\t\tcb_pos_ = 2;\n+\t\tparams_.yuv.y_pos = 1;\n+\t\tparams_.yuv.cb_pos = 2;\n \t\tbreak;\n \tcase libcamera::formats::YVYU:\n \t\tformatFamily_ = YUV;\n-\t\ty_pos_ = 0;\n-\t\tcb_pos_ = 3;\n+\t\tparams_.yuv.y_pos = 0;\n+\t\tparams_.yuv.cb_pos = 3;\n \t\tbreak;\n \tcase libcamera::formats::UYVY:\n \t\tformatFamily_ = YUV;\n-\t\ty_pos_ = 1;\n-\t\tcb_pos_ = 0;\n+\t\tparams_.yuv.y_pos = 1;\n+\t\tparams_.yuv.cb_pos = 0;\n \t\tbreak;\n \tcase libcamera::formats::YUYV:\n \t\tformatFamily_ = YUV;\n-\t\ty_pos_ = 0;\n-\t\tcb_pos_ = 1;\n+\t\tparams_.yuv.y_pos = 0;\n+\t\tparams_.yuv.cb_pos = 1;\n \t\tbreak;\n \n \tcase libcamera::formats::MJPEG:\n@@ -178,18 +178,20 @@ static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b)\n \n void FormatConverter::convertNV(const unsigned char *src, unsigned char *dst)\n {\n-\tunsigned int c_stride = width_ * (2 / horzSubSample_);\n-\tunsigned int c_inc = horzSubSample_ == 1 ? 2 : 0;\n-\tunsigned int cb_pos = nvSwap_ ? 1 : 0;\n-\tunsigned int cr_pos = nvSwap_ ? 0 : 1;\n+\tunsigned int c_stride = width_ * (2 / params_.nv.horzSubSample);\n+\tunsigned int c_inc = params_.nv.horzSubSample == 1 ? 2 : 0;\n+\tunsigned int cb_pos = params_.nv.nvSwap ? 1 : 0;\n+\tunsigned int cr_pos = params_.nv.nvSwap ? 0 : 1;\n \tconst unsigned char *src_c = src + width_ * height_;\n \tint r, g, b;\n \n \tfor (unsigned int y = 0; y < height_; y++) {\n \t\tconst unsigned char *src_y = src + y * width_;\n-\t\tconst unsigned char *src_cb = src_c + (y / vertSubSample_) *\n+\t\tconst unsigned char *src_cb = src_c +\n+\t\t\t\t\t      (y / params_.nv.vertSubSample) *\n \t\t\t\t\t      c_stride + cb_pos;\n-\t\tconst unsigned char *src_cr = src_c + (y / vertSubSample_) *\n+\t\tconst unsigned char *src_cr = src_c +\n+\t\t\t\t\t      (y / params_.nv.vertSubSample) *\n \t\t\t\t\t      c_stride + cr_pos;\n \n \t\tfor (unsigned int x = 0; x < width_; x += 2) {\n@@ -223,9 +225,9 @@ void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst)\n \n \tfor (y = 0; y < height_; y++) {\n \t\tfor (x = 0; x < width_; x++) {\n-\t\t\tr = src[bpp_ * x + r_pos_];\n-\t\t\tg = src[bpp_ * x + g_pos_];\n-\t\t\tb = src[bpp_ * x + b_pos_];\n+\t\t\tr = src[params_.rgb.bpp * x + params_.rgb.r_pos];\n+\t\t\tg = src[params_.rgb.bpp * x + params_.rgb.g_pos];\n+\t\t\tb = src[params_.rgb.bpp * x + params_.rgb.b_pos];\n \n \t\t\tdst[4 * x + 0] = b;\n \t\t\tdst[4 * x + 1] = g;\n@@ -233,7 +235,7 @@ void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst)\n \t\t\tdst[4 * x + 3] = 0xff;\n \t\t}\n \n-\t\tsrc += width_ * bpp_;\n+\t\tsrc += width_ * params_.rgb.bpp;\n \t\tdst += width_ * 4;\n \t}\n }\n@@ -246,16 +248,18 @@ void FormatConverter::convertYUV(const unsigned char *src, unsigned char *dst)\n \tunsigned int cr_pos;\n \tint r, g, b, y, cr, cb;\n \n-\tcr_pos = (cb_pos_ + 2) % 4;\n+\tcr_pos = (params_.yuv.cb_pos + 2) % 4;\n \tsrc_stride = width_ * 2;\n \tdst_stride = width_ * 4;\n \n \tfor (src_y = 0, dst_y = 0; dst_y < height_; src_y++, dst_y++) {\n \t\tfor (src_x = 0, dst_x = 0; dst_x < width_; ) {\n-\t\t\tcb = src[src_y * src_stride + src_x * 4 + cb_pos_];\n+\t\t\tcb = src[src_y * src_stride + src_x * 4 +\n+\t\t\t\t params_.yuv.cb_pos];\n \t\t\tcr = src[src_y * src_stride + src_x * 4 + cr_pos];\n \n-\t\t\ty = src[src_y * src_stride + src_x * 4 + y_pos_];\n+\t\t\ty = src[src_y * src_stride + src_x * 4 +\n+\t\t\t\tparams_.yuv.y_pos];\n \t\t\tyuv_to_rgb(y, cb, cr, &r, &g, &b);\n \t\t\tdst[dst_y * dst_stride + 4 * dst_x + 0] = b;\n \t\t\tdst[dst_y * dst_stride + 4 * dst_x + 1] = g;\n@@ -263,7 +267,8 @@ void FormatConverter::convertYUV(const unsigned char *src, unsigned char *dst)\n \t\t\tdst[dst_y * dst_stride + 4 * dst_x + 3] = 0xff;\n \t\t\tdst_x++;\n \n-\t\t\ty = src[src_y * src_stride + src_x * 4 + y_pos_ + 2];\n+\t\t\ty = src[src_y * src_stride + src_x * 4 +\n+\t\t\t\tparams_.yuv.y_pos + 2];\n \t\t\tyuv_to_rgb(y, cb, cr, &r, &g, &b);\n \t\t\tdst[dst_y * dst_stride + 4 * dst_x + 0] = b;\n \t\t\tdst[dst_y * dst_stride + 4 * dst_x + 1] = g;\ndiff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h\nindex e389b24..c53fa28 100644\n--- a/src/qcam/format_converter.h\n+++ b/src/qcam/format_converter.h\n@@ -40,20 +40,29 @@ private:\n \n \tenum FormatFamily formatFamily_;\n \n-\t/* NV parameters */\n-\tunsigned int horzSubSample_;\n-\tunsigned int vertSubSample_;\n-\tbool nvSwap_;\n-\n-\t/* RGB parameters */\n-\tunsigned int bpp_;\n-\tunsigned int r_pos_;\n-\tunsigned int g_pos_;\n-\tunsigned int b_pos_;\n-\n-\t/* YUV parameters */\n-\tunsigned int y_pos_;\n-\tunsigned int cb_pos_;\n+\tunion {\n+\t\t/* NV parameters */\n+\t\tstruct nv_params {\n+\t\t\tunsigned int horzSubSample;\n+\t\t\tunsigned int vertSubSample;\n+\t\t\tbool nvSwap;\n+\t\t} nv;\n+\n+\t\t/* RGB parameters */\n+\t\tstruct rgb_params {\n+\t\t\tunsigned int bpp;\n+\t\t\tunsigned int r_pos;\n+\t\t\tunsigned int g_pos;\n+\t\t\tunsigned int b_pos;\n+\t\t} rgb;\n+\n+\t\t/* YUV parameters */\n+\t\tstruct yuv_params {\n+\t\t\tunsigned int y_pos;\n+\t\t\tunsigned int cb_pos;\n+\t\t} yuv;\n+\t} params_;\n+\n };\n \n #endif /* __QCAM_FORMAT_CONVERTER_H__ */\n","prefixes":["libcamera-devel","RFC","v2","1/2"]}