JPEG Dequantizer

The principle is simple: each decoded coefficient is multiplied by a value. Each component can have it's own quantization table. After coefficient decoding (entropy decoder) the coefficients are dequantized.

But.. the order and number of DQT and SOS is quite flexible in progressive JPEG interchange format (JIF).
Each DQT can load up to 4 new tables. Old entries will be reloaded and overwritten.
Each Component in SOF specifies only a QT-entry to use for dequantisation.

This is not likely, but can happen, in the middle of decoding:

                    scan of                         scan of
                    Comp 1                          Comp 2 
                  
DQT Tq=0 ... SOS .............. DQT Tq=0 ... SOS ................ 
 |                               |
 |                               |
 load QT[0]              Qtable[0] overwritten! 

So.. we either dequantize when Comp 1 is finished or store and manage all quantization table <-> Comp relationships. Both require quite a bit of coding. I simply cut this out from the JPEG81 decoder: DQT loads.. after all scans decoding, dequantise.

                        Tq      values from DQT
                        +--+------------------------+
                        |0 | xx xx xx xx .. .. ..   |   
       load             +--+------------------------+  
      into Tq           |1 | yy yy yy .. .. .. ..   |   
DQT --------------->    +--+------------------------+      <---- Dequant: use table Comp->Qi
                        |2 | zz zz zz               |
                        +--+------------------------+
                        |3 |                        |
                        +--+------------------------+