From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 5925E42332 for ; Sat, 12 Mar 2022 11:10:56 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2906468B1E1; Sat, 12 Mar 2022 13:10:54 +0200 (EET) Received: from haasn.dev (haasn.dev [78.46.187.166]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 79DB268A048 for ; Sat, 12 Mar 2022 13:10:48 +0200 (EET) Received: from haasn.dev (unknown [10.30.0.2]) by haasn.dev (Postfix) with ESMTP id 7516447024 for ; Sat, 12 Mar 2022 12:10:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=haasn.xyz; s=mail; t=1647083447; bh=nSxpq4yYocQBRzZq6Ta2on7daOljpOGbQWxRnYF+ZIw=; h=Date:From:To:Subject:In-Reply-To:References:From; b=kd/0o2tjjBwKwGB2oH75Jvb8gfPoaDJHrzr9/81ljzVL+GoqgAuyXCZKkRYvmDT+w XzG4u1hn4QDkJYE/qxuklTGi8QjyRBLEO1YDnnaAM7OVQdxuHnTDAshDFMn2uatEcR mG/6vBlGXnxxXUxaAgaXttnJbUWwpyDGoMgX9ggM= Date: Sat, 12 Mar 2022 12:10:47 +0100 Message-ID: <20220312121047.GB102875@haasn.xyz> From: Niklas Haas To: ffmpeg-devel@ffmpeg.org In-Reply-To: References: <20220311101413.92878-1-ffmpeg@haasn.xyz> <20220311101741.104545-1-ffmpeg@haasn.xyz> MIME-Version: 1.0 Content-Disposition: inline Subject: Re: [FFmpeg-devel] [PATCH v2] avcodec/pngenc: support writing iCCP chunks X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Fri, 11 Mar 2022 12:18:13 +0100 Andreas Rheinhardt wrote: > 2. Using an AVBPrint with its dynamic reallocations is probably not good > here at all: It is easy to get a good upper bound via deflateBound() > which allows to omit the reallocations/the loop. (I should probably have > applied So, I rewrote the code to only use a single av_bprint_get_buffer() call, rather than looping through it. This is semantically identical to doing an extra malloc(), but also allows the 1K buffer on the stack. I did a survey of all (compressed) iCCP chunks found in PNG files in my "collection" (home folder..), and this is what I found: Min. 1st Qu. Median Mean 3rd Qu. Max. 275 2619 2639 3000 2639 14813 Only roughly 11.57% of files are below the "1K" cutoff threshold for using the small buffer optimization. In light of this, I don't think the 1K optimization is hugely important. But, using the AVBPrint does make the code slightly easier to work with in my eyes. The cleanest alternative, I think, would be to store the deflateBound on the ICC profile somewhere in the PNGEncContext, and then use av_malloc to get a temporary buffer inside `png_get_iccp`. It's of course possible to somehow write directly to the output packet buffer, but I don't think avoiding a ~4K malloc/memcpy is worth the hassle and bug risk of sidestepping png_write_chunk in favor of some custom chunk writing code. Thoughts? _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".