BitMiracle.LibJpeg.Classic.Internal.jpeg_inverse_dct.jpeg_idct_8x16 C# (CSharp) Method

jpeg_idct_8x16() private method

private jpeg_idct_8x16 ( int component_index, short coef_block, int output_row, int output_col ) : void
component_index int
coef_block short
output_row int
output_col int
return void
        private void jpeg_idct_8x16(int component_index, short[] coef_block, int output_row, int output_col)
        {
            /* buffers data between passes */
            int[] workspace = new int[8 * 16];

            /* Pass 1: process columns from input, store into work array. */
            /* 16 - point IDCT kernel, cK represents sqrt(2) * cos(K * pi / 32). */
            int coefBlockIndex = 0;

            int[] quantTable = m_dctTables[component_index].int_array;
            int quantTableIndex = 0;

            int workspaceIndex = 0;

            for (int ctr = 0; ctr < 8; ctr++)
            {
                /* Even part */
                int tmp0 = SLOW_INTEGER_DEQUANTIZE(coef_block[coefBlockIndex + JpegConstants.DCTSIZE * 0],
                    quantTable[quantTableIndex + JpegConstants.DCTSIZE * 0]);
                tmp0 <<= SLOW_INTEGER_CONST_BITS;
                /* Add fudge factor here for final descale. */
                tmp0 += 1 << (SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS - 1);

                int z1 = SLOW_INTEGER_DEQUANTIZE(coef_block[coefBlockIndex + JpegConstants.DCTSIZE * 4],
                    quantTable[quantTableIndex + JpegConstants.DCTSIZE * 4]);
                int tmp1 = z1 * SLOW_INTEGER_FIX(1.306562965);      /* c4[16] = c2[8] */
                int tmp2 = z1 * SLOW_INTEGER_FIX_0_541196100;       /* c12[16] = c6[8] */

                int tmp10 = tmp0 + tmp1;
                int tmp11 = tmp0 - tmp1;
                int tmp12 = tmp0 + tmp2;
                int tmp13 = tmp0 - tmp2;

                z1 = SLOW_INTEGER_DEQUANTIZE(coef_block[coefBlockIndex + JpegConstants.DCTSIZE * 2],
                    quantTable[quantTableIndex + JpegConstants.DCTSIZE * 2]);
                int z2 = SLOW_INTEGER_DEQUANTIZE(coef_block[coefBlockIndex + JpegConstants.DCTSIZE * 6],
                    quantTable[quantTableIndex + JpegConstants.DCTSIZE * 6]);
                int z3 = z1 - z2;
                int z4 = z3 * SLOW_INTEGER_FIX(0.275899379);        /* c14[16] = c7[8] */
                z3 = z3 * SLOW_INTEGER_FIX(1.387039845);        /* c2[16] = c1[8] */

                tmp0 = z3 + z2 * SLOW_INTEGER_FIX_2_562915447;  /* (c6+c2)[16] = (c3+c1)[8] */
                tmp1 = z4 + z1 * SLOW_INTEGER_FIX_0_899976223;  /* (c6-c14)[16] = (c3-c7)[8] */
                tmp2 = z3 - z1 * SLOW_INTEGER_FIX(0.601344887); /* (c2-c10)[16] = (c1-c5)[8] */
                int tmp3 = z4 - z2 * SLOW_INTEGER_FIX(0.509795579); /* (c10-c14)[16] = (c5-c7)[8] */

                int tmp20 = tmp10 + tmp0;
                int tmp27 = tmp10 - tmp0;
                int tmp21 = tmp12 + tmp1;
                int tmp26 = tmp12 - tmp1;
                int tmp22 = tmp13 + tmp2;
                int tmp25 = tmp13 - tmp2;
                int tmp23 = tmp11 + tmp3;
                int tmp24 = tmp11 - tmp3;

                /* Odd part */

                z1 = SLOW_INTEGER_DEQUANTIZE(coef_block[coefBlockIndex + JpegConstants.DCTSIZE * 1],
                    quantTable[quantTableIndex + JpegConstants.DCTSIZE * 1]);
                z2 = SLOW_INTEGER_DEQUANTIZE(coef_block[coefBlockIndex + JpegConstants.DCTSIZE * 3],
                    quantTable[quantTableIndex + JpegConstants.DCTSIZE * 3]);
                z3 = SLOW_INTEGER_DEQUANTIZE(coef_block[coefBlockIndex + JpegConstants.DCTSIZE * 5],
                    quantTable[quantTableIndex + JpegConstants.DCTSIZE * 5]);
                z4 = SLOW_INTEGER_DEQUANTIZE(coef_block[coefBlockIndex + JpegConstants.DCTSIZE * 7],
                    quantTable[quantTableIndex + JpegConstants.DCTSIZE * 7]);

                tmp11 = z1 + z3;

                tmp1 = (z1 + z2) * SLOW_INTEGER_FIX(1.353318001);   /* c3 */
                tmp2 = tmp11 * SLOW_INTEGER_FIX(1.247225013);   /* c5 */
                tmp3 = (z1 + z4) * SLOW_INTEGER_FIX(1.093201867);   /* c7 */
                tmp10 = (z1 - z4) * SLOW_INTEGER_FIX(0.897167586);   /* c9 */
                tmp11 = tmp11 * SLOW_INTEGER_FIX(0.666655658);   /* c11 */
                tmp12 = (z1 - z2) * SLOW_INTEGER_FIX(0.410524528);   /* c13 */
                tmp0 = tmp1 + tmp2 + tmp3 - z1 * SLOW_INTEGER_FIX(2.286341144);        /* c7+c5+c3-c1 */
                tmp13 = tmp10 + tmp11 + tmp12 - z1 * SLOW_INTEGER_FIX(1.835730603);        /* c9+c11+c13-c15 */
                z1 = (z2 + z3) * SLOW_INTEGER_FIX(0.138617169);   /* c15 */
                tmp1 += z1 + z2 * SLOW_INTEGER_FIX(0.071888074);  /* c9+c11-c3-c15 */
                tmp2 += z1 - z3 * SLOW_INTEGER_FIX(1.125726048);  /* c5+c7+c15-c3 */
                z1 = (z3 - z2) * SLOW_INTEGER_FIX(1.407403738);   /* c1 */
                tmp11 += z1 - z3 * SLOW_INTEGER_FIX(0.766367282);  /* c1+c11-c9-c13 */
                tmp12 += z1 + z2 * SLOW_INTEGER_FIX(1.971951411);  /* c1+c5+c13-c7 */
                z2 += z4;
                z1 = z2 * (-SLOW_INTEGER_FIX(0.666655658));      /* -c11 */
                tmp1 += z1;
                tmp3 += z1 + z4 * SLOW_INTEGER_FIX(1.065388962);  /* c3+c11+c15-c7 */
                z2 = z2 * (-SLOW_INTEGER_FIX(1.247225013));      /* -c5 */
                tmp10 += z2 + z4 * SLOW_INTEGER_FIX(3.141271809);  /* c1+c5+c9-c13 */
                tmp12 += z2;
                z2 = (z3 + z4) * (-SLOW_INTEGER_FIX(1.353318001)); /* -c3 */
                tmp2 += z2;
                tmp3 += z2;
                z2 = (z4 - z3) * SLOW_INTEGER_FIX(0.410524528);   /* c13 */
                tmp10 += z2;
                tmp11 += z2;

                /* Final output stage */

                workspace[workspaceIndex + 8 * 0] = JpegUtils.RIGHT_SHIFT(tmp20 + tmp0, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 15] = JpegUtils.RIGHT_SHIFT(tmp20 - tmp0, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 1] = JpegUtils.RIGHT_SHIFT(tmp21 + tmp1, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 14] = JpegUtils.RIGHT_SHIFT(tmp21 - tmp1, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 2] = JpegUtils.RIGHT_SHIFT(tmp22 + tmp2, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 13] = JpegUtils.RIGHT_SHIFT(tmp22 - tmp2, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 3] = JpegUtils.RIGHT_SHIFT(tmp23 + tmp3, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 12] = JpegUtils.RIGHT_SHIFT(tmp23 - tmp3, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 4] = JpegUtils.RIGHT_SHIFT(tmp24 + tmp10, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 11] = JpegUtils.RIGHT_SHIFT(tmp24 - tmp10, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 5] = JpegUtils.RIGHT_SHIFT(tmp25 + tmp11, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 10] = JpegUtils.RIGHT_SHIFT(tmp25 - tmp11, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 6] = JpegUtils.RIGHT_SHIFT(tmp26 + tmp12, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 9] = JpegUtils.RIGHT_SHIFT(tmp26 - tmp12, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 7] = JpegUtils.RIGHT_SHIFT(tmp27 + tmp13, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);
                workspace[workspaceIndex + 8 * 8] = JpegUtils.RIGHT_SHIFT(tmp27 - tmp13, SLOW_INTEGER_CONST_BITS - SLOW_INTEGER_PASS1_BITS);

                /* advance pointers to next column */
                coefBlockIndex++;
                quantTableIndex++;
                workspaceIndex++;
            }

            /* Pass 2: process rows from work array, store into output array.
             * Note that we must descale the results by a factor of 8 == 2**3,
             * and also undo the PASS1_BITS scaling.
             * 8-point IDCT kernel, cK represents sqrt(2) * cos(K*pi/16).
             */
            workspaceIndex = 0;
            byte[] limit = m_cinfo.m_sample_range_limit;
            int limitOffset = m_cinfo.m_sampleRangeLimitOffset - RANGE_SUBSET;

            for (int ctr = 0; ctr < 16; ctr++)
            {
                /* Even part: reverse the even part of the forward DCT.
                 * The rotator is c(-6).
                 */

                /* Add range center and fudge factor for final descale and range-limit. */
                int z2 = workspace[workspaceIndex + 0] + 
                    (RANGE_CENTER << (SLOW_INTEGER_PASS1_BITS + 3)) + 
                    (1 << (SLOW_INTEGER_PASS1_BITS + 2));
                int z3 = workspace[workspaceIndex + 4];

                int tmp0 = (z2 + z3) << SLOW_INTEGER_CONST_BITS;
                int tmp1 = (z2 - z3) << SLOW_INTEGER_CONST_BITS;

                z2 = workspace[workspaceIndex + 2];
                z3 = workspace[workspaceIndex + 6];

                int z1 = (z2 + z3) * SLOW_INTEGER_FIX_0_541196100;       /* c6 */
                int tmp2 = z1 + z2 * SLOW_INTEGER_FIX_0_765366865;     /* c2-c6 */
                int tmp3 = z1 - z3 * SLOW_INTEGER_FIX_1_847759065;     /* c2+c6 */

                int tmp10 = tmp0 + tmp2;
                int tmp13 = tmp0 - tmp2;
                int tmp11 = tmp1 + tmp3;
                int tmp12 = tmp1 - tmp3;

                /* Odd part per figure 8; the matrix is unitary and hence its
                 * transpose is its inverse.  i0..i3 are y7,y5,y3,y1 respectively.
                 */

                tmp0 = workspace[workspaceIndex + 7];
                tmp1 = workspace[workspaceIndex + 5];
                tmp2 = workspace[workspaceIndex + 3];
                tmp3 = workspace[workspaceIndex + 1];

                z2 = tmp0 + tmp2;
                z3 = tmp1 + tmp3;

                z1 = (z2 + z3) * SLOW_INTEGER_FIX_1_175875602;       /*  c3 */
                z2 = z2 * (-SLOW_INTEGER_FIX_1_961570560);          /* -c3-c5 */
                z3 = z3 * (-SLOW_INTEGER_FIX_0_390180644);          /* -c3+c5 */
                z2 += z1;
                z3 += z1;

                z1 = (tmp0 + tmp3) * (-SLOW_INTEGER_FIX_0_899976223); /* -c3+c7 */
                tmp0 = tmp0 * SLOW_INTEGER_FIX_0_298631336;        /* -c1+c3+c5-c7 */
                tmp3 = tmp3 * SLOW_INTEGER_FIX_1_501321110;        /*  c1+c3-c5-c7 */
                tmp0 += z1 + z2;
                tmp3 += z1 + z3;

                z1 = (tmp1 + tmp2) * (-SLOW_INTEGER_FIX_2_562915447); /* -c1-c3 */
                tmp1 = tmp1 * SLOW_INTEGER_FIX_2_053119869;        /*  c1+c3-c5+c7 */
                tmp2 = tmp2 * SLOW_INTEGER_FIX_3_072711026;        /*  c1+c3+c5-c7 */
                tmp1 += z1 + z3;
                tmp2 += z1 + z2;

                /* Final output stage: inputs are tmp10..tmp13, tmp0..tmp3 */
                int currentOutRow = output_row + ctr;

                m_componentBuffer[currentOutRow][output_col + 0] = limit[limitOffset + JpegUtils.RIGHT_SHIFT(
                    tmp10 + tmp3, SLOW_INTEGER_CONST_BITS + SLOW_INTEGER_PASS1_BITS + 3) & RANGE_MASK];
                m_componentBuffer[currentOutRow][output_col + 7] = limit[limitOffset + JpegUtils.RIGHT_SHIFT(
                    tmp10 - tmp3, SLOW_INTEGER_CONST_BITS + SLOW_INTEGER_PASS1_BITS + 3) & RANGE_MASK];
                m_componentBuffer[currentOutRow][output_col + 1] = limit[limitOffset + JpegUtils.RIGHT_SHIFT(
                    tmp11 + tmp2, SLOW_INTEGER_CONST_BITS + SLOW_INTEGER_PASS1_BITS + 3) & RANGE_MASK];
                m_componentBuffer[currentOutRow][output_col + 6] = limit[limitOffset + JpegUtils.RIGHT_SHIFT(
                    tmp11 - tmp2, SLOW_INTEGER_CONST_BITS + SLOW_INTEGER_PASS1_BITS + 3) & RANGE_MASK];
                m_componentBuffer[currentOutRow][output_col + 2] = limit[limitOffset + JpegUtils.RIGHT_SHIFT(
                    tmp12 + tmp1, SLOW_INTEGER_CONST_BITS + SLOW_INTEGER_PASS1_BITS + 3) & RANGE_MASK];
                m_componentBuffer[currentOutRow][output_col + 5] = limit[limitOffset + JpegUtils.RIGHT_SHIFT(
                    tmp12 - tmp1, SLOW_INTEGER_CONST_BITS + SLOW_INTEGER_PASS1_BITS + 3) & RANGE_MASK];
                m_componentBuffer[currentOutRow][output_col + 3] = limit[limitOffset + JpegUtils.RIGHT_SHIFT(
                    tmp13 + tmp0, SLOW_INTEGER_CONST_BITS + SLOW_INTEGER_PASS1_BITS + 3) & RANGE_MASK];
                m_componentBuffer[currentOutRow][output_col + 4] = limit[limitOffset + JpegUtils.RIGHT_SHIFT(
                    tmp13 - tmp0, SLOW_INTEGER_CONST_BITS + SLOW_INTEGER_PASS1_BITS + 3) & RANGE_MASK];

                workspaceIndex += JpegConstants.DCTSIZE;		/* advance pointer to next row */
            }
        }