google-code-export / purepdf

Automatically exported from code.google.com/p/purepdf
2 stars 1 forks source link

Performance improvement suggestion in TIFFEncoder #26

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
No problem, just a suggestion on improving TIFF generation speed. Using this 
appeared to speed up results by ~70%.  (I am using the library to generate some 
large image elements, where this was noticeable)

What is the expected output? What do you see instead?
-

What version of the product are you using? On what operating system?
TIFFEncoder svn rev 251.

Please provide any additional information below.

In TIFFEncoder, rather than doing a double for loop at line 133 to get each 
pixel and then perform bitshift operations, do two things:  1) use a local 
variable for the length getter and 2) make use of BitmapData.getPixels, which 
is native and very fast.

replace double for loop with the following:

// BitmapData getPixels is very fast, but returns values with an alpha channel, 
// i.e. ARGB. TIFF takes RGB. Loop through the entire bytearray, skipping the 
// first byte (the alpha channel), but retaining the next 3 (R,G,B).
var pixelsWithAlpha:ByteArray = bmp.getPixels( new Rectangle( 0, 0, bmp.width, 
bmp.height ));
// only call the length getter once, as function calls are more expensive than 
// local variable access
var pwaLength:uint = pixelsWithAlpha.length;
pixelsWithAlpha.position = 0;

for ( var j:uint = 0; j < pwaLength; j += 4 )
{
    img.writeBytes( pixelsWithAlpha, j + 1, 3 );
}

Original issue reported on code.google.com by lun...@gmail.com on 11 Jan 2012 at 2:03

GoogleCodeExporter commented 9 years ago
After another hour's worth of testing, I think you can disregard this - it's 
faster, but I'm seeing some pixel shifting in some images.  Apologize for the 
confusion - if there was a way for me to delete the issue I would :)

Original comment by lun...@gmail.com on 11 Jan 2012 at 3:00