jsjpeg.js
/**
 * Read and decode a single 8x8 data unit. In order, we:
 * - Decode the DC coefficient
 * - Decode the 63 AC coefficients
 * - Dequantize the 64 coefficients
 * - Convert coefficients from zig-zag order to sequential order
 * - Perform Inverse DCT (IDCT)
 * - Recenter the coefficients
 * 
 * F.2.1.2
 * 
 * @param {DataViewReader} reader Data source
 * @param {*} img Struct with information about the image, including frame + components
 * @param {*} scan Struct with information about this scan
 * @param {*} id ID of the current component. Used to look up the current DC predictor
 * @param {*} dcTable Huffman table to use for decoding DC coefficients
 * @param {*} acTable Huffamn table to use for decoding AC coefficients
 * @param {*} quantTable Quantization table for this block
 */
Read and decode a single 8x8 data unit.



@param {DataViewReader} reader Data source
@param {*} img Struct with information about the image, including frame + components
@param {*} scan Struct with information about this scan
@param {*} id ID of the current component. Used to look up the current DC predictor
@param {*} dcTable Huffman table to use for decoding DC coefficients
@param {*} acTable Huffamn table to use for decoding AC coefficients
@param {*} quantTable Quantization table for this block
Read and decode a single 8x8 data unit . @param { DataViewReader } reader Data source @param { * } img Struct with information about the image including frame + components @param { * } scan Struct with information about this scan @param { * } id ID of the current component . Used to look up the current DC predictor @param { * } dcTable Huffman table to use for decoding DC coefficients @param { * } acTable Huffamn table to use for decoding AC coefficients @param { * } quantTable Quantization table for this block
function decodeDataUnit(reader, img, scan, id, dcTable, acTable, quantTable) {
    scan.block.fill(0);
    scan.block[0] = decodeDCCoeff(reader, img, scan, id, dcTable);
    scan.dcpred[id] = scan.block[0];
    decodeACCoeffs(reader, img, scan.block, acTable);
    dequantize(scan.block, quantTable);
    reorder(scan.block, scan.scratch);
    let block = idctFn(scan.block);
    levelShift(block);
    return block;
}
function decodeDataUnit ( reader , img , scan , id , dcTable , acTable , quantTable ) { scan . block . fill ( 0 ) ; scan . block [ 0 ] = decodeDCCoeff ( reader , img , scan , id , dcTable ) ; scan . dcpred [ id ] = scan . block [ 0 ] ; decodeACCoeffs ( reader , img , scan . block , acTable ) ; dequantize ( scan . block , quantTable ) ; reorder ( scan . block , scan . scratch ) ; let block = idctFn ( scan . block ) ; levelShift ( block ) ; return block ; }
Read and decode a single 8x8 data unit.
Read and decode a single 8x8 data unit .
// 8x8 table of DC/AC coeffs // Decode DC Coeff for 8x8 block using DC table dest in scan header (F.2.2.1) // Decode AC coeffs for 8x8 block using AC table dest in scan header (F.2.2.2) // Dequantize using table dest in frame header (F.2.1.4) // Multiply each coefficient by the corresponding  // value in the quant table (which is in ZZ order too) // Reorder coefficients (de-zig-zag) // Calculate inverse IDCT on dequantized values (F.2.1.5) // Level-shift (F.2.1.5)