From b6bcc1b0f54284272606c761ddabad12821e6aa8 Mon Sep 17 00:00:00 2001 From: Rachael Alexanderson Date: Tue, 25 Sep 2018 03:34:23 -0400 Subject: [PATCH] Add 'normalNx' texture scaling --- src/textures/hires/hqresize.cpp | 47 +++++++++++++++++++++++++++++++-- wadsrc/static/language.enu | 3 +++ wadsrc/static/menudef.txt | 3 +++ 3 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/textures/hires/hqresize.cpp b/src/textures/hires/hqresize.cpp index 22f9f8f2f..6bcb2d805 100644 --- a/src/textures/hires/hqresize.cpp +++ b/src/textures/hires/hqresize.cpp @@ -47,7 +47,7 @@ CUSTOM_CVAR(Int, gl_texture_hqresize, 0, CVAR_ARCHIVE | CVAR_GLOBALCONFIG | CVAR_NOINITCALL) { - if (self < 0 || self > 19) + if (self < 0 || self > 22) { self = 0; } @@ -187,7 +187,6 @@ static void scale4x ( uint32_t* inputBuffer, uint32_t* outputBuffer, int inWidth delete[] buffer2x; } - static unsigned char *scaleNxHelper( void (*scaleNxFunction) ( uint32_t* , uint32_t* , int , int), const int N, unsigned char *inputBuffer, @@ -205,6 +204,44 @@ static unsigned char *scaleNxHelper( void (*scaleNxFunction) ( uint32_t* , uint3 return newBuffer; } +static void normalNx ( uint32_t* inputBuffer, uint32_t* outputBuffer, int inWidth, int inHeight, int size ) +{ + const int width = size * inWidth; + const int height = size * inHeight; + + for ( int i = 0; i < inWidth; ++i ) + { + for ( int j = 0; j < inHeight; ++j ) + { + const uint32_t E = inputBuffer[ i +inWidth*j ]; + for ( int k = 0; k < size; k++ ) + { + for ( int l = 0; l < size; l++ ) + { + outputBuffer[size*i+k + width*(size*j+l)] = E; + } + } + } + } +} + +static unsigned char *normalNxHelper( void (normalNxFunction) ( uint32_t* , uint32_t* , int , int, int), + const int N, + unsigned char *inputBuffer, + const int inWidth, + const int inHeight, + int &outWidth, + int &outHeight ) +{ + outWidth = N * inWidth; + outHeight = N *inHeight; + unsigned char * newBuffer = new unsigned char[outWidth*outHeight*4]; + + normalNxFunction ( reinterpret_cast ( inputBuffer ), reinterpret_cast ( newBuffer ), inWidth, inHeight, N ); + delete[] inputBuffer; + return newBuffer; +} + #ifdef HAVE_MMX static unsigned char *hqNxAsmHelper( void (*hqNxFunction) ( int*, unsigned char*, int, int, int ), const int N, @@ -396,6 +433,12 @@ unsigned char *FTexture::CreateUpsampledTextureBuffer (unsigned char *inputBuffe case 18: case 19: return xbrzHelper(xbrz::scale, type - 13, inputBuffer, inWidth, inHeight, outWidth, outHeight); + case 20: + return normalNxHelper( &normalNx, 2, inputBuffer, inWidth, inHeight, outWidth, outHeight ); + case 21: + return normalNxHelper( &normalNx, 3, inputBuffer, inWidth, inHeight, outWidth, outHeight ); + case 22: + return normalNxHelper( &normalNx, 4, inputBuffer, inWidth, inHeight, outWidth, outHeight ); } } return inputBuffer; diff --git a/wadsrc/static/language.enu b/wadsrc/static/language.enu index 7880ea125..b444f27db 100644 --- a/wadsrc/static/language.enu +++ b/wadsrc/static/language.enu @@ -2872,6 +2872,9 @@ OPTVAL_ROUND = "Round"; OPTVAL_SCALE2X = "Scale2x"; OPTVAL_SCALE3X = "Scale3x"; OPTVAL_SCALE4X = "Scale4x"; +OPTVAL_NORMAL2X = "Normal2x"; +OPTVAL_NORMAL3X = "Normal3x"; +OPTVAL_NORMAL4X = "Normal4x"; OPTVAL_HQ2X = "hq2x"; OPTVAL_HQ3X = "hq3x"; OPTVAL_HQ4X = "hq4x"; diff --git a/wadsrc/static/menudef.txt b/wadsrc/static/menudef.txt index 9b527e2eb..931ba51a1 100644 --- a/wadsrc/static/menudef.txt +++ b/wadsrc/static/menudef.txt @@ -2165,6 +2165,9 @@ OptionValue "HqResizeModes" 15, "$OPTVAL_OLD_4XBRZ" 16, "$OPTVAL_OLD_5XBRZ" 17, "$OPTVAL_OLD_6XBRZ" + 20, "$OPTVAL_NORMAL2X" + 21, "$OPTVAL_NORMAL3X" + 22, "$OPTVAL_NORMAL4X" } OptionValue "HqResizeModesNoMMX"