[{"id":14971,"web_url":"https://patchwork.libcamera.org/comment/14971/","msgid":"<20210204153149.nxo46ipge42ykeu6@uno.localdomain>","date":"2021-02-04T15:31:49","subject":"Re: [libcamera-devel] [PATCH v2] android: camera_device: Generate\n\tJPEG thumbnail sizes","submitter":{"id":3,"url":"https://patchwork.libcamera.org/api/people/3/","name":"Jacopo Mondi","email":"jacopo@jmondi.org"},"content":"Hi me,\n\nOn Thu, Feb 04, 2021 at 04:08:20PM +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 | 39 ++++++++++++++++++++++++++++++-----\n>  1 file changed, 34 insertions(+), 5 deletions(-)\n>\n> diff --git a/src/android/camera_device.cpp b/src/android/camera_device.cpp\n> index df5e295656d7..cdb28f1f2d28 100644\n> --- a/src/android/camera_device.cpp\n> +++ b/src/android/camera_device.cpp\n> @@ -871,12 +871,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> +\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\nI just realized space for the additional entries have to reserved in\nthe staticMetadata_ pack, as we have more sizes than the single {} we\nhad before.\n\nI'll go for the better-safe-then-sorry approach and reserve 8\nadditional bytes for each JPEG size to accommodate the worst case\nscenario where they all have a different aspect ratio.\n\n>\n>  \t/*\n>  \t * \\todo Calculate the maximum JPEG buffer size by asking the encoder\n> --\n> 2.30.0\n>\n> _______________________________________________\n> libcamera-devel mailing list\n> libcamera-devel@lists.libcamera.org\n> https://lists.libcamera.org/listinfo/libcamera-devel","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 18FE2BD162\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu,  4 Feb 2021 15:31:29 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 9AC8F6142F;\n\tThu,  4 Feb 2021 16:31:28 +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 0912D60305\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Feb 2021 16:31:28 +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 A4F8CE000A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu,  4 Feb 2021 15:31:27 +0000 (UTC)"],"X-Originating-IP":"93.61.96.190","Date":"Thu, 4 Feb 2021 16:31:49 +0100","From":"Jacopo Mondi <jacopo@jmondi.org>","To":"libcamera-devel@lists.libcamera.org","Message-ID":"<20210204153149.nxo46ipge42ykeu6@uno.localdomain>","References":"<20210204150820.38427-1-jacopo@jmondi.org>","MIME-Version":"1.0","Content-Disposition":"inline","In-Reply-To":"<20210204150820.38427-1-jacopo@jmondi.org>","Subject":"Re: [libcamera-devel] [PATCH v2] android: camera_device: Generate\n\tJPEG 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>","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>"}}]