Return-Path: X-Original-To: apmail-commons-issues-archive@minotaur.apache.org Delivered-To: apmail-commons-issues-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 1993379A0 for ; Tue, 4 Oct 2011 22:56:59 +0000 (UTC) Received: (qmail 61621 invoked by uid 500); 4 Oct 2011 22:56:58 -0000 Delivered-To: apmail-commons-issues-archive@commons.apache.org Received: (qmail 61543 invoked by uid 500); 4 Oct 2011 22:56:58 -0000 Mailing-List: contact issues-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: issues@commons.apache.org Delivered-To: mailing list issues@commons.apache.org Received: (qmail 61535 invoked by uid 99); 4 Oct 2011 22:56:58 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Oct 2011 22:56:58 +0000 X-ASF-Spam-Status: No, hits=-2000.5 required=5.0 tests=ALL_TRUSTED,RP_MATCHES_RCVD X-Spam-Check-By: apache.org Received: from [140.211.11.116] (HELO hel.zones.apache.org) (140.211.11.116) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Oct 2011 22:56:55 +0000 Received: from hel.zones.apache.org (hel.zones.apache.org [140.211.11.116]) by hel.zones.apache.org (Postfix) with ESMTP id 02C842A937C for ; Tue, 4 Oct 2011 22:56:34 +0000 (UTC) Date: Tue, 4 Oct 2011 22:56:34 +0000 (UTC) From: "Gary Lucas (Updated) (JIRA)" To: issues@commons.apache.org Message-ID: <1170892653.9797.1317768994013.JavaMail.tomcat@hel.zones.apache.org> In-Reply-To: <1752103185.4298.1317227085430.JavaMail.tomcat@hel.zones.apache.org> Subject: [jira] [Updated] (SANSELAN-56) proposed enhancement reduces load time for some image files by 40 percent MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/SANSELAN-56?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ] Gary Lucas updated SANSELAN-56: ------------------------------- Attachment: (was: ImagePrep.java) > proposed enhancement reduces load time for some image files by 40 percent > ------------------------------------------------------------------------- > > Key: SANSELAN-56 > URL: https://issues.apache.org/jira/browse/SANSELAN-56 > Project: Commons Sanselan > Issue Type: Improvement > Environment: Tested in Windows, Linux, MacOS > Reporter: Gary Lucas > Labels: api-change > Attachments: Sanselan-56-SpeedEnhanceTiff.patch > > Original Estimate: 48h > Remaining Estimate: 48h > > I have identified an enhancement that reduces the time required to load TIFF image by 40 percent. I have tested a modified version of Sanselan under Windows, Linux, and MacOS with consistent savings on each platform. Additionally, I suspect that this technique may be applicable to other areas of the Sanselan code base, including more popular image formats supported by Sanselan such as JPEG, PNG, etc. > I propose to add the relevant code changes to the Sanselan code base. Once these modifications are in place, there would be an opportunity for others to look at the pro's and cons' of applying the techniques to other data formats. > The Enhancement > To load an image from a TIFF file, Sanselan performs extensive data processing in order to obtain RGB values for the pixels in the output image. The code for that processing appears to be well written and efficient. Once the RGB value are obtained, they are stored in a Java BufferedImage using a call to the setRGB() method. > Unfortunately, setRGB() is an extremely inefficient method. A much, much better approach is to store the data into an integer array and defer the creation of the buffered image until all information for the image has been collected. Java has a nice (though somewhat obscure) API that lets memory in an integer array be transferred directly to a BufferedImage so that the system does not have to allocate additional memory for this procedure (a very nice feature when dealing with huge images). This change virtually eliminated the overhead for transferring data to images, which accounted for 40 percent of the time required to load images. For TIFF files, this was a reasonable approach because the TiffImageParser class always loads 4-byte image and the getGrayscaleBufferedImage() method is never used. I have not investigated the code for the other renders, but some refinement might be needed for the one-byte grayscale images. > Steps to Integration > In sanselan.common, a new class called ImagePrep was created. ImagePrep carries a width, height, and an integer array for storing pixels. It provides its own setRGB() method which looks just like the one in BufferedImage. Finally, it provides a method called getBufferedImage() which creates a BufferedImage from its internal the integer array when the processing is complete. > In the TiffImageParser classes, data is read from input stream and transferred to pixel values in a series of classes known as PhotometricInterpreters. These were modified to operate on ImagePrep objects rather than BufferedImage objects. The DataReader and TiffImageParser classes were modified to pass ImagePrep objects into the photometric interpreters rather than using BufferedImages. > At the very last step, before passing its result back to the calling method (the Sanselan main class, etc.), the TiffImageParser used the ImagePrep.getBufferedImage() to convert the result to the expected form. -- This message is automatically generated by JIRA. If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa For more information on JIRA, see: http://www.atlassian.com/software/jira