/* * Copyright (c) 1999-2000 University of California, Riverside. * Permission to copy is granted provided that this header remains * intact. This software is provided with no warranties. * * Version : 1.0 */ /*--------------------------------------------------------------------------*/ static const short code COS_TABLE[8][8] = { { 32768, 32138, 30273, 27245, 23170, 18204, 12539, 6392 }, { 32768, 27245, 12539, -6392, -23170, -32138, -30273, -18204 }, { 32768, 18204, -12539, -32138, -23170, 6392, 30273, 27245 }, { 32768, 6392, -30273, -18204, 23170, 27245, -12539, -32138 }, { 32768, -6392, -30273, 18204, 23170, -27245, -12539, 32138 }, { 32768, -18204, -12539, 32138, -23170, -6392, 30273, -27245 }, { 32768, -27245, 12539, 6392, -23170, 32138, -30273, 18204 }, { 32768, -32138, 30273, -27245, 23170, -18204, 12539, -6392 } }; /*--------------------------------------------------------------------------*/ static const short ONE_OVER_SQRT_TWO = 23170; /*--------------------------------------------------------------------------*/ static short xdata inBuffer[8][8]; static short xdata outBuffer[8][8]; static int idx; /*--------------------------------------------------------------------------*/ static float Y(int a, int b) { return COS_TABLE[a][b] / 32768.0; } /*--------------------------------------------------------------------------*/ static float C(int h) { return h ? 1.0 : ONE_OVER_SQRT_TWO / 32768.0; } /*--------------------------------------------------------------------------*/ static int F(int u, int v, short img[8][8]) { float s[8], r = 0; unsigned short x; for(x=0; x<8; x++) { s[x] = img[x][0] * Y(0, v) + img[x][1] * Y(1, v) + img[x][2] * Y(2, v) + img[x][3] * Y(3, v) + img[x][4] * Y(4, v) + img[x][5] * Y(5, v) + img[x][6] * Y(6, v) + img[x][7] * Y(7, v); } for(x=0; x<8; x++) { r += s[x] * Y(x, u); } return (short)(r * .25 * C(u) * C(v)); } /*--------------------------------------------------------------------------*/ void CodecInitialize(void) { idx = 0; } /*--------------------------------------------------------------------------*/ void CodecPushPixel(short p) { if( idx == 64 ) { idx = 0; } inBuffer[idx / 8][idx % 8] = p; idx++; } /*--------------------------------------------------------------------------*/ short CodecPopPixel(void) { short p; if( idx == 64 ) { idx = 0; } p = outBuffer[idx / 8][idx % 8]; idx++; return p; } /*--------------------------------------------------------------------------*/ void CodecDoFdct(void) { unsigned short x, y; for(x=0; x<8; x++) { for(y=0; y<8; y++) { outBuffer[x][y] = F(x, y, inBuffer); } } idx = 0; }