- Completely removed code for the PNG filter heuristic from the compiled code when it's been disabled.

- Added a temporary cvar called pal to play with the offset used by D3DFB::SetPaletteTexture().

SVN r701 (trunk)
This commit is contained in:
Randy Heit 2008-01-12 17:06:38 +00:00
parent 2e613c3557
commit cb47b3a1f7
2 changed files with 27 additions and 16 deletions

View file

@ -55,6 +55,12 @@
// size of the compression buffer it allocates on the stack. // size of the compression buffer it allocates on the stack.
#define PNG_WRITE_SIZE 32768 #define PNG_WRITE_SIZE 32768
// Set this to 1 to use a simple heuristic to select the filter to apply
// for each row of RGB image saves. As it turns out, it seems no filtering
// is the best for Doom screenshots, no matter what the heuristic might
// determine, so that's why this is 0 here.
#define USE_FILTER_HEURISTIC 0
// TYPES ------------------------------------------------------------------- // TYPES -------------------------------------------------------------------
struct IHDR struct IHDR
@ -759,13 +765,12 @@ DWORD CalcSum(Byte *row, int len)
// //
//========================================================================== //==========================================================================
#if USE_FILTER_HEURISTIC
static int SelectFilter(Byte row[5][1 + MAXWIDTH*3], Byte prior[MAXWIDTH*3], int width) static int SelectFilter(Byte row[5][1 + MAXWIDTH*3], Byte prior[MAXWIDTH*3], int width)
{ {
#if 1
// As it turns out, it seems no filtering is the best for Doom screenshots, // As it turns out, it seems no filtering is the best for Doom screenshots,
// no matter what the heuristic might determine. // no matter what the heuristic might determine.
return 0; return 0;
#else
DWORD sum; DWORD sum;
DWORD bestsum; DWORD bestsum;
int bestfilter; int bestfilter;
@ -880,8 +885,10 @@ static int SelectFilter(Byte row[5][1 + MAXWIDTH*3], Byte prior[MAXWIDTH*3], int
} }
return bestfilter; return bestfilter;
#endif
} }
#else
#define SelectFilter(x,y,z) 0
#endif
//========================================================================== //==========================================================================
// //
@ -894,9 +901,13 @@ static int SelectFilter(Byte row[5][1 + MAXWIDTH*3], Byte prior[MAXWIDTH*3], int
bool M_SaveBitmap(const BYTE *from, ESSType color_type, int width, int height, int pitch, FILE *file) bool M_SaveBitmap(const BYTE *from, ESSType color_type, int width, int height, int pitch, FILE *file)
{ {
#if USE_FILTER_HEURISTIC
Byte prior[MAXWIDTH*3]; Byte prior[MAXWIDTH*3];
Byte buffer[PNG_WRITE_SIZE];
Byte temprow[5][1 + MAXWIDTH*3]; Byte temprow[5][1 + MAXWIDTH*3];
#else
Byte temprow[1][1 + MAXWIDTH*3];
#endif
Byte buffer[PNG_WRITE_SIZE];
z_stream stream; z_stream stream;
int err; int err;
int y; int y;
@ -917,17 +928,19 @@ bool M_SaveBitmap(const BYTE *from, ESSType color_type, int width, int height, i
stream.avail_out = sizeof(buffer); stream.avail_out = sizeof(buffer);
temprow[0][0] = 0; temprow[0][0] = 0;
#if USE_FILTER_HEURISTIC
temprow[1][0] = 1; temprow[1][0] = 1;
temprow[2][0] = 2; temprow[2][0] = 2;
temprow[3][0] = 3; temprow[3][0] = 3;
temprow[4][0] = 4; temprow[4][0] = 4;
// Fill the prior row to 0 for RGB images. Paletted is always filter 0, // Fill the prior row with 0 for RGB images. Paletted is always filter 0,
// so it doesn't need this. // so it doesn't need this.
if (color_type != SS_PAL) if (color_type != SS_PAL)
{ {
memset(prior, 0, width * 3); memset(prior, 0, width * 3);
} }
#endif
while (y-- > 0 && err == Z_OK) while (y-- > 0 && err == Z_OK)
{ {
@ -957,11 +970,13 @@ bool M_SaveBitmap(const BYTE *from, ESSType color_type, int width, int height, i
stream.avail_in = width * 3 + 1; stream.avail_in = width * 3 + 1;
break; break;
} }
#if USE_FILTER_HEURISTIC
if (color_type != SS_PAL) if (color_type != SS_PAL)
{ {
// Save this row for filter calculations on the next row. // Save this row for filter calculations on the next row.
memcpy (prior, &temprow[0][1], stream.avail_in - 1); memcpy (prior, &temprow[0][1], stream.avail_in - 1);
} }
#endif
from += pitch; from += pitch;

View file

@ -296,17 +296,12 @@ D3DFB::D3DFB (int width, int height, bool fullscreen)
HRESULT hr; HRESULT hr;
if (FAILED(hr = D3D->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window, if (FAILED(hr = D3D->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3dpp, &D3DDevice))) D3DCREATE_HARDWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3dpp, &D3DDevice)))
{ {
D3DDevice = NULL; if (FAILED(D3D->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window,
if (fullscreen) D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3dpp, &D3DDevice)))
{ {
d3dpp.BackBufferFormat = D3DFMT_R5G6B5; D3DDevice = NULL;
if (FAILED(D3D->CreateDevice (D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, Window,
D3DCREATE_SOFTWARE_VERTEXPROCESSING | D3DCREATE_FPU_PRESERVE, &d3dpp, &D3DDevice)))
{
D3DDevice = NULL;
}
} }
} }
if (D3DDevice != NULL) if (D3DDevice != NULL)
@ -3062,12 +3057,13 @@ void D3DFB::SetTexture(int tnum, IDirect3DTexture9 *texture)
} }
} }
CVAR(Float, pal, 0.5f, 0)
void D3DFB::SetPaletteTexture(IDirect3DTexture9 *texture, int count) void D3DFB::SetPaletteTexture(IDirect3DTexture9 *texture, int count)
{ {
if (count == 256 || SM14) if (count == 256 || SM14)
{ {
// Shader Model 1.4 only uses 256-color palettes. // Shader Model 1.4 only uses 256-color palettes.
SetConstant(2, 255 / 256.f, 0.5f / 256.f, 0, 0); SetConstant(2, 255 / 256.f, pal / 256.f, 0, 0);
} }
else else
{ {
@ -3083,7 +3079,7 @@ void D3DFB::SetPaletteTexture(IDirect3DTexture9 *texture, int count)
// The constant register c2 is used to hold the multiplier in the // The constant register c2 is used to hold the multiplier in the
// x part and the adder in the y part. // x part and the adder in the y part.
float fcount = 1 / float(count); float fcount = 1 / float(count);
SetConstant(2, 255 * fcount, 0.5f * fcount, 0, 0); SetConstant(2, 255 * fcount, pal * fcount, 0, 0);
} }
SetTexture(1, texture); SetTexture(1, texture);
} }