fn dequantize_and_idct_block_4x4(
    coefficients: &[i16],
    quantization_table: &[u16; 64],
    output_linestride: usize,
    output: &mut [u8],
) {
    debug_assert_eq!(coefficients.len(), 64);
    let mut temp = [Wrapping(0i32); 4 * 4];

    const CONST_BITS: usize = 12;
    const PASS1_BITS: usize = 2;
    const FINAL_BITS: usize = CONST_BITS + PASS1_BITS + 3;

    // columns
    for i in 0..4 {
        let s0 = Wrapping(coefficients[i + 8 * 0] as i32 * quantization_table[i + 8 * 0] as i32);
        let s1 = Wrapping(coefficients[i + 8 * 1] as i32 * quantization_table[i + 8 * 1] as i32);
        let s2 = Wrapping(coefficients[i + 8 * 2] as i32 * quantization_table[i + 8 * 2] as i32);
        let s3 = Wrapping(coefficients[i + 8 * 3] as i32 * quantization_table[i + 8 * 3] as i32);

        let x0 = (s0 + s2) << PASS1_BITS;
        let x2 = (s0 - s2) << PASS1_BITS;

        let p1 = (s1 + s3) * stbi_f2f(0.541196100);
        let t0 = (p1 + s3 * stbi_f2f(-1.847759065) + Wrapping(512)) >> (CONST_BITS - PASS1_BITS);
        let t2 = (p1 + s1 * stbi_f2f(0.765366865) + Wrapping(512)) >> (CONST_BITS - PASS1_BITS);

        temp[i + 4 * 0] = x0 + t2;
        temp[i + 4 * 3] = x0 - t2;
        temp[i + 4 * 1] = x2 + t0;
        temp[i + 4 * 2] = x2 - t0;
    }

    for i in 0..4 {
        let s0 = temp[i * 4 + 0];
        let s1 = temp[i * 4 + 1];
        let s2 = temp[i * 4 + 2];
        let s3 = temp[i * 4 + 3];

        let x0 = (s0 + s2) << CONST_BITS;
        let x2 = (s0 - s2) << CONST_BITS;

        let p1 = (s1 + s3) * stbi_f2f(0.541196100);
        let t0 = p1 + s3 * stbi_f2f(-1.847759065);
        let t2 = p1 + s1 * stbi_f2f(0.765366865);

        // constants scaled things up by 1<<12, plus we had 1<<2 from first
        // loop, plus horizontal and vertical each scale by sqrt(8) so together
        // we've got an extra 1<<3, so 1<<17 total we need to remove.
        // so we want to round that, which means adding 0.5 * 1<<17,
        // aka 65536. Also, we'll end up with -128 to 127 that we want
        // to encode as 0..255 by adding 128, so we'll add that before the shift
        let x0 = x0 + Wrapping(1 << (FINAL_BITS - 1)) + Wrapping(128 << FINAL_BITS);
        let x2 = x2 + Wrapping(1 << (FINAL_BITS - 1)) + Wrapping(128 << FINAL_BITS);

        output[i * output_linestride + 0] = stbi_clamp((x0 + t2) >> FINAL_BITS);
        output[i * output_linestride + 3] = stbi_clamp((x0 - t2) >> FINAL_BITS);
        output[i * output_linestride + 1] = stbi_clamp((x2 + t0) >> FINAL_BITS);
        output[i * output_linestride + 2] = stbi_clamp((x2 - t0) >> FINAL_BITS);
    }
}
// 4x4 and 2x2 IDCT based on Rakesh Dugad and Narendra Ahuja: "A Fast Scheme for Image Size Change in the Compressed Domain" (2001).
// http://sylvana.net/jpegcrop/jidctred/
4x4 and 2x2 IDCT based on Rakesh Dugad and Narendra Ahuja: "A Fast Scheme for Image Size Change in the Compressed Domain" (2001).
4x4 and 2x2 IDCT based on Rakesh Dugad and Narendra Ahuja : " A Fast Scheme for Image Size Change in the Compressed Domain " ( 2001 ) .
fn dequantize_and_idct_block_4x4(
    coefficients: &[i16],
    quantization_table: &[u16; 64],
    output_linestride: usize,
    output: &mut [u8],
) {
    debug_assert_eq!(coefficients.len(), 64);
    let mut temp = [Wrapping(0i32); 4 * 4];
    const CONST_BITS: usize = 12;
    const PASS1_BITS: usize = 2;
    const FINAL_BITS: usize = CONST_BITS + PASS1_BITS + 3;
    // columns
    for i in 0..4 {
        let s0 = Wrapping(coefficients[i + 8 * 0] as i32 * quantization_table[i + 8 * 0] as i32);
        let s1 = Wrapping(coefficients[i + 8 * 1] as i32 * quantization_table[i + 8 * 1] as i32);
        let s2 = Wrapping(coefficients[i + 8 * 2] as i32 * quantization_table[i + 8 * 2] as i32);
        let s3 = Wrapping(coefficients[i + 8 * 3] as i32 * quantization_table[i + 8 * 3] as i32);
        let x0 = (s0 + s2) << PASS1_BITS;
        let x2 = (s0 - s2) << PASS1_BITS;
        let p1 = (s1 + s3) * stbi_f2f(0.541196100);
        let t0 = (p1 + s3 * stbi_f2f(-1.847759065) + Wrapping(512)) >> (CONST_BITS - PASS1_BITS);
        let t2 = (p1 + s1 * stbi_f2f(0.765366865) + Wrapping(512)) >> (CONST_BITS - PASS1_BITS);
        temp[i + 4 * 0] = x0 + t2;
        temp[i + 4 * 3] = x0 - t2;
        temp[i + 4 * 1] = x2 + t0;
        temp[i + 4 * 2] = x2 - t0;
    }
    for i in 0..4 {
        let s0 = temp[i * 4 + 0];
        let s1 = temp[i * 4 + 1];
        let s2 = temp[i * 4 + 2];
        let s3 = temp[i * 4 + 3];
        let x0 = (s0 + s2) << CONST_BITS;
        let x2 = (s0 - s2) << CONST_BITS;
        let p1 = (s1 + s3) * stbi_f2f(0.541196100);
        let t0 = p1 + s3 * stbi_f2f(-1.847759065);
        let t2 = p1 + s1 * stbi_f2f(0.765366865);
        // constants scaled things up by 1<<12, plus we had 1<<2 from first
        // loop, plus horizontal and vertical each scale by sqrt(8) so together
        // we've got an extra 1<<3, so 1<<17 total we need to remove.
        // so we want to round that, which means adding 0.5 * 1<<17,
        // aka 65536. Also, we'll end up with -128 to 127 that we want
        // to encode as 0..255 by adding 128, so we'll add that before the shift
        let x0 = x0 + Wrapping(1 << (FINAL_BITS - 1)) + Wrapping(128 << FINAL_BITS);
        let x2 = x2 + Wrapping(1 << (FINAL_BITS - 1)) + Wrapping(128 << FINAL_BITS);
        output[i * output_linestride + 0] = stbi_clamp((x0 + t2) >> FINAL_BITS);
        output[i * output_linestride + 3] = stbi_clamp((x0 - t2) >> FINAL_BITS);
        output[i * output_linestride + 1] = stbi_clamp((x2 + t0) >> FINAL_BITS);
        output[i * output_linestride + 2] = stbi_clamp((x2 - t0) >> FINAL_BITS);
    }
}
fn dequantize_and_idct_block_4x4 ( coefficients : & [ i16 ] , quantization_table : & [ u16 ; 64 ] , output_linestride : usize , output : & mut [ u8 ] , ) { debug_assert_eq ! ( coefficients len ( ) 64 ) ; let mut temp = [ Wrapping ( 0i32 ) ; 4 * 4 ] ; const CONST_BITS : usize = 12 ; const PASS1_BITS : usize = 2 ; const FINAL_BITS : usize = CONST_BITS + PASS1_BITS + 3 ; // columns for i in 0 .. 4 { let s0 = Wrapping ( coefficients [ i + 8 * 0 ] as i32 * quantization_table [ i + 8 * 0 ] as i32 ) ; let s1 = Wrapping ( coefficients [ i + 8 * 1 ] as i32 * quantization_table [ i + 8 * 1 ] as i32 ) ; let s2 = Wrapping ( coefficients [ i + 8 * 2 ] as i32 * quantization_table [ i + 8 * 2 ] as i32 ) ; let s3 = Wrapping ( coefficients [ i + 8 * 3 ] as i32 * quantization_table [ i + 8 * 3 ] as i32 ) ; let x0 = ( s0 + s2 ) << PASS1_BITS ; let x2 = ( s0 - s2 ) << PASS1_BITS ; let p1 = ( s1 + s3 ) * stbi_f2f ( 0.541196100 ) ; let t0 = ( p1 + s3 * stbi_f2f ( - 1.847759065 ) + Wrapping ( 512 ) ) >> ( CONST_BITS - PASS1_BITS ) ; let t2 = ( p1 + s1 * stbi_f2f ( 0.765366865 ) + Wrapping ( 512 ) ) >> ( CONST_BITS - PASS1_BITS ) ; temp [ i + 4 * 0 ] = x0 + t2 ; temp [ i + 4 * 3 ] = x0 - t2 ; temp [ i + 4 * 1 ] = x2 + t0 ; temp [ i + 4 * 2 ] = x2 - t0 ; } for i in 0 .. 4 { let s0 = temp [ i * 4 + 0 ] ; let s1 = temp [ i * 4 + 1 ] ; let s2 = temp [ i * 4 + 2 ] ; let s3 = temp [ i * 4 + 3 ] ; let x0 = ( s0 + s2 ) << CONST_BITS ; let x2 = ( s0 - s2 ) << CONST_BITS ; let p1 = ( s1 + s3 ) * stbi_f2f ( 0.541196100 ) ; let t0 = p1 + s3 * stbi_f2f ( - 1.847759065 ) ; let t2 = p1 + s1 * stbi_f2f ( 0.765366865 ) ; // constants scaled things up by 1<<12, plus we had 1<<2 from first // loop, plus horizontal and vertical each scale by sqrt(8) so together // we've got an extra 1<<3, so 1<<17 total we need to remove. // so we want to round that, which means adding 0.5 * 1<<17, // aka 65536. Also, we'll end up with -128 to 127 that we want // to encode as 0..255 by adding 128, so we'll add that before the shift let x0 = x0 + Wrapping ( 1 << ( FINAL_BITS - 1 ) ) + Wrapping ( 128 << FINAL_BITS ) ; let x2 = x2 + Wrapping ( 1 << ( FINAL_BITS - 1 ) ) + Wrapping ( 128 << FINAL_BITS ) ; output [ i * output_linestride + 0 ] = stbi_clamp ( ( x0 + t2 ) >> FINAL_BITS ) ; output [ i * output_linestride + 3 ] = stbi_clamp ( ( x0 - t2 ) >> FINAL_BITS ) ; output [ i * output_linestride + 1 ] = stbi_clamp ( ( x2 + t0 ) >> FINAL_BITS ) ; output [ i * output_linestride + 2 ] = stbi_clamp ( ( x2 - t0 ) >> FINAL_BITS ) ; } }
4x4 and 2x2 IDCT based on Rakesh Dugad and Narendra Ahuja: "A Fast Scheme for Image Size Change in the Compressed Domain" (2001).
4x4 and 2x2 IDCT based on Rakesh Dugad and Narendra Ahuja : " A Fast Scheme for Image Size Change in the Compressed Domain " ( 2001 ) .
coefficients
&[i16]
quantization_table
&[u16; 64]
output_linestride
usize
output
&mut [u8]