Jump to content
Site Stability Read more... ×
  • Advertisement
Sign in to follow this  

Quantization scaling for JPEG decoder based on Arai Agui and Nakajima

This topic is 2100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey people,


I'm currently working on a jpeg decoder based on the algorithm of Arai, Agui and Nakajima. While my solution is almost working I am missing a critical scaling operation that is key for this approach (which turns dct values into a dft values). I am supposed to scale the quantization matrix with based on the position of the values in the quantization matrix/ I just can't figure out how to calculate these scaling factors.


A good reference I am working with can be found here: http://vsr.informatik.tu-chemnitz.de/~jan/MPEG/HTML/IDCT.html


Hoping to find some people that have practical experience with this.


Thanks in advance!

Share this post

Link to post
Share on other sites

Alright... found the solution!biggrin.png


In case someone else runs into this, here is how it works. You need to scale the quantization matrices with a value depending on the row and column position of each element in this matrix. The formula for this is:

scaling = 4 / Cu * cos((PI * u) / 16)

The trick is that Cu is 1/sqrt(2) in case u is 0 and 1 in any other case. The scaling must be done for both the row and column. Because I work with 8x8 blocks the pseudo code looks like:


// Pre-calculate 1/sqrt(2)
var oneOverSqrtTwo = 0.70710678118654752440084436210485;

// Our quantization is an 1D array with 64 (8x8) elements.
var index = 0;

// Go through all columns.
for (column in 0...8) 
     // Calculate scaling for the column and divide by 1/sqrt(2) if needed.
     var columnScaling = 4 * Math.cos(Math.PI * column  * 0.0625);
     if (column == 0) columnScaling /= oneOverSqrtTwo; 

     for (r in 0...8)
          // Calculate scaling for the row and divide by 1/sqrt(2) if needed.
          var rowScaling = 4 * Math.cos(Math.PI * r * 0.0625);
          if (r == 0) rowScaling /= oneOverSqrtTwo;

         // Scale quantization.
         quantization[index] *= rowScaling * columnScaling;

         // Advance the index.
         index ++;


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!