[{"id":1556,"web_url":"https://patchwork.libcamera.org/comment/1556/","msgid":"<20190503220529.GA20236@localhost.localdomain>","date":"2019-05-03T22:05:29","subject":"Re: [libcamera-devel] [PATCH] qcam: format_converter: Add RGB\n\tformats support","submitter":{"id":17,"url":"https://patchwork.libcamera.org/api/people/17/","name":"Paul Elder","email":"paul.elder@ideasonboard.com"},"content":"Hi Laurent,\n\nThank you for the patch.\n\nOn Thu, May 02, 2019 at 07:27:23PM +0300, Laurent Pinchart wrote:\n> Add support for the RGB format supported by VIMC (V4L2_PIX_FMT_BGR24,\n> V4L2_PIX_FMT_RGB24 and V4L2_PIX_FMT_ARGB32).\n> \n> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nLooks good to me.\n\nReviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n\n> ---\n>  src/qcam/format_converter.cpp | 52 ++++++++++++++++++++++++++++++++++-\n>  src/qcam/format_converter.h   |  8 ++++++\n>  2 files changed, 59 insertions(+), 1 deletion(-)\n> \n> diff --git a/src/qcam/format_converter.cpp b/src/qcam/format_converter.cpp\n> index bda9057e17b6..d9088c38f0d4 100644\n> --- a/src/qcam/format_converter.cpp\n> +++ b/src/qcam/format_converter.cpp\n> @@ -31,23 +31,49 @@ int FormatConverter::configure(unsigned int format, unsigned int width,\n>  \t\t\t       unsigned int height)\n>  {\n>  \tswitch (format) {\n> +\tcase V4L2_PIX_FMT_BGR24:\n> +\t\tyuv_ = false;\n> +\t\tr_pos_ = 2;\n> +\t\tg_pos_ = 1;\n> +\t\tb_pos_ = 0;\n> +\t\tbpp_ = 3;\n> +\t\tbreak;\n> +\tcase V4L2_PIX_FMT_RGB24:\n> +\t\tyuv_ = false;\n> +\t\tr_pos_ = 0;\n> +\t\tg_pos_ = 1;\n> +\t\tb_pos_ = 2;\n> +\t\tbpp_ = 3;\n> +\t\tbreak;\n> +\tcase V4L2_PIX_FMT_ARGB32:\n> +\t\tyuv_ = false;\n> +\t\tr_pos_ = 1;\n> +\t\tg_pos_ = 2;\n> +\t\tb_pos_ = 3;\n> +\t\tbpp_ = 4;\n> +\t\tbreak;\n>  \tcase V4L2_PIX_FMT_VYUY:\n> +\t\tyuv_ = true;\n>  \t\ty_pos_ = 1;\n>  \t\tcb_pos_ = 2;\n>  \t\tbreak;\n>  \tcase V4L2_PIX_FMT_YVYU:\n> +\t\tyuv_ = true;\n>  \t\ty_pos_ = 0;\n>  \t\tcb_pos_ = 3;\n>  \t\tbreak;\n>  \tcase V4L2_PIX_FMT_UYVY:\n> +\t\tyuv_ = true;\n>  \t\ty_pos_ = 1;\n>  \t\tcb_pos_ = 0;\n>  \t\tbreak;\n>  \tcase V4L2_PIX_FMT_YUYV:\n> +\t\tyuv_ = true;\n>  \t\ty_pos_ = 0;\n>  \t\tcb_pos_ = 1;\n>  \t\tbreak;\n>  \tcase V4L2_PIX_FMT_MJPEG:\n> +\t\tyuv_ = false;\n>  \t\tbreak;\n>  \tdefault:\n>  \t\treturn -EINVAL;\n> @@ -65,8 +91,32 @@ void FormatConverter::convert(const unsigned char *src, size_t size,\n>  {\n>  \tif (format_ == V4L2_PIX_FMT_MJPEG)\n>  \t\tdst->loadFromData(src, size, \"JPEG\");\n> -\telse\n> +\telse if (yuv_)\n>  \t\tconvertYUV(src, dst->bits());\n> +\telse\n> +\t\tconvertRGB(src, dst->bits());\n> +}\n> +\n> +void FormatConverter::convertRGB(const unsigned char *src, unsigned char *dst)\n> +{\n> +\tunsigned int x, y;\n> +\tint r, g, b;\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> +\n> +\t\t\tdst[4 * x + 0] = b;\n> +\t\t\tdst[4 * x + 1] = g;\n> +\t\t\tdst[4 * x + 2] = r;\n> +\t\t\tdst[4 * x + 3] = 0xff;\n> +\t\t}\n> +\n> +\t\tsrc += width_ * bpp_;\n> +\t\tdst += width_ * 4;\n> +\t}\n>  }\n>  \n>  static void yuv_to_rgb(int y, int u, int v, int *r, int *g, int *b)\n> diff --git a/src/qcam/format_converter.h b/src/qcam/format_converter.h\n> index 396d0bea116a..76cd9f1cab56 100644\n> --- a/src/qcam/format_converter.h\n> +++ b/src/qcam/format_converter.h\n> @@ -20,11 +20,19 @@ public:\n>  \tvoid convert(const unsigned char *src, size_t size, QImage *dst);\n>  \n>  private:\n> +\tvoid convertRGB(const unsigned char *src, unsigned char *dst);\n>  \tvoid convertYUV(const unsigned char *src, unsigned char *dst);\n>  \n>  \tunsigned int format_;\n>  \tunsigned int width_;\n>  \tunsigned int height_;\n> +\n> +\tunsigned int bpp_;\n> +\tunsigned int r_pos_;\n> +\tunsigned int g_pos_;\n> +\tunsigned int b_pos_;\n> +\n> +\tbool yuv_;\n>  \tunsigned int y_pos_;\n>  \tunsigned int cb_pos_;\n>  };\n> -- \n> Regards,\n> \n> Laurent Pinchart\n> \n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","headers":{"Return-Path":"<paul.elder@ideasonboard.com>","Received":["from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 466F560E61\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSat,  4 May 2019 00:05:37 +0200 (CEST)","from localhost.localdomain (unknown [96.44.9.117])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2CBD731E;\n\tSat,  4 May 2019 00:05:36 +0200 (CEST)"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1556921136;\n\tbh=1Ie9tgdPNdsXUjI1o6XQ3mT4D+chV64Nzz5dLpYT6sM=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=lV7YYRI9AEOj+j6jS6CqSzgY3V5JzOSOlwqYlqfOly0TCHK5qBKvX4s+ZM0SZ1xNr\n\tUCdbD7DtAKF1109FyFaVUlm0ShrKDWC3a6yJVFIcQoj9WyEtbc8R8sedj9IYk+sfOm\n\t1vkyvXm1IFNt2JN7DlYnRyRRLci9PNgucA2gzVdo=","Date":"Fri, 3 May 2019 18:05:29 -0400","From":"Paul Elder <paul.elder@ideasonboard.com>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Message-ID":"<20190503220529.GA20236@localhost.localdomain>","References":"<20190502162723.30511-1-laurent.pinchart@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=us-ascii","Content-Disposition":"inline","In-Reply-To":"<20190502162723.30511-1-laurent.pinchart@ideasonboard.com>","User-Agent":"Mutt/1.10.1 (2018-07-13)","Subject":"Re: [libcamera-devel] [PATCH] qcam: format_converter: Add RGB\n\tformats support","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.23","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>","X-List-Received-Date":"Fri, 03 May 2019 22:05:37 -0000"}}]