[Glide64] Make Hi Res logs use char instead of wchar_t

This commit is contained in:
zilmar 2016-03-10 22:14:33 +11:00
parent 68a8ed0369
commit 043f0465cb
9 changed files with 169 additions and 161 deletions

View File

@ -160,7 +160,7 @@ struct GHQTexInfo {
* } * }
*/ */
#define INFO_BUF 4095 #define INFO_BUF 4095
typedef void (*dispInfoFuncExt)(const wchar_t *format, ...); typedef void (*dispInfoFuncExt)(const char *format, ...);
#ifndef TXFILTER_DLL #ifndef TXFILTER_DLL
boolean ext_ghq_init(int maxwidth, /* maximum texture width supported by hardware */ boolean ext_ghq_init(int maxwidth, /* maximum texture width supported by hardware */

View File

@ -103,11 +103,11 @@ TxCache::add(uint64 checksum, GHQTexInfo *info, int dataSize)
if (compress2(dest, &destLen, info->data, dataSize, 1) != Z_OK) if (compress2(dest, &destLen, info->data, dataSize, 1) != Z_OK)
{ {
dest = info->data; dest = info->data;
DBG_INFO(80, L"Error: zlib compression failed!\n"); DBG_INFO(80, "Error: zlib compression failed!\n");
} }
else else
{ {
DBG_INFO(80, L"zlib compressed: %.02fkb->%.02fkb\n", (float)dataSize / 1000, (float)destLen / 1000); DBG_INFO(80, "zlib compressed: %.02fkb->%.02fkb\n", (float)dataSize / 1000, (float)destLen / 1000);
dataSize = destLen; dataSize = destLen;
format |= GR_TEXFMT_GZ; format |= GR_TEXFMT_GZ;
} }
@ -143,7 +143,7 @@ TxCache::add(uint64 checksum, GHQTexInfo *info, int dataSize)
/* remove from _cachelist */ /* remove from _cachelist */
_cachelist.erase(_cachelist.begin(), itList); _cachelist.erase(_cachelist.begin(), itList);
DBG_INFO(80, L"+++++++++\n"); DBG_INFO(80, "+++++++++\n");
} }
_totalSize -= dataSize; _totalSize -= dataSize;
} }
@ -176,25 +176,25 @@ TxCache::add(uint64 checksum, GHQTexInfo *info, int dataSize)
_cache.insert(std::map<uint64, TXCACHE*>::value_type(checksum, txCache)); _cache.insert(std::map<uint64, TXCACHE*>::value_type(checksum, txCache));
#ifdef DEBUG #ifdef DEBUG
DBG_INFO(80, L"[%5d] added!! crc:%08X %08X %d x %d gfmt:%x total:%.02fmb\n", DBG_INFO(80, "[%5d] added!! crc:%08X %08X %d x %d gfmt:%x total:%.02fmb\n",
_cache.size(), (uint32)(checksum >> 32), (uint32)(checksum & 0xffffffff), _cache.size(), (uint32)(checksum >> 32), (uint32)(checksum & 0xffffffff),
info->width, info->height, info->format, (float)_totalSize / 1000000); info->width, info->height, info->format, (float)_totalSize / 1000000);
DBG_INFO(80, L"smalllodlog2:%d largelodlog2:%d aspectratiolog2:%d\n", DBG_INFO(80, "smalllodlog2:%d largelodlog2:%d aspectratiolog2:%d\n",
txCache->info.smallLodLog2, txCache->info.largeLodLog2, txCache->info.aspectRatioLog2); txCache->info.smallLodLog2, txCache->info.largeLodLog2, txCache->info.aspectRatioLog2);
if (info->tiles) if (info->tiles)
{ {
DBG_INFO(80, L"tiles:%d un-tiled size:%d x %d\n", info->tiles, info->untiled_width, info->untiled_height); DBG_INFO(80, "tiles:%d un-tiled size:%d x %d\n", info->tiles, info->untiled_width, info->untiled_height);
} }
if (_cacheSize > 0) if (_cacheSize > 0)
{ {
DBG_INFO(80, L"cache max config:%.02fmb\n", (float)_cacheSize / 1000000); DBG_INFO(80, "cache max config:%.02fmb\n", (float)_cacheSize / 1000000);
if (_cache.size() != _cachelist.size()) if (_cache.size() != _cachelist.size())
{ {
DBG_INFO(80, L"Error: cache/cachelist mismatch! (%d/%d)\n", _cache.size(), _cachelist.size()); DBG_INFO(80, "Error: cache/cachelist mismatch! (%d/%d)\n", _cache.size(), _cachelist.size());
} }
} }
#endif #endif
@ -237,12 +237,12 @@ TxCache::get(uint64 checksum, GHQTexInfo *info)
uint8 *dest = (_gzdest0 == info->data) ? _gzdest1 : _gzdest0; uint8 *dest = (_gzdest0 == info->data) ? _gzdest1 : _gzdest0;
if (uncompress(dest, &destLen, info->data, ((*itMap).second)->size) != Z_OK) if (uncompress(dest, &destLen, info->data, ((*itMap).second)->size) != Z_OK)
{ {
DBG_INFO(80, L"Error: zlib decompression failed!\n"); DBG_INFO(80, "Error: zlib decompression failed!\n");
return 0; return 0;
} }
info->data = dest; info->data = dest;
info->format &= ~GR_TEXFMT_GZ; info->format &= ~GR_TEXFMT_GZ;
DBG_INFO(80, L"zlib decompressed: %.02fkb->%.02fkb\n", (float)(((*itMap).second)->size) / 1000, (float)destLen / 1000); DBG_INFO(80, "zlib decompressed: %.02fkb->%.02fkb\n", (float)(((*itMap).second)->size) / 1000, (float)destLen / 1000);
} }
return 1; return 1;
} }
@ -256,7 +256,7 @@ boolean TxCache::save(const char *path, const char *filename, int config)
CPath(path, "").DirectoryCreate(); CPath(path, "").DirectoryCreate();
gzFile gzfp = gzopen(CPath(path, filename), "wb1"); gzFile gzfp = gzopen(CPath(path, filename), "wb1");
DBG_INFO(80, L"gzfp:%x file:%ls\n", gzfp, filename); DBG_INFO(80, "gzfp:%x file:%ls\n", gzfp, filename);
if (gzfp) if (gzfp)
{ {
/* write header to determine config match */ /* write header to determine config match */
@ -314,7 +314,7 @@ boolean TxCache::save(const char *path, const char *filename, int config)
/* not ready yet */ /* not ready yet */
/*if (_callback) /*if (_callback)
(*_callback)(L"Total textures saved to HDD: %d\n", std::distance(itMap, _cache.begin()));*/ (*_callback)("Total textures saved to HDD: %d\n", std::distance(itMap, _cache.begin()));*/
} }
gzclose(gzfp); gzclose(gzfp);
} }
@ -328,7 +328,7 @@ boolean TxCache::load(const char *path, const char *filename, int config)
CPath cbuf(path, filename); CPath cbuf(path, filename);
gzFile gzfp = gzopen(cbuf, "rb"); gzFile gzfp = gzopen(cbuf, "rb");
DBG_INFO(80, L"gzfp:%x file:%ls\n", gzfp, filename); DBG_INFO(80, "gzfp:%x file:%ls\n", gzfp, filename);
if (gzfp) if (gzfp)
{ {
/* yep, we have it. load it into memory cache. */ /* yep, we have it. load it into memory cache. */
@ -380,7 +380,7 @@ boolean TxCache::load(const char *path, const char *filename, int config)
/* skip in between to prevent the loop from being tied down to vsync */ /* skip in between to prevent the loop from being tied down to vsync */
if (_callback && (!(_cache.size() % 100) || gzeof(gzfp))) if (_callback && (!(_cache.size() % 100) || gzeof(gzfp)))
(*_callback)(L"[%d] total mem:%.02fmb - %ls\n", _cache.size(), (float)_totalSize / 1000000, filename); (*_callback)("[%d] total mem:%.02fmb - %ls\n", _cache.size(), (float)_totalSize / 1000000, filename);
} while (!gzeof(gzfp)); } while (!gzeof(gzfp));
gzclose(gzfp); gzclose(gzfp);
} }
@ -404,7 +404,7 @@ boolean TxCache::del(uint64 checksum)
delete (*itMap).second; delete (*itMap).second;
_cache.erase(itMap); _cache.erase(itMap);
DBG_INFO(80, L"removed from cache: checksum = %08X %08X\n", (uint32)(checksum & 0xffffffff), (uint32)(checksum >> 32)); DBG_INFO(80, "removed from cache: checksum = %08X %08X\n", (uint32)(checksum & 0xffffffff), (uint32)(checksum >> 32));
return 1; return 1;
} }

View File

@ -28,18 +28,26 @@
#include <stdarg.h> #include <stdarg.h>
#include <Common/StdString.h> #include <Common/StdString.h>
#include <Common/path.h> #include <Common/path.h>
#include <Glide64/Config.h>
#include <Settings/Settings.h>
TxDbg::TxDbg() TxDbg::TxDbg()
{ {
char log_dir[260];
memset(log_dir, 0, sizeof(log_dir));
if (Set_log_dir != 0)
{
GetSystemSettingSz(Set_log_dir, log_dir, sizeof(log_dir));
}
_level = DBG_LEVEL; _level = DBG_LEVEL;
CPath Dir(CPath::MODULE_DIRECTORY, "");
Dir.AppendDirectory("Logs");
if (!_dbgfile) if (!_dbgfile)
#ifdef GHQCHK #ifdef GHQCHK
_dbgfile = fopen(CPath(Dir,"ghqchk.txt"), "w"); _dbgfile = fopen(CPath(log_dir, "ghqchk.txt"), "w");
#else #else
_dbgfile = fopen(CPath((LPCSTR)Dir, "glidehq.dbg"), "w"); _dbgfile = fopen(CPath((LPCSTR)log_dir, "glidehq.dbg"), "w");
#endif #endif
} }
@ -54,16 +62,16 @@ TxDbg::~TxDbg()
} }
void void
TxDbg::output(const int level, const wchar_t *format, ...) TxDbg::output(const int level, const char *format, ...)
{ {
if (level > _level) if (level > _level)
return; return;
stdstr_f newformat("%d:\t%s", level, stdstr().FromUTF16(format).c_str()); stdstr_f newformat("%d:\t%s", level, format);
va_list args; va_list args;
va_start(args, format); va_start(args, format);
vfwprintf(_dbgfile, newformat.ToUTF16().c_str(), args); vfprintf(_dbgfile, newformat.c_str(), args);
fflush(_dbgfile); fflush(_dbgfile);
va_end(args); va_end(args);
} }

View File

@ -39,7 +39,7 @@ public:
return &txDbg; return &txDbg;
} }
~TxDbg(); ~TxDbg();
void output(const int level, const wchar_t *format, ...); void output(const int level, const char *format, ...);
}; };
#ifdef DEBUG #ifdef DEBUG

View File

@ -82,18 +82,18 @@ TxFilter::TxFilter(int maxwidth, int maxheight, int maxbpp, int options,
/* shamelessness :P this first call to the debug output message creates /* shamelessness :P this first call to the debug output message creates
* a file in the executable directory. */ * a file in the executable directory. */
INFO(0, L"------------------------------------------------------------------\n"); INFO(0, "------------------------------------------------------------------\n");
#ifdef GHQCHK #ifdef GHQCHK
INFO(0, L" GlideHQ Hires Texture Checker 1.02.00.%d\n", 0); INFO(0, " GlideHQ Hires Texture Checker 1.02.00.%d\n", 0);
#else #else
INFO(0, L" GlideHQ version 1.02.00.%d\n", 0); INFO(0, " GlideHQ version 1.02.00.%d\n", 0);
#endif #endif
INFO(0, L" Copyright (C) 2010 Hiroshi Morii All Rights Reserved\n"); INFO(0, " Copyright (C) 2010 Hiroshi Morii All Rights Reserved\n");
INFO(0, L" email : koolsmoky(at)users.sourceforge.net\n"); INFO(0, " email : koolsmoky(at)users.sourceforge.net\n");
INFO(0, L" website : http://www.3dfxzone.it/koolsmoky\n"); INFO(0, " website : http://www.3dfxzone.it/koolsmoky\n");
INFO(0, L"\n"); INFO(0, "\n");
INFO(0, L" Glide64 official website : http://glide64.emuxhaven.net\n"); INFO(0, " Glide64 official website : http://glide64.emuxhaven.net\n");
INFO(0, L"------------------------------------------------------------------\n"); INFO(0, "------------------------------------------------------------------\n");
_options = options; _options = options;
@ -189,14 +189,14 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
if (!g64crc) if (!g64crc)
g64crc = (uint64)(_txUtil->checksumTx(texture, srcwidth, srcheight, srcformat)); g64crc = (uint64)(_txUtil->checksumTx(texture, srcwidth, srcheight, srcformat));
DBG_INFO(80, L"filter: crc:%08X %08X %d x %d gfmt:%x\n", DBG_INFO(80, "filter: crc:%08X %08X %d x %d gfmt:%x\n",
(uint32)(g64crc >> 32), (uint32)(g64crc & 0xffffffff), srcwidth, srcheight, srcformat); (uint32)(g64crc >> 32), (uint32)(g64crc & 0xffffffff), srcwidth, srcheight, srcformat);
#if 0 /* use hirestex to retrieve cached textures. */ #if 0 /* use hirestex to retrieve cached textures. */
/* check if we have it in cache */ /* check if we have it in cache */
if (!(g64crc & 0xffffffff00000000) && /* we reach here only when there is no hires texture for this crc */ if (!(g64crc & 0xffffffff00000000) && /* we reach here only when there is no hires texture for this crc */
_txTexCache->get(g64crc, info)) { _txTexCache->get(g64crc, info)) {
DBG_INFO(80, L"cache hit: %d x %d gfmt:%x\n", info->width, info->height, info->format); DBG_INFO(80, "cache hit: %d x %d gfmt:%x\n", info->width, info->height, info->format);
return 1; /* yep, we've got it */ return 1; /* yep, we've got it */
} }
#endif #endif
@ -215,7 +215,7 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
#endif #endif
if (srcformat != GR_TEXFMT_ARGB_8888) { if (srcformat != GR_TEXFMT_ARGB_8888) {
if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, 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); DBG_INFO(80, "Error: unsupported format! gfmt:%x\n", srcformat);
return 0; return 0;
} }
texture = tmptex; texture = tmptex;
@ -336,7 +336,7 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
if (srcformat != GR_TEXFMT_ARGB_8888) { if (srcformat != GR_TEXFMT_ARGB_8888) {
tmptex = (texture == _tex1) ? _tex2 : _tex1; tmptex = (texture == _tex1) ? _tex2 : _tex1;
if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, GR_TEXFMT_ARGB_8888, srcformat)) { if (!_txQuantize->quantize(texture, tmptex, srcwidth, srcheight, GR_TEXFMT_ARGB_8888, srcformat)) {
DBG_INFO(80, L"Error: unsupported format! gfmt:%x\n", srcformat); DBG_INFO(80, "Error: unsupported format! gfmt:%x\n", srcformat);
return 0; return 0;
} }
texture = tmptex; texture = tmptex;
@ -437,7 +437,7 @@ TxFilter::filter(uint8 *src, int srcwidth, int srcheight, uint16 srcformat, uint
/* cache the texture. */ /* cache the texture. */
if (_cacheSize) _txTexCache->add(g64crc, info); if (_cacheSize) _txTexCache->add(g64crc, info);
DBG_INFO(80, L"filtered texture: %d x %d gfmt:%x\n", info->width, info->height, info->format); DBG_INFO(80, "filtered texture: %d x %d gfmt:%x\n", info->width, info->height, info->format);
return 1; return 1;
} }
@ -455,7 +455,7 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
* (can be any other crc if robust) * (can be any other crc if robust)
*/ */
DBG_INFO(80, L"hirestex: r_crc64:%08X %08X, g64crc:%08X %08X\n", DBG_INFO(80, "hirestex: r_crc64:%08X %08X, g64crc:%08X %08X\n",
(uint32)(r_crc64 >> 32), (uint32)(r_crc64 & 0xffffffff), (uint32)(r_crc64 >> 32), (uint32)(r_crc64 & 0xffffffff),
(uint32)(g64crc >> 32), (uint32)(g64crc & 0xffffffff)); (uint32)(g64crc >> 32), (uint32)(g64crc & 0xffffffff));
@ -463,7 +463,7 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
/* check if we have it in hires memory cache. */ /* check if we have it in hires memory cache. */
if ((_options & HIRESTEXTURES_MASK) && r_crc64) { if ((_options & HIRESTEXTURES_MASK) && r_crc64) {
if (_txHiResCache->get(r_crc64, info)) { if (_txHiResCache->get(r_crc64, info)) {
DBG_INFO(80, L"hires hit: %d x %d gfmt:%x\n", info->width, info->height, info->format); DBG_INFO(80, "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 /* TODO: Enable emulation for special N64 combiner modes. There are few ways
* to get this done. Also applies for CI textures below. * to get this done. Also applies for CI textures below.
@ -490,7 +490,7 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
return 1; /* yep, got it */ return 1; /* yep, got it */
} }
if (_txHiResCache->get((r_crc64 & 0xffffffff), info)) { 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); DBG_INFO(80, "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 /* for true CI textures, we use the passed in palette to convert to
* ARGB1555 and add it to memory cache. * ARGB1555 and add it to memory cache.
@ -502,7 +502,7 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
* A comp comes before RGB comp. * A comp comes before RGB comp.
*/ */
if (palette && info->format == GR_TEXFMT_P_8) { if (palette && info->format == GR_TEXFMT_P_8) {
DBG_INFO(80, L"found GR_TEXFMT_P_8 format. Need conversion!!\n"); DBG_INFO(80, "found GR_TEXFMT_P_8 format. Need conversion!!\n");
int width = info->width; int width = info->width;
int height = info->height; int height = info->height;
@ -534,7 +534,7 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
} }
else { else {
/*if (!_txQuantize->quantize(texture, tmptex, info->width, info->height, GR_TEXFMT_ARGB_8888, GR_TEXFMT_ARGB_1555)) { /*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); DBG_INFO(80, "Error: unsupported format! gfmt:%x\n", format);
return 0; return 0;
}*/ }*/
texture = tmptex; texture = tmptex;
@ -557,7 +557,7 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
/* XXX: add to hires texture cache!!! */ /* XXX: add to hires texture cache!!! */
_txHiResCache->add(r_crc64, info); _txHiResCache->add(r_crc64, info);
DBG_INFO(80, L"GR_TEXFMT_P_8 loaded as gfmt:%x!\n", format); DBG_INFO(80, "GR_TEXFMT_P_8 loaded as gfmt:%x!\n", format);
} }
return 1; return 1;
@ -570,12 +570,12 @@ TxFilter::hirestex(uint64 g64crc, uint64 r_crc64, uint16 *palette, GHQTexInfo *i
{ {
if (_txTexCache->get(g64crc, info)) if (_txTexCache->get(g64crc, info))
{ {
DBG_INFO(80, L"cache hit: %d x %d gfmt:%x\n", info->width, info->height, info->format); DBG_INFO(80, "cache hit: %d x %d gfmt:%x\n", info->width, info->height, info->format);
return 1; /* yep, we've got it */ return 1; /* yep, we've got it */
} }
} }
DBG_INFO(80, L"no cache hits.\n"); DBG_INFO(80, "no cache hits.\n");
return 0; return 0;
} }
@ -601,8 +601,8 @@ TxFilter::dmptx(uint8 *src, int width, int height, int rowStridePixel, uint16 gf
{ {
return 0; return 0;
} }
DBG_INFO(80, L"gfmt = %02x n64fmt = %02x\n", gfmt, n64fmt); DBG_INFO(80, "gfmt = %02x n64fmt = %02x\n", gfmt, n64fmt);
DBG_INFO(80, L"hirestex: r_crc64:%08X %08X\n", DBG_INFO(80, "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)) if (!_txQuantize->quantize(src, _tex1, rowStridePixel, height, (gfmt & 0x00ff), GR_TEXFMT_ARGB_8888))
@ -659,7 +659,7 @@ TxFilter::dmptx(uint8 *src, int width, int height, int rowStridePixel, uint16 gf
boolean TxFilter::reloadhirestex() boolean TxFilter::reloadhirestex()
{ {
DBG_INFO(80, L"Reload hires textures from texture pack.\n"); DBG_INFO(80, "Reload hires textures from texture pack.\n");
if (_txHiResCache->load(0)) { if (_txHiResCache->load(0)) {
if (_txHiResCache->empty()) _options &= ~HIRESTEXTURES_MASK; if (_txHiResCache->empty()) _options &= ~HIRESTEXTURES_MASK;

View File

@ -149,16 +149,16 @@ TxHiResCache::load(boolean replace) /* 0 : reload, 1 : replace partial */
case GHQ_HIRESTEXTURES: case GHQ_HIRESTEXTURES:
break; break;
case RICE_HIRESTEXTURES: case RICE_HIRESTEXTURES:
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"using Rice hires texture format...\n"); INFO(80, "using Rice hires texture format...\n");
INFO(80, L" must be one of the following;\n"); INFO(80, " must be one of the following;\n");
INFO(80, L" 1) *_rgb.png + *_a.png\n"); INFO(80, " 1) *_rgb.png + *_a.png\n");
INFO(80, L" 2) *_all.png\n"); INFO(80, " 2) *_all.png\n");
INFO(80, L" 3) *_ciByRGBA.png\n"); INFO(80, " 3) *_ciByRGBA.png\n");
INFO(80, L" 4) *_allciByRGBA.png\n"); INFO(80, " 4) *_allciByRGBA.png\n");
INFO(80, L" 5) *_ci.bmp\n"); INFO(80, " 5) *_ci.bmp\n");
INFO(80, L" usage of only 2) and 3) highly recommended!\n"); INFO(80, " usage of only 2) and 3) highly recommended!\n");
INFO(80, L" folder names must be in US-ASCII characters!\n"); INFO(80, " folder names must be in US-ASCII characters!\n");
dir_path.AppendDirectory(_ident.c_str()); dir_path.AppendDirectory(_ident.c_str());
loadHiResTextures(dir_path, replace); loadHiResTextures(dir_path, replace);
@ -175,15 +175,15 @@ TxHiResCache::load(boolean replace) /* 0 : reload, 1 : replace partial */
boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace) boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
{ {
#ifdef _WIN32 #ifdef _WIN32
DBG_INFO(80, L"-----\n"); DBG_INFO(80, "-----\n");
DBG_INFO(80, L"path: %s\n", stdstr(dir_path).ToUTF16().c_str()); DBG_INFO(80, "path: %s\n", stdstr(dir_path).ToUTF16().c_str());
CPath TextureDir(dir_path, ""); CPath TextureDir(dir_path, "");
/* find it on disk */ /* find it on disk */
if (!TextureDir.DirectoryExists()) if (!TextureDir.DirectoryExists())
{ {
INFO(80, L"Error: path not found!\n"); INFO(80, "Error: path not found!\n");
return 0; return 0;
} }
@ -205,13 +205,13 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
if (KBHIT(0x1B)) if (KBHIT(0x1B))
{ {
_abortLoad = 1; _abortLoad = 1;
if (_callback) (*_callback)(L"Aborted loading hiresolution texture!\n"); if (_callback) (*_callback)("Aborted loading hiresolution texture!\n");
INFO(80, L"Error: aborted loading hiresolution texture!\n"); INFO(80, "Error: aborted loading hiresolution texture!\n");
} }
if (_abortLoad) break; if (_abortLoad) break;
DBG_INFO(80, L"-----\n"); DBG_INFO(80, "-----\n");
DBG_INFO(80, L"file: %ls\n", stdstr(TextureDir.GetNameExtension().c_str()).ToUTF16().c_str()); DBG_INFO(80, "file: %ls\n", stdstr(TextureDir.GetNameExtension().c_str()).ToUTF16().c_str());
int width = 0, height = 0; int width = 0, height = 0;
uint16 format = 0; uint16 format = 0;
@ -260,11 +260,11 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
pfname == strstr(fname, ".dds"))) pfname == strstr(fname, ".dds")))
{ {
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
INFO(80, L"Error: not png or bmp or dds!\n"); INFO(80, "Error: not png or bmp or dds!\n");
continue; continue;
} }
pfname = strstr(fname, ident.c_str()); pfname = strstr(fname, ident.c_str());
@ -279,20 +279,20 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
} }
if (!pfname) { if (!pfname) {
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
INFO(80, L"Error: not Rice texture naming convention!\n"); INFO(80, "Error: not Rice texture naming convention!\n");
continue; continue;
} }
if (!chksum) { if (!chksum) {
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
INFO(80, L"Error: crc32 = 0!\n"); INFO(80, "Error: crc32 = 0!\n");
continue; continue;
} }
@ -303,16 +303,16 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
chksum64 |= (uint64)chksum; chksum64 |= (uint64)chksum;
if (TxCache::is_cached(chksum64)) { if (TxCache::is_cached(chksum64)) {
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
INFO(80, L"Error: already cached! duplicate texture!\n"); INFO(80, "Error: already cached! duplicate texture!\n");
continue; continue;
} }
} }
DBG_INFO(80, L"rom: %ls chksum:%08X %08X fmt:%x size:%x\n", _ident.c_str(), chksum, palchksum, fmt, siz); DBG_INFO(80, "rom: %ls chksum:%08X %08X fmt:%x size:%x\n", _ident.c_str(), chksum, palchksum, fmt, siz);
/* Deal with the wackiness some texture packs utilize Rice format. /* Deal with the wackiness some texture packs utilize Rice format.
* Read in the following order: _a.* + _rgb.*, _all.png _ciByRGBA.png, * Read in the following order: _a.* + _rgb.*, _all.png _ciByRGBA.png,
@ -343,11 +343,11 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
if (!TargetFile.Exists()) if (!TargetFile.Exists())
{ {
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
INFO(80, L"Error: missing _rgb.*! _a.* must be paired with _rgb.*!\n"); INFO(80, "Error: missing _rgb.*! _a.* must be paired with _rgb.*!\n");
continue; continue;
} }
} }
@ -388,18 +388,18 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
if (!tex || width != tmpwidth || height != tmpheight || if (!tex || width != tmpwidth || height != tmpheight ||
format != GR_TEXFMT_ARGB_8888 || tmpformat != GR_TEXFMT_ARGB_8888) { format != GR_TEXFMT_ARGB_8888 || tmpformat != GR_TEXFMT_ARGB_8888) {
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
if (!tex) { if (!tex) {
INFO(80, L"Error: missing _rgb.*!\n"); INFO(80, "Error: missing _rgb.*!\n");
} }
else if (width != tmpwidth || height != tmpheight) { else if (width != tmpwidth || height != tmpheight) {
INFO(80, L"Error: _rgb.* and _a.* have mismatched width or height!\n"); INFO(80, "Error: _rgb.* and _a.* have mismatched width or height!\n");
} }
else if (format != GR_TEXFMT_ARGB_8888 || tmpformat != GR_TEXFMT_ARGB_8888) { else if (format != GR_TEXFMT_ARGB_8888 || tmpformat != GR_TEXFMT_ARGB_8888) {
INFO(80, L"Error: _rgb.* or _a.* not in 32bit color!\n"); INFO(80, "Error: _rgb.* or _a.* not in 32bit color!\n");
} }
if (tex) free(tex); if (tex) free(tex);
if (tmptex) free(tmptex); if (tmptex) free(tmptex);
@ -412,7 +412,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
if (tex) { if (tex) {
if (tmptex) { if (tmptex) {
/* merge (A)RGB and A comp */ /* merge (A)RGB and A comp */
DBG_INFO(80, L"merge (A)RGB and A comp\n"); DBG_INFO(80, "merge (A)RGB and A comp\n");
int i; int i;
for (i = 0; i < height * width; i++) { for (i = 0; i < height * width; i++) {
#if 1 #if 1
@ -443,11 +443,11 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
else { else {
/* clobber A comp. never a question of alpha. only RGB used. */ /* clobber A comp. never a question of alpha. only RGB used. */
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
INFO(80, L"Warning: missing _a.*! only using _rgb.*. treat as opaque texture.\n"); INFO(80, "Warning: missing _a.*! only using _rgb.*. treat as opaque texture.\n");
int i; int i;
for (i = 0; i < height * width; i++) { for (i = 0; i < height * width; i++) {
((uint32*)tex)[i] |= 0xff000000; ((uint32*)tex)[i] |= 0xff000000;
@ -492,11 +492,11 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
free(tex); free(tex);
tex = NULL; tex = NULL;
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
INFO(80, L"Error: W:H aspect ratio range not 8:1 - 1:8!\n"); INFO(80, "Error: W:H aspect ratio range not 8:1 - 1:8!\n");
continue; continue;
} }
if (width != _txReSample->nextPow2(width) || if (width != _txReSample->nextPow2(width) ||
@ -504,11 +504,11 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
free(tex); free(tex);
tex = NULL; tex = NULL;
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
INFO(80, L"Error: not power of 2 size!\n"); INFO(80, "Error: not power of 2 size!\n");
continue; continue;
} }
} }
@ -517,14 +517,14 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
/* if we do not have a texture at this point we are screwed */ /* if we do not have a texture at this point we are screwed */
if (!tex) { if (!tex) {
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
INFO(80, L"Error: load failed!\n"); INFO(80, "Error: load failed!\n");
continue; continue;
} }
DBG_INFO(80, L"read in as %d x %d gfmt:%x\n", tmpwidth, tmpheight, tmpformat); DBG_INFO(80, "read in as %d x %d gfmt:%x\n", tmpwidth, tmpheight, tmpformat);
/* check if size and format are OK */ /* check if size and format are OK */
if (!(format == GR_TEXFMT_ARGB_8888 || if (!(format == GR_TEXFMT_ARGB_8888 ||
@ -536,11 +536,11 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
free(tex); free(tex);
tex = NULL; tex = NULL;
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
INFO(80, L"Error: not width * height > 4 or 8bit palette color or 32bpp or dxt1 or dxt3 or dxt5!\n"); INFO(80, "Error: not width * height > 4 or 8bit palette color or 32bpp or dxt1 or dxt3 or dxt5!\n");
continue; continue;
} }
@ -560,7 +560,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
* meter. The same goes for fmt:2 textures. See Mollymutt's * meter. The same goes for fmt:2 textures. See Mollymutt's
* PaperMario text. */ * PaperMario text. */
if ((fmt == 0 && siz == 2) || fmt == 2) { if ((fmt == 0 && siz == 2) || fmt == 2) {
DBG_INFO(80, L"Remove black, white, etc borders along the alpha edges.\n"); DBG_INFO(80, "Remove black, white, etc borders along the alpha edges.\n");
/* round A comp */ /* round A comp */
for (i = 0; i < height * width; i++) { for (i = 0; i < height * width; i++) {
uint32 texel = ((uint32*)tex)[i]; uint32 texel = ((uint32*)tex)[i];
@ -647,7 +647,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
} }
if (!intensity && alphabits == 8) break; if (!intensity && alphabits == 8) break;
} }
DBG_INFO(80, L"required alpha bits:%d zero acomp texels:%d rgb as intensity:%d\n", alphabits, fullalpha, intensity); DBG_INFO(80, "required alpha bits:%d zero acomp texels:%d rgb as intensity:%d\n", alphabits, fullalpha, intensity);
/* preparations based on above analysis */ /* preparations based on above analysis */
#if !REDUCE_TEXTURE_FOOTPRINT #if !REDUCE_TEXTURE_FOOTPRINT
@ -683,7 +683,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
} }
} }
DBG_INFO(80, L"best gfmt:%x\n", destformat); DBG_INFO(80, "best gfmt:%x\n", destformat);
} }
/* /*
* Rice hi-res textures: end */ * Rice hi-res textures: end */
@ -706,26 +706,26 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
/* minification to enable glide64 style texture tiling */ /* minification to enable glide64 style texture tiling */
/* determine the minification ratio to tile the texture into 256x256 size */ /* determine the minification ratio to tile the texture into 256x256 size */
if ((_options & TILE_HIRESTEX) && _maxwidth >= 256 && _maxheight >= 256) { if ((_options & TILE_HIRESTEX) && _maxwidth >= 256 && _maxheight >= 256) {
DBG_INFO(80, L"determine minification ratio to tile\n"); DBG_INFO(80, "determine minification ratio to tile\n");
tmpwidth = width; tmpwidth = width;
tmpheight = height; tmpheight = height;
if (height > 256) { if (height > 256) {
ratio = ((height - 1) >> 8) + 1; ratio = ((height - 1) >> 8) + 1;
tmpwidth = width / ratio; tmpwidth = width / ratio;
tmpheight = height / ratio; tmpheight = height / ratio;
DBG_INFO(80, L"height > 256, minification ratio:%d %d x %d -> %d x %d\n", DBG_INFO(80, "height > 256, minification ratio:%d %d x %d -> %d x %d\n",
ratio, width, height, tmpwidth, tmpheight); ratio, width, height, tmpwidth, tmpheight);
} }
if (tmpwidth > 256 && (((tmpwidth - 1) >> 8) + 1) * tmpheight > 256) { if (tmpwidth > 256 && (((tmpwidth - 1) >> 8) + 1) * tmpheight > 256) {
ratio *= ((((((tmpwidth - 1) >> 8) + 1) * tmpheight) - 1) >> 8) + 1; ratio *= ((((((tmpwidth - 1) >> 8) + 1) * tmpheight) - 1) >> 8) + 1;
DBG_INFO(80, L"width > 256, minification ratio:%d %d x %d -> %d x %d\n", DBG_INFO(80, "width > 256, minification ratio:%d %d x %d -> %d x %d\n",
ratio, width, height, width / ratio, height / ratio); ratio, width, height, width / ratio, height / ratio);
} }
} }
else { else {
/* normal minification to fit max texture size */ /* normal minification to fit max texture size */
if (width > _maxwidth || height > _maxheight) { if (width > _maxwidth || height > _maxheight) {
DBG_INFO(80, L"determine minification ratio to fit max texture size\n"); DBG_INFO(80, "determine minification ratio to fit max texture size\n");
tmpwidth = width; tmpwidth = width;
tmpheight = height; tmpheight = height;
while (tmpwidth > _maxwidth) { while (tmpwidth > _maxwidth) {
@ -738,7 +738,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
tmpwidth >>= 1; tmpwidth >>= 1;
ratio <<= 1; ratio <<= 1;
} }
DBG_INFO(80, L"minification ratio:%d %d x %d -> %d x %d\n", DBG_INFO(80, "minification ratio:%d %d x %d -> %d x %d\n",
ratio, width, height, tmpwidth, tmpheight); ratio, width, height, tmpwidth, tmpheight);
} }
} }
@ -747,7 +747,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
if (!_txReSample->minify(&tex, &width, &height, ratio)) { if (!_txReSample->minify(&tex, &width, &height, ratio)) {
free(tex); free(tex);
tex = NULL; tex = NULL;
DBG_INFO(80, L"Error: minification failed!\n"); DBG_INFO(80, "Error: minification failed!\n");
continue; continue;
} }
} }
@ -796,7 +796,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
/* tile it! do the actual tiling into 256x256 size */ /* tile it! do the actual tiling into 256x256 size */
if (usetile) { if (usetile) {
DBG_INFO(80, L"Glide64 style texture tiling\n"); DBG_INFO(80, "Glide64 style texture tiling\n");
int x, y, z, ratio, offset; int x, y, z, ratio, offset;
offset = 0; offset = 0;
@ -825,7 +825,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
untiled_height = height; untiled_height = height;
width = 256; width = 256;
height *= ratio; height *= ratio;
DBG_INFO(80, L"Tiled: %d x %d -> %d x %d\n", untiled_width, untiled_height, width, height); DBG_INFO(80, "Tiled: %d x %d -> %d x %d\n", untiled_width, untiled_height, width, height);
} }
} }
} }
@ -843,7 +843,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
if (!_txReSample->minify(&tex, &width, &height, ratio)) { if (!_txReSample->minify(&tex, &width, &height, ratio)) {
free(tex); free(tex);
tex = NULL; tex = NULL;
DBG_INFO(80, L"Error: minification failed!\n"); DBG_INFO(80, "Error: minification failed!\n");
continue; continue;
} }
} }
@ -876,7 +876,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
#endif #endif
free(tex); free(tex);
tex = NULL; tex = NULL;
DBG_INFO(80, L"Error: aspect ratio adjustment failed!\n"); DBG_INFO(80, "Error: aspect ratio adjustment failed!\n");
continue; continue;
} }
#endif #endif
@ -960,7 +960,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
#endif #endif
free(tex); free(tex);
tex = NULL; tex = NULL;
DBG_INFO(80, L"Error: aspect ratio adjustment failed!\n"); DBG_INFO(80, "Error: aspect ratio adjustment failed!\n");
continue; continue;
} }
#endif #endif
@ -1016,17 +1016,17 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
/* last minute validations */ /* last minute validations */
if (!tex || !chksum || !width || !height || !format || width > _maxwidth || height > _maxheight) { if (!tex || !chksum || !width || !height || !format || width > _maxwidth || height > _maxheight) {
#if !DEBUG #if !DEBUG
INFO(80, L"-----\n"); INFO(80, "-----\n");
INFO(80, L"path: %ls\n", stdstr(dir_path).ToUTF16().c_str()); INFO(80, "path: %ls\n", stdstr(dir_path).ToUTF16().c_str());
INFO(80, L"file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str()); INFO(80, "file: %ls\n", TextureDir.GetNameExtension().ToUTF16().c_str());
#endif #endif
if (tex) { if (tex) {
free(tex); free(tex);
tex = NULL; tex = NULL;
INFO(80, L"Error: bad format or size! %d x %d gfmt:%x\n", width, height, format); INFO(80, "Error: bad format or size! %d x %d gfmt:%x\n", width, height, format);
} }
else { else {
INFO(80, L"Error: load failed!!\n"); INFO(80, "Error: load failed!!\n");
} }
continue; continue;
} }
@ -1060,7 +1060,7 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
/* remove redundant in cache */ /* remove redundant in cache */
if (replace && TxCache::del(chksum64)) { if (replace && TxCache::del(chksum64)) {
DBG_INFO(80, L"removed duplicate old cache.\n"); DBG_INFO(80, "removed duplicate old cache.\n");
} }
/* add to cache */ /* add to cache */
@ -1070,9 +1070,9 @@ boolean TxHiResCache::loadHiResTextures(const char * dir_path, boolean replace)
if (_callback) { if (_callback) {
wchar_t tmpbuf[MAX_PATH]; wchar_t tmpbuf[MAX_PATH];
mbstowcs(tmpbuf, fname, MAX_PATH); mbstowcs(tmpbuf, fname, MAX_PATH);
(*_callback)(L"[%d] total mem:%.2fmb - %ls\n", _cache.size(), (float)_totalSize / 1000000, tmpbuf); (*_callback)("[%d] total mem:%.2fmb - %ls\n", _cache.size(), (float)_totalSize / 1000000, tmpbuf);
} }
DBG_INFO(80, L"texture loaded!\n"); DBG_INFO(80, "texture loaded!\n");
} }
free(tex); free(tex);
} }

View File

@ -61,7 +61,7 @@ TxImage::getPNGInfo(FILE *fp, png_structp *png_ptr, png_infop *info_ptr)
} }
if (setjmp(png_jmpbuf(*png_ptr))) { if (setjmp(png_jmpbuf(*png_ptr))) {
DBG_INFO(80, L"error reading png!\n"); DBG_INFO(80, "error reading png!\n");
png_destroy_read_struct(png_ptr, info_ptr, NULL); png_destroy_read_struct(png_ptr, info_ptr, NULL);
return 0; return 0;
} }
@ -93,8 +93,9 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
if (!fp) if (!fp)
return NULL; return NULL;
if (!getPNGInfo(fp, &png_ptr, &info_ptr)) { if (!getPNGInfo(fp, &png_ptr, &info_ptr))
INFO(80, L"error reading png file! png image is corrupt.\n"); {
INFO(80, "error reading png file! png image is corrupt.\n");
return NULL; return NULL;
} }
@ -102,7 +103,7 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
(png_uint_32*)&o_width, (png_uint_32*)&o_height, &bit_depth, &color_type, (png_uint_32*)&o_width, (png_uint_32*)&o_height, &bit_depth, &color_type,
&interlace_type, &compression_type, &filter_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", DBG_INFO(80, "png format %d x %d bitdepth:%d color:%x interlace:%x compression:%x filter:%x\n",
o_width, o_height, bit_depth, color_type, o_width, o_height, bit_depth, color_type,
interlace_type, compression_type, filter_type); interlace_type, compression_type, filter_type);
@ -158,7 +159,7 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
/* punt invalid formats */ /* punt invalid formats */
if (color_type != PNG_COLOR_TYPE_RGB_ALPHA) { if (color_type != PNG_COLOR_TYPE_RGB_ALPHA) {
png_destroy_read_struct(&png_ptr, &info_ptr, NULL); png_destroy_read_struct(&png_ptr, &info_ptr, NULL);
DBG_INFO(80, L"Error: not PNG_COLOR_TYPE_RGB_ALPHA format!\n"); DBG_INFO(80, "Error: not PNG_COLOR_TYPE_RGB_ALPHA format!\n");
return NULL; return NULL;
} }
@ -236,7 +237,7 @@ TxImage::readPNG(FILE* fp, int* width, int* height, uint16* format)
#ifdef DEBUG #ifdef DEBUG
if (!image) { if (!image) {
DBG_INFO(80, L"Error: failed to load png image!\n"); DBG_INFO(80, "Error: failed to load png image!\n");
} }
#endif #endif
@ -512,11 +513,11 @@ TxImage::readBMP(FILE* fp, int* width, int* height, uint16* format)
return NULL; return NULL;
if (!getBMPInfo(fp, &bmp_fhdr, &bmp_ihdr)) { if (!getBMPInfo(fp, &bmp_fhdr, &bmp_ihdr)) {
INFO(80, L"error reading bitmap file! bitmap image is corrupt.\n"); INFO(80, "error reading bitmap file! bitmap image is corrupt.\n");
return NULL; return NULL;
} }
DBG_INFO(80, L"bmp format %d x %d bitdepth:%d compression:%x offset:%d\n", DBG_INFO(80, "bmp format %d x %d bitdepth:%d compression:%x offset:%d\n",
bmp_ihdr.biWidth, bmp_ihdr.biHeight, bmp_ihdr.biBitCount, bmp_ihdr.biWidth, bmp_ihdr.biHeight, bmp_ihdr.biBitCount,
bmp_ihdr.biCompression, bmp_fhdr.bfOffBits); bmp_ihdr.biCompression, bmp_fhdr.bfOffBits);
@ -528,7 +529,7 @@ TxImage::readBMP(FILE* fp, int* width, int* height, uint16* format)
/* Rice hi-res textures */ /* Rice hi-res textures */
if (!(bmp_ihdr.biBitCount == 8 || bmp_ihdr.biBitCount == 4 || bmp_ihdr.biBitCount == 32 || bmp_ihdr.biBitCount == 24) || if (!(bmp_ihdr.biBitCount == 8 || bmp_ihdr.biBitCount == 4 || bmp_ihdr.biBitCount == 32 || bmp_ihdr.biBitCount == 24) ||
bmp_ihdr.biCompression != 0) { bmp_ihdr.biCompression != 0) {
DBG_INFO(80, L"Error: incompatible bitmap format!\n"); DBG_INFO(80, "Error: incompatible bitmap format!\n");
return NULL; return NULL;
} }
@ -647,7 +648,7 @@ TxImage::readBMP(FILE* fp, int* width, int* height, uint16* format)
#ifdef DEBUG #ifdef DEBUG
if (!image) { if (!image) {
DBG_INFO(80, L"Error: failed to load bmp image!\n"); DBG_INFO(80, "Error: failed to load bmp image!\n");
} }
#endif #endif
@ -745,43 +746,43 @@ TxImage::readDDS(FILE* fp, int* width, int* height, uint16* format)
return NULL; return NULL;
if (!getDDSInfo(fp, &dds_fhdr)) { if (!getDDSInfo(fp, &dds_fhdr)) {
INFO(80, L"error reading dds file! dds image is corrupt.\n"); INFO(80, "error reading dds file! dds image is corrupt.\n");
return NULL; return NULL;
} }
DBG_INFO(80, L"dds format %d x %d HeaderSize %d LinearSize %d\n", DBG_INFO(80, "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))) { if (!(dds_fhdr.dwFlags & (DDSD_CAPS|DDSD_WIDTH|DDSD_HEIGHT|DDSD_PIXELFORMAT|DDSD_LINEARSIZE))) {
DBG_INFO(80, L"Error: incompatible dds format!\n"); DBG_INFO(80, "Error: incompatible dds format!\n");
return NULL; return NULL;
} }
if ((dds_fhdr.dwFlags & DDSD_MIPMAPCOUNT) && dds_fhdr.dwMipMapCount != 1) { if ((dds_fhdr.dwFlags & DDSD_MIPMAPCOUNT) && dds_fhdr.dwMipMapCount != 1) {
DBG_INFO(80, L"Error: mipmapped dds not supported!\n"); DBG_INFO(80, "Error: mipmapped dds not supported!\n");
return NULL; return NULL;
} }
if (!((dds_fhdr.ddpf.dwFlags & DDPF_FOURCC) && dds_fhdr.dwCaps2 == 0)) { if (!((dds_fhdr.ddpf.dwFlags & DDPF_FOURCC) && dds_fhdr.dwCaps2 == 0)) {
DBG_INFO(80, L"Error: not fourcc standard texture!\n"); DBG_INFO(80, "Error: not fourcc standard texture!\n");
return NULL; return NULL;
} }
if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT1", 4) == 0) { if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT1", 4) == 0) {
DBG_INFO(80, L"DXT1 format\n"); DBG_INFO(80, "DXT1 format\n");
/* compensate for missing LinearSize */ /* compensate for missing LinearSize */
dds_fhdr.dwLinearSize = (dds_fhdr.dwWidth * dds_fhdr.dwHeight) >> 1; dds_fhdr.dwLinearSize = (dds_fhdr.dwWidth * dds_fhdr.dwHeight) >> 1;
tmpformat = GR_TEXFMT_ARGB_CMP_DXT1; tmpformat = GR_TEXFMT_ARGB_CMP_DXT1;
} else if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT3", 4) == 0) { } else if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT3", 4) == 0) {
DBG_INFO(80, L"DXT3 format\n"); DBG_INFO(80, "DXT3 format\n");
dds_fhdr.dwLinearSize = dds_fhdr.dwWidth * dds_fhdr.dwHeight; dds_fhdr.dwLinearSize = dds_fhdr.dwWidth * dds_fhdr.dwHeight;
tmpformat = GR_TEXFMT_ARGB_CMP_DXT3; tmpformat = GR_TEXFMT_ARGB_CMP_DXT3;
} else if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT5", 4) == 0) { } else if (memcmp(&dds_fhdr.ddpf.dwFourCC, "DXT5", 4) == 0) {
DBG_INFO(80, L"DXT5 format\n"); DBG_INFO(80, "DXT5 format\n");
dds_fhdr.dwLinearSize = dds_fhdr.dwWidth * dds_fhdr.dwHeight; dds_fhdr.dwLinearSize = dds_fhdr.dwWidth * dds_fhdr.dwHeight;
tmpformat = GR_TEXFMT_ARGB_CMP_DXT5; tmpformat = GR_TEXFMT_ARGB_CMP_DXT5;
} else { } else {
DBG_INFO(80, L"Error: not DXT1 or DXT3 or DXT5 format!\n"); DBG_INFO(80, "Error: not DXT1 or DXT3 or DXT5 format!\n");
return NULL; return NULL;
} }

View File

@ -91,15 +91,14 @@ TxReSample::nextPow2(uint8** image, int* width, int* height, int bpp, boolean us
row_bytes = (n_width * bpp) >> 3; row_bytes = (n_width * bpp) >> 3;
} }
} }
DBG_INFO(80, L"using 3dfx W:H aspect ratio range (8:1 - 1:8).\n"); DBG_INFO(80, "using 3dfx W:H aspect ratio range (8:1 - 1:8).\n");
} }
/* do we really need to do this ? */ /* do we really need to do this ? */
if (o_width == n_width && o_height == n_height) if (o_width == n_width && o_height == n_height)
return 1; /* nope */ return 1; /* nope */
DBG_INFO(80, L"expand image to next power of 2 dimensions. %d x %d -> %d x %d\n", DBG_INFO(80, "expand image to next power of 2 dimensions. %d x %d -> %d x %d\n", o_width, o_height, n_width, n_height);
o_width, o_height, n_width, n_height);
if (o_width > n_width) if (o_width > n_width)
o_width = n_width; o_width = n_width;
@ -410,7 +409,7 @@ TxReSample::minify(uint8 **src, int *width, int *height, int ratio)
*width = tmpwidth; *width = tmpwidth;
*height = tmpheight; *height = tmpheight;
DBG_INFO(80, L"minification ratio:%d -> %d x %d\n", ratio, *width, *height); DBG_INFO(80, "minification ratio:%d -> %d x %d\n", ratio, *width, *height);
return 1; return 1;
#endif #endif

View File

@ -126,7 +126,7 @@ TxUtil::sizeofTx(int width, int height, uint16 format)
break; break;
default: default:
/* unsupported format */ /* unsupported format */
DBG_INFO(80, L"Error: cannot get size. unsupported gfmt:%x\n", format); DBG_INFO(80, "Error: cannot get size. unsupported gfmt:%x\n", format);
; ;
} }