Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

opj_decompress is 3x slow on Windows for PGM #1194

Open
krasin opened this issue May 22, 2019 · 0 comments
Open

opj_decompress is 3x slow on Windows for PGM #1194

krasin opened this issue May 22, 2019 · 0 comments

Comments

@krasin
Copy link

krasin commented May 22, 2019

Hi there,

Thank you for maintaining OpenJPEG!

Today, I profiled opj_decompress on Windows and Linux and mentioned that it's 3x slower on Windows. After a deeper look (for which I had to add some printfs and compile opj_decompress.exe), I realized that imagetopnm takes 165ms, while decompressor just 62ms:

$ time -p bin/opj_decompress.exe -i lala.jp2 -o lala2.pgm

load image + initialize: 0.390500 ms
[INFO] Start to read j2k main header (85).
[INFO] Main header has been correctly decoded.
[INFO] No decoded area parameters, set the decoded area to the whole image
[INFO] Header of tile 1 / 1 has been read.
[INFO] Stream reached its end !
[INFO] Generated Outfile lala2.pgm
imagetopnm: 164.228699 ms
decode time: 62 ms
total time: 228.419403 ms
real 0.28
user 0.00
sys 0.01

The reason for this is the fact that imagetopng calls fprintf for every pixel. For text-based variants (such as P2), it could be justified, but for binary PGM (P5), it can be way faster.

My quick and dirty experiment, where I just generate the output array for a 16-bit PGM in a loop (shuffling the bytes, so that they are in bigendian mode, as required for PGM) and then call a single fwrite, the time for imagetopnm goes down to ~7 ms.

Would you be open for a patch that will have a (much) faster path for saving binary PGM files?

I will be totally cool to work on that, but would appreciate an early signal that this is an acceptable approach.

Thank you in advance,
Ivan Krasin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant