Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Mystery solved: HQ2x filter lookup tables weren't initialized in time…
… for the worker thread. Now the fonts are looking really sharp! I can use menu-scale 1.0 without everything turning into a blurry mush...
  • Loading branch information
skyjake committed Aug 8, 2007
1 parent 886ef2f commit 6c6aed9
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions doomsday/engine/portable/src/gl_texmanager.c
Expand Up @@ -3,8 +3,8 @@
* License: GPL
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2007 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2007 Daniel Swanson <danij@dengine.net>
*\author Copyright © 2003-2007 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2005-2007 Daniel Swanson <danij@dengine.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand Down Expand Up @@ -128,7 +128,7 @@ int filterSprites = true;
int texMagMode = 1; // Linear.
int texAniso = -1; // Use best.

float texGamma = 0;
float texGamma = 0;
byte gammatable[256];

// Convert a 18-bit RGB (666) value to a playpal index.
Expand Down Expand Up @@ -229,6 +229,9 @@ void GL_EarlyInitTextureManager(void)
{
int i;

// Initialize the smart texture filtering routines.
GL_InitSmartFilter();

// The palette lump, for color information (really??!!?!?!).
pallump = W_GetNumForName(PALLUMPNAME);

Expand Down Expand Up @@ -297,9 +300,6 @@ void GL_InitTextureManager(void)

// Initialization done.
texInited = true;

// Initialize the smart texture filtering routines.
GL_InitSmartFilter();
}

/*
Expand Down Expand Up @@ -334,15 +334,15 @@ static void LoadPalette(void)
{
int i, c;
byte *playpal;
byte paldata[256 * 3];
byte paldata[256 * 3];
double invgamma;

pallump = W_GetNumForName(PALLUMPNAME);
playpal = GL_GetPalette();

// Clamp to a sane range.
invgamma = 1.0f - MINMAX_OF(0, texGamma, 1);
for(i = 0; i < 256; ++i)
for(i = 0; i < 256; ++i)
gammatable[i] = (byte)(255.0f * pow(i / 255.0f, invgamma));

// Prepare the color table.
Expand Down Expand Up @@ -2626,46 +2626,61 @@ DGLuint GL_BindTexPatch(patch_t *p)
else
{
// Use data from the normal lump.
int addBorder = (upscaleAndSharpenPatches? 1 : 0);
boolean scaleSharp = (upscaleAndSharpenPatches ||
(p->info.modFlags & TXIF_UPSCALE_AND_SHARPEN));
int addBorder = (scaleSharp? 1 : 0);
int patchWidth = SHORT(patch->width) + addBorder*2;
int patchHeight = SHORT(patch->height) + addBorder*2;
int numpels = patchWidth * patchHeight, alphaChannel;
byte *buffer;
boolean scaleSharp = (upscaleAndSharpenPatches ||
(p->info.modFlags & TXIF_UPSCALE_AND_SHARPEN));

if(!numpels)
return 0; // This won't do!

// Allocate memory for the patch.
buffer = M_Calloc(2 * numpels);

alphaChannel =
DrawRealPatch(buffer, patchWidth, patchHeight,
patch, addBorder, addBorder, false, 0, true);

if(filloutlines && !scaleSharp)
ColorOutlines(buffer, patchWidth, patchHeight);

if(monochrome || (p->info.modFlags & TXIF_MONOCHROME))
{
DeSaturate(buffer, GL_GetPalette(), patchWidth, patchHeight);
p->info.modFlags |= TXIF_MONOCHROME;
}

if(scaleSharp)
{
byte* rgbaPixels = M_Malloc(numpels * 4 * 2); // also for the final output
byte* upscaledPixels = M_Malloc(numpels * 4 * 4);

GL_ConvertBuffer(patchWidth, patchHeight, 2, 4, buffer, rgbaPixels,
GL_GetPalette(), false);

GL_SmartFilter2x(rgbaPixels, upscaledPixels, patchWidth, patchHeight,
patchWidth * 8);
patchWidth *= 2;
patchHeight *= 2;


/*
{
static int counter = 1;
FILE *f;
char buf[100];
sprintf(buf, "dumped-%s-%i.dat", W_LumpName(p->lump), counter++);
f = fopen(buf, "wb");
fwrite(upscaledPixels, 4 * 4 * numpels, 1, f);
fclose(f);
}
*/
/*
Con_Message("upscale and sharpen on %s (lump %i) monochrome:%i\n", W_LumpName(p->lump),
p->lump, p->info.modFlags & TXIF_MONOCHROME);
*/

//EnhanceContrast(upscaledPixels, patchWidth, patchHeight);
SharpenPixels(upscaledPixels, patchWidth, patchHeight);
Expand Down Expand Up @@ -3010,12 +3025,12 @@ void GL_TexReset(void)
/**
* Called when changing the value of the texture gamma cvar.
*/
void GL_DoUpdateTexGamma(cvar_t *unused)
{
GL_TexReset();
void GL_DoUpdateTexGamma(cvar_t *unused)
{
GL_TexReset();
LoadPalette();

Con_Printf("Gamma correction set to %f.\n", texGamma);

Con_Printf("Gamma correction set to %f.\n", texGamma);
}

/**
Expand Down

0 comments on commit 6c6aed9

Please sign in to comment.