Skip to content

Implementing or porting an accurate, SIMD optimized IDCT algorithm #306

Description

@antonfirsov

We are constantly (re)evaluating the design and implementation plans for our Jpeg decoder, but one thing is sure: we can't go without a SIMD-optimized and accurate IDCT (Inverse Discrete Cosine Transform) implementation.

The issue description is in WIP state. I'm trying to add notes here while doing research.

What we currently have:

What we need

A standard conformant, accurate implementation, that's fast enough. Most likely a floating point one.
Good candidates:

We need to SIMD-optimize our color conversion code as well, and we should use Vector<float> or Vector4 for that. I think, we should expect better accuracy and performance, if our entire post processing chain is done with floats, so I would prefer floating point IDCT implementations over integer ones.

On .NET SIMD API-s

  • I don't know when do the new .NET SIMD API-s land. Even if ETA is not that much, I'm afraid using them will hurt the portability and cross-platform nature of ImageSharp. So, unless someone has a good reason, I prefer not using them.
  • In my experience, even Vector<T> is not mature enough at the moment. SIMD support for different methods is not well documented. It's easy to loose it, eg. by using Vector<T> as a struct member. Some reverse-engineering hints on this topic could be found here.
  • In short: I think having an implementation that uses nothing more than the plain-old Vector4 should be good enough, but correct me if I am wrong! :)

Testing conformance and accuracy

We should unit-test our algorithms against reference implentations in the following way:
image

We have accurate, mathematically correct FDCT/IDCT reference implementations in our test code base. We should always test the new ones against them.

Activity

  1. KLuuKer commented on Aug 25, 2017

    @KLuuKer

    +1 on the actual\trusted implementation it would allow for easy testing if a new\existing piece of code is correct.

    Maybe if there is a good way to detect what features\types are available we could switch between different algorithms automatically (and trough configuration of course).
    That is if you want to maintain all those different pieces of code.

  2. antonfirsov commented on Aug 25, 2017

    @antonfirsov
    MemberAuthor

    @KLuuKer this modularity is actually what I plan. Our users don't need to know about the backing IDCT algorithms. We can introduce something easy for them though, like:

    public enum PerformanceMode
    {
        Fast,
        Accurate
    }
  3. antonfirsov commented on Aug 30, 2017

    @antonfirsov
    MemberAuthor

    I'm closing this because there is nothing wrong with the accuracy of our IDCT implementation. All I needed to do was this.

    Inaccurate is the new accurate!

  4. tocsoft commented on Aug 30, 2017

    @tocsoft
    Member

    too accurate, got to laugh. We should probably add a flag to toggle compatiblity vs accuracy.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions