From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Alan Third Newsgroups: gmane.emacs.bugs Subject: bug#74476: [PATCH] Explore JPEG loading without quantization Date: Sat, 30 Nov 2024 11:44:29 +0000 Message-ID: References: <871pz39v6p.fsf@ledu-giraud.fr> <86iks581nf.fsf@gnu.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="10436"; mail-complaints-to="usenet@ciao.gmane.io" Cc: Manuel Giraud , 74476@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 30 12:45:24 2024 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1tHLud-0002ZE-Uq for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Nov 2024 12:45:24 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tHLuK-0002PO-P7; Sat, 30 Nov 2024 06:45:04 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1tHLuI-0002PB-Ts for bug-gnu-emacs@gnu.org; Sat, 30 Nov 2024 06:45:02 -0500 Original-Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1tHLuI-00014P-Kt for bug-gnu-emacs@gnu.org; Sat, 30 Nov 2024 06:45:02 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=In-Reply-To:MIME-Version:References:From:Date:To:Subject; bh=OYj4pHAQGIbajKyGN+BhzDUsZQeUJd5qBT9PsErqFzY=; b=Hs9WHiqrgPUDjvXxXKpUxXfe8iji/u0HpZEBs6hLQRyGY15JyXAH0l+GcwKy/nLDJUWyqa0r+AnCk9ulQBjhO9skrOKlCI+1QWQVtPPinQvPLF8qERNaql/3N4/XnCqrzbc9K1MUaSMOewgJ9U8behghV/D7mF2xgiHQ+NmZZxN60i5VKe6PCUxYRLZizjOb+9svcyMPWD7jpjTjewq0H1j9Vpcjz7XTJRxUe2RSCCKLiQ5J6jtou7Gk0wCgdlKsJoD3wpRLXKfnaT/L7ct8Jz6vnf643d0UScTOuBp/gdn4QCSA5IiyPZF7K9IJBdY/9c1bPLyYvw6H29+VvY8JBg==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tHLuI-0004Bq-AD for bug-gnu-emacs@gnu.org; Sat, 30 Nov 2024 06:45:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Alan Third Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Nov 2024 11:45:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 74476 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch Original-Received: via spool by 74476-submit@debbugs.gnu.org id=B74476.173296708016050 (code B ref 74476); Sat, 30 Nov 2024 11:45:02 +0000 Original-Received: (at 74476) by debbugs.gnu.org; 30 Nov 2024 11:44:40 +0000 Original-Received: from localhost ([127.0.0.1]:45796 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tHLtw-0004Ao-3m for submit@debbugs.gnu.org; Sat, 30 Nov 2024 06:44:40 -0500 Original-Received: from dane.soverin.net ([185.233.34.158]:54233) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tHLtt-0004AV-Jk for 74476@debbugs.gnu.org; Sat, 30 Nov 2024 06:44:38 -0500 Original-Received: from smtp.soverin.net (c04smtp-lb01.int.sover.in [10.10.4.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by dane.soverin.net (Postfix) with ESMTPS id 4Y0p9q3TzHzyXh; Sat, 30 Nov 2024 11:44:31 +0000 (UTC) Original-Received: from smtp.soverin.net (smtp.soverin.net [10.10.4.100]) by soverin.net (Postfix) with ESMTPSA id 4Y0p9p6j8JzB4; Sat, 30 Nov 2024 11:44:30 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=idiocy.org; s=soverin; t=1732967071; bh=6pPEzugMCT+sttn44jgVBSbPws0WhvETmG/eNGdg0uE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=d1m1CWolAonODmAr4mUGr8kGKQOvqMKGzQ2K6P8k7XDcKVh9oFTiDr8/uB31iic+8 fmBE67Mbr61x7qXn7vDsgsJWWND+ypKshDpOIvbujaEW5fK3wCMfXGUFSaFwzp6wE9 Ve6kx2X+P9dVaUKgJYRT0gCNjUtQTBxIgVq3nmm3KfQfLTE56BtQ8UTAqAKtAlcecs X3/Jf3LYKlbzNY3LxpYwjUcychIhWY/ygs8SZaHlYG/D+cJFz61a4dhj/X28Z7fXq6 V8maziG44uOMyRjE6KhJxzfVWGXEv5hvzcRykjEMoDCweLjnagsNPepZ87C98bUFzO xZuWqZYVJo7WQ== Original-Received: from localhost (faroe.holly.idiocy.org [local]) by faroe.holly.idiocy.org (OpenSMTPD) with ESMTPA id 4faf1a16; Sat, 30 Nov 2024 11:44:29 +0000 (UTC) Mail-Followup-To: Alan Third , Eli Zaretskii , Manuel Giraud , 74476@debbugs.gnu.org Content-Disposition: inline In-Reply-To: <86iks581nf.fsf@gnu.org> X-Spampanel-Class: ham X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Original-Sender: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Xref: news.gmane.io gmane.emacs.bugs:296158 Archived-At: On Sat, Nov 30, 2024 at 12:19:16PM +0200, Eli Zaretskii wrote: > > Date: Fri, 22 Nov 2024 15:53:18 +0100 > > From: Manuel Giraud via "Bug reports for GNU Emacs, > > the Swiss army knife of text editors" > > > > While trying to speed up "emacs as an image viewer", I found that emacs > > is using libjpeg with color quantization and it seems that removing this > > quantization could speed up JPEG loading a bit. > > > > My simple limited benchmark: > > > > - M-: (clear-image-cache) > > - Open an image in folder with some large enough pictures in > > it (4000x3000 here) > > - M-: (benchmark-run 10 (image-next-file 1)) > > > > Here are the results I get: > > > > without this path: (5.415405491 1 0.09232176400000025) > > with: (3.079911418 1 0.0751190459999993) > > > > I don't think that this patch could be applied as is (it is rather > > ugly). And I also think that I probably have missed some (many?) use > > case (where color quantization is mandatory). But I'm submitting this > > patch anyway as a conversation starter on the subject. > > Alan, any comments? I know nothing about this "color quantization" > aspect of JPEG images. Hi Eli, I'm not an expert on this part of the image code, but I think the jpeg colour quantization path exists for colour mapped environments. For example you can pass it an array of 256 colours and it will map all the colours in the jpeg to those colours. I don't think we need to do this. In most cases we're not in a colour mapped environment, and the existing code doesn't ask the jpeg code to map to the existing colour map anyway. AFAICT Emacs provides its own functions for colour mapping, so I think we should try turning off this quantization and rely on our own methods. That works for PNGs and others, after all. Manuel, I think you want to use lookup_rgb_color when setting the pixels in the final image buffer. This should do the right thing. You presumably also need to call init_color_table before using it, and I see calls to colors_in_color_table and free_color_table which look necessary, but I think they're already in the jpeg code. -- Alan Third