From patchwork Fri Jan 24 21:58:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Milan Zamazal X-Patchwork-Id: 22652 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 9C641C322E for ; Fri, 24 Jan 2025 21:59:02 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 2A8056856F; Fri, 24 Jan 2025 22:59:02 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="JG376bKE"; dkim-atps=neutral Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 2A50E6857A for ; Fri, 24 Jan 2025 22:58:55 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1737755933; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lwce1DZOVj1hcy0X3NaOakK2sv5Id5eOhgvaBoGXNb0=; b=JG376bKEIO8hl+cFZJbq6iD5U+O+YMv4ZNmFbxqzlwmQd/tcR1V03M2QN9lw2bZleki5/6 /BYF9aDXzwEPkrHANLC5K2C7pHwTjXUfJcZ35mpJtvdWF2wG222pPRxCVspSpr+2+BhZ0Z CKEYJbK5WZH3NBpoJPwoEADjbFtaa2E= Received: from mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-359-bdL8TsYyMpGnKEch5v0Nzg-1; Fri, 24 Jan 2025 16:58:50 -0500 X-MC-Unique: bdL8TsYyMpGnKEch5v0Nzg-1 X-Mimecast-MFC-AGG-ID: bdL8TsYyMpGnKEch5v0Nzg Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 7EF6F1801F11 for ; Fri, 24 Jan 2025 21:58:49 +0000 (UTC) Received: from mzamazal-thinkpadp1gen3.tpbc.com (unknown [10.39.192.49]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 2ADCF1800358; Fri, 24 Jan 2025 21:58:47 +0000 (UTC) From: Milan Zamazal To: libcamera-devel@lists.libcamera.org Cc: Milan Zamazal Subject: [RFC PATCH v2 13/13] apps: cam: Write raw file if PPM cannot be written Date: Fri, 24 Jan 2025 22:58:04 +0100 Message-ID: <20250124215806.158024-14-mzamazal@redhat.com> In-Reply-To: <20250124215806.158024-1-mzamazal@redhat.com> References: <20250124215806.158024-1-mzamazal@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 X-Mimecast-Spam-Score: 0 X-Mimecast-MFC-PROC-ID: ZDXTlqgnUaUC4iUHfmq8WDcEiU3tmTouZPkjzIrtl7o_1737755929 X-Mimecast-Originator: redhat.com content-type: text/plain; charset="US-ASCII"; x-default=true 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: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" `cam' application can be requested to write its output as a PPM file. However, this is supported only for certain formats (only BGR888 currently). If the output format cannot be written, `cam' reports an error and doesn't write anything. This is all right with a single stream input but impractical with multiple streams of different output formats (e.g. a processed stream + a raw stream) where some of them can be written in the supported format while the other not. In such a case, it's better to write the supported formats as PPM files and the unsupported formats as raw files, with the corresponding warning on stderr. `.raw' extension is added to the file name in such a case to make clear it's not a PPM file. This is a sort of hack but serves the purpose for the moment. Signed-off-by: Milan Zamazal --- src/apps/cam/file_sink.cpp | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/src/apps/cam/file_sink.cpp b/src/apps/cam/file_sink.cpp index 76e21db9..1a866137 100644 --- a/src/apps/cam/file_sink.cpp +++ b/src/apps/cam/file_sink.cpp @@ -7,6 +7,7 @@ #include #include +#include #include #include #include @@ -133,11 +134,16 @@ void FileSink::writeBuffer(const Stream *stream, FrameBuffer *buffer, if (fileType_ == FileType::Ppm) { ret = PPMWriter::write(filename.c_str(), stream->configuration(), image->data(0)); - if (ret < 0) - std::cerr << "failed to write PPM file `" << filename - << "'" << std::endl; - - return; + if (ret == -EINVAL) { + filename += ".raw"; + std::cerr << "cannot write file in PPM format, writing `" + << filename << "' instead" << std::endl; + } else { + if (ret < 0) + std::cerr << "failed to write PPM file `" << filename + << "'" << std::endl; + return; + } } fd = open(filename.c_str(), O_CREAT | O_WRONLY |