[{"id":14977,"web_url":"https://patchwork.libcamera.org/comment/14977/","msgid":"<YBwqdTGvrU/JJikd@pendragon.ideasonboard.com>","date":"2021-02-04T17:10:13","subject":"Re: [libcamera-devel] [PATCH v3 2/2] android: camera_device:\n\tGenerate JPEG thumbnail sizes","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Jacopo,\n\nThank you for the patch.\n\nOn Thu, Feb 04, 2021 at 05:22:44PM +0100, Jacopo Mondi wrote:\n> The list of the available thumbnail sizes is generated from the\n> list of available JPEG resolution, one for each aspect ratio.\n> \n> This change fixes the CTS test\n> android.hardware.cts.CameraTest#testJpegThumbnailSize\n> \n> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> ---\n>  src/android/camera_device.cpp | 55 ++++++++++++++++++++++++++++++-----\n>  1 file changed, 48 insertions(+), 7 deletions(-)\n> \n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index 70170e243d06..65d37860cf95 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -705,10 +705,10 @@ std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize()\n>  {\n>  \t/*\n>  \t * \\todo Keep this in sync with the actual number of entries.\n> -\t * Currently: 53 entries, 846 bytes of static metadata\n> +\t * Currently: 53 entries, 838 bytes of static metadata\n>  \t */\n>  \tuint32_t numEntries = 53;\n> -\tuint32_t byteSize = 846;\n> +\tuint32_t byteSize = 838;\n>  \n>  \t/*\n>  \t * Calculate space occupation in bytes for dynamically built metadata\n> @@ -720,6 +720,18 @@ std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize()\n>  \t */\n>  \tbyteSize += streamConfigurations_.size() * 48;\n>  \n> +\t/*\n> +\t * 2 32bits integers for each HAL_PIXEL_FORMAT_BLOB for thumbnail sizes\n> +\t * 2 32bits integers for the (0, 0) thumbnail size\n\nI'd add\n\n\t* This is a worst case estimates as different configurations with the\n\t* same aspect ratio will generate the same size.\n\n(and there's no need to optimize this)\n\n> +\t */\n> +\tfor (const auto &entry : streamConfigurations_) {\n> +\t\tif (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB)\n> +\t\t\tcontinue;\n> +\n> +\t\tbyteSize += 8;\n> +\t}\n> +\tbyteSize += 8;\n> +\n>  \treturn std::make_tuple(numEntries, byteSize);\n>  }\n>  \n> @@ -871,12 +883,41 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n>  \t\t\t\t  &availableControlModes, 1);\n>  \n>  \t/* JPEG static metadata. */\n> -\tstd::vector<int32_t> availableThumbnailSizes = {\n> -\t\t0, 0,\n> -\t};\n> +\n> +\t/*\n> +\t * Create the list of supported thumbnail sizes by inspecting the\n> +\t * available JPEG resolutions collected in streamConfigurations_ and\n> +\t * generate one entry for each aspect ratio.\n> +\t *\n> +\t * The JPEG thumbnailer can freely scale, so pick an arbitrary\n> +\t * (160, 160) size as designated thumbnail size.\n\nMaybe\n\n\t * (160, 160) size as the bounding rectangle, which is then cropped to\n\t * the different supported aspect ratios.\n\nor something similar ?\n\nReviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\n> +\t */\n> +\tconstexpr Size maxJpegThumbnail(160, 160);\n> +\tstd::vector<Size> thumbnailSizes;\n> +\tthumbnailSizes.push_back({ 0, 0 });\n> +\tfor (const auto &entry : streamConfigurations_) {\n> +\t\tif (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB)\n> +\t\t\tcontinue;\n> +\n> +\t\tSize thumbnailSize = maxJpegThumbnail\n> +\t\t\t\t     .boundedToAspectRatio({ entry.resolution.width,\n> +\t\t\t\t\t\t\t     entry.resolution.height });\n> +\t\tthumbnailSizes.push_back(thumbnailSize);\n> +\t}\n> +\n> +\tstd::sort(thumbnailSizes.begin(), thumbnailSizes.end());\n> +\tauto last = std::unique(thumbnailSizes.begin(), thumbnailSizes.end());\n> +\tthumbnailSizes.erase(last, thumbnailSizes.end());\n> +\n> +\t/* Transform sizes in to a list of integers that can be consumed. */\n> +\tstd::vector<int32_t> thumbnailEntries;\n> +\tthumbnailEntries.reserve(thumbnailSizes.size() * 2);\n> +\tfor (const auto &size : thumbnailSizes) {\n> +\t\tthumbnailEntries.push_back(size.width);\n> +\t\tthumbnailEntries.push_back(size.height);\n> +\t}\n>  \tstaticMetadata_->addEntry(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES,\n> -\t\t\t\t  availableThumbnailSizes.data(),\n> -\t\t\t\t  availableThumbnailSizes.size());\n> +\t\t\t\t  thumbnailEntries.data(), thumbnailEntries.size());\n>  \n>  \t/*\n>  \t * \\todo Calculate the maximum JPEG buffer size by asking the encoder","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 75463BD162\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Feb 2021 17:10:37 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id EFB6061453;\n\tThu,  4 Feb 2021 18:10:36 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DE42061430\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Feb 2021 18:10:35 +0100 (CET)","from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 58EC4510;\n\tThu,  4 Feb 2021 18:10:35 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com;\n\tdkim=fail reason=\"signature verification failed\" (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"TfLXySUm\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1612458635;\n\tbh=7Y/OaUo9hQUTS9HPyNQXsC1D0uJHsdgLr5yvSzsI6HI=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=TfLXySUmlnJCvRdCrxtGkp+yd1OTH/Kf7Q0YyKsuBLTTwWl8mTR9GImXBGIGr3wx+\n\txOMxuNrnXZmJzl1wIxJLwPivW09c9ji2B9FYL5gq/EM0SAknwopblnsBDmbM9bvf43\n\tEp19rPo7hcPhPs7S4qq5Rcj93la/L2AB6GJ/4TEA=","Date":"Thu, 4 Feb 2021 19:10:13 +0200","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Jacopo Mondi <jacopo@jmondi.org>","Message-ID":"<YBwqdTGvrU/JJikd@pendragon.ideasonboard.com>","References":"<20210204162244.53630-1-jacopo@jmondi.org>\n\t<20210204162244.53630-2-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210204162244.53630-2-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v3 2/2] android: camera_device:\n\tGenerate JPEG thumbnail sizes","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>","Cc":"libcamera-devel@lists.libcamera.org","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>"}},{"id":14978,"web_url":"https://patchwork.libcamera.org/comment/14978/","msgid":"<20210204171340.bm6xqfgam27lhl4r@uno.localdomain>","date":"2021-02-04T17:13:40","subject":"Re: [libcamera-devel] [PATCH v3 2/2] android: camera_device:\n\tGenerate JPEG thumbnail sizes","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi Laurent,\n\nOn Thu, Feb 04, 2021 at 07:10:13PM +0200, Laurent Pinchart wrote:\n> Hi Jacopo,\n>\n> Thank you for the patch.\n>\n> On Thu, Feb 04, 2021 at 05:22:44PM +0100, Jacopo Mondi wrote:\n> > The list of the available thumbnail sizes is generated from the\n> > list of available JPEG resolution, one for each aspect ratio.\n> >\n> > This change fixes the CTS test\n> > android.hardware.cts.CameraTest#testJpegThumbnailSize\n> >\n> > Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> > Signed-off-by: Jacopo Mondi <jacopo@jmondi.org>\n> > ---\n> >  src/android/camera_device.cpp | 55 ++++++++++++++++++++++++++++++-----\n> >  1 file changed, 48 insertions(+), 7 deletions(-)\n> >\n> > diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> > index 70170e243d06..65d37860cf95 100644\n> > --- a/src/android/camera_device.cpp\n> > +++ b/src/android/camera_device.cpp\n> > @@ -705,10 +705,10 @@ std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize()\n> >  {\n> >  \t/*\n> >  \t * \\todo Keep this in sync with the actual number of entries.\n> > -\t * Currently: 53 entries, 846 bytes of static metadata\n> > +\t * Currently: 53 entries, 838 bytes of static metadata\n> >  \t */\n> >  \tuint32_t numEntries = 53;\n> > -\tuint32_t byteSize = 846;\n> > +\tuint32_t byteSize = 838;\n> >\n> >  \t/*\n> >  \t * Calculate space occupation in bytes for dynamically built metadata\n> > @@ -720,6 +720,18 @@ std::tuple<uint32_t, uint32_t> CameraDevice::calculateStaticMetadataSize()\n> >  \t */\n> >  \tbyteSize += streamConfigurations_.size() * 48;\n> >\n> > +\t/*\n> > +\t * 2 32bits integers for each HAL_PIXEL_FORMAT_BLOB for thumbnail sizes\n> > +\t * 2 32bits integers for the (0, 0) thumbnail size\n>\n> I'd add\n>\n> \t* This is a worst case estimates as different configurations with the\n> \t* same aspect ratio will generate the same size.\n>\n> (and there's no need to optimize this)\n>\n> > +\t */\n> > +\tfor (const auto &entry : streamConfigurations_) {\n> > +\t\tif (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB)\n> > +\t\t\tcontinue;\n> > +\n> > +\t\tbyteSize += 8;\n> > +\t}\n> > +\tbyteSize += 8;\n> > +\n> >  \treturn std::make_tuple(numEntries, byteSize);\n> >  }\n> >\n> > @@ -871,12 +883,41 @@ const camera_metadata_t *CameraDevice::getStaticMetadata()\n> >  \t\t\t\t  &availableControlModes, 1);\n> >\n> >  \t/* JPEG static metadata. */\n> > -\tstd::vector<int32_t> availableThumbnailSizes = {\n> > -\t\t0, 0,\n> > -\t};\n> > +\n> > +\t/*\n> > +\t * Create the list of supported thumbnail sizes by inspecting the\n> > +\t * available JPEG resolutions collected in streamConfigurations_ and\n> > +\t * generate one entry for each aspect ratio.\n> > +\t *\n> > +\t * The JPEG thumbnailer can freely scale, so pick an arbitrary\n> > +\t * (160, 160) size as designated thumbnail size.\n>\n> Maybe\n>\n> \t * (160, 160) size as the bounding rectangle, which is then cropped to\n> \t * the different supported aspect ratios.\n>\n> or something similar ?\n>\n> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n\nSure, I'll take your comments in and I'll push.\n\nThanks\n  j\n\n>\n> > +\t */\n> > +\tconstexpr Size maxJpegThumbnail(160, 160);\n> > +\tstd::vector<Size> thumbnailSizes;\n> > +\tthumbnailSizes.push_back({ 0, 0 });\n> > +\tfor (const auto &entry : streamConfigurations_) {\n> > +\t\tif (entry.androidFormat != HAL_PIXEL_FORMAT_BLOB)\n> > +\t\t\tcontinue;\n> > +\n> > +\t\tSize thumbnailSize = maxJpegThumbnail\n> > +\t\t\t\t     .boundedToAspectRatio({ entry.resolution.width,\n> > +\t\t\t\t\t\t\t     entry.resolution.height });\n> > +\t\tthumbnailSizes.push_back(thumbnailSize);\n> > +\t}\n> > +\n> > +\tstd::sort(thumbnailSizes.begin(), thumbnailSizes.end());\n> > +\tauto last = std::unique(thumbnailSizes.begin(), thumbnailSizes.end());\n> > +\tthumbnailSizes.erase(last, thumbnailSizes.end());\n> > +\n> > +\t/* Transform sizes in to a list of integers that can be consumed. */\n> > +\tstd::vector<int32_t> thumbnailEntries;\n> > +\tthumbnailEntries.reserve(thumbnailSizes.size() * 2);\n> > +\tfor (const auto &size : thumbnailSizes) {\n> > +\t\tthumbnailEntries.push_back(size.width);\n> > +\t\tthumbnailEntries.push_back(size.height);\n> > +\t}\n> >  \tstaticMetadata_->addEntry(ANDROID_JPEG_AVAILABLE_THUMBNAIL_SIZES,\n> > -\t\t\t\t  availableThumbnailSizes.data(),\n> > -\t\t\t\t  availableThumbnailSizes.size());\n> > +\t\t\t\t  thumbnailEntries.data(), thumbnailEntries.size());\n> >\n> >  \t/*\n> >  \t * \\todo Calculate the maximum JPEG buffer size by asking the encoder\n>\n> --\n> Regards,\n>\n> Laurent Pinchart","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 07DF3BD160\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Feb 2021 17:13:20 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9FEE161450;\n\tThu,  4 Feb 2021 18:13:19 +0100 (CET)","from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net\n\t[217.70.183.196])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 32E4961430\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Feb 2021 18:13:19 +0100 (CET)","from uno.localdomain (93-61-96-190.ip145.fastwebnet.it\n\t[93.61.96.190]) (Authenticated sender: jacopo@jmondi.org)\n\tby relay4-d.mail.gandi.net (Postfix) with ESMTPSA id B8B2CE000D;\n\tThu,  4 Feb 2021 17:13:18 +0000 (UTC)"],"X-Originating-IP":"93.61.96.190","Date":"Thu, 4 Feb 2021 18:13:40 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","Message-ID":"<20210204171340.bm6xqfgam27lhl4r@uno.localdomain>","References":"<20210204162244.53630-1-jacopo@jmondi.org>\n\t<20210204162244.53630-2-jacopo@jmondi.org>\n\t<YBwqdTGvrU/JJikd@pendragon.ideasonboard.com>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<YBwqdTGvrU/JJikd@pendragon.ideasonboard.com>","Subject":"Re: [libcamera-devel] [PATCH v3 2/2] android: camera_device:\n\tGenerate JPEG thumbnail sizes","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>","Cc":"libcamera-devel@lists.libcamera.org","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>"}}]