Use more portable hqx code from googlecode hqx

Conflicts:
	src/CMakeLists.txt
This commit is contained in:
galtgendo 2014-03-02 11:32:45 +01:00
parent 4a23b97963
commit 4909aa750f
12 changed files with 13347 additions and 14998 deletions

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,145 +0,0 @@
//CImage class - loading and saving BMP and TGA files
//----------------------------------------------------------
//Copyright (C) 2003 MaxSt ( maxst@hiend3d.com )
//
//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
//#ifdef WIN32
//#define DLL __declspec(dllexport)
//#else
#define DLL
//#endif
#include <stdio.h>
#pragma once
#pragma warning(disable: 4103)
#pragma pack(1)
typedef struct { unsigned char b, g, r; } _BGR;
typedef struct { unsigned char b, g, r, a; } _BGRA;
class CImage
{
public:
DLL CImage();
DLL ~CImage();
enum CImageErrors
{
eConvUnknownFormat = 10,
eConvSourceMemory = 11,
eConvDestMemory = 12,
eSaveBmpFileOpen = 20,
eSaveBmpFileWrite = 21,
eSaveBmpSourceMemory = 22,
eSaveBmpColorDepth = 23,
eLoadBmpFileOpen = 30,
eLoadBmpFileRead = 31,
eLoadBmpBadFormat = 32,
eLoadBmpInit = 33,
eLoadBmpColorDepth = 34,
eSaveTgaFileOpen = 40,
eSaveTgaFileWrite = 41,
eSaveTgaSourceMemory = 42,
eSaveTgaColorDepth = 43,
eLoadTgaFileOpen = 50,
eLoadTgaFileRead = 51,
eLoadTgaBadFormat = 52,
eLoadTgaInit = 53,
eLoadTgaColorDepth = 54,
eLoadFilename = 60,
eSaveFilename = 61,
};
struct _BMPFILEHEADER
{
unsigned short bfType;
long int bfSize, bfRes1, bfOffBits;
};
struct _BMPIMAGEHEADEROLD
{
long int biSize;
unsigned short biWidth, biHeight;
unsigned short biPlanes, biBitCount;
};
struct _BMPIMAGEHEADER
{
long int biSize, biWidth, biHeight;
unsigned short biPlanes, biBitCount;
long int biCompression, biSizeImage;
long int biXPelsPerMeter, biYPelsPerMeter;
long int biClrUsed, biClrImportant;
};
struct _TGAHEADER
{
unsigned char tiIdentSize;
unsigned char tiPaletteIncluded;
unsigned char tiImageType;
unsigned short tiPaletteStart;
unsigned short tiPaletteSize;
unsigned char tiPaletteBpp;
unsigned short tiX0;
unsigned short tiY0;
unsigned short tiXres;
unsigned short tiYres;
unsigned char tiBitPerPixel;
unsigned char tiAttrBits;
};
public:
int DLL Init( int Xres, int Yres, unsigned short BitPerPixel );
int DLL SetImage(unsigned char *img, int width, int height, int bpp);
int DLL Destroy();
int DLL ConvertTo32( void );
int DLL ConvertTo24( void );
int DLL ConvertTo16( void );
int DLL Convert8To17( int transindex );
int DLL Convert32To17( void );
int SaveBmp(char *szFilename);
int LoadBmp(char *szFilename);
int SaveTga(char *szFilename, bool bCompressed );
int LoadTga(char *szFilename);
int DLL Load(char *szFilename);
int DLL Save(char *szFilename);
private:
void Output( char * pcData, int nSize );
void Output( char c );
void Output( void );
unsigned char Input( void );
public:
int m_Xres, m_Yres;
unsigned short m_BitPerPixel;
unsigned short m_BytePerPixel;
unsigned char * m_pBitmap;
_BGR m_Pal[256];
private:
int m_NumPixel;
FILE * f;
int m_nCount;
char m_cBuf[32768];
};
#pragma pack(8)

141
src/gl/hqnx/common.h Normal file
View file

@ -0,0 +1,141 @@
/*
* Copyright (C) 2003 Maxim Stepin ( maxst@hiend3d.com )
*
* Copyright (C) 2010 Cameron Zemek ( grom@zeminvaders.net)
* Copyright (C) 2011 Francois Gannaz <mytskine@gmail.com>
*
* 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
*/
#ifndef __HQX_COMMON_H_
#define __HQX_COMMON_H_
#include <stdlib.h>
#include <stdint.h>
#define MASK_2 0x0000FF00
#define MASK_13 0x00FF00FF
#define MASK_RGB 0x00FFFFFF
#define MASK_ALPHA 0xFF000000
#define Ymask 0x00FF0000
#define Umask 0x0000FF00
#define Vmask 0x000000FF
#define trY 0x00300000
#define trU 0x00000700
#define trV 0x00000006
/* RGB to YUV lookup table */
extern uint32_t RGBtoYUV[16777216];
static inline uint32_t rgb_to_yuv(uint32_t c)
{
// Mask against MASK_RGB to discard the alpha channel
return RGBtoYUV[MASK_RGB & c];
}
/* Test if there is difference in color */
static inline int yuv_diff(uint32_t yuv1, uint32_t yuv2) {
return (( abs((yuv1 & Ymask) - (yuv2 & Ymask)) > trY ) ||
( abs((yuv1 & Umask) - (yuv2 & Umask)) > trU ) ||
( abs((yuv1 & Vmask) - (yuv2 & Vmask)) > trV ) );
}
static inline int Diff(uint32_t c1, uint32_t c2)
{
return yuv_diff(rgb_to_yuv(c1), rgb_to_yuv(c2));
}
/* Interpolate functions */
static inline uint32_t Interpolate_2(uint32_t c1, int w1, uint32_t c2, int w2, int s)
{
if (c1 == c2) {
return c1;
}
return
(((((c1 & MASK_ALPHA) >> 24) * w1 + ((c2 & MASK_ALPHA) >> 24) * w2) << (24-s)) & MASK_ALPHA) +
((((c1 & MASK_2) * w1 + (c2 & MASK_2) * w2) >> s) & MASK_2) +
((((c1 & MASK_13) * w1 + (c2 & MASK_13) * w2) >> s) & MASK_13);
}
static inline uint32_t Interpolate_3(uint32_t c1, int w1, uint32_t c2, int w2, uint32_t c3, int w3, int s)
{
return
(((((c1 & MASK_ALPHA) >> 24) * w1 + ((c2 & MASK_ALPHA) >> 24) * w2 + ((c3 & MASK_ALPHA) >> 24) * w3) << (24-s)) & MASK_ALPHA) +
((((c1 & MASK_2) * w1 + (c2 & MASK_2) * w2 + (c3 & MASK_2) * w3) >> s) & MASK_2) +
((((c1 & MASK_13) * w1 + (c2 & MASK_13) * w2 + (c3 & MASK_13) * w3) >> s) & MASK_13);
}
static inline uint32_t Interp1(uint32_t c1, uint32_t c2)
{
//(c1*3+c2) >> 2;
return Interpolate_2(c1, 3, c2, 1, 2);
}
static inline uint32_t Interp2(uint32_t c1, uint32_t c2, uint32_t c3)
{
//(c1*2+c2+c3) >> 2;
return Interpolate_3(c1, 2, c2, 1, c3, 1, 2);
}
static inline uint32_t Interp3(uint32_t c1, uint32_t c2)
{
//(c1*7+c2)/8;
return Interpolate_2(c1, 7, c2, 1, 3);
}
static inline uint32_t Interp4(uint32_t c1, uint32_t c2, uint32_t c3)
{
//(c1*2+(c2+c3)*7)/16;
return Interpolate_3(c1, 2, c2, 7, c3, 7, 4);
}
static inline uint32_t Interp5(uint32_t c1, uint32_t c2)
{
//(c1+c2) >> 1;
return Interpolate_2(c1, 1, c2, 1, 1);
}
static inline uint32_t Interp6(uint32_t c1, uint32_t c2, uint32_t c3)
{
//(c1*5+c2*2+c3)/8;
return Interpolate_3(c1, 5, c2, 2, c3, 1, 3);
}
static inline uint32_t Interp7(uint32_t c1, uint32_t c2, uint32_t c3)
{
//(c1*6+c2+c3)/8;
return Interpolate_3(c1, 6, c2, 1, c3, 1, 3);
}
static inline uint32_t Interp8(uint32_t c1, uint32_t c2)
{
//(c1*5+c2*3)/8;
return Interpolate_2(c1, 5, c2, 3, 3);
}
static inline uint32_t Interp9(uint32_t c1, uint32_t c2, uint32_t c3)
{
//(c1*2+(c2+c3)*3)/8;
return Interpolate_3(c1, 2, c2, 3, c3, 3, 3);
}
static inline uint32_t Interp10(uint32_t c1, uint32_t c2, uint32_t c3)
{
//(c1*14+c2+c3)/16;
return Interpolate_3(c1, 14, c2, 1, c3, 1, 4);
}
#endif

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

File diff suppressed because it is too large Load diff

View file

@ -1,35 +0,0 @@
//hqnx filter library
//----------------------------------------------------------
//Copyright (C) 2003 MaxSt ( maxst@hiend3d.com )
//Copyright (C) 2009 Benjamin Berkels
//
//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
#ifndef __HQNX_H__
#define __HQNX_H__
#pragma warning(disable:4799)
#include "Image.h"
void DLL hq2x_32( int * pIn, unsigned char * pOut, int Xres, int Yres, int BpL );
void DLL hq3x_32( int * pIn, unsigned char * pOut, int Xres, int Yres, int BpL );
void DLL hq4x_32( int * pIn, unsigned char * pOut, int Xres, int Yres, int BpL );
int DLL hq4x_32 ( CImage &ImageIn, CImage &ImageOut );
void DLL InitLUTs();
#endif //__HQNX_H__

55
src/gl/hqnx/hqx.h Normal file
View file

@ -0,0 +1,55 @@
/*
* Copyright (C) 2003 Maxim Stepin ( maxst@hiend3d.com )
*
* Copyright (C) 2010 Cameron Zemek ( grom@zeminvaders.net)
*
* 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
*/
#ifndef __HQX_H_
#define __HQX_H_
#include <stdint.h>
#if defined( __GNUC__ )
#ifdef __MINGW32__
#define HQX_CALLCONV __stdcall
#else
#define HQX_CALLCONV
#endif
#else
#define HQX_CALLCONV
#endif
#if defined(_WIN32)
#ifdef DLL_EXPORT
#define HQX_API __declspec(dllexport)
#else
#define HQX_API __declspec(dllimport)
#endif
#else
#define HQX_API
#endif
HQX_API void HQX_CALLCONV hqxInit(void);
HQX_API void HQX_CALLCONV hq2x_32( uint32_t * src, uint32_t * dest, int width, int height );
HQX_API void HQX_CALLCONV hq3x_32( uint32_t * src, uint32_t * dest, int width, int height );
HQX_API void HQX_CALLCONV hq4x_32( uint32_t * src, uint32_t * dest, int width, int height );
HQX_API void HQX_CALLCONV hq2x_32_rb( uint32_t * src, uint32_t src_rowBytes, uint32_t * dest, uint32_t dest_rowBytes, int width, int height );
HQX_API void HQX_CALLCONV hq3x_32_rb( uint32_t * src, uint32_t src_rowBytes, uint32_t * dest, uint32_t dest_rowBytes, int width, int height );
HQX_API void HQX_CALLCONV hq4x_32_rb( uint32_t * src, uint32_t src_rowBytes, uint32_t * dest, uint32_t dest_rowBytes, int width, int height );
#endif

38
src/gl/hqnx/init.cpp Normal file
View file

@ -0,0 +1,38 @@
/*
* Copyright (C) 2010 Cameron Zemek ( grom@zeminvaders.net)
*
* 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 <stdint.h>
#include "hqx.h"
uint32_t RGBtoYUV[16777216];
uint32_t YUV1, YUV2;
HQX_API void HQX_CALLCONV hqxInit(void)
{
/* Initalize RGB to YUV lookup table */
uint32_t c, r, g, b, y, u, v;
for (c = 0; c < 16777215; c++) {
r = (c & 0xFF0000) >> 16;
g = (c & 0x00FF00) >> 8;
b = c & 0x0000FF;
y = (uint32_t)(0.299*r + 0.587*g + 0.114*b);
u = (uint32_t)(-0.169*r - 0.331*g + 0.5*b) + 128;
v = (uint32_t)(0.5*r - 0.419*g - 0.081*b) + 128;
RGBtoYUV[c] = (y << 16) + (u << 8) + v;
}
}

View file

@ -59,21 +59,6 @@ CUSTOM_CVAR (Float, vid_contrast, 1.f, CVAR_ARCHIVE|CVAR_GLOBALCONFIG)
// when they are actually valid.
void gl_SetupMenu()
{
#ifndef _MSC_VER
FOptionValues **opt = OptionValues.CheckKey("HqResizeModes");
if (opt != NULL)
{
for(int i = (*opt)->mValues.Size()-1; i>=0; i--)
{
// Delete HQnX resize modes for non MSVC targets
if ((*opt)->mValues[i].Value >= 4.0)
{
(*opt)->mValues.Delete(i);
}
}
}
#endif
if (gl.shadermodel < 4)
{
// Radial fog and Doom lighting are not available in SM < 4 cards

View file

@ -39,18 +39,11 @@
#include "gl/renderer/gl_renderer.h"
#include "gl/textures/gl_texture.h"
#include "c_cvars.h"
// [BB] hqnx scaling is only supported with the MS compiler.
#if (defined _MSC_VER) && (!defined _WIN64)
#include "gl/hqnx/hqnx.h"
#endif
#include "gl/hqnx/hqx.h"
CUSTOM_CVAR(Int, gl_texture_hqresize, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL)
{
#ifdef _MSC_VER
if (self < 0 || self > 6)
#else
if (self < 0 || self > 3)
#endif
self = 0;
GLRenderer->FlushTextures();
}
@ -186,9 +179,7 @@ static unsigned char *scaleNxHelper( void (*scaleNxFunction) ( uint32* , uint32*
return newBuffer;
}
// [BB] hqnx scaling is only supported with the MS compiler.
#if (defined _MSC_VER) && (!defined _WIN64)
static unsigned char *hqNxHelper( void (*hqNxFunction) ( int*, unsigned char*, int, int, int ),
static unsigned char *hqNxHelper( void (*hqNxFunction) ( unsigned*, unsigned*, int, int ),
const int N,
unsigned char *inputBuffer,
const int inWidth,
@ -200,22 +191,17 @@ static unsigned char *hqNxHelper( void (*hqNxFunction) ( int*, unsigned char*, i
if (!initdone)
{
InitLUTs();
hqxInit();
initdone = true;
}
outWidth = N * inWidth;
outHeight = N *inHeight;
CImage cImageIn;
cImageIn.SetImage(inputBuffer, inWidth, inHeight, 32);
cImageIn.Convert32To17();
unsigned char * newBuffer = new unsigned char[outWidth*outHeight*4];
hqNxFunction( reinterpret_cast<int*>(cImageIn.m_pBitmap), newBuffer, cImageIn.m_Xres, cImageIn.m_Yres, outWidth*4 );
hqNxFunction( reinterpret_cast<unsigned*>(inputBuffer), reinterpret_cast<unsigned*>(newBuffer), inWidth, inHeight );
delete[] inputBuffer;
return newBuffer;
}
#endif
//===========================================================================
//
@ -263,11 +249,13 @@ unsigned char *gl_CreateUpsampledTextureBuffer ( const FTexture *inputTexture, u
outWidth = inWidth;
outHeight = inHeight;
int type = gl_texture_hqresize;
#if 0
// hqNx does not preserve the alpha channel so fall back to ScaleNx for such textures
if (hasAlpha && type > 3)
{
type -= 3;
}
#endif
switch (type)
{
@ -277,15 +265,12 @@ unsigned char *gl_CreateUpsampledTextureBuffer ( const FTexture *inputTexture, u
return scaleNxHelper( &scale3x, 3, inputBuffer, inWidth, inHeight, outWidth, outHeight );
case 3:
return scaleNxHelper( &scale4x, 4, inputBuffer, inWidth, inHeight, outWidth, outHeight );
// [BB] hqnx scaling is only supported with the MS compiler.
#if (defined _MSC_VER) && (!defined _WIN64)
case 4:
return hqNxHelper( &hq2x_32, 2, inputBuffer, inWidth, inHeight, outWidth, outHeight );
case 5:
return hqNxHelper( &hq3x_32, 3, inputBuffer, inWidth, inHeight, outWidth, outHeight );
case 6:
return hqNxHelper( &hq4x_32, 4, inputBuffer, inWidth, inHeight, outWidth, outHeight );
#endif
}
}
return inputBuffer;