From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Manuel Giraud via "Bug reports for GNU Emacs, the Swiss army knife of text editors" Newsgroups: gmane.emacs.bugs Subject: bug#74476: [PATCH] Explore JPEG loading without quantization Date: Sat, 30 Nov 2024 18:25:01 +0100 Message-ID: <87h67obpn6.fsf@ledu-giraud.fr> References: <871pz39v6p.fsf@ledu-giraud.fr> <86iks581nf.fsf@gnu.org> <87y11093gx.fsf@ledu-giraud.fr> Reply-To: Manuel Giraud Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="14774"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Cc: Eli Zaretskii , 74476@debbugs.gnu.org To: Alan Third Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Sat Nov 30 18:26:21 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 1tHREa-0003eZ-R2 for geb-bug-gnu-emacs@m.gmane-mx.org; Sat, 30 Nov 2024 18:26:21 +0100 Original-Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tHREO-0003yY-KQ; Sat, 30 Nov 2024 12:26:09 -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 1tHREJ-0003yO-R2 for bug-gnu-emacs@gnu.org; Sat, 30 Nov 2024 12:26:05 -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 1tHREI-00076T-OK for bug-gnu-emacs@gnu.org; Sat, 30 Nov 2024 12:26:03 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:References:In-Reply-To:From:To:Subject; bh=XY7D/q9zUTOvDD28GU45lrmbQXyfHCIJOs06P+gehQs=; b=MQGWPof1+sIB4Hzj4EcNLX5OIvlD0vJB0lVHHO9YyUjfYnGw7YIEIITSX1yv2kNJlBAnnMwwRrRf8oxYpWB/YzKZs2SFjJBPgUNkQThhtQifYX8AEpHK4HgQXm7CDLNiddvArB8a+PMfvQzYZZPAaORXggYYtYU63A2YqbXM/iFVLuhslWVWme0MuttwoqKTGdwSetzbf4QkbYHgqP30wLpVP33Pm7AlYt6ZsQ0ouLP5jnTIs/0ebuaD74vwcqhcqHYE9XuvLX5sn2aEEex8fu6+MW/P9y/QL0hclWxNNX3g/qk02WHXtdnQCtyi8+sc1Q9t4pyWmM3JoR7Cshz6gQ==; Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tHREI-0006Bh-Io for bug-gnu-emacs@gnu.org; Sat, 30 Nov 2024 12:26:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Manuel Giraud Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Sat, 30 Nov 2024 17:26: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.173298750723527 (code B ref 74476); Sat, 30 Nov 2024 17:26:02 +0000 Original-Received: (at 74476) by debbugs.gnu.org; 30 Nov 2024 17:25:07 +0000 Original-Received: from localhost ([127.0.0.1]:48886 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tHRDO-00066q-Vy for submit@debbugs.gnu.org; Sat, 30 Nov 2024 12:25:07 -0500 Original-Received: from ledu-giraud.fr ([51.159.28.247]:7612) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tHRDM-00064g-Pm for 74476@debbugs.gnu.org; Sat, 30 Nov 2024 12:25:06 -0500 DKIM-Signature: v=1; a=ed25519-sha256; c=simple/simple; s=ed25519; bh=bAyFug5Y biPULmKwXvU2vy9GaMPM1qU9rkDkYh6j1yI=; h=date:references:in-reply-to: subject:cc:to:from; d=ledu-giraud.fr; b=psg0TFLhTc2rkZqqmzkUclXEqn6rWc E53RTqXbkdvebyfbJSUvJ6ZhdVVZFCY1A7w1nNtigEVwx8Uek8U5e1BA== DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; s=rsa; bh=bAyFug5YbiPULmKw XvU2vy9GaMPM1qU9rkDkYh6j1yI=; h=date:references:in-reply-to:subject: cc:to:from; d=ledu-giraud.fr; b=EHzQ6NWuVYWGUsp9FNkCsBxSqcrjRb249s4WrJ rAIXLbCgXpK7qOXR5+9kIkXcic0tICLH4arpGis37PtZYckcY8vEH0gn1+4KLzeRAlXDLe keKdVrevDi/OUDUweHHynf42ypFwyGeO3jeDuS0hU5NHMbDZ1e7cpAu7sPlvhml93YRgWW IeFmNRxvYY/xV4IGSP87KDHMWjlGDB84PEhEHIndZXI8epp0JWXzyuDs7cHAcHzhslxzZK 04NbKubqQ6b5rNIlzkVbrgdo8SSib4Zxpg3bzBDLPJDfLYhyEJ7QyWFVVWt2iszJaOGQrL iFHiq9K/J0JXZ4+ObZHZ2vpw== Original-Received: from computer ( [10.1.1.1]) by ledu-giraud.fr (OpenSMTPD) with ESMTPSA id f1c65b05 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Sat, 30 Nov 2024 18:25:03 +0100 (CET) In-Reply-To: (Alan Third's message of "Sat, 30 Nov 2024 15:37:29 +0000") 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:296185 Archived-At: --=-=-= Content-Type: text/plain Here is a new version with Alan suggestions. FTR, the gain is much less interesting. Here is the new timing with same benchmark (see below): (4.381739669 1 0.1034133749999997) > 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) --=-=-= Content-Type: text/x-patch Content-Disposition: attachment; filename=0001-Explore-JPEG-loading-without-quantization.patch >From abf0a548ee1fa66db4bdf1051cd605231e29cf55 Mon Sep 17 00:00:00 2001 From: Manuel Giraud Date: Thu, 21 Nov 2024 17:19:59 +0100 Subject: [PATCH] Explore JPEG loading without quantization --- src/image.c | 66 ++++++++++++++--------------------------------------- 1 file changed, 17 insertions(+), 49 deletions(-) diff --git a/src/image.c b/src/image.c index db7f6acd171..a31c2e2658a 100644 --- a/src/image.c +++ b/src/image.c @@ -8949,9 +8949,8 @@ jpeg_load_body (struct frame *f, struct image *img, FILE *fp = NULL; JSAMPARRAY buffer; int row_stride, x, y; - int width, height; - int i, ir, ig, ib; - unsigned long *colors; + int width, height, ncomp; + int off, r, g, b; Emacs_Pix_Container volatile ximg_volatile = NULL; /* Open the JPEG file. */ @@ -9049,12 +9048,11 @@ jpeg_load_body (struct frame *f, struct image *img, jpeg_read_header (&mgr->cinfo, 1); - /* Customize decompression so that color quantization will be used. - Start decompression. */ - mgr->cinfo.quantize_colors = 1; + /* Start decompression. */ jpeg_start_decompress (&mgr->cinfo); width = img->width = mgr->cinfo.output_width; height = img->height = mgr->cinfo.output_height; + ncomp = mgr->cinfo.output_components; if (!check_image_size (f, width, height)) { @@ -9073,53 +9071,24 @@ jpeg_load_body (struct frame *f, struct image *img, sys_longjmp (mgr->setjmp_buffer, 1); } - /* Allocate colors. When color quantization is used, - mgr->cinfo.actual_number_of_colors has been set with the number of - colors generated, and mgr->cinfo.colormap is a two-dimensional array - of color indices in the range 0..mgr->cinfo.actual_number_of_colors. - No more than 255 colors will be generated. */ - USE_SAFE_ALLOCA; - { - if (mgr->cinfo.out_color_components > 2) - ir = 0, ig = 1, ib = 2; - else if (mgr->cinfo.out_color_components > 1) - ir = 0, ig = 1, ib = 0; - else - ir = 0, ig = 0, ib = 0; - - /* Use the color table mechanism because it handles colors that - cannot be allocated nicely. Such colors will be replaced with - a default color, and we don't have to care about which colors - can be freed safely, and which can't. */ - init_color_table (); - SAFE_NALLOCA (colors, 1, mgr->cinfo.actual_number_of_colors); - - for (i = 0; i < mgr->cinfo.actual_number_of_colors; ++i) - { - /* Multiply RGB values with 255 because X expects RGB values - in the range 0..0xffff. */ - int r = mgr->cinfo.colormap[ir][i] << 8; - int g = mgr->cinfo.colormap[ig][i] << 8; - int b = mgr->cinfo.colormap[ib][i] << 8; - colors[i] = lookup_rgb_color (f, r, g, b); - } - -#ifdef COLOR_TABLE_SUPPORT - /* Remember those colors actually allocated. */ - img->colors = colors_in_color_table (&img->ncolors); - free_color_table (); -#endif /* COLOR_TABLE_SUPPORT */ - } - - /* Read pixels. */ - row_stride = width * mgr->cinfo.output_components; + /* Allocate scanlines buffer and Emacs color table. */ + row_stride = width * ncomp; buffer = mgr->cinfo.mem->alloc_sarray ((j_common_ptr) &mgr->cinfo, JPOOL_IMAGE, row_stride, 1); + init_color_table (); + + /* Fill the X image from JPEG data. */ for (y = 0; y < height; ++y) { jpeg_read_scanlines (&mgr->cinfo, buffer, 1); - for (x = 0; x < mgr->cinfo.output_width; ++x) - PUT_PIXEL (ximg, x, y, colors[buffer[0][x]]); + for (x = 0; x < width; ++x) + { + off = x * ncomp; + r = buffer[0][off] << 8; + g = buffer[0][off + 1] << 8; + b = buffer[0][off + 2] << 8; + PUT_PIXEL (ximg, x, y, lookup_rgb_color (f, r, g, b)); + } } /* Clean up. */ @@ -9135,7 +9104,6 @@ jpeg_load_body (struct frame *f, struct image *img, /* Put ximg into the image. */ image_put_x_image (f, img, ximg, 0); - SAFE_FREE (); return 1; } -- 2.47.0 --=-=-= Content-Type: text/plain -- Manuel Giraud --=-=-=--