mirror of
https://github.com/blawar/GLideN64.git
synced 2024-07-07 03:13:49 +00:00
Remove FXT1 code.
This commit is contained in:
parent
5a7872f898
commit
d20b228284
|
@ -34,7 +34,7 @@
|
|||
#define CHDIR(a) SetCurrentDirectoryW(a)
|
||||
#else
|
||||
#include <iostream>
|
||||
#include <dlfcn.h>
|
||||
#include <dlfcn.h>
|
||||
#define MAX_PATH 4095
|
||||
#define TXHMODULE void*
|
||||
#define DLOPEN(a) dlopen(a, RTLD_LAZY|RTLD_GLOBAL)
|
||||
|
@ -80,7 +80,6 @@ typedef unsigned char boolean;
|
|||
|
||||
#define COMPRESSION_MASK 0x0000f000
|
||||
#define NO_COMPRESSION 0x00000000
|
||||
#define FXT1_COMPRESSION 0x00001000
|
||||
#define NCC_COMPRESSION 0x00002000
|
||||
#define S3TC_COMPRESSION 0x00003000
|
||||
|
||||
|
@ -116,9 +115,6 @@ typedef unsigned char boolean;
|
|||
#define GR_TEXFMT_ARGB_4444 0xc
|
||||
#define GR_TEXFMT_ALPHA_INTENSITY_88 0xd
|
||||
|
||||
/* from 3Dfx Interactive Inc. g3ext.h */
|
||||
#define GR_TEXFMT_ARGB_CMP_FXT1 0x11
|
||||
|
||||
#define GR_TEXFMT_ARGB_8888 0x12
|
||||
|
||||
#define GR_TEXFMT_ARGB_CMP_DXT1 0x16
|
||||
|
@ -163,47 +159,47 @@ typedef void (*dispInfoFuncExt)(const wchar_t *format, ...);
|
|||
|
||||
#ifndef TXFILTER_DLL
|
||||
boolean ext_ghq_init(int maxwidth, /* maximum texture width supported by hardware */
|
||||
int maxheight,/* maximum texture height supported by hardware */
|
||||
int maxbpp, /* maximum texture bpp supported by hardware */
|
||||
int options, /* options */
|
||||
int cachesize,/* cache textures to system memory */
|
||||
wchar_t *path, /* plugin directory. must be smaller than MAX_PATH */
|
||||
wchar_t *ident, /* name of ROM. must be no longer than 64 in character. */
|
||||
dispInfoFuncExt callback /* callback function to display info */
|
||||
);
|
||||
int maxheight,/* maximum texture height supported by hardware */
|
||||
int maxbpp, /* maximum texture bpp supported by hardware */
|
||||
int options, /* options */
|
||||
int cachesize,/* cache textures to system memory */
|
||||
wchar_t *path, /* plugin directory. must be smaller than MAX_PATH */
|
||||
wchar_t *ident, /* name of ROM. must be no longer than 64 in character. */
|
||||
dispInfoFuncExt callback /* callback function to display info */
|
||||
);
|
||||
|
||||
void ext_ghq_shutdown(void);
|
||||
|
||||
boolean ext_ghq_txfilter(unsigned char *src, /* input texture */
|
||||
int srcwidth, /* width of input texture */
|
||||
int srcheight, /* height of input texture */
|
||||
unsigned short srcformat, /* format of input texture */
|
||||
uint64 g64crc, /* glide64 crc */
|
||||
GHQTexInfo *info /* output */
|
||||
);
|
||||
int srcwidth, /* width of input texture */
|
||||
int srcheight, /* height of input texture */
|
||||
unsigned short srcformat, /* format of input texture */
|
||||
uint64 g64crc, /* glide64 crc */
|
||||
GHQTexInfo *info /* output */
|
||||
);
|
||||
|
||||
boolean ext_ghq_hirestex(uint64 g64crc, /* glide64 crc */
|
||||
uint64 r_crc64, /* checksum hi:palette low:texture */
|
||||
unsigned short *palette, /* palette for CI textures */
|
||||
GHQTexInfo *info /* output */
|
||||
);
|
||||
uint64 r_crc64, /* checksum hi:palette low:texture */
|
||||
unsigned short *palette, /* palette for CI textures */
|
||||
GHQTexInfo *info /* output */
|
||||
);
|
||||
|
||||
uint64 ext_ghq_checksum(unsigned char *src, /* input texture */
|
||||
int width, /* width of texture */
|
||||
int height, /* height of texture */
|
||||
int size, /* type of texture pixel */
|
||||
int rowStride, /* row stride in bytes */
|
||||
unsigned char *palette /* palette */
|
||||
);
|
||||
int width, /* width of texture */
|
||||
int height, /* height of texture */
|
||||
int size, /* type of texture pixel */
|
||||
int rowStride, /* row stride in bytes */
|
||||
unsigned char *palette /* palette */
|
||||
);
|
||||
|
||||
boolean ext_ghq_dmptx(unsigned char *src, /* input texture (must be in 3Dfx Glide format) */
|
||||
int width, /* width of texture */
|
||||
int height, /* height of texture */
|
||||
int rowStridePixel, /* row stride of input texture in pixels */
|
||||
unsigned short gfmt, /* glide format of input texture */
|
||||
unsigned short n64fmt,/* N64 format hi:format low:size */
|
||||
uint64 r_crc64 /* checksum hi:palette low:texture */
|
||||
);
|
||||
int width, /* width of texture */
|
||||
int height, /* height of texture */
|
||||
int rowStridePixel, /* row stride of input texture in pixels */
|
||||
unsigned short gfmt, /* glide format of input texture */
|
||||
unsigned short n64fmt,/* N64 format hi:format low:size */
|
||||
uint64 r_crc64 /* checksum hi:palette low:texture */
|
||||
);
|
||||
|
||||
boolean ext_ghq_reloadhirestex();
|
||||
#endif /* TXFILTER_DLL */
|
||||
|
|
|
@ -56,16 +56,16 @@ TxFilter::~TxFilter()
|
|||
}
|
||||
|
||||
TxFilter::TxFilter(int maxwidth, int maxheight, int maxbpp, int options,
|
||||
int cachesize, wchar_t *path, wchar_t *ident,
|
||||
dispInfoFuncExt callback)
|
||||
int cachesize, wchar_t *path, wchar_t *ident,
|
||||
dispInfoFuncExt callback)
|
||||
{
|
||||
/* HACKALERT: the emulator misbehaves and sometimes forgets to shutdown */
|
||||
if ((ident && wcscmp(ident, L"DEFAULT") != 0 && _ident.compare(ident) == 0) &&
|
||||
_maxwidth == maxwidth &&
|
||||
_maxheight == maxheight &&
|
||||
_maxbpp == maxbpp &&
|
||||
_options == options &&
|
||||
_cacheSize == cachesize) return;
|
||||
_maxwidth == maxwidth &&
|
||||
_maxheight == maxheight &&
|
||||
_maxbpp == maxbpp &&
|
||||
_options == options &&
|
||||
_cacheSize == cachesize) return;
|
||||
clear(); /* gcc does not allow the destructor to be called */
|
||||
|
||||
/* shamelessness :P this first call to the debug output message creates
|
||||
|
@ -108,34 +108,30 @@ TxFilter::TxFilter(int maxwidth, int maxheight, int maxbpp, int options,
|
|||
|
||||
/* save path name */
|
||||
if (path)
|
||||
_path.assign(path);
|
||||
_path.assign(path);
|
||||
|
||||
/* save ROM name */
|
||||
if (ident && wcscmp(ident, L"DEFAULT") != 0)
|
||||
_ident.assign(ident);
|
||||
_ident.assign(ident);
|
||||
|
||||
/* check for dxtn extensions */
|
||||
if (!TxLoadLib::getInstance()->getdxtCompressTexFuncExt())
|
||||
_options &= ~S3TC_COMPRESSION;
|
||||
|
||||
if (!TxLoadLib::getInstance()->getfxtCompressTexFuncExt())
|
||||
_options &= ~FXT1_COMPRESSION;
|
||||
_options &= ~S3TC_COMPRESSION;
|
||||
|
||||
switch (options & COMPRESSION_MASK) {
|
||||
case FXT1_COMPRESSION:
|
||||
case S3TC_COMPRESSION:
|
||||
break;
|
||||
break;
|
||||
case NCC_COMPRESSION:
|
||||
default:
|
||||
_options &= ~COMPRESSION_MASK;
|
||||
_options &= ~COMPRESSION_MASK;
|
||||
}
|
||||
|
||||
if (TxMemBuf::getInstance()->init(_maxwidth, _maxheight)) {
|
||||
if (!_tex1)
|
||||
_tex1 = TxMemBuf::getInstance()->get(0);
|
||||
if (!_tex1)
|
||||
_tex1 = TxMemBuf::getInstance()->get(0);
|
||||
|
||||
if (!_tex2)
|
||||
_tex2 = TxMemBuf::getInstance()->get(1);
|
||||
if (!_tex2)
|
||||
_tex2 = TxMemBuf::getInstance()->get(1);
|
||||
}
|
||||
|
||||
#if !_16BPP_HACK
|
||||
|
@ -151,14 +147,14 @@ TxFilter::TxFilter(int maxwidth, int maxheight, int maxbpp, int options,
|
|||
_txHiResCache = new TxHiResCache(_maxwidth, _maxheight, _maxbpp, _options, _path.c_str(), _ident.c_str(), callback);
|
||||
|
||||
if (_txHiResCache->empty())
|
||||
_options &= ~HIRESTEXTURES_MASK;
|
||||
_options &= ~HIRESTEXTURES_MASK;
|
||||
#endif
|
||||
|
||||
if (!(_options & COMPRESS_TEX))
|
||||
_options &= ~COMPRESSION_MASK;
|
||||
_options &= ~COMPRESSION_MASK;
|
||||
|
||||
if (_tex1 && _tex2)
|
||||
_initialized = 1;
|
||||
_initialized = 1;
|
||||
}
|
||||
|
||||
boolean
|
||||
|
@ -174,20 +170,20 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
|
|||
/* find cached textures */
|
||||
if (_cacheSize) {
|
||||
|
||||
/* calculate checksum of source texture */
|
||||
if (!g64crc)
|
||||
g64crc = (uint64)(_txUtil->checksumTx(texture, srcwidth, srcheight, srcformat));
|
||||
/* calculate checksum of source texture */
|
||||
if (!g64crc)
|
||||
g64crc = (uint64)(_txUtil->checksumTx(texture, srcwidth, srcheight, srcformat));
|
||||
|
||||
DBG_INFO(80, L"filter: crc:%08X %08X %d x %d gfmt:%x\n",
|
||||
(uint32)(g64crc >> 32), (uint32)(g64crc & 0xffffffff), srcwidth, srcheight, srcformat);
|
||||
DBG_INFO(80, L"filter: crc:%08X %08X %d x %d gfmt:%x\n",
|
||||
(uint32)(g64crc >> 32), (uint32)(g64crc & 0xffffffff), srcwidth, srcheight, srcformat);
|
||||
|
||||
#if 0 /* use hirestex to retrieve cached textures. */
|
||||
/* check if we have it in cache */
|
||||
if (!(g64crc & 0xffffffff00000000) && /* we reach here only when there is no hires texture for this crc */
|
||||
_txTexCache->get(g64crc, info)) {
|
||||
DBG_INFO(80, L"cache hit: %d x %d gfmt:%x\n", info->width, info->height, info->format);
|
||||
return 1; /* yep, we've got it */
|
||||
}
|
||||
/* check if we have it in cache */
|
||||
if (!(g64crc & 0xffffffff00000000) && /* we reach here only when there is no hires texture for this crc */
|
||||
_txTexCache->get(g64crc, info)) {
|
||||
DBG_INFO(80, L"cache hit: %d x %d gfmt:%x\n", info->width, info->height, info->format);
|
||||
return 1; /* yep, we've got it */
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -196,250 +192,247 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
|
|||
* Bypass _options to do ARGB8888->16bpp if _maxbpp=16 or forced color reduction.
|
||||
*/
|
||||
if ((srcwidth >= 4 && srcheight >= 4) &&
|
||||
((_options & (FILTER_MASK|ENHANCEMENT_MASK|COMPRESSION_MASK)) ||
|
||||
(srcformat == GR_TEXFMT_ARGB_8888 && (_maxbpp < 32 || _options & FORCE16BPP_TEX)))) {
|
||||
((_options & (FILTER_MASK|ENHANCEMENT_MASK|COMPRESSION_MASK)) ||
|
||||
(srcformat == GR_TEXFMT_ARGB_8888 && (_maxbpp < 32 || _options & FORCE16BPP_TEX)))) {
|
||||
|
||||
#if !_16BPP_HACK
|
||||
/* convert textures to a format that the compressor accepts (ARGB8888) */
|
||||
if (_options & COMPRESSION_MASK) {
|
||||
/* convert textures to a format that the compressor accepts (ARGB8888) */
|
||||
if (_options & COMPRESSION_MASK) {
|
||||
#endif
|
||||
if (srcformat != GR_TEXFMT_ARGB_8888) {
|
||||
if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, srcformat, GR_TEXFMT_ARGB_8888)) {
|
||||
DBG_INFO(80, L"Error: unsupported format! gfmt:%x\n", srcformat);
|
||||
return 0;
|
||||
}
|
||||
texture = tmptex;
|
||||
destformat = GR_TEXFMT_ARGB_8888;
|
||||
}
|
||||
if (srcformat != GR_TEXFMT_ARGB_8888) {
|
||||
if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, srcformat, GR_TEXFMT_ARGB_8888)) {
|
||||
DBG_INFO(80, L"Error: unsupported format! gfmt:%x\n", srcformat);
|
||||
return 0;
|
||||
}
|
||||
texture = tmptex;
|
||||
destformat = GR_TEXFMT_ARGB_8888;
|
||||
}
|
||||
#if !_16BPP_HACK
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
switch (destformat) {
|
||||
case GR_TEXFMT_ARGB_8888:
|
||||
switch (destformat) {
|
||||
case GR_TEXFMT_ARGB_8888:
|
||||
|
||||
/*
|
||||
* prepare texture enhancements (x2, x4 scalers)
|
||||
*/
|
||||
int scale_shift = 0, num_filters = 0;
|
||||
uint32 filter = 0;
|
||||
/*
|
||||
* prepare texture enhancements (x2, x4 scalers)
|
||||
*/
|
||||
int scale_shift = 0, num_filters = 0;
|
||||
uint32 filter = 0;
|
||||
|
||||
if ((_options & ENHANCEMENT_MASK) == HQ4X_ENHANCEMENT) {
|
||||
if (srcwidth <= (_maxwidth >> 2) && srcheight <= (_maxheight >> 2)) {
|
||||
filter |= HQ4X_ENHANCEMENT;
|
||||
scale_shift = 2;
|
||||
num_filters++;
|
||||
} else if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
filter |= HQ2X_ENHANCEMENT;
|
||||
scale_shift = 1;
|
||||
num_filters++;
|
||||
}
|
||||
} else if (_options & ENHANCEMENT_MASK) {
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
filter |= (_options & ENHANCEMENT_MASK);
|
||||
scale_shift = 1;
|
||||
num_filters++;
|
||||
}
|
||||
}
|
||||
if ((_options & ENHANCEMENT_MASK) == HQ4X_ENHANCEMENT) {
|
||||
if (srcwidth <= (_maxwidth >> 2) && srcheight <= (_maxheight >> 2)) {
|
||||
filter |= HQ4X_ENHANCEMENT;
|
||||
scale_shift = 2;
|
||||
num_filters++;
|
||||
} else if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
filter |= HQ2X_ENHANCEMENT;
|
||||
scale_shift = 1;
|
||||
num_filters++;
|
||||
}
|
||||
} else if (_options & ENHANCEMENT_MASK) {
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
filter |= (_options & ENHANCEMENT_MASK);
|
||||
scale_shift = 1;
|
||||
num_filters++;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* prepare texture filters
|
||||
*/
|
||||
if (_options & (SMOOTH_FILTER_MASK|SHARP_FILTER_MASK)) {
|
||||
filter |= (_options & (SMOOTH_FILTER_MASK|SHARP_FILTER_MASK));
|
||||
num_filters++;
|
||||
}
|
||||
/*
|
||||
* prepare texture filters
|
||||
*/
|
||||
if (_options & (SMOOTH_FILTER_MASK|SHARP_FILTER_MASK)) {
|
||||
filter |= (_options & (SMOOTH_FILTER_MASK|SHARP_FILTER_MASK));
|
||||
num_filters++;
|
||||
}
|
||||
|
||||
/*
|
||||
* execute texture enhancements and filters
|
||||
*/
|
||||
while (num_filters > 0) {
|
||||
/*
|
||||
* execute texture enhancements and filters
|
||||
*/
|
||||
while (num_filters > 0) {
|
||||
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
|
||||
uint8 *_texture = texture;
|
||||
uint8 *_tmptex = tmptex;
|
||||
uint8 *_texture = texture;
|
||||
uint8 *_tmptex = tmptex;
|
||||
|
||||
unsigned int numcore = _numcore;
|
||||
unsigned int blkrow = 0;
|
||||
while (numcore > 1 && blkrow == 0) {
|
||||
blkrow = (srcheight >> 2) / numcore;
|
||||
numcore--;
|
||||
}
|
||||
if (blkrow > 0 && numcore > 1) {
|
||||
boost::thread *thrd[MAX_NUMCORE];
|
||||
unsigned int i;
|
||||
int blkheight = blkrow << 2;
|
||||
unsigned int srcStride = (srcwidth * blkheight) << 2;
|
||||
unsigned int destStride = srcStride << scale_shift << scale_shift;
|
||||
for (i = 0; i < numcore - 1; i++) {
|
||||
thrd[i] = new boost::thread(boost::bind(filter_8888,
|
||||
(uint32*)_texture,
|
||||
srcwidth,
|
||||
blkheight,
|
||||
(uint32*)_tmptex,
|
||||
filter));
|
||||
_texture += srcStride;
|
||||
_tmptex += destStride;
|
||||
}
|
||||
thrd[i] = new boost::thread(boost::bind(filter_8888,
|
||||
(uint32*)_texture,
|
||||
srcwidth,
|
||||
srcheight - blkheight * i,
|
||||
(uint32*)_tmptex,
|
||||
filter));
|
||||
for (i = 0; i < numcore; i++) {
|
||||
thrd[i]->join();
|
||||
delete thrd[i];
|
||||
}
|
||||
} else {
|
||||
filter_8888((uint32*)_texture, srcwidth, srcheight, (uint32*)_tmptex, filter);
|
||||
}
|
||||
unsigned int numcore = _numcore;
|
||||
unsigned int blkrow = 0;
|
||||
while (numcore > 1 && blkrow == 0) {
|
||||
blkrow = (srcheight >> 2) / numcore;
|
||||
numcore--;
|
||||
}
|
||||
if (blkrow > 0 && numcore > 1) {
|
||||
boost::thread *thrd[MAX_NUMCORE];
|
||||
unsigned int i;
|
||||
int blkheight = blkrow << 2;
|
||||
unsigned int srcStride = (srcwidth * blkheight) << 2;
|
||||
unsigned int destStride = srcStride << scale_shift << scale_shift;
|
||||
for (i = 0; i < numcore - 1; i++) {
|
||||
thrd[i] = new boost::thread(boost::bind(filter_8888,
|
||||
(uint32*)_texture,
|
||||
srcwidth,
|
||||
blkheight,
|
||||
(uint32*)_tmptex,
|
||||
filter));
|
||||
_texture += srcStride;
|
||||
_tmptex += destStride;
|
||||
}
|
||||
thrd[i] = new boost::thread(boost::bind(filter_8888,
|
||||
(uint32*)_texture,
|
||||
srcwidth,
|
||||
srcheight - blkheight * i,
|
||||
(uint32*)_tmptex,
|
||||
filter));
|
||||
for (i = 0; i < numcore; i++) {
|
||||
thrd[i]->join();
|
||||
delete thrd[i];
|
||||
}
|
||||
} else {
|
||||
filter_8888((uint32*)_texture, srcwidth, srcheight, (uint32*)_tmptex, filter);
|
||||
}
|
||||
|
||||
if (filter & ENHANCEMENT_MASK) {
|
||||
srcwidth <<= scale_shift;
|
||||
srcheight <<= scale_shift;
|
||||
filter &= ~ENHANCEMENT_MASK;
|
||||
scale_shift = 0;
|
||||
}
|
||||
if (filter & ENHANCEMENT_MASK) {
|
||||
srcwidth <<= scale_shift;
|
||||
srcheight <<= scale_shift;
|
||||
filter &= ~ENHANCEMENT_MASK;
|
||||
scale_shift = 0;
|
||||
}
|
||||
|
||||
texture = tmptex;
|
||||
num_filters--;
|
||||
}
|
||||
texture = tmptex;
|
||||
num_filters--;
|
||||
}
|
||||
|
||||
/*
|
||||
* texture compression
|
||||
*/
|
||||
/* ignored if we only have texture compression option on.
|
||||
* only done when texture enhancer is used. see constructor. */
|
||||
if ((_options & COMPRESSION_MASK) &&
|
||||
(srcwidth >= 64 && srcheight >= 64) /* Texture compression is not suitable for low pixel coarse detail
|
||||
* textures. The assumption here is that textures larger than 64x64
|
||||
* have enough detail to produce decent quality when compressed. The
|
||||
* down side is that narrow stripped textures that the N64 often use
|
||||
* for large background textures are also ignored. It would be more
|
||||
* reasonable if decisions are made based on fourier-transform
|
||||
* spectrum or RMS error.
|
||||
*/
|
||||
) {
|
||||
int compressionType = _options & COMPRESSION_MASK;
|
||||
int tmpwidth, tmpheight;
|
||||
uint16 tmpformat;
|
||||
/* XXX: textures that use 8bit alpha channel look bad with the current
|
||||
* fxt1 library, so we substitute it with dxtn for now. afaik all gfx
|
||||
* cards that support fxt1 also support dxtn. (3dfx and Intel) */
|
||||
if ((destformat == GR_TEXFMT_ALPHA_INTENSITY_88) ||
|
||||
(destformat == GR_TEXFMT_ARGB_8888) ||
|
||||
(destformat == GR_TEXFMT_ALPHA_8)) {
|
||||
compressionType = S3TC_COMPRESSION;
|
||||
}
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (_txQuantize->compress(texture, tmptex,
|
||||
srcwidth, srcheight, srcformat,
|
||||
&tmpwidth, &tmpheight, &tmpformat,
|
||||
compressionType)) {
|
||||
srcwidth = tmpwidth;
|
||||
srcheight = tmpheight;
|
||||
destformat = tmpformat;
|
||||
texture = tmptex;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* texture compression
|
||||
*/
|
||||
/* ignored if we only have texture compression option on.
|
||||
* only done when texture enhancer is used. see constructor. */
|
||||
if ((_options & COMPRESSION_MASK) &&
|
||||
(srcwidth >= 64 && srcheight >= 64) /* Texture compression is not suitable for low pixel coarse detail
|
||||
* textures. The assumption here is that textures larger than 64x64
|
||||
* have enough detail to produce decent quality when compressed. The
|
||||
* down side is that narrow stripped textures that the N64 often use
|
||||
* for large background textures are also ignored. It would be more
|
||||
* reasonable if decisions are made based on fourier-transform
|
||||
* spectrum or RMS error.
|
||||
*/
|
||||
) {
|
||||
int compressionType = _options & COMPRESSION_MASK;
|
||||
int tmpwidth, tmpheight;
|
||||
uint16 tmpformat;
|
||||
if ((destformat == GR_TEXFMT_ALPHA_INTENSITY_88) ||
|
||||
(destformat == GR_TEXFMT_ARGB_8888) ||
|
||||
(destformat == GR_TEXFMT_ALPHA_8)) {
|
||||
compressionType = S3TC_COMPRESSION;
|
||||
}
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (_txQuantize->compress(texture, tmptex,
|
||||
srcwidth, srcheight, srcformat,
|
||||
&tmpwidth, &tmpheight, &tmpformat,
|
||||
compressionType)) {
|
||||
srcwidth = tmpwidth;
|
||||
srcheight = tmpheight;
|
||||
destformat = tmpformat;
|
||||
texture = tmptex;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* texture (re)conversions
|
||||
*/
|
||||
if (destformat == GR_TEXFMT_ARGB_8888) {
|
||||
if (srcformat == GR_TEXFMT_ARGB_8888 && (_maxbpp < 32 || _options & FORCE16BPP_TEX)) srcformat = GR_TEXFMT_ARGB_4444;
|
||||
if (srcformat != GR_TEXFMT_ARGB_8888) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, GR_TEXFMT_ARGB_8888, srcformat)) {
|
||||
DBG_INFO(80, L"Error: unsupported format! gfmt:%x\n", srcformat);
|
||||
return 0;
|
||||
}
|
||||
texture = tmptex;
|
||||
destformat = srcformat;
|
||||
}
|
||||
}
|
||||
/*
|
||||
* texture (re)conversions
|
||||
*/
|
||||
if (destformat == GR_TEXFMT_ARGB_8888) {
|
||||
if (srcformat == GR_TEXFMT_ARGB_8888 && (_maxbpp < 32 || _options & FORCE16BPP_TEX)) srcformat = GR_TEXFMT_ARGB_4444;
|
||||
if (srcformat != GR_TEXFMT_ARGB_8888) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, GR_TEXFMT_ARGB_8888, srcformat)) {
|
||||
DBG_INFO(80, L"Error: unsupported format! gfmt:%x\n", srcformat);
|
||||
return 0;
|
||||
}
|
||||
texture = tmptex;
|
||||
destformat = srcformat;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
break;
|
||||
#if !_16BPP_HACK
|
||||
case GR_TEXFMT_ARGB_4444:
|
||||
case GR_TEXFMT_ARGB_4444:
|
||||
|
||||
int scale_shift = 0;
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
int scale_shift = 0;
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
|
||||
switch (_options & ENHANCEMENT_MASK) {
|
||||
case HQ4X_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 2) && srcheight <= (_maxheight >> 2)) {
|
||||
hq4x_4444((uint8*)texture, (uint8*)tmptex, srcwidth, srcheight, srcwidth, srcwidth * 4 * 2);
|
||||
scale_shift = 2;
|
||||
}/* else if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
hq2x_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}*/
|
||||
break;
|
||||
case HQ2X_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
hq2x_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}
|
||||
break;
|
||||
case HQ2XS_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
hq2xS_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}
|
||||
break;
|
||||
case LQ2X_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
lq2x_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}
|
||||
break;
|
||||
case LQ2XS_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
lq2xS_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}
|
||||
break;
|
||||
case X2SAI_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
Super2xSaI_4444((uint16*)texture, (uint16*)tmptex, srcwidth, srcheight, srcwidth);
|
||||
scale_shift = 1;
|
||||
}
|
||||
break;
|
||||
case X2_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
Texture2x_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}
|
||||
}
|
||||
if (scale_shift) {
|
||||
srcwidth <<= scale_shift;
|
||||
srcheight <<= scale_shift;
|
||||
texture = tmptex;
|
||||
}
|
||||
switch (_options & ENHANCEMENT_MASK) {
|
||||
case HQ4X_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 2) && srcheight <= (_maxheight >> 2)) {
|
||||
hq4x_4444((uint8*)texture, (uint8*)tmptex, srcwidth, srcheight, srcwidth, srcwidth * 4 * 2);
|
||||
scale_shift = 2;
|
||||
}/* else if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
hq2x_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}*/
|
||||
break;
|
||||
case HQ2X_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
hq2x_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}
|
||||
break;
|
||||
case HQ2XS_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
hq2xS_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}
|
||||
break;
|
||||
case LQ2X_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
lq2x_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}
|
||||
break;
|
||||
case LQ2XS_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
lq2xS_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}
|
||||
break;
|
||||
case X2SAI_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
Super2xSaI_4444((uint16*)texture, (uint16*)tmptex, srcwidth, srcheight, srcwidth);
|
||||
scale_shift = 1;
|
||||
}
|
||||
break;
|
||||
case X2_ENHANCEMENT:
|
||||
if (srcwidth <= (_maxwidth >> 1) && srcheight <= (_maxheight >> 1)) {
|
||||
Texture2x_16((uint8*)texture, srcwidth * 2, (uint8*)tmptex, srcwidth * 2 * 2, srcwidth, srcheight);
|
||||
scale_shift = 1;
|
||||
}
|
||||
}
|
||||
if (scale_shift) {
|
||||
srcwidth <<= scale_shift;
|
||||
srcheight <<= scale_shift;
|
||||
texture = tmptex;
|
||||
}
|
||||
|
||||
if (_options & SMOOTH_FILTER_MASK) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
SmoothFilter_4444((uint16*)texture, srcwidth, srcheight, (uint16*)tmptex, (_options & SMOOTH_FILTER_MASK));
|
||||
texture = tmptex;
|
||||
} else if (_options & SHARP_FILTER_MASK) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
SharpFilter_4444((uint16*)texture, srcwidth, srcheight, (uint16*)tmptex, (_options & SHARP_FILTER_MASK));
|
||||
texture = tmptex;
|
||||
}
|
||||
if (_options & SMOOTH_FILTER_MASK) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
SmoothFilter_4444((uint16*)texture, srcwidth, srcheight, (uint16*)tmptex, (_options & SMOOTH_FILTER_MASK));
|
||||
texture = tmptex;
|
||||
} else if (_options & SHARP_FILTER_MASK) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
SharpFilter_4444((uint16*)texture, srcwidth, srcheight, (uint16*)tmptex, (_options & SHARP_FILTER_MASK));
|
||||
texture = tmptex;
|
||||
}
|
||||
|
||||
break;
|
||||
case GR_TEXFMT_ARGB_1555:
|
||||
break;
|
||||
case GR_TEXFMT_RGB_565:
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_8:
|
||||
break;
|
||||
break;
|
||||
case GR_TEXFMT_ARGB_1555:
|
||||
break;
|
||||
case GR_TEXFMT_RGB_565:
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_8:
|
||||
break;
|
||||
#endif /* _16BPP_HACK */
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* fill in the texture info. */
|
||||
|
@ -474,120 +467,120 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
|
|||
*/
|
||||
|
||||
DBG_INFO(80, L"hirestex: r_crc64:%08X %08X, g64crc:%08X %08X\n",
|
||||
(uint32)(r_crc64 >> 32), (uint32)(r_crc64 & 0xffffffff),
|
||||
(uint32)(g64crc >> 32), (uint32)(g64crc & 0xffffffff));
|
||||
(uint32)(r_crc64 >> 32), (uint32)(r_crc64 & 0xffffffff),
|
||||
(uint32)(g64crc >> 32), (uint32)(g64crc & 0xffffffff));
|
||||
|
||||
#if HIRES_TEXTURE
|
||||
/* check if we have it in hires memory cache. */
|
||||
if ((_options & HIRESTEXTURES_MASK) && r_crc64) {
|
||||
if (_txHiResCache->get(r_crc64, info)) {
|
||||
DBG_INFO(80, L"hires hit: %d x %d gfmt:%x\n", info->width, info->height, info->format);
|
||||
if (_txHiResCache->get(r_crc64, info)) {
|
||||
DBG_INFO(80, L"hires hit: %d x %d gfmt:%x\n", info->width, info->height, info->format);
|
||||
|
||||
/* TODO: Enable emulation for special N64 combiner modes. There are few ways
|
||||
* to get this done. Also applies for CI textures below.
|
||||
*
|
||||
* Solution 1. Load the hiresolution textures in ARGB8888 (or A8, IA88) format
|
||||
* to cache. When a cache is hit, then we take the modes passed in from Glide64
|
||||
* (also TODO) and apply the modification. Then we do color reduction or format
|
||||
* conversion or compression if desired and stuff it into the non-hires texture
|
||||
* cache.
|
||||
*
|
||||
* Solution 2. When a cache is hit and if the combiner modes are present,
|
||||
* convert the texture to ARGB4444 and pass it back to Glide64 to process.
|
||||
* If a texture is compressed, it needs to be decompressed first. Then add
|
||||
* the processed texture to the non-hires texture cache.
|
||||
*
|
||||
* Solution 3. Hybrid of the above 2. Load the textures in ARGB8888 (A8, IA88)
|
||||
* format. Convert the texture to ARGB4444 and pass it back to Glide64 when
|
||||
* the combiner modes are present. Get the processed texture back from Glide64
|
||||
* and compress if desired and add it to the non-hires texture cache.
|
||||
*
|
||||
* Solution 4. Take the easy way out and forget about this whole thing.
|
||||
*/
|
||||
/* TODO: Enable emulation for special N64 combiner modes. There are few ways
|
||||
* to get this done. Also applies for CI textures below.
|
||||
*
|
||||
* Solution 1. Load the hiresolution textures in ARGB8888 (or A8, IA88) format
|
||||
* to cache. When a cache is hit, then we take the modes passed in from Glide64
|
||||
* (also TODO) and apply the modification. Then we do color reduction or format
|
||||
* conversion or compression if desired and stuff it into the non-hires texture
|
||||
* cache.
|
||||
*
|
||||
* Solution 2. When a cache is hit and if the combiner modes are present,
|
||||
* convert the texture to ARGB4444 and pass it back to Glide64 to process.
|
||||
* If a texture is compressed, it needs to be decompressed first. Then add
|
||||
* the processed texture to the non-hires texture cache.
|
||||
*
|
||||
* Solution 3. Hybrid of the above 2. Load the textures in ARGB8888 (A8, IA88)
|
||||
* format. Convert the texture to ARGB4444 and pass it back to Glide64 when
|
||||
* the combiner modes are present. Get the processed texture back from Glide64
|
||||
* and compress if desired and add it to the non-hires texture cache.
|
||||
*
|
||||
* Solution 4. Take the easy way out and forget about this whole thing.
|
||||
*/
|
||||
|
||||
return 1; /* yep, got it */
|
||||
}
|
||||
if (_txHiResCache->get((r_crc64 & 0xffffffff), info)) {
|
||||
DBG_INFO(80, L"hires hit: %d x %d gfmt:%x\n", info->width, info->height, info->format);
|
||||
return 1; /* yep, got it */
|
||||
}
|
||||
if (_txHiResCache->get((r_crc64 & 0xffffffff), info)) {
|
||||
DBG_INFO(80, L"hires hit: %d x %d gfmt:%x\n", info->width, info->height, info->format);
|
||||
|
||||
/* for true CI textures, we use the passed in palette to convert to
|
||||
* ARGB1555 and add it to memory cache.
|
||||
*
|
||||
* NOTE: we do this AFTER all other texture cache searches because
|
||||
* only a few texture packs actually use true CI textures.
|
||||
*
|
||||
* NOTE: the pre-converted palette from Glide64 is in RGBA5551 format.
|
||||
* A comp comes before RGB comp.
|
||||
*/
|
||||
if (palette && info->format == GR_TEXFMT_P_8) {
|
||||
DBG_INFO(80, L"found GR_TEXFMT_P_8 format. Need conversion!!\n");
|
||||
/* for true CI textures, we use the passed in palette to convert to
|
||||
* ARGB1555 and add it to memory cache.
|
||||
*
|
||||
* NOTE: we do this AFTER all other texture cache searches because
|
||||
* only a few texture packs actually use true CI textures.
|
||||
*
|
||||
* NOTE: the pre-converted palette from Glide64 is in RGBA5551 format.
|
||||
* A comp comes before RGB comp.
|
||||
*/
|
||||
if (palette && info->format == GR_TEXFMT_P_8) {
|
||||
DBG_INFO(80, L"found GR_TEXFMT_P_8 format. Need conversion!!\n");
|
||||
|
||||
int width = info->width;
|
||||
int height = info->height;
|
||||
uint16 format = info->format;
|
||||
/* XXX: avoid collision with zlib compression buffer in TxHiResTexture::get */
|
||||
uint8 *texture = info->data;
|
||||
uint8 *tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
int width = info->width;
|
||||
int height = info->height;
|
||||
uint16 format = info->format;
|
||||
/* XXX: avoid collision with zlib compression buffer in TxHiResTexture::get */
|
||||
uint8 *texture = info->data;
|
||||
uint8 *tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
|
||||
/* use palette and convert to 16bit format */
|
||||
_txQuantize->P8_16BPP((uint32*)texture, (uint32*)tmptex, info->width, info->height, (uint32*)palette);
|
||||
texture = tmptex;
|
||||
format = GR_TEXFMT_ARGB_1555;
|
||||
/* use palette and convert to 16bit format */
|
||||
_txQuantize->P8_16BPP((uint32*)texture, (uint32*)tmptex, info->width, info->height, (uint32*)palette);
|
||||
texture = tmptex;
|
||||
format = GR_TEXFMT_ARGB_1555;
|
||||
|
||||
#if 1
|
||||
/* XXX: compressed if memory cache compression is ON */
|
||||
if (_options & COMPRESSION_MASK) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (_txQuantize->quantize(texture, tmptex, info->width, info->height, format, GR_TEXFMT_ARGB_8888)) {
|
||||
texture = tmptex;
|
||||
format = GR_TEXFMT_ARGB_8888;
|
||||
}
|
||||
if (format == GR_TEXFMT_ARGB_8888) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (_txQuantize->compress(texture, tmptex,
|
||||
info->width, info->height, GR_TEXFMT_ARGB_1555,
|
||||
&width, &height, &format,
|
||||
_options & COMPRESSION_MASK)) {
|
||||
texture = tmptex;
|
||||
} else {
|
||||
/*if (!_txQuantize->quantize(texture, tmptex, info->width, info->height, GR_TEXFMT_ARGB_8888, GR_TEXFMT_ARGB_1555)) {
|
||||
DBG_INFO(80, L"Error: unsupported format! gfmt:%x\n", format);
|
||||
return 0;
|
||||
}*/
|
||||
texture = tmptex;
|
||||
format = GR_TEXFMT_ARGB_1555;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* XXX: compressed if memory cache compression is ON */
|
||||
if (_options & COMPRESSION_MASK) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (_txQuantize->quantize(texture, tmptex, info->width, info->height, format, GR_TEXFMT_ARGB_8888)) {
|
||||
texture = tmptex;
|
||||
format = GR_TEXFMT_ARGB_8888;
|
||||
}
|
||||
if (format == GR_TEXFMT_ARGB_8888) {
|
||||
tmptex = (texture == _tex1) ? _tex2 : _tex1;
|
||||
if (_txQuantize->compress(texture, tmptex,
|
||||
info->width, info->height, GR_TEXFMT_ARGB_1555,
|
||||
&width, &height, &format,
|
||||
_options & COMPRESSION_MASK)) {
|
||||
texture = tmptex;
|
||||
} else {
|
||||
/*if (!_txQuantize->quantize(texture, tmptex, info->width, info->height, GR_TEXFMT_ARGB_8888, GR_TEXFMT_ARGB_1555)) {
|
||||
DBG_INFO(80, L"Error: unsupported format! gfmt:%x\n", format);
|
||||
return 0;
|
||||
}*/
|
||||
texture = tmptex;
|
||||
format = GR_TEXFMT_ARGB_1555;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* fill in the required info to return */
|
||||
info->data = texture;
|
||||
info->width = width;
|
||||
info->height = height;
|
||||
info->format = format;
|
||||
info->smallLodLog2 = _txUtil->grLodLog2(width, height);
|
||||
info->largeLodLog2 = info->smallLodLog2;
|
||||
info->aspectRatioLog2 = _txUtil->grAspectRatioLog2(width, height);
|
||||
info->is_hires_tex = 1;
|
||||
/* fill in the required info to return */
|
||||
info->data = texture;
|
||||
info->width = width;
|
||||
info->height = height;
|
||||
info->format = format;
|
||||
info->smallLodLog2 = _txUtil->grLodLog2(width, height);
|
||||
info->largeLodLog2 = info->smallLodLog2;
|
||||
info->aspectRatioLog2 = _txUtil->grAspectRatioLog2(width, height);
|
||||
info->is_hires_tex = 1;
|
||||
|
||||
/* XXX: add to hires texture cache!!! */
|
||||
_txHiResCache->add(r_crc64, info);
|
||||
/* XXX: add to hires texture cache!!! */
|
||||
_txHiResCache->add(r_crc64, info);
|
||||
|
||||
DBG_INFO(80, L"GR_TEXFMT_P_8 loaded as gfmt:%x!\n", format);
|
||||
}
|
||||
DBG_INFO(80, L"GR_TEXFMT_P_8 loaded as gfmt:%x!\n", format);
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/* check if we have it in memory cache */
|
||||
if (_cacheSize && g64crc) {
|
||||
if (_txTexCache->get(g64crc, info)) {
|
||||
DBG_INFO(80, L"cache hit: %d x %d gfmt:%x\n", info->width, info->height, info->format);
|
||||
return 1; /* yep, we've got it */
|
||||
}
|
||||
if (_txTexCache->get(g64crc, info)) {
|
||||
DBG_INFO(80, L"cache hit: %d x %d gfmt:%x\n", info->width, info->height, info->format);
|
||||
return 1; /* yep, we've got it */
|
||||
}
|
||||
}
|
||||
|
||||
DBG_INFO(80, L"no cache hits.\n");
|
||||
|
@ -599,7 +592,7 @@ uint64
|
|||
TxFilter::checksum64(uint8 *src, int width, int height, int size, int rowStride, uint8 *palette)
|
||||
{
|
||||
if (_options & (HIRESTEXTURES_MASK|DUMP_TEX))
|
||||
return _txUtil->checksum64(src, width, height, size, rowStride, palette);
|
||||
return _txUtil->checksum64(src, width, height, size, rowStride, palette);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -608,60 +601,60 @@ boolean
|
|||
TxFilter::dmptx(uint8 *src, int width, int height, int rowStridePixel, uint16 gfmt, uint16 n64fmt, uint64 r_crc64)
|
||||
{
|
||||
if (!_initialized)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (!(_options & DUMP_TEX))
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
DBG_INFO(80, L"gfmt = %02x n64fmt = %02x\n", gfmt, n64fmt);
|
||||
DBG_INFO(80, L"hirestex: r_crc64:%08X %08X\n",
|
||||
(uint32)(r_crc64 >> 32), (uint32)(r_crc64 & 0xffffffff));
|
||||
(uint32)(r_crc64 >> 32), (uint32)(r_crc64 & 0xffffffff));
|
||||
|
||||
if (!_txQuantize->quantize(src, _tex1, rowStridePixel, height, (gfmt & 0x00ff), GR_TEXFMT_ARGB_8888))
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
src = _tex1;
|
||||
|
||||
if (!_path.empty() && !_ident.empty()) {
|
||||
/* dump it to disk */
|
||||
FILE *fp = NULL;
|
||||
std::wstring tmpbuf;
|
||||
/* dump it to disk */
|
||||
FILE *fp = NULL;
|
||||
std::wstring tmpbuf;
|
||||
|
||||
/* create directories */
|
||||
tmpbuf.assign(_path + L"/texture_dump");
|
||||
if (!boost::filesystem::exists(tmpbuf) &&
|
||||
!boost::filesystem::create_directory(tmpbuf))
|
||||
return 0;
|
||||
/* create directories */
|
||||
tmpbuf.assign(_path + L"/texture_dump");
|
||||
if (!boost::filesystem::exists(tmpbuf) &&
|
||||
!boost::filesystem::create_directory(tmpbuf))
|
||||
return 0;
|
||||
|
||||
tmpbuf.append(L"/" + _ident);
|
||||
if (!boost::filesystem::exists(tmpbuf) &&
|
||||
!boost::filesystem::create_directory(tmpbuf))
|
||||
return 0;
|
||||
tmpbuf.append(L"/" + _ident);
|
||||
if (!boost::filesystem::exists(tmpbuf) &&
|
||||
!boost::filesystem::create_directory(tmpbuf))
|
||||
return 0;
|
||||
|
||||
tmpbuf.append(L"/GlideHQ");
|
||||
if (!boost::filesystem::exists(tmpbuf) &&
|
||||
!boost::filesystem::create_directory(tmpbuf))
|
||||
return 0;
|
||||
tmpbuf.append(L"/GlideHQ");
|
||||
if (!boost::filesystem::exists(tmpbuf) &&
|
||||
!boost::filesystem::create_directory(tmpbuf))
|
||||
return 0;
|
||||
|
||||
if ((n64fmt >> 8) == 0x2) {
|
||||
tmpbuf.append(boost::str(boost::wformat(L"/%ls#%08X#%01X#%01X#%08X_ciByRGBA.png")
|
||||
% _ident.c_str() % (uint32)(r_crc64 & 0xffffffff) % (n64fmt >> 8) % (n64fmt & 0xf) % (uint32)(r_crc64 >> 32)));
|
||||
} else {
|
||||
tmpbuf.append(boost::str(boost::wformat(L"/%ls#%08X#%01X#%01X_all.png")
|
||||
% _ident.c_str() % (uint32)(r_crc64 & 0xffffffff) % (n64fmt >> 8) % (n64fmt & 0xf)));
|
||||
}
|
||||
if ((n64fmt >> 8) == 0x2) {
|
||||
tmpbuf.append(boost::str(boost::wformat(L"/%ls#%08X#%01X#%01X#%08X_ciByRGBA.png")
|
||||
% _ident.c_str() % (uint32)(r_crc64 & 0xffffffff) % (n64fmt >> 8) % (n64fmt & 0xf) % (uint32)(r_crc64 >> 32)));
|
||||
} else {
|
||||
tmpbuf.append(boost::str(boost::wformat(L"/%ls#%08X#%01X#%01X_all.png")
|
||||
% _ident.c_str() % (uint32)(r_crc64 & 0xffffffff) % (n64fmt >> 8) % (n64fmt & 0xf)));
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
if ((fp = _wfopen(tmpbuf.c_str(), L"wb")) != NULL) {
|
||||
if ((fp = _wfopen(tmpbuf.c_str(), L"wb")) != NULL) {
|
||||
#else
|
||||
char cbuf[MAX_PATH];
|
||||
wcstombs(cbuf, tmpbuf.c_str(), MAX_PATH);
|
||||
if ((fp = fopen(cbuf, "wb")) != NULL) {
|
||||
char cbuf[MAX_PATH];
|
||||
wcstombs(cbuf, tmpbuf.c_str(), MAX_PATH);
|
||||
if ((fp = fopen(cbuf, "wb")) != NULL) {
|
||||
#endif
|
||||
_txImage->writePNG(src, fp, width, height, (rowStridePixel << 2), 0x0003, 0);
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
_txImage->writePNG(src, fp, width, height, (rowStridePixel << 2), 0x0003, 0);
|
||||
fclose(fp);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -673,10 +666,10 @@ TxFilter::reloadhirestex()
|
|||
DBG_INFO(80, L"Reload hires textures from texture pack.\n");
|
||||
|
||||
if (_txHiResCache->load(0)) {
|
||||
if (_txHiResCache->empty()) _options &= ~HIRESTEXTURES_MASK;
|
||||
else _options |= HIRESTEXTURES_MASK;
|
||||
if (_txHiResCache->empty()) _options &= ~HIRESTEXTURES_MASK;
|
||||
else _options |= HIRESTEXTURES_MASK;
|
||||
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -896,24 +896,6 @@ TxHiResCache::loadHiResTextures(boost::filesystem::wpath dir_path, boolean repla
|
|||
;
|
||||
}
|
||||
break;
|
||||
case FXT1_COMPRESSION:
|
||||
switch (destformat) {
|
||||
case GR_TEXFMT_ARGB_1555:
|
||||
case GR_TEXFMT_RGB_565:
|
||||
case GR_TEXFMT_INTENSITY_8:
|
||||
dataSize = (width * height) >> 1;
|
||||
break;
|
||||
/* XXX: textures that use 8bit alpha channel look bad with the current
|
||||
* fxt1 library, so we substitute it with dxtn for now. afaik all gfx
|
||||
* cards that support fxt1 also support dxtn. (3dfx and Intel) */
|
||||
case GR_TEXFMT_ALPHA_INTENSITY_88:
|
||||
case GR_TEXFMT_ARGB_8888:
|
||||
compressionType = S3TC_COMPRESSION;
|
||||
dataSize = width * height;
|
||||
break;
|
||||
case GR_TEXFMT_ALPHA_8: /* no size benefit with dxtn */
|
||||
;
|
||||
}
|
||||
}
|
||||
/* compress it! */
|
||||
if (dataSize) {
|
||||
|
|
|
@ -40,30 +40,30 @@ TxImage::getPNGInfo(FILE *fp, png_structp *png_ptr, png_infop *info_ptr)
|
|||
|
||||
/* check for valid file pointer */
|
||||
if (!fp)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* check if file is PNG */
|
||||
if (fread(sig, 1, PNG_CHK_BYTES, fp) != PNG_CHK_BYTES)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (png_sig_cmp(sig, 0, PNG_CHK_BYTES) != 0)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* get PNG file info */
|
||||
*png_ptr = png_create_read_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (!*png_ptr)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
*info_ptr = png_create_info_struct(*png_ptr);
|
||||
if (!*info_ptr) {
|
||||
png_destroy_read_struct(png_ptr, NULL, NULL);
|
||||
return 0;
|
||||
png_destroy_read_struct(png_ptr, NULL, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (setjmp(png_jmpbuf(*png_ptr))) {
|
||||
DBG_INFO(80, L"error reading png!\n");
|
||||
png_destroy_read_struct(png_ptr, info_ptr, NULL);
|
||||
return 0;
|
||||
DBG_INFO(80, L"error reading png!\n");
|
||||
png_destroy_read_struct(png_ptr, info_ptr, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
png_init_io(*png_ptr, fp);
|
||||
|
@ -82,7 +82,7 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
|
|||
png_infop info_ptr;
|
||||
uint8 *image = NULL;
|
||||
int bit_depth, color_type, interlace_type, compression_type, filter_type,
|
||||
row_bytes, o_width, o_height, num_pas;
|
||||
row_bytes, o_width, o_height, num_pas;
|
||||
|
||||
/* initialize */
|
||||
*width = 0;
|
||||
|
@ -91,20 +91,20 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
|
|||
|
||||
/* check if we have a valid png file */
|
||||
if (!fp)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
if (!getPNGInfo(fp, &png_ptr, &info_ptr)) {
|
||||
INFO(80, L"error reading png file! png image is corrupt.\n");
|
||||
return NULL;
|
||||
INFO(80, L"error reading png file! png image is corrupt.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
png_get_IHDR(png_ptr, info_ptr,
|
||||
(png_uint_32*)&o_width, (png_uint_32*)&o_height, &bit_depth, &color_type,
|
||||
&interlace_type, &compression_type, &filter_type);
|
||||
(png_uint_32*)&o_width, (png_uint_32*)&o_height, &bit_depth, &color_type,
|
||||
&interlace_type, &compression_type, &filter_type);
|
||||
|
||||
DBG_INFO(80, L"png format %d x %d bitdepth:%d color:%x interlace:%x compression:%x filter:%x\n",
|
||||
o_width, o_height, bit_depth, color_type,
|
||||
interlace_type, compression_type, filter_type);
|
||||
o_width, o_height, bit_depth, color_type,
|
||||
interlace_type, compression_type, filter_type);
|
||||
|
||||
/* transformations */
|
||||
|
||||
|
@ -117,8 +117,8 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
|
|||
|
||||
/* strip if color channel is larger than 8 bits */
|
||||
if (bit_depth > 8) {
|
||||
png_set_strip_16(png_ptr);
|
||||
bit_depth = 8;
|
||||
png_set_strip_16(png_ptr);
|
||||
bit_depth = 8;
|
||||
}
|
||||
|
||||
#if 1
|
||||
|
@ -127,44 +127,44 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
|
|||
*/
|
||||
/* convert palette color to rgb color */
|
||||
if (color_type == PNG_COLOR_TYPE_PALETTE) {
|
||||
png_set_palette_to_rgb(png_ptr);
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
png_set_palette_to_rgb(png_ptr);
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
}
|
||||
|
||||
/* expand 1,2,4 bit gray scale to 8 bit gray scale */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8)
|
||||
png_set_expand_gray_1_2_4_to_8(png_ptr);
|
||||
png_set_expand_gray_1_2_4_to_8(png_ptr);
|
||||
|
||||
/* convert gray scale or gray scale + alpha to rgb color */
|
||||
if (color_type == PNG_COLOR_TYPE_GRAY ||
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
|
||||
png_set_gray_to_rgb(png_ptr);
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
color_type == PNG_COLOR_TYPE_GRAY_ALPHA) {
|
||||
png_set_gray_to_rgb(png_ptr);
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* add alpha channel if any */
|
||||
if (png_get_valid(png_ptr, info_ptr, PNG_INFO_tRNS)) {
|
||||
png_set_tRNS_to_alpha(png_ptr);
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
png_set_tRNS_to_alpha(png_ptr);
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
}
|
||||
|
||||
/* convert rgb to rgba */
|
||||
if (color_type == PNG_COLOR_TYPE_RGB) {
|
||||
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
png_set_filler(png_ptr, 0xff, PNG_FILLER_AFTER);
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
}
|
||||
|
||||
/* punt invalid formats */
|
||||
if (color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
DBG_INFO(80, L"Error: not PNG_COLOR_TYPE_RGB_ALPHA format!\n");
|
||||
return NULL;
|
||||
png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
|
||||
DBG_INFO(80, L"Error: not PNG_COLOR_TYPE_RGB_ALPHA format!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/*png_color_8p sig_bit;
|
||||
if (png_get_sBIT(png_ptr, info_ptr, &sig_bit))
|
||||
png_set_shift(png_ptr, sig_bit);*/
|
||||
png_set_shift(png_ptr, sig_bit);*/
|
||||
|
||||
/* convert rgba to bgra */
|
||||
png_set_bgr(png_ptr);
|
||||
|
@ -184,49 +184,49 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
|
|||
|
||||
/* read in image */
|
||||
if (image) {
|
||||
int pas, i;
|
||||
uint8* tmpimage;
|
||||
int pas, i;
|
||||
uint8* tmpimage;
|
||||
|
||||
for (pas = 0; pas < num_pas; pas++) { /* deal with interlacing */
|
||||
tmpimage = image;
|
||||
for (pas = 0; pas < num_pas; pas++) { /* deal with interlacing */
|
||||
tmpimage = image;
|
||||
|
||||
for (i = 0; i < o_height; i++) {
|
||||
/* copy row */
|
||||
png_read_rows(png_ptr, &tmpimage, NULL, 1);
|
||||
tmpimage += row_bytes;
|
||||
}
|
||||
}
|
||||
for (i = 0; i < o_height; i++) {
|
||||
/* copy row */
|
||||
png_read_rows(png_ptr, &tmpimage, NULL, 1);
|
||||
tmpimage += row_bytes;
|
||||
}
|
||||
}
|
||||
|
||||
/* read rest of the info structure */
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
/* read rest of the info structure */
|
||||
png_read_end(png_ptr, info_ptr);
|
||||
|
||||
*width = (row_bytes >> 2);
|
||||
*height = o_height;
|
||||
*format = GR_TEXFMT_ARGB_8888;
|
||||
*width = (row_bytes >> 2);
|
||||
*height = o_height;
|
||||
*format = GR_TEXFMT_ARGB_8888;
|
||||
|
||||
#if POW2_TEXTURES
|
||||
/* next power of 2 size conversions */
|
||||
/* NOTE: I can do this in the above loop for faster operations, but some
|
||||
* texture packs require a workaround. see HACKALERT in nextPow2().
|
||||
*/
|
||||
/* next power of 2 size conversions */
|
||||
/* NOTE: I can do this in the above loop for faster operations, but some
|
||||
* texture packs require a workaround. see HACKALERT in nextPow2().
|
||||
*/
|
||||
|
||||
TxReSample txReSample = new TxReSample; // XXX: temporary. move to a better place.
|
||||
TxReSample txReSample = new TxReSample; // XXX: temporary. move to a better place.
|
||||
|
||||
#if (POW2_TEXTURES == 2)
|
||||
if (!txReSample->nextPow2(&image, width, height, 32, 1)) {
|
||||
if (!txReSample->nextPow2(&image, width, height, 32, 1)) {
|
||||
#else
|
||||
if (!txReSample->nextPow2(&image, width, height, 32, 0)) {
|
||||
if (!txReSample->nextPow2(&image, width, height, 32, 0)) {
|
||||
#endif
|
||||
if (image) {
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
*width = 0;
|
||||
*height = 0;
|
||||
*format = 0;
|
||||
}
|
||||
if (image) {
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
*width = 0;
|
||||
*height = 0;
|
||||
*format = 0;
|
||||
}
|
||||
|
||||
delete txReSample;
|
||||
delete txReSample;
|
||||
|
||||
#endif /* POW2_TEXTURES */
|
||||
}
|
||||
|
@ -236,7 +236,7 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
|
|||
|
||||
#ifdef DEBUG
|
||||
if (!image) {
|
||||
DBG_INFO(80, L"Error: failed to load png image!\n");
|
||||
DBG_INFO(80, L"Error: failed to load png image!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -256,21 +256,21 @@ TxImage::writePNG(uint8* src, FILE* fp, int width, int height, int rowStride, ui
|
|||
//uint16 srcfmt, destfmt;
|
||||
|
||||
if (!src || !fp)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL);
|
||||
if (png_ptr == NULL)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
info_ptr = png_create_info_struct(png_ptr);
|
||||
if (info_ptr == NULL) {
|
||||
png_destroy_write_struct(&png_ptr, NULL);
|
||||
return 0;
|
||||
png_destroy_write_struct(&png_ptr, NULL);
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (setjmp(png_ptr->jmpbuf)) {
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
return 0;
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
png_init_io(png_ptr, fp);
|
||||
|
@ -287,84 +287,84 @@ TxImage::writePNG(uint8* src, FILE* fp, int width, int height, int rowStride, ui
|
|||
/* each channel is saved in 8bits for consistency */
|
||||
switch (format) {
|
||||
case 0x0002:/* RGBA5551 */
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 5;
|
||||
sig_bit.green = 5;
|
||||
sig_bit.blue = 5;
|
||||
sig_bit.alpha = 1;
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
break;
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 5;
|
||||
sig_bit.green = 5;
|
||||
sig_bit.blue = 5;
|
||||
sig_bit.alpha = 1;
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
break;
|
||||
case 0x0003:/* RGBA8888 */
|
||||
case 0x0302:/* IA88 */
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 8;
|
||||
sig_bit.green = 8;
|
||||
sig_bit.blue = 8;
|
||||
sig_bit.alpha = 8;
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
break;
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 8;
|
||||
sig_bit.green = 8;
|
||||
sig_bit.blue = 8;
|
||||
sig_bit.alpha = 8;
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
break;
|
||||
case 0x0300:/* IA31 */
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 3;
|
||||
sig_bit.green = 3;
|
||||
sig_bit.blue = 3;
|
||||
sig_bit.alpha = 1;
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
break;
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 3;
|
||||
sig_bit.green = 3;
|
||||
sig_bit.blue = 3;
|
||||
sig_bit.alpha = 1;
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
break;
|
||||
case 0x0301:/* IA44 */
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 4;
|
||||
sig_bit.green = 4;
|
||||
sig_bit.blue = 4;
|
||||
sig_bit.alpha = 4;
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
break;
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 4;
|
||||
sig_bit.green = 4;
|
||||
sig_bit.blue = 4;
|
||||
sig_bit.alpha = 4;
|
||||
color_type = PNG_COLOR_TYPE_RGB_ALPHA;
|
||||
break;
|
||||
case 0x0400:/* I4 */
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 4;
|
||||
sig_bit.green = 4;
|
||||
sig_bit.blue = 4;
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
break;
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 4;
|
||||
sig_bit.green = 4;
|
||||
sig_bit.blue = 4;
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
break;
|
||||
case 0x0401:/* I8 */
|
||||
case 0x0402:/* I16 */
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 8;
|
||||
sig_bit.green = 8;
|
||||
sig_bit.blue = 8;
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
break;
|
||||
bit_depth = 8;
|
||||
sig_bit.red = 8;
|
||||
sig_bit.green = 8;
|
||||
sig_bit.blue = 8;
|
||||
color_type = PNG_COLOR_TYPE_RGB;
|
||||
break;
|
||||
case 0x0200:/* CI4 */
|
||||
bit_depth = 8;
|
||||
num_palette = 16;
|
||||
color_type = PNG_COLOR_TYPE_PALETTE;
|
||||
break;
|
||||
bit_depth = 8;
|
||||
num_palette = 16;
|
||||
color_type = PNG_COLOR_TYPE_PALETTE;
|
||||
break;
|
||||
case 0x0201:/* CI8 */
|
||||
bit_depth = 8;
|
||||
num_palette = 256;
|
||||
color_type = PNG_COLOR_TYPE_PALETTE;
|
||||
break;
|
||||
bit_depth = 8;
|
||||
num_palette = 256;
|
||||
color_type = PNG_COLOR_TYPE_PALETTE;
|
||||
break;
|
||||
case 0x0102:/* YUV ? */
|
||||
case 0x0103:
|
||||
default:
|
||||
/* unsupported format */
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
return 0;
|
||||
/* unsupported format */
|
||||
png_destroy_write_struct(&png_ptr, &info_ptr);
|
||||
return 0;
|
||||
}
|
||||
|
||||
switch (color_type) {
|
||||
case PNG_COLOR_TYPE_RGB_ALPHA:
|
||||
case PNG_COLOR_TYPE_RGB:
|
||||
//row_bytes = (bit_depth * width) >> 1;
|
||||
row_bytes = rowStride;
|
||||
png_set_bgr(png_ptr);
|
||||
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
break;
|
||||
//row_bytes = (bit_depth * width) >> 1;
|
||||
row_bytes = rowStride;
|
||||
png_set_bgr(png_ptr);
|
||||
png_set_sBIT(png_ptr, info_ptr, &sig_bit);
|
||||
break;
|
||||
case PNG_COLOR_TYPE_PALETTE:
|
||||
//row_bytes = (bit_depth * width) >> 3;
|
||||
row_bytes = rowStride;
|
||||
png_set_PLTE(png_ptr, info_ptr, palette_ptr, num_palette);
|
||||
png_set_tRNS(png_ptr, info_ptr, trans_ptr, num_palette, 0);
|
||||
//row_bytes = (bit_depth * width) >> 3;
|
||||
row_bytes = rowStride;
|
||||
png_set_PLTE(png_ptr, info_ptr, palette_ptr, num_palette);
|
||||
png_set_tRNS(png_ptr, info_ptr, trans_ptr, num_palette, 0);
|
||||
}
|
||||
|
||||
//png_set_filter(png_ptr, 0, PNG_ALL_FILTERS);
|
||||
|
@ -376,15 +376,15 @@ TxImage::writePNG(uint8* src, FILE* fp, int width, int height, int rowStride, ui
|
|||
// png_set_packswap(png_ptr);
|
||||
|
||||
png_set_IHDR(png_ptr, info_ptr, width, height,
|
||||
bit_depth, color_type, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
bit_depth, color_type, PNG_INTERLACE_NONE,
|
||||
PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT);
|
||||
|
||||
//png_set_gAMA(png_ptr, info_ptr, 1.0);
|
||||
|
||||
png_write_info(png_ptr, info_ptr);
|
||||
for (i = 0; i < height; i++) {
|
||||
png_write_row(png_ptr, (png_bytep)src);
|
||||
src += row_bytes;
|
||||
png_write_row(png_ptr, (png_bytep)src);
|
||||
src += row_bytes;
|
||||
}
|
||||
png_write_end(png_ptr, info_ptr);
|
||||
|
||||
|
@ -404,26 +404,26 @@ TxImage::getBMPInfo(FILE* fp, BITMAPFILEHEADER* bmp_fhdr, BITMAPINFOHEADER* bmp_
|
|||
|
||||
/* is this a BMP file? */
|
||||
if (fread(&bmp_fhdr->bfType, 2, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (memcmp(&bmp_fhdr->bfType, "BM", 2) != 0)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* get file size */
|
||||
if (fread(&bmp_fhdr->bfSize, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* reserved 1 */
|
||||
if (fread(&bmp_fhdr->bfReserved1, 2, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* reserved 2 */
|
||||
if (fread(&bmp_fhdr->bfReserved2, 2, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* offset to the image data */
|
||||
if (fread(&bmp_fhdr->bfOffBits, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/*
|
||||
* read in BITMAPINFOHEADER
|
||||
|
@ -431,27 +431,27 @@ TxImage::getBMPInfo(FILE* fp, BITMAPFILEHEADER* bmp_fhdr, BITMAPINFOHEADER* bmp_
|
|||
|
||||
/* size of BITMAPINFOHEADER */
|
||||
if (fread(&bmp_ihdr->biSize, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* is this a Windows BMP? */
|
||||
if (bmp_ihdr->biSize != 40)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* width of the bitmap in pixels */
|
||||
if (fread(&bmp_ihdr->biWidth, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* height of the bitmap in pixels */
|
||||
if (fread(&bmp_ihdr->biHeight, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* number of planes (always 1) */
|
||||
if (fread(&bmp_ihdr->biPlanes, 2, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* number of bits-per-pixel. (1, 4, 8, 16, 24, 32) */
|
||||
if (fread(&bmp_ihdr->biBitCount, 2, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* compression for a compressed bottom-up bitmap
|
||||
* 0 : uncompressed format
|
||||
|
@ -460,27 +460,27 @@ TxImage::getBMPInfo(FILE* fp, BITMAPFILEHEADER* bmp_fhdr, BITMAPINFOHEADER* bmp_
|
|||
* 3 : bitfield
|
||||
*/
|
||||
if (fread(&bmp_ihdr->biCompression, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* size of the image in bytes */
|
||||
if (fread(&bmp_ihdr->biSizeImage, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* horizontal resolution in pixels-per-meter */
|
||||
if (fread(&bmp_ihdr->biXPelsPerMeter, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* vertical resolution in pixels-per-meter */
|
||||
if (fread(&bmp_ihdr->biYPelsPerMeter, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* number of color indexes in the color table that are actually used */
|
||||
if (fread(&bmp_ihdr->biClrUsed, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* the number of color indexes that are required for displaying */
|
||||
if (fread(&bmp_ihdr->biClrImportant, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -508,16 +508,16 @@ TxImage::readBMP(FILE* fp, int* width, int* height, uint16* format)
|
|||
|
||||
/* check if we have a valid bmp file */
|
||||
if (!fp)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
if (!getBMPInfo(fp, &bmp_fhdr, &bmp_ihdr)) {
|
||||
INFO(80, L"error reading bitmap file! bitmap image is corrupt.\n");
|
||||
return NULL;
|
||||
INFO(80, L"error reading bitmap file! bitmap image is corrupt.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBG_INFO(80, L"bmp format %d x %d bitdepth:%d compression:%x offset:%d\n",
|
||||
bmp_ihdr.biWidth, bmp_ihdr.biHeight, bmp_ihdr.biBitCount,
|
||||
bmp_ihdr.biCompression, bmp_fhdr.bfOffBits);
|
||||
bmp_ihdr.biWidth, bmp_ihdr.biHeight, bmp_ihdr.biBitCount,
|
||||
bmp_ihdr.biCompression, bmp_fhdr.bfOffBits);
|
||||
|
||||
/* rowStride in bytes */
|
||||
row_bytes = (bmp_ihdr.biWidth * bmp_ihdr.biBitCount) >> 3;
|
||||
|
@ -526,127 +526,127 @@ TxImage::readBMP(FILE* fp, int* width, int* height, uint16* format)
|
|||
|
||||
/* Rice hi-res textures */
|
||||
if (!(bmp_ihdr.biBitCount == 8 || bmp_ihdr.biBitCount == 4 || bmp_ihdr.biBitCount == 32 || bmp_ihdr.biBitCount == 24) ||
|
||||
bmp_ihdr.biCompression != 0) {
|
||||
DBG_INFO(80, L"Error: incompatible bitmap format!\n");
|
||||
return NULL;
|
||||
bmp_ihdr.biCompression != 0) {
|
||||
DBG_INFO(80, L"Error: incompatible bitmap format!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
switch (bmp_ihdr.biBitCount) {
|
||||
case 8:
|
||||
case 32:
|
||||
/* 8 bit, 32 bit bitmap */
|
||||
image = (uint8*)malloc(row_bytes * bmp_ihdr.biHeight);
|
||||
if (image) {
|
||||
tmpimage = image;
|
||||
pos = bmp_fhdr.bfOffBits + row_bytes * (bmp_ihdr.biHeight - 1);
|
||||
for (i = 0; i < bmp_ihdr.biHeight; i++) {
|
||||
/* read in image */
|
||||
fseek(fp, pos, SEEK_SET);
|
||||
fread(tmpimage, row_bytes, 1, fp);
|
||||
tmpimage += row_bytes;
|
||||
pos -= row_bytes;
|
||||
}
|
||||
}
|
||||
break;
|
||||
/* 8 bit, 32 bit bitmap */
|
||||
image = (uint8*)malloc(row_bytes * bmp_ihdr.biHeight);
|
||||
if (image) {
|
||||
tmpimage = image;
|
||||
pos = bmp_fhdr.bfOffBits + row_bytes * (bmp_ihdr.biHeight - 1);
|
||||
for (i = 0; i < bmp_ihdr.biHeight; i++) {
|
||||
/* read in image */
|
||||
fseek(fp, pos, SEEK_SET);
|
||||
fread(tmpimage, row_bytes, 1, fp);
|
||||
tmpimage += row_bytes;
|
||||
pos -= row_bytes;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 4:
|
||||
/* 4bit bitmap */
|
||||
image = (uint8*)malloc((row_bytes * bmp_ihdr.biHeight) << 1);
|
||||
image_row = (uint8*)malloc(row_bytes);
|
||||
if (image && image_row) {
|
||||
tmpimage = image;
|
||||
pos = bmp_fhdr.bfOffBits + row_bytes * (bmp_ihdr.biHeight - 1);
|
||||
for (i = 0; i < bmp_ihdr.biHeight; i++) {
|
||||
/* read in image */
|
||||
fseek(fp, pos, SEEK_SET);
|
||||
fread(image_row, row_bytes, 1, fp);
|
||||
/* expand 4bpp to 8bpp. stuff 4bit values into 8bit comps. */
|
||||
for (j = 0; j < row_bytes; j++) {
|
||||
tmpimage[j << 1] = image_row[j] & 0x0f;
|
||||
tmpimage[(j << 1) + 1] = (image_row[j] & 0xf0) >> 4;
|
||||
}
|
||||
tmpimage += (row_bytes << 1);
|
||||
pos -= row_bytes;
|
||||
}
|
||||
free(image_row);
|
||||
} else {
|
||||
if (image_row) free(image_row);
|
||||
if (image) free(image);
|
||||
image = NULL;
|
||||
}
|
||||
break;
|
||||
/* 4bit bitmap */
|
||||
image = (uint8*)malloc((row_bytes * bmp_ihdr.biHeight) << 1);
|
||||
image_row = (uint8*)malloc(row_bytes);
|
||||
if (image && image_row) {
|
||||
tmpimage = image;
|
||||
pos = bmp_fhdr.bfOffBits + row_bytes * (bmp_ihdr.biHeight - 1);
|
||||
for (i = 0; i < bmp_ihdr.biHeight; i++) {
|
||||
/* read in image */
|
||||
fseek(fp, pos, SEEK_SET);
|
||||
fread(image_row, row_bytes, 1, fp);
|
||||
/* expand 4bpp to 8bpp. stuff 4bit values into 8bit comps. */
|
||||
for (j = 0; j < row_bytes; j++) {
|
||||
tmpimage[j << 1] = image_row[j] & 0x0f;
|
||||
tmpimage[(j << 1) + 1] = (image_row[j] & 0xf0) >> 4;
|
||||
}
|
||||
tmpimage += (row_bytes << 1);
|
||||
pos -= row_bytes;
|
||||
}
|
||||
free(image_row);
|
||||
} else {
|
||||
if (image_row) free(image_row);
|
||||
if (image) free(image);
|
||||
image = NULL;
|
||||
}
|
||||
break;
|
||||
case 24:
|
||||
/* 24 bit bitmap */
|
||||
image = (uint8*)malloc((bmp_ihdr.biWidth * bmp_ihdr.biHeight) << 2);
|
||||
image_row = (uint8*)malloc(row_bytes);
|
||||
if (image && image_row) {
|
||||
tmpimage = image;
|
||||
pos = bmp_fhdr.bfOffBits + row_bytes * (bmp_ihdr.biHeight - 1);
|
||||
for (i = 0; i < bmp_ihdr.biHeight; i++) {
|
||||
/* read in image */
|
||||
fseek(fp, pos, SEEK_SET);
|
||||
fread(image_row, row_bytes, 1, fp);
|
||||
/* convert 24bpp to 32bpp. */
|
||||
for (j = 0; j < bmp_ihdr.biWidth; j++) {
|
||||
tmpimage[(j << 2)] = image_row[j * 3];
|
||||
tmpimage[(j << 2) + 1] = image_row[j * 3 + 1];
|
||||
tmpimage[(j << 2) + 2] = image_row[j * 3 + 2];
|
||||
tmpimage[(j << 2) + 3] = 0xFF;
|
||||
}
|
||||
tmpimage += (bmp_ihdr.biWidth << 2);
|
||||
pos -= row_bytes;
|
||||
}
|
||||
free(image_row);
|
||||
} else {
|
||||
if (image_row) free(image_row);
|
||||
if (image) free(image);
|
||||
image = NULL;
|
||||
}
|
||||
/* 24 bit bitmap */
|
||||
image = (uint8*)malloc((bmp_ihdr.biWidth * bmp_ihdr.biHeight) << 2);
|
||||
image_row = (uint8*)malloc(row_bytes);
|
||||
if (image && image_row) {
|
||||
tmpimage = image;
|
||||
pos = bmp_fhdr.bfOffBits + row_bytes * (bmp_ihdr.biHeight - 1);
|
||||
for (i = 0; i < bmp_ihdr.biHeight; i++) {
|
||||
/* read in image */
|
||||
fseek(fp, pos, SEEK_SET);
|
||||
fread(image_row, row_bytes, 1, fp);
|
||||
/* convert 24bpp to 32bpp. */
|
||||
for (j = 0; j < bmp_ihdr.biWidth; j++) {
|
||||
tmpimage[(j << 2)] = image_row[j * 3];
|
||||
tmpimage[(j << 2) + 1] = image_row[j * 3 + 1];
|
||||
tmpimage[(j << 2) + 2] = image_row[j * 3 + 2];
|
||||
tmpimage[(j << 2) + 3] = 0xFF;
|
||||
}
|
||||
tmpimage += (bmp_ihdr.biWidth << 2);
|
||||
pos -= row_bytes;
|
||||
}
|
||||
free(image_row);
|
||||
} else {
|
||||
if (image_row) free(image_row);
|
||||
if (image) free(image);
|
||||
image = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
if (image) {
|
||||
*width = (row_bytes << 3) / bmp_ihdr.biBitCount;
|
||||
*height = bmp_ihdr.biHeight;
|
||||
*width = (row_bytes << 3) / bmp_ihdr.biBitCount;
|
||||
*height = bmp_ihdr.biHeight;
|
||||
|
||||
switch (bmp_ihdr.biBitCount) {
|
||||
case 8:
|
||||
case 4:
|
||||
*format = GR_TEXFMT_P_8;
|
||||
break;
|
||||
case 32:
|
||||
case 24:
|
||||
*format = GR_TEXFMT_ARGB_8888;
|
||||
}
|
||||
switch (bmp_ihdr.biBitCount) {
|
||||
case 8:
|
||||
case 4:
|
||||
*format = GR_TEXFMT_P_8;
|
||||
break;
|
||||
case 32:
|
||||
case 24:
|
||||
*format = GR_TEXFMT_ARGB_8888;
|
||||
}
|
||||
|
||||
#if POW2_TEXTURES
|
||||
/* next power of 2 size conversions */
|
||||
/* NOTE: I can do this in the above loop for faster operations, but some
|
||||
* texture packs require a workaround. see HACKALERT in nextPow2().
|
||||
*/
|
||||
/* next power of 2 size conversions */
|
||||
/* NOTE: I can do this in the above loop for faster operations, but some
|
||||
* texture packs require a workaround. see HACKALERT in nextPow2().
|
||||
*/
|
||||
|
||||
TxReSample txReSample = new TxReSample; // XXX: temporary. move to a better place.
|
||||
TxReSample txReSample = new TxReSample; // XXX: temporary. move to a better place.
|
||||
|
||||
#if (POW2_TEXTURES == 2)
|
||||
if (!txReSample->nextPow2(&image, width, height, 8, 1)) {
|
||||
if (!txReSample->nextPow2(&image, width, height, 8, 1)) {
|
||||
#else
|
||||
if (!txReSample->nextPow2(&image, width, height, 8, 0)) {
|
||||
if (!txReSample->nextPow2(&image, width, height, 8, 0)) {
|
||||
#endif
|
||||
if (image) {
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
*width = 0;
|
||||
*height = 0;
|
||||
*format = 0;
|
||||
}
|
||||
if (image) {
|
||||
free(image);
|
||||
image = NULL;
|
||||
}
|
||||
*width = 0;
|
||||
*height = 0;
|
||||
*format = 0;
|
||||
}
|
||||
|
||||
delete txReSample;
|
||||
delete txReSample;
|
||||
|
||||
#endif /* POW2_TEXTURES */
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
if (!image) {
|
||||
DBG_INFO(80, L"Error: failed to load bmp image!\n");
|
||||
DBG_INFO(80, L"Error: failed to load bmp image!\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -662,67 +662,67 @@ TxImage::getDDSInfo(FILE *fp, DDSFILEHEADER *dds_fhdr)
|
|||
|
||||
/* is this a DDS file? */
|
||||
if (fread(&dds_fhdr->dwMagic, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (memcmp(&dds_fhdr->dwMagic, "DDS ", 4) != 0)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->dwSize, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* get file flags */
|
||||
if (fread(&dds_fhdr->dwFlags, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* height of dds in pixels */
|
||||
if (fread(&dds_fhdr->dwHeight, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
/* width of dds in pixels */
|
||||
if (fread(&dds_fhdr->dwWidth, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->dwLinearSize, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->dwDepth, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->dwMipMapCount, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->dwReserved1, 4 * 11, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->ddpf.dwSize, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->ddpf.dwFlags, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->ddpf.dwFourCC, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->ddpf.dwRGBBitCount, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->ddpf.dwRBitMask, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->ddpf.dwGBitMask, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->ddpf.dwBBitMask, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->ddpf.dwRGBAlphaBitMask, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->dwCaps1, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
if (fread(&dds_fhdr->dwCaps2, 4, 1, fp) != 1)
|
||||
return 0;
|
||||
return 0;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
@ -741,58 +741,58 @@ TxImage::readDDS(FILE* fp, int* width, int* height, uint16* format)
|
|||
|
||||
/* check if we have a valid dds file */
|
||||
if (!fp)
|
||||
return NULL;
|
||||
return NULL;
|
||||
|
||||
if (!getDDSInfo(fp, &dds_fhdr)) {
|
||||
INFO(80, L"error reading dds file! dds image is corrupt.\n");
|
||||
return NULL;
|
||||
INFO(80, L"error reading dds file! dds image is corrupt.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
DBG_INFO(80, L"dds format %d x %d HeaderSize %d LinearSize %d\n",
|
||||
dds_fhdr.dwWidth, dds_fhdr.dwHeight, dds_fhdr.dwSize, dds_fhdr.dwLinearSize);
|
||||
dds_fhdr.dwWidth, dds_fhdr.dwHeight, dds_fhdr.dwSize, dds_fhdr.dwLinearSize);
|
||||
|
||||
if (!(dds_fhdr.dwFlags & (DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT|DDSD_LINEARSIZE))) {
|
||||
DBG_INFO(80, L"Error: incompatible dds format!\n");
|
||||
return NULL;
|
||||
DBG_INFO(80, L"Error: incompatible dds format!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if ((dds_fhdr.dwFlags & DDSD_MIPMAPCOUNT) && dds_fhdr.dwMipMapCount != 1) {
|
||||
DBG_INFO(80, L"Error: mipmapped dds not supported!\n");
|
||||
return NULL;
|
||||
DBG_INFO(80, L"Error: mipmapped dds not supported!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!((dds_fhdr.ddpf.dwFlags & DDPF_FOURCC) && dds_fhdr.dwCaps2 == 0)) {
|
||||
DBG_INFO(80, L"Error: not fourcc standard texture!\n");
|
||||
return NULL;
|
||||
DBG_INFO(80, L"Error: not fourcc standard texture!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT1", 4) == 0) {
|
||||
DBG_INFO(80, L"DXT1 format\n");
|
||||
/* compensate for missing LinearSize */
|
||||
dds_fhdr.dwLinearSize = (dds_fhdr.dwWidth * dds_fhdr.dwHeight) >> 1;
|
||||
tmpformat = GR_TEXFMT_ARGB_CMP_DXT1;
|
||||
DBG_INFO(80, L"DXT1 format\n");
|
||||
/* compensate for missing LinearSize */
|
||||
dds_fhdr.dwLinearSize = (dds_fhdr.dwWidth * dds_fhdr.dwHeight) >> 1;
|
||||
tmpformat = GR_TEXFMT_ARGB_CMP_DXT1;
|
||||
} else if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT3", 4) == 0) {
|
||||
DBG_INFO(80, L"DXT3 format\n");
|
||||
dds_fhdr.dwLinearSize = dds_fhdr.dwWidth * dds_fhdr.dwHeight;
|
||||
tmpformat = GR_TEXFMT_ARGB_CMP_DXT3;
|
||||
DBG_INFO(80, L"DXT3 format\n");
|
||||
dds_fhdr.dwLinearSize = dds_fhdr.dwWidth * dds_fhdr.dwHeight;
|
||||
tmpformat = GR_TEXFMT_ARGB_CMP_DXT3;
|
||||
} else if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT5", 4) == 0) {
|
||||
DBG_INFO(80, L"DXT5 format\n");
|
||||
dds_fhdr.dwLinearSize = dds_fhdr.dwWidth * dds_fhdr.dwHeight;
|
||||
tmpformat = GR_TEXFMT_ARGB_CMP_DXT5;
|
||||
DBG_INFO(80, L"DXT5 format\n");
|
||||
dds_fhdr.dwLinearSize = dds_fhdr.dwWidth * dds_fhdr.dwHeight;
|
||||
tmpformat = GR_TEXFMT_ARGB_CMP_DXT5;
|
||||
} else {
|
||||
DBG_INFO(80, L"Error: not DXT1 or DXT3 or DXT5 format!\n");
|
||||
return NULL;
|
||||
DBG_INFO(80, L"Error: not DXT1 or DXT3 or DXT5 format!\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* read in image */
|
||||
image = (uint8*)malloc(dds_fhdr.dwLinearSize);
|
||||
if (image) {
|
||||
*width = dds_fhdr.dwWidth;
|
||||
*height = dds_fhdr.dwHeight;
|
||||
*format = tmpformat;
|
||||
*width = dds_fhdr.dwWidth;
|
||||
*height = dds_fhdr.dwHeight;
|
||||
*format = tmpformat;
|
||||
|
||||
fseek(fp, 128, SEEK_SET); /* size of header is 128 bytes */
|
||||
fread(image, dds_fhdr.dwLinearSize, 1, fp);
|
||||
fseek(fp, 128, SEEK_SET); /* size of header is 128 bytes */
|
||||
fread(image, dds_fhdr.dwLinearSize, 1, fp);
|
||||
}
|
||||
|
||||
return image;
|
||||
|
|
|
@ -51,11 +51,6 @@ typedef unsigned long uint32;
|
|||
#define GL_COMPRESSED_RGBA_S3TC_DXT3_EXT 0x83F2
|
||||
#define GL_COMPRESSED_RGBA_S3TC_DXT5_EXT 0x83F3
|
||||
|
||||
/* for explicit fxt1 compression */
|
||||
#define CC_CHROMA 0x0
|
||||
#define CC_HI 0x1
|
||||
#define CC_ALPHA 0x2
|
||||
|
||||
/* in-memory zlib texture compression */
|
||||
#define GR_TEXFMT_GZ 0x8000
|
||||
|
||||
|
|
|
@ -39,7 +39,6 @@ TxQuantize::TxQuantize()
|
|||
_numcore = _txUtil->getNumberofProcessors();
|
||||
|
||||
/* get dxtn extensions */
|
||||
_tx_compress_fxt1 = TxLoadLib::getInstance()->getfxtCompressTexFuncExt();
|
||||
_tx_compress_dxtn = TxLoadLib::getInstance()->getdxtCompressTexFuncExt();
|
||||
}
|
||||
|
||||
|
@ -955,86 +954,6 @@ TxQuantize::quantize(uint8* src, uint8* dest, int width, int height, uint16 srcf
|
|||
return 1;
|
||||
}
|
||||
|
||||
boolean
|
||||
TxQuantize::FXT1(uint8 *src, uint8 *dest,
|
||||
int srcwidth, int srcheight, uint16 srcformat,
|
||||
int *destwidth, int *destheight, uint16 *destformat)
|
||||
{
|
||||
/*
|
||||
* NOTE: src must be in ARGB8888 format, srcformat describes
|
||||
* the closest 16bbp representation of src.
|
||||
*
|
||||
* NOTE: I have modified the dxtn library to use ARGB format
|
||||
* which originaly was ABGR format.
|
||||
*/
|
||||
|
||||
boolean bRet = 0;
|
||||
|
||||
if (_tx_compress_fxt1 &&
|
||||
srcwidth >= 8 && srcheight >= 4) {
|
||||
/* compress to fxt1
|
||||
* width and height must be larger than 8 and 4 respectively
|
||||
*/
|
||||
int dstRowStride = ((srcwidth + 7) & ~7) << 1;
|
||||
int srcRowStride = (srcwidth << 2);
|
||||
|
||||
unsigned int numcore = _numcore;
|
||||
unsigned int blkrow = 0;
|
||||
while (numcore > 1 && blkrow == 0) {
|
||||
blkrow = (srcheight >> 2) / numcore;
|
||||
numcore--;
|
||||
}
|
||||
if (blkrow > 0 && numcore > 1) {
|
||||
boost::thread *thrd[MAX_NUMCORE];
|
||||
unsigned int i;
|
||||
int blkheight = blkrow << 2;
|
||||
unsigned int srcStride = (srcwidth * blkheight) << 2;
|
||||
unsigned int destStride = dstRowStride * blkrow;
|
||||
for (i = 0; i < numcore - 1; i++) {
|
||||
thrd[i] = new boost::thread(boost::bind(_tx_compress_fxt1,
|
||||
srcwidth,
|
||||
blkheight,
|
||||
4,
|
||||
src,
|
||||
srcRowStride,
|
||||
dest,
|
||||
dstRowStride));
|
||||
src += srcStride;
|
||||
dest += destStride;
|
||||
}
|
||||
thrd[i] = new boost::thread(boost::bind(_tx_compress_fxt1,
|
||||
srcwidth,
|
||||
srcheight - blkheight * i,
|
||||
4,
|
||||
src,
|
||||
srcRowStride,
|
||||
dest,
|
||||
dstRowStride));
|
||||
for (i = 0; i < numcore; i++) {
|
||||
thrd[i]->join();
|
||||
delete thrd[i];
|
||||
}
|
||||
} else {
|
||||
(*_tx_compress_fxt1)(srcwidth, /* width */
|
||||
srcheight, /* height */
|
||||
4, /* comps: ARGB8888=4, RGB888=3 */
|
||||
src, /* source */
|
||||
srcRowStride, /* width*comps */
|
||||
dest, /* destination */
|
||||
dstRowStride); /* 16 bytes per 8x4 texel */
|
||||
}
|
||||
|
||||
/* dxtn adjusts width and height to M8 and M4 respectively by replication */
|
||||
*destwidth = (srcwidth + 7) & ~7;
|
||||
*destheight = (srcheight + 3) & ~3;
|
||||
*destformat = GR_TEXFMT_ARGB_CMP_FXT1;
|
||||
|
||||
bRet = 1;
|
||||
}
|
||||
|
||||
return bRet;
|
||||
}
|
||||
|
||||
boolean
|
||||
TxQuantize::DXTn(uint8 *src, uint8 *dest,
|
||||
int srcwidth, int srcheight, uint16 srcformat,
|
||||
|
@ -1151,11 +1070,6 @@ TxQuantize::compress(uint8 *src, uint8 *dest,
|
|||
boolean bRet = 0;
|
||||
|
||||
switch (compressionType) {
|
||||
case FXT1_COMPRESSION:
|
||||
bRet = FXT1(src, dest,
|
||||
srcwidth, srcheight, srcformat,
|
||||
destwidth, destheight, destformat);
|
||||
break;
|
||||
case S3TC_COMPRESSION:
|
||||
bRet = DXTn(src, dest,
|
||||
srcwidth, srcheight, srcformat,
|
||||
|
|
|
@ -37,7 +37,6 @@ private:
|
|||
TxUtil *_txUtil;
|
||||
int _numcore;
|
||||
|
||||
fxtCompressTexFuncExt _tx_compress_fxt1;
|
||||
dxtCompressTexFuncExt _tx_compress_dxtn;
|
||||
|
||||
/* fast optimized... well, sort of. */
|
||||
|
@ -64,12 +63,9 @@ private:
|
|||
void ARGB8888_I8_Slow(uint32* src, uint32* dst, int width, int height);
|
||||
|
||||
/* compressors */
|
||||
boolean FXT1(uint8 *src, uint8 *dest,
|
||||
int srcwidth, int srcheight, uint16 srcformat,
|
||||
int *destwidth, int *destheight, uint16 *destformat);
|
||||
boolean DXTn(uint8 *src, uint8 *dest,
|
||||
int srcwidth, int srcheight, uint16 srcformat,
|
||||
int *destwidth, int *destheight, uint16 *destformat);
|
||||
int srcwidth, int srcheight, uint16 srcformat,
|
||||
int *destwidth, int *destheight, uint16 *destformat);
|
||||
|
||||
public:
|
||||
TxQuantize();
|
||||
|
@ -81,15 +77,15 @@ public:
|
|||
boolean quantize(uint8* src, uint8* dest, int width, int height, uint16 srcformat, uint16 destformat, boolean fastQuantizer = 1);
|
||||
|
||||
boolean compress(uint8 *src, uint8 *dest,
|
||||
int srcwidth, int srcheight, uint16 srcformat,
|
||||
int *destwidth, int *destheight, uint16 *destformat,
|
||||
int compressionType);
|
||||
int srcwidth, int srcheight, uint16 srcformat,
|
||||
int *destwidth, int *destheight, uint16 *destformat,
|
||||
int compressionType);
|
||||
|
||||
|
||||
#if 0 /* unused */
|
||||
void ARGB8888_I8(uint32* src, uint32* dst, int width, int height);
|
||||
void I8_ARGB8888(uint32* src, uint32* dst, int width, int height);
|
||||
|
||||
|
||||
void ARGB1555_ABGR8888(uint32* src, uint32* dst, int width, int height);
|
||||
void ARGB4444_ABGR8888(uint32* src, uint32* dst, int width, int height);
|
||||
void ARGB8888_ABGR8888(uint32* src, uint32* dst, int width, int height);
|
||||
|
|
|
@ -31,22 +31,7 @@
|
|||
******************************************************************************/
|
||||
TxLoadLib::TxLoadLib()
|
||||
{
|
||||
#ifdef DXTN_DLL
|
||||
if (!_dxtnlib)
|
||||
_dxtnlib = LoadLibrary("dxtn");
|
||||
|
||||
if (_dxtnlib) {
|
||||
if (!_tx_compress_dxtn)
|
||||
_tx_compress_dxtn = (dxtCompressTexFuncExt)DLSYM(_dxtnlib, "tx_compress_dxtn");
|
||||
|
||||
if (!_tx_compress_fxt1)
|
||||
_tx_compress_fxt1 = (fxtCompressTexFuncExt)DLSYM(_dxtnlib, "fxt1_encode");
|
||||
}
|
||||
#else
|
||||
_tx_compress_dxtn = tx_compress_dxtn;
|
||||
_tx_compress_fxt1 = fxt1_encode;
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
TxLoadLib::~TxLoadLib()
|
||||
|
@ -59,12 +44,6 @@ TxLoadLib::~TxLoadLib()
|
|||
|
||||
}
|
||||
|
||||
fxtCompressTexFuncExt
|
||||
TxLoadLib::getfxtCompressTexFuncExt()
|
||||
{
|
||||
return _tx_compress_fxt1;
|
||||
}
|
||||
|
||||
dxtCompressTexFuncExt
|
||||
TxLoadLib::getdxtCompressTexFuncExt()
|
||||
{
|
||||
|
@ -96,9 +75,6 @@ TxUtil::sizeofTx(int width, int height, uint16 format)
|
|||
|
||||
/* a lookup table for the shifts would be better */
|
||||
switch (format) {
|
||||
case GR_TEXFMT_ARGB_CMP_FXT1:
|
||||
dataSize = (((width + 0x7) & ~0x7) * ((height + 0x3) & ~0x3)) >> 1;
|
||||
break;
|
||||
case GR_TEXFMT_ARGB_CMP_DXT1:
|
||||
dataSize = (((width + 0x3) & ~0x3) * ((height + 0x3) & ~0x3)) >> 1;
|
||||
break;
|
||||
|
|
|
@ -35,25 +35,18 @@
|
|||
extern "C"{
|
||||
#endif
|
||||
void tx_compress_dxtn(int srccomps, int width, int height,
|
||||
const void *source, int destformat, void *dest,
|
||||
int destRowStride);
|
||||
const void *source, int destformat, void *dest,
|
||||
int destRowStride);
|
||||
|
||||
int fxt1_encode(int width, int height, int comps,
|
||||
const void *source, int srcRowStride,
|
||||
void *dest, int destRowStride);
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
#endif /* DXTN_DLL */
|
||||
|
||||
typedef void (*dxtCompressTexFuncExt)(int srccomps, int width,
|
||||
int height, const void *srcPixData,
|
||||
int destformat, void *dest,
|
||||
int dstRowStride);
|
||||
|
||||
typedef int (*fxtCompressTexFuncExt)(int width, int height, int comps,
|
||||
const void *source, int srcRowStride,
|
||||
void *dest, int destRowStride);
|
||||
int height, const void *srcPixData,
|
||||
int destformat, void *dest,
|
||||
int dstRowStride);
|
||||
|
||||
class TxLoadLib
|
||||
{
|
||||
|
@ -61,16 +54,14 @@ private:
|
|||
#ifdef DXTN_DLL
|
||||
HMODULE _dxtnlib;
|
||||
#endif
|
||||
fxtCompressTexFuncExt _tx_compress_fxt1;
|
||||
dxtCompressTexFuncExt _tx_compress_dxtn;
|
||||
TxLoadLib();
|
||||
public:
|
||||
static TxLoadLib* getInstance() {
|
||||
static TxLoadLib txLoadLib;
|
||||
return &txLoadLib;
|
||||
static TxLoadLib txLoadLib;
|
||||
return &txLoadLib;
|
||||
}
|
||||
~TxLoadLib();
|
||||
fxtCompressTexFuncExt getfxtCompressTexFuncExt();
|
||||
dxtCompressTexFuncExt getdxtCompressTexFuncExt();
|
||||
};
|
||||
|
||||
|
@ -81,9 +72,9 @@ private:
|
|||
uint32 Adler32(const uint8* src, int width, int height, int size, int rowStride);
|
||||
uint32 RiceCRC32(const uint8* src, int width, int height, int size, int rowStride);
|
||||
boolean RiceCRC32_CI4(const uint8* src, int width, int height, int size, int rowStride,
|
||||
uint32* crc32, uint32* cimax);
|
||||
uint32* crc32, uint32* cimax);
|
||||
boolean RiceCRC32_CI8(const uint8* src, int width, int height, int size, int rowStride,
|
||||
uint32* crc32, uint32* cimax);
|
||||
uint32* crc32, uint32* cimax);
|
||||
int log2(int num);
|
||||
public:
|
||||
TxUtil() { }
|
||||
|
@ -108,8 +99,8 @@ private:
|
|||
TxMemBuf();
|
||||
public:
|
||||
static TxMemBuf* getInstance() {
|
||||
static TxMemBuf txMemBuf;
|
||||
return &txMemBuf;
|
||||
static TxMemBuf txMemBuf;
|
||||
return &txMemBuf;
|
||||
}
|
||||
~TxMemBuf();
|
||||
boolean init(int maxwidth, int maxheight);
|
||||
|
|
Loading…
Reference in New Issue
Block a user