Began incorporating hqXx filter. Removed old, unused Win32 code.

This commit is contained in:
William Kendrick 2003-12-20 18:03:29 +00:00
parent dba2ecf3b3
commit a6427c94ee
12 changed files with 9247 additions and 335 deletions

122
src/hqxx.c Normal file
View file

@ -0,0 +1,122 @@
/*
hqNx filter look-up table init
Copyright (C) 2003 MaxSt ( maxst@hiend3d.com )
Library-ified by Bill Kendrick <bill@newbreedsoftware.com>
Based on "hq3x_src_c.zip" dated August 5, 2003
from: http://www.hiend3d.com/hq3x.html
December 20, 2003 - December 20, 2003
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser 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
*/
#include "hqxx.h"
const int Ymask = 0x00FF0000;
const int Umask = 0x0000FF00;
const int Vmask = 0x000000FF;
const int trY = 0x00300000;
const int trU = 0x00000700;
const int trV = 0x00000006;
void InitLUTs(int * LUT16to32, int * RGBtoYUV)
{
int i, j, k, r, g, b, Y, u, v;
for (i=0; i<65536; i++)
LUT16to32[i] = ((i & 0xF800) << 8) + ((i & 0x07E0) << 5) + ((i & 0x001F) << 3);
for (i=0; i<32; i++)
for (j=0; j<64; j++)
for (k=0; k<32; k++)
{
r = i << 3;
g = j << 2;
b = k << 3;
Y = (r + g + b) >> 2;
u = 128 + ((r - b) >> 2);
v = 128 + ((-r + 2*g -b)>>3);
RGBtoYUV[ (i << 11) + (j << 5) + k ] = (Y<<16) + (u<<8) + v;
}
}
inline void Interp1(unsigned char * pc, int c1, int c2)
{
*((int*)pc) = (c1*3+c2) >> 2;
}
inline void Interp2(unsigned char * pc, int c1, int c2, int c3)
{
*((int*)pc) = (c1*2+c2+c3) >> 2;
}
inline void Interp3(unsigned char * pc, int c1, int c2)
{
//*((int*)pc) = (c1*7+c2)/8;
*((int*)pc) = ((((c1 & 0x00FF00)*7 + (c2 & 0x00FF00) ) & 0x0007F800) +
(((c1 & 0xFF00FF)*7 + (c2 & 0xFF00FF) ) & 0x07F807F8)) >> 3;
}
inline void Interp4(unsigned char * pc, int c1, int c2, int c3)
{
//*((int*)pc) = (c1*2+(c2+c3)*7)/16;
*((int*)pc) = ((((c1 & 0x00FF00)*2 + ((c2 & 0x00FF00) + (c3 & 0x00FF00))*7 ) & 0x000FF000) +
(((c1 & 0xFF00FF)*2 + ((c2 & 0xFF00FF) + (c3 & 0xFF00FF))*7 ) & 0x0FF00FF0)) >> 4;
}
inline void Interp5(unsigned char * pc, int c1, int c2)
{
*((int*)pc) = (c1+c2) >> 1;
}
inline void Interp6(unsigned char * pc, int c1, int c2, int c3)
{
//*((int*)pc) = (c1*5+c2*2+c3)/8;
*((int*)pc) = ((((c1 & 0x00FF00)*5 + (c2 & 0x00FF00)*2 + (c3 & 0x00FF00) ) & 0x0007F800) +
(((c1 & 0xFF00FF)*5 + (c2 & 0xFF00FF)*2 + (c3 & 0xFF00FF) ) & 0x07F807F8)) >> 3;
}
inline void Interp7(unsigned char * pc, int c1, int c2, int c3)
{
//*((int*)pc) = (c1*6+c2+c3)/8;
*((int*)pc) = ((((c1 & 0x00FF00)*6 + (c2 & 0x00FF00) + (c3 & 0x00FF00) ) & 0x0007F800) +
(((c1 & 0xFF00FF)*6 + (c2 & 0xFF00FF) + (c3 & 0xFF00FF) ) & 0x07F807F8)) >> 3;
}
inline void Interp8(unsigned char * pc, int c1, int c2)
{
//*((int*)pc) = (c1*5+c2*3)/8;
*((int*)pc) = ((((c1 & 0x00FF00)*5 + (c2 & 0x00FF00)*3 ) & 0x0007F800) +
(((c1 & 0xFF00FF)*5 + (c2 & 0xFF00FF)*3 ) & 0x07F807F8)) >> 3;
}
inline int Diff(unsigned int w1, unsigned int w2)
{
YUV1 = w1; /* RGBtoYUV[w1]; */
YUV2 = w2; /* RGBtoYUV[w2]; */
return ( ( abs((YUV1 & Ymask) - (YUV2 & Ymask)) > trY ) ||
( abs((YUV1 & Umask) - (YUV2 & Umask)) > trU ) ||
( abs((YUV1 & Vmask) - (YUV2 & Vmask)) > trV ) );
}