-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Faster JBIG2 bitmap decoding #5114
Faster JBIG2 bitmap decoding #5114
Conversation
@@ -159,6 +219,13 @@ var Jbig2Image = (function Jbig2ImageClosure() { | |||
error('JBIG2 error: MMR encoding is not supported'); | |||
} | |||
|
|||
// Use optimized version for the most common case | |||
if (templateIndex === 0 && !useskip && !prediction && at.length === 4 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't useskip not declared until line 229?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ouch. Thanks, I'll fix that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
Fixed unnecessary newlines. |
I noticed that an extra for loop for the case of i < 2 in my previous commit was not necessary. This commit does the same but is 20 lines shorter. |
Each time I commit the code I think it is as simple it can get, and nothing can be improved. |
/botio test |
From: Bot.io (Windows)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.22.172.223:8877/da966027eba9712/output.txt |
From: Bot.io (Linux)ReceivedCommand cmd_test from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/dbe0a25ad6f39a6/output.txt |
From: Bot.io (Windows)SuccessFull output at http://107.22.172.223:8877/da966027eba9712/output.txt Total script time: 19.62 mins
|
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/dbe0a25ad6f39a6/output.txt Total script time: 22.65 mins
|
/botio-linux preview |
From: Bot.io (Linux)ReceivedCommand cmd_preview from @timvandermeij received. Current queue size: 0 Live output at: http://107.21.233.14:8877/94cea4f3c3450e3/output.txt |
From: Bot.io (Linux)SuccessFull output at http://107.21.233.14:8877/94cea4f3c3450e3/output.txt Total script time: 0.76 mins Published
|
BTW: There's a FF regression in nightly 34 (Linux only): The university logo in scanned_example_1.pdf turns black. It's not caused by this PR. |
@fkaelberer Please open a separate issue for that. Thank you! |
Faster JBIG2 bitmap decoding
Looks good thanks |
Reported upstream: https://bugzilla.mozilla.org/show_bug.cgi?id=1050788 |
While debugging the JBIG2 code I noticed that jbig2dec and xpdf both have special code paths for each of the four standard templates, for performance reasons. And indeed, the code can be simplified a lot if the context template is known.
In this PR, I wrote the decoding procedure from scratch for the case of the most common standard template and the
at
pixels at the standard location (which is the case for most jbig2 documents I have). In this case, each pixel in the main loop can be decoded without looping or branching, and it is much easier to understand what's happening.The decoding time of #3816 and #2909 and others is reduced by ~25%.