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

Faster JBIG2 bitmap decoding #5114

Merged
merged 1 commit into from
Aug 7, 2014

Conversation

fkaelberer
Copy link
Contributor

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%.

@@ -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 &&

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?

Copy link
Contributor Author

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@fkaelberer
Copy link
Contributor Author

Fixed unnecessary newlines.

@fkaelberer
Copy link
Contributor Author

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.

@fkaelberer
Copy link
Contributor Author

Each time I commit the code I think it is as simple it can get, and nothing can be improved.
Nope, I was wrong again. The new code is again much simpler than the last one. So you have to test once more.

@timvandermeij
Copy link
Contributor

/botio test

@pdfjsbot
Copy link

pdfjsbot commented Aug 5, 2014

From: Bot.io (Windows)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://107.22.172.223:8877/da966027eba9712/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Aug 5, 2014

From: Bot.io (Linux)


Received

Command cmd_test from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/dbe0a25ad6f39a6/output.txt

@pdfjsbot
Copy link

pdfjsbot commented Aug 5, 2014

From: Bot.io (Windows)


Success

Full output at http://107.22.172.223:8877/da966027eba9712/output.txt

Total script time: 19.62 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@pdfjsbot
Copy link

pdfjsbot commented Aug 5, 2014

From: Bot.io (Linux)


Success

Full output at http://107.21.233.14:8877/dbe0a25ad6f39a6/output.txt

Total script time: 22.65 mins

  • Font tests: Passed
  • Unit tests: Passed
  • Regression tests: Passed

@yurydelendik yurydelendik self-assigned this Aug 5, 2014
@timvandermeij
Copy link
Contributor

/botio-linux preview

@pdfjsbot
Copy link

pdfjsbot commented Aug 6, 2014

From: Bot.io (Linux)


Received

Command cmd_preview from @timvandermeij received. Current queue size: 0

Live output at: http://107.21.233.14:8877/94cea4f3c3450e3/output.txt

@fkaelberer
Copy link
Contributor Author

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.

@timvandermeij
Copy link
Contributor

@fkaelberer Please open a separate issue for that. Thank you!

yurydelendik added a commit that referenced this pull request Aug 7, 2014
@yurydelendik yurydelendik merged commit 669a4d1 into mozilla:master Aug 7, 2014
@yurydelendik
Copy link
Contributor

Looks good thanks

@fkaelberer
Copy link
Contributor Author

Reported upstream: https://bugzilla.mozilla.org/show_bug.cgi?id=1050788

@fkaelberer fkaelberer deleted the fasterJBIG2decodeBitmap branch August 8, 2014 14:51
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

Successfully merging this pull request may close these issues.

5 participants