Skip to content

Commit

Permalink
Fixed HQ2x scaling to work on big-endian processors.
Browse files Browse the repository at this point in the history
Magic tricks to improve readability of the original font lumps. When the font lumps are being uploaded, the DD_UPSCALE_AND_SHARPEN_PATCHES variable is set to "true", which causes the patches to be HQ2x-upscaled and a black outline will be applied to the upscaled version of the texture. Gives a marked improvement on Heretic and Hexen fonts, but Doom fonts could use a contrast enhancement, too.
  • Loading branch information
skyjake committed Aug 6, 2007
1 parent 8d770da commit cafc49f
Show file tree
Hide file tree
Showing 8 changed files with 134 additions and 74 deletions.
1 change: 1 addition & 0 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -215,6 +215,7 @@ extern "C" {
DD_MONOCHROME_PATCHES, // DJS - convert patch image data to monochrome. 1= linear 2= weighted
DD_GAME_DATA_FORMAT,
DD_GAME_DRAW_HUD_HINT, // Doomsday advises not to draw the HUD
DD_UPSCALE_AND_SHARPEN_PATCHES,
DD_LAST_VALUE,

// General constants (not to be used with Get/Set).
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/gl_texmanager.h
Expand Up @@ -101,6 +101,7 @@ extern int texMagMode, texAniso;
extern int useSmartFilter;
extern byte loadExtAlways;
extern int texMagMode;
extern int upscaleAndSharpenPatches;

extern unsigned int curtex;

Expand Down
2 changes: 2 additions & 0 deletions doomsday/engine/portable/include/r_data.h
Expand Up @@ -243,6 +243,8 @@ typedef struct {
typedef struct {
short width;
short height;
short offsetX;
short offsetY;
byte masked; // Is the (DGL) texture masked?
detailinfo_t detail; // Detail texture information.
} texinfo_t;
Expand Down
3 changes: 2 additions & 1 deletion doomsday/engine/portable/src/dd_main.c
Expand Up @@ -896,7 +896,8 @@ ddvalue_t ddValues[DD_LAST_VALUE - DD_FIRST_VALUE - 1] = {
{&weaponOffsetScaleY, &weaponOffsetScaleY},
{&monochrome, &monochrome},
{&gamedataformat, &gamedataformat},
{&gamedrawhud, 0}
{&gamedrawhud, 0},
{&upscaleAndSharpenPatches, &upscaleAndSharpenPatches}
};
/* *INDENT-ON* */

Expand Down
14 changes: 13 additions & 1 deletion doomsday/engine/portable/src/gl_draw.c
Expand Up @@ -150,8 +150,10 @@ void GL_DrawRawScreen(int lump, float offx, float offy)
/*
* Drawing with the Current State.
*/
void GL_DrawPatch_CS(int x, int y, int lumpnum)
void GL_DrawPatch_CS(int posX, int posY, int lumpnum)
{
float x = posX;
float y = posY;
float w, h;
texinfo_t *texinfo;

Expand All @@ -166,6 +168,16 @@ void GL_DrawPatch_CS(int x, int y, int lumpnum)
x += (int) p->offx;
y += (int) p->offy;
}
if(texinfo->offsetX)
{
// This offset is used only for the extra borders in the
// "upscaled and sharpened" patches, so we can tweak the values
// to our liking a bit more.
x += texinfo->offsetX * .75f;
y += texinfo->offsetY * .75f;
w -= fabs(texinfo->offsetX) / 2;
h -= fabs(texinfo->offsetY) / 2;
}

gl.Begin(DGL_QUADS);
gl.TexCoord2f(0, 0);
Expand Down
66 changes: 16 additions & 50 deletions doomsday/engine/portable/src/gl_hq2x.c
Expand Up @@ -28,14 +28,15 @@
* Based on the routine by Maxim Stepin <maxst@hiend3d.com>
* For more information, see: http://hiend3d.com/hq2x.html
*
* Now uses 32-bit data and 0xAABBGGRR pixel byte order (assume Intel!).
* Now uses 32-bit data and 0xAABBGGRR pixel byte order (little endian).
* Alpha is taken into account in the processing to preserve edges.
* Not quite as efficient as the original version.
*/

// HEADER FILES ------------------------------------------------------------

#include "dd_types.h"
#include "dd_share.h"

#include <stdlib.h>

Expand All @@ -55,7 +56,7 @@
#define trU ((int)0x00000700)
#define trV ((int)0x00000006)

#define PIXEL00_0 *((uint*)(pOut)) = c[5];
#define PIXEL00_0 *((uint*)(pOut)) = ULONG( c[5] );
#define PIXEL00_10 Interp1(pOut, c[5], c[1]);
#define PIXEL00_11 Interp1(pOut, c[5], c[4]);
#define PIXEL00_12 Interp1(pOut, c[5], c[2]);
Expand All @@ -67,7 +68,7 @@
#define PIXEL00_70 Interp7(pOut, c[5], c[4], c[2]);
#define PIXEL00_90 Interp9(pOut, c[5], c[4], c[2]);
#define PIXEL00_100 Interp10(pOut, c[5], c[4], c[2]);
#define PIXEL01_0 *((uint*)(pOut+4)) = c[5];
#define PIXEL01_0 *((uint*)(pOut+4)) = ULONG( c[5] );
#define PIXEL01_10 Interp1(pOut+4, c[5], c[3]);
#define PIXEL01_11 Interp1(pOut+4, c[5], c[2]);
#define PIXEL01_12 Interp1(pOut+4, c[5], c[6]);
Expand All @@ -79,7 +80,7 @@
#define PIXEL01_70 Interp7(pOut+4, c[5], c[2], c[6]);
#define PIXEL01_90 Interp9(pOut+4, c[5], c[2], c[6]);
#define PIXEL01_100 Interp10(pOut+4, c[5], c[2], c[6]);
#define PIXEL10_0 *((uint*)(pOut+BpL)) = c[5];
#define PIXEL10_0 *((uint*)(pOut+BpL)) = ULONG( c[5] );
#define PIXEL10_10 Interp1(pOut+BpL, c[5], c[7]);
#define PIXEL10_11 Interp1(pOut+BpL, c[5], c[8]);
#define PIXEL10_12 Interp1(pOut+BpL, c[5], c[4]);
Expand All @@ -91,7 +92,7 @@
#define PIXEL10_70 Interp7(pOut+BpL, c[5], c[8], c[4]);
#define PIXEL10_90 Interp9(pOut+BpL, c[5], c[8], c[4]);
#define PIXEL10_100 Interp10(pOut+BpL, c[5], c[8], c[4]);
#define PIXEL11_0 *((uint*)(pOut+BpL+4)) = c[5];
#define PIXEL11_0 *((uint*)(pOut+BpL+4)) = ULONG( c[5] );
#define PIXEL11_10 Interp1(pOut+BpL+4, c[5], c[9]);
#define PIXEL11_11 Interp1(pOut+BpL+4, c[5], c[6]);
#define PIXEL11_12 Interp1(pOut+BpL+4, c[5], c[8]);
Expand Down Expand Up @@ -126,7 +127,7 @@ static int YUV1, YUV2;
static void LerpColor(unsigned char *out, uint c1, uint c2, uint c3, uint f1,
uint f2, uint f3)
{
int i, total = f1 + f2 + f3;
int i, total = f1 + f2 + f3;

for(i = 0; i < 4; i++)
{
Expand All @@ -137,66 +138,31 @@ static void LerpColor(unsigned char *out, uint c1, uint c2, uint c3, uint f1,

static void Interp1(unsigned char *pc, uint c1, uint c2)
{
//*((uint*)pc) = (c1*3 + c2) >> 2;
LerpColor(pc, c1, c2, 0, 3, 1, 0);
}

static void Interp2(unsigned char *pc, uint c1, uint c2, uint c3)
{
// *((uint*)pc) = (c1*2 + c2 + c3) >> 2;
LerpColor(pc, c1, c2, c3, 2, 1, 1);
}

/*static void Interp5(unsigned char * pc, uint c1, uint c2)
{
*((uint*)pc) = (c1+c2) >> 1;
} */

static void Interp6(unsigned char *pc, uint c1, uint c2, uint c3)
{
//*((uint*)pc) = (c1*5+c2*2+c3)/8;

/* *((uint*)pc) = ((((c1 & 0x00FF00)*5 + (c2 & 0x00FF00)*2 + (c3 & 0x00FF00) )
& 0x0007F800) +
(((c1 & 0xFF00FF)*5 + (c2 & 0xFF00FF)*2 + (c3 & 0xFF00FF) )
& 0x07F807F8)) >> 3; */

LerpColor(pc, c1, c2, c3, 5, 2, 1);
}

static void Interp7(unsigned char *pc, uint c1, uint c2, uint c3)
{
//*((uint*)pc) = (c1*6+c2+c3)/8;

/* *((uint*)pc) = ((((c1 & 0x00FF00)*6 + (c2 & 0x00FF00) + (c3 & 0x00FF00) ) &
0x0007F800) +
(((c1 & 0xFF00FF)*6 + (c2 & 0xFF00FF) + (c3 & 0xFF00FF) ) &
0x07F807F8)) >> 3; */

LerpColor(pc, c1, c2, c3, 6, 1, 1);
}

static void Interp9(unsigned char *pc, uint c1, uint c2, uint c3)
{
//*((uint*)pc) = (c1*2+(c2+c3)*3)/8;

/* *((uint*)pc) = ((((c1 & 0x00FF00)*2 + ((c2 & 0x00FF00) +
(c3 & 0x00FF00))*3 ) & 0x0007F800) +
(((c1 & 0xFF00FF)*2 + ((c2 & 0xFF00FF) +
(c3 & 0xFF00FF))*3 ) & 0x07F807F8))
>> 3; */

LerpColor(pc, c1, c2, c3, 2, 3, 3);
}

static void Interp10(unsigned char *pc, uint c1, uint c2, uint c3)
{
//*((uint*)pc) = (c1*14+c2+c3)/16;

/* *((uint*)pc) = ((((c1 & 0x00FF00)*14 + (c2 & 0x00FF00) + (c3 & 0x00FF00) )
& 0x000FF000) +
(((c1 & 0xFF00FF)*14 + (c2 & 0xFF00FF) + (c3 & 0xFF00FF) )
& 0x0FF00FF0)) >> 4; */
LerpColor(pc, c1, c2, c3, 14, 1, 1);
}

Expand Down Expand Up @@ -275,15 +241,15 @@ void GL_SmartFilter2x(unsigned char *pIn, unsigned char *pOut, int Xres,
for(i = 0; i < Xres; i++)
{
// The image data has 32-bit pixels.
dw[2] = *((unsigned int *) (pIn + prevline));
dw[5] = *((unsigned int *) pIn);
dw[8] = *((unsigned int *) (pIn + nextline));
dw[2] = ULONG( *((uint*) (pIn + prevline)) );
dw[5] = ULONG( *((uint*) pIn) );
dw[8] = ULONG( *((uint*) (pIn + nextline)) );

if(i > 0)
{
dw[1] = *((unsigned int *) (pIn + prevline - BPP));
dw[4] = *((unsigned int *) (pIn - BPP));
dw[7] = *((unsigned int *) (pIn + nextline - BPP));
dw[1] = ULONG( *((uint*) (pIn + prevline - BPP)) );
dw[4] = ULONG( *((uint*) (pIn - BPP)) );
dw[7] = ULONG( *((uint*) (pIn + nextline - BPP)) );
}
else
{
Expand All @@ -294,9 +260,9 @@ void GL_SmartFilter2x(unsigned char *pIn, unsigned char *pOut, int Xres,

if(i < Xres - 1)
{
dw[3] = *((unsigned int *) (pIn + prevline + BPP));
dw[6] = *((unsigned int *) (pIn + BPP));
dw[9] = *((unsigned int *) (pIn + nextline + BPP));
dw[3] = ULONG( *((uint*) (pIn + prevline + BPP)) );
dw[6] = ULONG( *((uint*) (pIn + BPP)) );
dw[9] = ULONG( *((uint*) (pIn + nextline + BPP)) );
}
else
{
Expand Down

0 comments on commit cafc49f

Please sign in to comment.