From patchwork Wed Dec 14 09:33:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cheng-Hao Yang X-Patchwork-Id: 18005 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id B5257BDE6B for ; Wed, 14 Dec 2022 09:33:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6D1466336B; Wed, 14 Dec 2022 10:33:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1671010424; bh=daXYMF8pm6qgpBdXIabLGjj0pOsp/unPaaChNbMmp3o=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=ddyb+pM5G/0A4BkMU6EZtak0hScDDjkGzHhEn4r9PcawtG5vC6B35+7GIUQqxdN6h ZvwS52nQC7D9t8zRpi0yNcAK7YJF+LC6/JX9NiKcvlk09Kwya34IwrxcUXw+ru125F A1Y1cSAX/kd2aDLR8U2AkkI+I/qeAsKKqHpimFvHf9+3Cr3Axs+rmC5cbJNF5dy2es nccj/nhZZJOWzfmX/NH05BP+ZO9UCPN35I1nf4QE1IEPWvqdfbBTKMoG9HWXpA58iT pHEWpBBMuexrR02E8RLvSht+eC6Dt4rs0TGyX6wZ0IiZnycxTnsY0BUzieFV1iy5SF 9ssSszdL8IQrg== Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B2B1B63354 for ; Wed, 14 Dec 2022 10:33:41 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="ATUdldNI"; dkim-atps=neutral Received: by mail-pg1-x536.google.com with SMTP id f3so1598806pgc.2 for ; Wed, 14 Dec 2022 01:33:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eGDdbiTIZndt734ffHSG72L0rpNEhdtkKxEhG+F6B38=; b=ATUdldNIv68absLXrWuDaXkMNa1f8yOKOTbFKjP5nwmg/Wqz1hfAF1YVQHdjlfdRr8 CCTnrsUifwiomIQQlR8Osrr6eSY/VQdDCOPAaYvjmUt/wCtGhDUF0UKYsqKsZsliuzdY WKC3YQDii/NJVu6agSc5PukFUYjOlr9e5x/iY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eGDdbiTIZndt734ffHSG72L0rpNEhdtkKxEhG+F6B38=; b=x38k/mYtioghElDIVg9FnYKhdoLInqBELufsTYxbUEoi+klSkxcN5Y3og1PLK4pdBz HRUGeJENBqfbW38LvWZkvIAu4k65EBp6ueMV6ppKJQ+SbHJG+dbF6nX8f7RNIxugQoeB 7JWM/D3O/LaNyvI7y9z1WnJNFpAKkPtw7evI0vQl2bPVu15JSST90zd/ZzK6s1jj/ayt FUYZrBjXgZ6rUqqpVzxjUD1yMJc4pk83Di9lkNSmXtNxMM2nxlmkSb9UkXUPJT4SWjD6 w/orZ1az9BQ78buh+D1V4aegwwwsxujOMh3exfpUTGipBEbziHtUdtvaPovwSxOsNqip Bwmg== X-Gm-Message-State: ANoB5pnB9KpwHJocuz/EfQdyZkOv1CY0sV5jZX1WcEsKi+FuwFD+at1z lMLdc5VT7TagAcsWCCddcJ7zeo2BIrHx8/rd X-Google-Smtp-Source: AA0mqf70udHcMvwEfFN0MZzWOv/aym16pqd+VxKJ+SWPVXtQO6u64eU9CsSGxzVVJzaFtnsKeWcpxA== X-Received: by 2002:a05:6a00:1912:b0:56b:ca7a:2de2 with SMTP id y18-20020a056a00191200b0056bca7a2de2mr28662939pfi.14.1671010419609; Wed, 14 Dec 2022 01:33:39 -0800 (PST) Received: from chenghaoyang-low.c.googlers.com.com (46.165.189.35.bc.googleusercontent.com. [35.189.165.46]) by smtp.gmail.com with ESMTPSA id d206-20020a621dd7000000b0056bc742d21esm9331190pfd.176.2022.12.14.01.33.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 14 Dec 2022 01:33:39 -0800 (PST) X-Google-Original-From: Harvey Yang To: libcamera-devel@lists.libcamera.org Date: Wed, 14 Dec 2022 09:33:27 +0000 Message-Id: <20221214093330.3345421-5-chenghaoyang@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog In-Reply-To: <20221214093330.3345421-1-chenghaoyang@google.com> References: <20221214093330.3345421-1-chenghaoyang@google.com> MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH v8 4/7] Add an internal Encoder class in EncoderLibJpeg X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Harvey Yang via libcamera-devel From: Cheng-Hao Yang Reply-To: Harvey Yang Cc: Harvey Yang , Harvey Yang Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" To move the thumbnail encoder into EncoderLibJpeg in the following patch, this patch adds a wrapper/internal Encoder class that allows EncoderLibJpeg to have more than one encoder to tackle both captures and thumbnails. Signed-off-by: Harvey Yang Reviewed-by: Laurent Pinchart --- src/android/jpeg/encoder_libjpeg.cpp | 32 +++++++++++++++++++++------- src/android/jpeg/encoder_libjpeg.h | 30 ++++++++++++++++++++------ 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/android/jpeg/encoder_libjpeg.cpp b/src/android/jpeg/encoder_libjpeg.cpp index fd62bd9c..d849547f 100644 --- a/src/android/jpeg/encoder_libjpeg.cpp +++ b/src/android/jpeg/encoder_libjpeg.cpp @@ -68,7 +68,16 @@ const struct JPEGPixelFormatInfo &findPixelInfo(const PixelFormat &format) } /* namespace */ -EncoderLibJpeg::EncoderLibJpeg() +EncoderLibJpeg::EncoderLibJpeg() = default; + +EncoderLibJpeg::~EncoderLibJpeg() = default; + +int EncoderLibJpeg::configure(const StreamConfiguration &cfg) +{ + return encoder_.configure(cfg); +} + +EncoderLibJpeg::Encoder::Encoder() { /* \todo Expand error handling coverage with a custom handler. */ compress_.err = jpeg_std_error(&jerr_); @@ -76,12 +85,12 @@ EncoderLibJpeg::EncoderLibJpeg() jpeg_create_compress(&compress_); } -EncoderLibJpeg::~EncoderLibJpeg() +EncoderLibJpeg::Encoder::~Encoder() { jpeg_destroy_compress(&compress_); } -int EncoderLibJpeg::configure(const StreamConfiguration &cfg) +int EncoderLibJpeg::Encoder::configure(const StreamConfiguration &cfg) { const struct JPEGPixelFormatInfo info = findPixelInfo(cfg.pixelFormat); if (info.colorSpace == JCS_UNKNOWN) @@ -103,7 +112,7 @@ int EncoderLibJpeg::configure(const StreamConfiguration &cfg) return 0; } -void EncoderLibJpeg::compressRGB(const std::vector> &planes) +void EncoderLibJpeg::Encoder::compressRGB(const std::vector> &planes) { unsigned char *src = const_cast(planes[0].data()); /* \todo Stride information should come from buffer configuration. */ @@ -121,7 +130,7 @@ void EncoderLibJpeg::compressRGB(const std::vector> &planes) * Compress the incoming buffer from a supported NV format. * This naively unpacks the semi-planar NV12 to a YUV888 format for libjpeg. */ -void EncoderLibJpeg::compressNV(const std::vector> &planes) +void EncoderLibJpeg::Encoder::compressNV(const std::vector> &planes) { uint8_t tmprowbuf[compress_.image_width * 3]; @@ -188,12 +197,19 @@ int EncoderLibJpeg::encode(const FrameBuffer &source, Span dest, return frame.error(); } - return encode(frame.planes(), dest, exifData, quality); + return encoder_.encode(frame.planes(), dest, exifData, quality); } int EncoderLibJpeg::encode(const std::vector> &src, - Span dest, Span exifData, - unsigned int quality) + Span dest, Span exifData, + unsigned int quality) +{ + return encoder_.encode(src, std::move(dest), std::move(exifData), quality); +} + +int EncoderLibJpeg::Encoder::encode(const std::vector> &src, + Span dest, Span exifData, + unsigned int quality) { unsigned char *destination = dest.data(); unsigned long size = dest.size(); diff --git a/src/android/jpeg/encoder_libjpeg.h b/src/android/jpeg/encoder_libjpeg.h index 1b3ac067..97182b96 100644 --- a/src/android/jpeg/encoder_libjpeg.h +++ b/src/android/jpeg/encoder_libjpeg.h @@ -32,14 +32,30 @@ public: unsigned int quality); private: - void compressRGB(const std::vector> &planes); - void compressNV(const std::vector> &planes); + class Encoder + { + public: + Encoder(); + ~Encoder(); - struct jpeg_compress_struct compress_; - struct jpeg_error_mgr jerr_; + int encode(const std::vector> &planes, + libcamera::Span destination, + libcamera::Span exifData, + unsigned int quality); + int configure(const libcamera::StreamConfiguration &cfg); - const libcamera::PixelFormatInfo *pixelFormatInfo_; + private: + void compressRGB(const std::vector> &planes); + void compressNV(const std::vector> &planes); - bool nv_; - bool nvSwap_; + struct jpeg_compress_struct compress_; + struct jpeg_error_mgr jerr_; + + const libcamera::PixelFormatInfo *pixelFormatInfo_; + + bool nv_; + bool nvSwap_; + }; + + Encoder encoder_; };