/* libhpojip -- HP OfficeJet image-processing library. */ /* Copyright (C) 1995-2002 HP Company * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * is provided AS IS, WITHOUT ANY WARRANTY; without even the implied * warranty of MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, and * NON-INFRINGEMENT. See the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, * MA 02111-1307, USA. * * In addition, as a special exception, HP Company * gives permission to link the code of this program with any * version of the OpenSSL library which is distributed under a * license identical to that listed in the included LICENSE.OpenSSL * file, and distribute linked combinations including the two. * You must obey the GNU General Public License in all respects * for all of the code used other than OpenSSL. If you modify * this file, you may extend this exception to your version of the * file, but you are not obligated to do so. If you do not wish to * do so, delete this exception statement from your version. */ /* Original author: Mark Overton and others. * * Ported to Linux by David Paschal. */ /*____________________________________________________________________________ | | | | xjpg_dct.c | Computes forward and inverse DCT for JPEG | |____________|_______________________________________________________________| | | | Mark Overton, May 1997 | |____________________________________________________________________________| */ #include "xjpg_dct.h" /*____________________________________________________________________________ | | | | SUB_AND_ADD | replaces a with a-b, and b with a+b using no temp registers | |_____________|______________________________________________________________| */ #define SUB_AND_ADD(a,b) { \ b += a; \ a += a; \ a -= b; \ } /*____________________________________________________________________________ | | | | MUL_ROUND | computes x = round(x*c), using no temp registers | |___________|________________________________________________________________| | | | c is assumed to have CONST_FRAC_BITS bits of fraction. | |____________________________________________________________________________| */ #if (defined _WINDOWS) && !(defined _WIN32) /* We are compiling for 16-bit Windows 3.1 */ #define MUL_ROUND(c,x) { \ long product; \ product = (long)(x) * ((long)(c) << (16-CONST_FRAC_BITS)); \ x = (product+0x8000L) >> 16; \ } #else #define MUL_ROUND(c,x) { \ x = (short)(x) * (short)(c); \ x = ((x)+(1l<<(CONST_FRAC_BITS-1))) >> CONST_FRAC_BITS; \ } #endif /*____________________________________________________________________________ | | | | dct_forward | computes DCT for JPEG | |_____________|______________________________________________________________| | | | This is the DCT algorithm based on the small FFT Winograd transform | | from Trans. IEICE, vol. E 71(11), 1095-1097, Nov. 1988 | | | | Input: 'block' is 64 level-shifted pixels (-128..127 each). | | | | Output: 'block' is the DCT (64 words). | | These values need to be scaled by the forward correction matrix | | for the Winograd DCT. | |____________________________________________________________________________| */ void dct_forward (register int *block_p) { #define CONST_FRAC_BITS 14 /* bits of frac in CONST_1-CONST_5 below */ #define CONST_1 (23170/2) /* 15 bits of frac shifted down to 14 */ #define CONST_2 (17734/2) #define CONST_3 (23170/2) #define CONST_4 (42813/2) /* this one wouldn't fit with 15 bits of frac */ #define CONST_5 (12540/2) int *data_p; int d0, d1, d2, d3, d4, d5, d6, d7; /******************/ /* Transform Rows */ /******************/ for (data_p=block_p; data_p