-
-
Notifications
You must be signed in to change notification settings - Fork 854
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 Jpeg Huffman Scan Decoding #601
Comments
@JimBobSquarePants As of StbImage, take a look at this: |
@hypeartist Very useful indeed! I've got something I can debug against now. Thanks! |
I had another look at |
@JimBobSquarePants I could give a try and port mozjpeg to C# if you like. What do you think? |
If you could pull the off I would be blown away! Have a look at our code, it should just be the huffman decoder you need to port. |
@JimBobSquarePants It's much easier to me to port the whole stuff so you can strip off unneeded bits. :) |
It’s totally up to you but we’ve already got all the marker parsing code in place plus we have SIMD optimized IDCT and colorspace conversion code. As far as I understand the Mozjpeg source it’s only two jdhuff files to port |
@JimBobSquarePants Ok. I got you. Already grabbed the source and started to examine. Will write you back asap. |
Brilliant thanks! |
@JimBobSquarePants isn't "Faster Jpeg Huffman Decoding" a better title for this? Gonna post some up-to-date profiler results tonight, but @hypeartist in my opinion the fastest way to look for improvement opportunities is doing a comparative debug/analysis against other decoders. Doing a full port is very time consuming + having something fast in languages like C, C++, go, rust etc. doesn't guarantee the same code will be fast in C#. (We've been there several times!) |
@antonfirsov Perhaps, yeah... Naming is hard, it's the Scan segment we're decoding but it's Huffman encoded. Those two sections will definitely be slowing us down.
There's established practises that we should definitely be trying to adapt from MozJpeg, I just haven't managed to get it working with restart markers. |
@antonfirsov @hypeartist @saucecontrol So I revisited this problem this morning and took another look at porting the huffman decoder from StbSharp. Check out the ScanDecoder.cs class in the I'm actually getting somewhere! I'm working on baseline currently, with 6/10 tests passing with spectral accuracy. I think the failing tests are due to me not reading the correct byte following a marker (I could be wrong though). I could really do with another pair of eyes on the problem as I think once we have baseline ported, progressive will follow swiftly. It's definitely worth it imo as without any additional optimisation the port is already yielding healthy performance improvements (PdfJs Port).
|
9/10 working now. Only |
Got both baseline and progressive working!! Latest changes pushed to the branch, will cleanup code asap. |
Prerequisites
DEBUG
andRELEASE
modeDescription
With #571 now included in the codebase we have an opportunity to further enhance the performance of our jpeg decoder.
There is one obvious candidate for improvement within the decoder: The decoding of the SOS (Start of Scan) segment.
Our approach works but is naïve. We only read/decode one byte at a time and do not use optimized tables for Huffman code lookup. There are further optimizations available with AC Huffman decoding that we also do not do.
I believe that with the correct implementation we can reduce our decoding time by at least 10ms when compared to our current benchmarks.
Inspiration for better code
I'm looking for help here. I've made several attempts to port from both sources but have failed miserably so far.
Update
@bitbank2 Has kindly written some information with pointers to demonstrate how to optimise entropy decoding.
http://bitbanksoftware.blogspot.com/2018/06/optimizing-jpeg-entropy-decoding.html
The text was updated successfully, but these errors were encountered: