[poppler] Patches for SplashBitmap/PNGWriter

Stefan Thomas thomas at txtbear.com
Fri Jul 16 09:36:14 PDT 2010


  Hey Albert,

> Seems like it duplicates some code from the other method, would it be possible
> to merge them a bit more?

I tried with a single function first. Too many special cases and you 
don't want any if's in those performance-sensitive inner loops. 
Eventually I split it into two functions, sacrificing brevity for 
readability, simplicity and performance.

I'm sure a better, faster, shorter solution is possible, but I'm no John 
Carmack. :)


> valgrind does not complain about it when i do
>    valgrind ./utils/pdftoppm -jpeg ~/pdf_reference_1-7.pdf -f 1 -l 1 foo
>
> Are you sure that is the problem?

It turns out that my transparent image patch seems to introduce the 
problem that the second patch fixes. It also contains another bug where 
if(withAlpha) should be if(!withAlpha) that the second patch also fixes.

I've moved the fix for the withAlpha issue to the first patch. So the 
second patch now only fixes the JPEG issue.

If you apply only the first patch Valgrind does indeed not complain. You 
get the corrupted JPEG, but no segfault or error from valgrind. What I 
believe is happening is that libjpeg is smart enough to detect the 
problem and aborts the image generation to protect it's host process.

Once you apply the second patch - which changes nothing other than 
freeing the temporary buffer after the call to writer->close() - the 
problem disappears.

Here is the valgrind output from a test run with the first patch only 
(note: no errors) and attached the resulting image (note: bottom 
corrupted/cut off):

moon at clymene:/atlas/www/txtbear/local/test$ valgrind 
../../dist/poppler-http/utils/pdftoppm -jpeg -r 25 -f 1 -l 1 
/atlas/www/txtbear/data/assets/00/01/14/7c/source.pdf outtest
==31979== Memcheck, a memory error detector
==31979== Copyright (C) 2002-2009, and GNU GPL'd, by Julian Seward et al.
==31979== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for 
copyright info
==31979== Command: ../../dist/poppler-http/utils/pdftoppm -jpeg -r 25 -f 
1 -l 1 /atlas/www/txtbear/data/assets/00/01/14/7c/source.pdf outtest
==31979==
==31979==
==31979== HEAP SUMMARY:
==31979==     in use at exit: 0 bytes in 0 blocks
==31979==   total heap usage: 51,067 allocs, 51,067 frees, 10,131,934 
bytes allocated
==31979==
==31979== All heap blocks were freed -- no leaks are possible
==31979==
==31979== For counts of detected and suppressed errors, rerun with: -v
==31979== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 85 from 10)

Go figure.

Cheers,

Stefan Thomas
-------------- next part --------------
A non-text attachment was scrubbed...
Name: outtest-01.jpg
Type: image/jpeg
Size: 24576 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/poppler/attachments/20100716/569b3d62/attachment-0001.jpg>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: 0001-Add-support-for-transparent-PNGs-to-PNGWriter-and-Sp.patch
URL: <http://lists.freedesktop.org/archives/poppler/attachments/20100716/569b3d62/attachment-0001.asc>


More information about the poppler mailing list