📄 jidct_bin_a1.c
字号:
/* * jidct_bin_a1.c * * binDCT from Chen-Wang's algorithm: * Version C7 in the paper: 9 Shifts, 28 Adds. Coding gain: 8.7686dB. * Use floor operation for all right-shifting. * * * Reference: * J. Liang, T. D. Tran, Fast Multiplierless Approximations of the DCT with the Lifting * Scheme, IEEE Trans. Signal Processing, Vol. 49, No. 12, pp. 3032-3044, Dec. 2001. * * Trac D. Tran and Jie Liang * ECE Department, The Johns Hopkins University * 3400 North Charles Street, 105 Barton Hall, * Baltimore, MD 21218 * E-mail: trac@jhu.edu, jieliang@jhu.edu * Dec. 2000 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - * Copyright (c) 2000 Trac D Tran and Jie Liang * This program is Copyright (c) by Trac D Tran and Jie Liang. * It may not be redistributed without the consent of the copyright * holders. In no circumstances may the copyright notice be removed. * The program may not be sold for profit nor may they be incorporated * in commercial programs without the written permission of the copyright * holders. This program is provided as is, without any express or * implied warranty, without even the warranty of fitness for a * particular purpose. *----------------------------------------------------------------------- * * Copyright (C) 1994-1996, Thomas G. Lane. * This file is modified from the DCT routine in the Independent JPEG Group (IJG)'s software. * For conditions of distribution and use, see the README file in IJG's package. * *//* ************************************************ * * $Log: jidct_bin_a1.c,v $ * Revision 1.2 2000/07/23 15:38:02 jliang * *** empty log message *** * * Revision 1.1 2000/06/26 01:06:44 jliang * Initial revision * * * ************************************************ *//************************************************************************* Modification History:* Date Programmer Description* -------- ---------- --------------------------------------------*************************************************************************/#define JPEG_INTERNALS#include "jinclude.h"#include "jpeglib.h"#include "jdct.h" /* Private declarations for DCT subsystem */#ifdef DCT_BIN_A1_SUPPORTED/* * This module is specialized to the case DCTSIZE = 8. */#if DCTSIZE != 8 Sorry, this code only copes with 8x8 DCTs. /* deliberate syntax err */#endif//Jie 07/07/00: lossless binDCT flag, defined in djpeg.extern boolean lossless_codec;/* Multiply an INT32 variable by an INT32 constant to yield an INT32 result. * For 8-bit samples with the recommended scaling, all the variable * and constant values involved are no more than 16 bits wide, so a * 16x16->32 bit multiply can be used instead of a full 32x32 multiply. * For 12-bit samples, a full 32-bit multiplication will be needed. */#if BITS_IN_JSAMPLE == 8#define MULTIPLY(var,const) MULTIPLY16C16(var,const)#else#define MULTIPLY(var,const) ((var) * (const))#endif/* Dequantize a coefficient by multiplying it by the multiplier-table * entry; produce an int result. In this module, both inputs and result * are 16 bits or less, so either int or short multiply will work. */#define DEQUANTIZE(coef,quantval) (((ISLOW_MULT_TYPE) (coef)) * (quantval))/* * Perform dequantization and inverse DCT on one block of coefficients. */GLOBAL(void)jpeg_idct_bin_a1 (j_decompress_ptr cinfo, jpeg_component_info * compptr, JCOEFPTR coef_block, JSAMPARRAY output_buf, JDIMENSION output_col){ INT32 tmp0, tmp1, tmp2, tmp3,tmp4,tmp5,tmp6,tmp7; INT32 tmp10, tmp11, tmp12, tmp13; /* INT32 z0,z1, z2, z3, z4,z10,z11,z12,z13;*/ JCOEFPTR inptr; ISLOW_MULT_TYPE * quantptr; int * wsptr; JSAMPROW outptr; JSAMPLE *range_limit = IDCT_range_limit(cinfo); int ctr; int workspace[DCTSIZE2]; /* buffers data between passes */ int dcval; SHIFT_TEMPS//Case 1: lossless binDCT not required. All scaling caused by butterfly//are performed at the last stage.if (!lossless_codec){ /* Pass 1: process columns from input, store into work array. */ /* Note results are scaled up by sqrt(8) compared to a true IDCT; */ /* furthermore, we scale the results by 2**PASS1_BITS. */ inptr = coef_block; quantptr = (ISLOW_MULT_TYPE *) compptr->dct_table; wsptr = workspace; for (ctr = DCTSIZE; ctr > 0; ctr--) { /* Due to quantization, we will usually find that many of the input * coefficients are zero, especially the AC terms. We can exploit this * by short-circuiting the IDCT calculation for any column in which all * the AC terms are zero. In that case each output is equal to the * DC coefficient (with scale factor as needed). * With typical images and quantization tables, half or more of the * column DCT calculations can be simplified this way. */ if (inptr[DCTSIZE*1] == 0 && inptr[DCTSIZE*2] == 0 && inptr[DCTSIZE*3] == 0 && inptr[DCTSIZE*4] == 0 && inptr[DCTSIZE*5] == 0 && inptr[DCTSIZE*6] == 0 && inptr[DCTSIZE*7] == 0) { dcval = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]) >> 1; wsptr[DCTSIZE*0] = dcval; wsptr[DCTSIZE*1] = dcval; wsptr[DCTSIZE*2] = dcval; wsptr[DCTSIZE*3] = dcval; wsptr[DCTSIZE*4] = dcval; wsptr[DCTSIZE*5] = dcval; wsptr[DCTSIZE*6] = dcval; wsptr[DCTSIZE*7] = dcval; inptr++; quantptr++; wsptr++; continue; } tmp0 = DEQUANTIZE(inptr[DCTSIZE*0], quantptr[DCTSIZE*0]); tmp1 = DEQUANTIZE(inptr[DCTSIZE*4], quantptr[DCTSIZE*4]); tmp2 = DEQUANTIZE(inptr[DCTSIZE*6], quantptr[DCTSIZE*6]); tmp3 = DEQUANTIZE(inptr[DCTSIZE*2], quantptr[DCTSIZE*2]); tmp4 = DEQUANTIZE(inptr[DCTSIZE*7], quantptr[DCTSIZE*7]); tmp5 = DEQUANTIZE(inptr[DCTSIZE*5], quantptr[DCTSIZE*5]); tmp6 = DEQUANTIZE(inptr[DCTSIZE*3], quantptr[DCTSIZE*3]); tmp7 = DEQUANTIZE(inptr[DCTSIZE*1], quantptr[DCTSIZE*1]); /* fprintf(stderr, "%10d", tmp0); fprintf(stderr, "%10d", tmp7); fprintf(stderr, "%10d", tmp3); fprintf(stderr, "%10d", tmp6); fprintf(stderr, "%10d", tmp1); fprintf(stderr, "%10d", tmp5); fprintf(stderr, "%10d", tmp2); fprintf(stderr, "%10d", tmp4); fprintf(stderr, "\n"); */ /* X[0] and X[4] */ tmp11 = ((tmp0 ) >> 1) - tmp1; tmp10 = tmp0 - tmp11; /* X[6] and X[2]: 1/2, 1/2 */ tmp13 = tmp3 + ((tmp2 ) >> 1); tmp12 = ((tmp13 ) >> 1) - tmp2; tmp0 = tmp10 + tmp13; tmp3 = tmp10 - tmp13; tmp1 = tmp11 + tmp12; tmp2 = tmp11 - tmp12; /* X[7] and X[1]: */ /* 7pi/16 = 1/4d 1/4u */ tmp13 = tmp7 + ((tmp4 ) >> 2 ); tmp10 = ( ( tmp13 ) >> 2 ) - tmp4; /* X[5] and X[3] */ /* new 1/2 and -1*/ tmp12 = tmp6 + ((tmp5 ) >> 1); tmp11 = tmp5 - tmp12; /* Butterfly */ tmp4 = tmp10 + tmp11; tmp5 = tmp10 - tmp11; tmp6 = tmp13 - tmp12; tmp7 = tmp13 + tmp12; /* pi/4 = -1/2u -3/4d 1/2u */ tmp5 = (( tmp6 ) >> 1) - tmp5; tmp6 = tmp6 - tmp5 + ((tmp5 ) >> 2); tmp5 = tmp5 + ((tmp6 ) >> 1); /* last stage: butterfly */ wsptr[DCTSIZE*0] = (tmp0 + tmp7); wsptr[DCTSIZE*7] = (tmp0 - tmp7); wsptr[DCTSIZE*1] = (tmp1 + tmp6); wsptr[DCTSIZE*6] = (tmp1 - tmp6); wsptr[DCTSIZE*2] = (tmp2 + tmp5); wsptr[DCTSIZE*5] = (tmp2 - tmp5); wsptr[DCTSIZE*3] = (tmp3 + tmp4); wsptr[DCTSIZE*4] = (tmp3 - tmp4); inptr++; /* advance pointers to next column */ quantptr++; wsptr++; } /* 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. */ //fprintf(stderr, "\nAfter inverse DCT:\n"); wsptr = workspace; for (ctr = 0; ctr < DCTSIZE; ctr++) { outptr = output_buf[ctr] + output_col; /* Rows of zeroes can be exploited in the same way as we did with columns. * However, the column calculation has created many nonzero AC terms, so * the simplification applies less often (typically 5% to 10% of the time). * On machines with very fast multiplication, it's possible that the * test takes more time than it's worth. In that case this section * may be commented out. */ #ifndef NO_ZERO_ROW_TEST if (wsptr[1] == 0 && wsptr[2] == 0 && wsptr[3] == 0 && wsptr[4] == 0 && wsptr[5] == 0 && wsptr[6] == 0 && wsptr[7] == 0) { /* if all AC are 0, the IDCT will all equal to 1/2 DC, so downscale by 2, After that, apply the downscale of 16 caused by butterflies, so total downscale = 32.*/ JSAMPLE dcval = range_limit[(int) DESCALE((INT32) wsptr[0], 5) & RANGE_MASK]; outptr[0] = dcval; outptr[1] = dcval; outptr[2] = dcval; outptr[3] = dcval; outptr[4] = dcval; outptr[5] = dcval; outptr[6] = dcval; outptr[7] = dcval; wsptr += DCTSIZE; continue; }#endif /* Even part: reverse the even part of the forward DCT. */ /* The rotator is sqrt(2)*c(-6). */ /* Even part *//**********************//* not necessary ??? *//************************//******** tmp0 = (INT32) wsptr[0]; tmp1 = (INT32) wsptr[4]; tmp2 = (INT32) wsptr[6]; tmp3 = (INT32) wsptr[2]; tmp4 = (INT32) wsptr[7]; tmp5 = (INT32) wsptr[5]; tmp6 = (INT32) wsptr[3]; tmp7 = (INT32) wsptr[1];*********/ /* X[0] and X[4] */ tmp11 = ((wsptr[0] ) >> 1) - wsptr[4]; tmp10 = wsptr[0] - tmp11; /* X[6] and X[2]: 1/2, 1/2 */ tmp13 = wsptr[2] + ((wsptr[6] ) >> 1); tmp12 = ((tmp13 ) >> 1) - wsptr[6]; tmp0 = tmp10 + tmp13; tmp3 = tmp10 - tmp13; tmp1 = tmp11 + tmp12; tmp2 = tmp11 - tmp12; /* 7pi/16 = -1/4d 1/4u */ tmp13 = wsptr[1] + ( ( wsptr[7] ) >> 2 ); tmp10 = ( (tmp13 ) >> 2 ) - wsptr[7]; /* 3pi/16 = */ /* new 1 and -1/2*/ tmp12 = wsptr[3] + ((wsptr[5] ) >> 1); tmp11 = wsptr[5] - tmp12; tmp4 = tmp10 + tmp11; tmp5 = tmp10 - tmp11; tmp6 = tmp13 - tmp12; tmp7 = tmp13 + tmp12; /* pi/4 = -1/2u -3/4d 1/2u */ tmp5 = (( tmp6 ) >> 1) - tmp5; tmp6 = tmp6 - tmp5 + ((tmp5 ) >> 2); tmp5 = tmp5 + ((tmp6 ) >> 1); /* last stage: butterfly */ /* Final output stage: scale down by a factor of 8 and range-limit */ tmp10=(tmp0 + tmp7); tmp11=(tmp0 - tmp7); outptr[0] = range_limit[(int)DESCALE(tmp10, 4 ) & RANGE_MASK]; outptr[7] = range_limit[(int)DESCALE(tmp11, 4 ) & RANGE_MASK]; //outptr[0] = (char)DESCALE(tmp10, 4); //outptr[7] = (char)DESCALE(tmp11,4); if (tmp10 > 4096 || tmp10 < -4096 || tmp11 > 4096 || tmp11 < -4096) { fprintf(stderr,"Possible IDCT overflow!\n"); } tmp10=(tmp1 + tmp6);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -