From a3a577f2e9b5cca5d39c5d6fd3dbe4a25a5e9c55 Mon Sep 17 00:00:00 2001 From: rogerman Date: Tue, 3 Oct 2017 14:26:36 -0700 Subject: [PATCH] Windows Port: Replace the backlight kludge in the DirectDraw display method with the new ColorspaceApplyIntensityToBuffer32(). (Related to commits f5c9a36, 3a000b6 and 74ba49e.) - Also fixes a build problem in MSVC. (Regression from commit 74ba49e.) --- desmume/src/frontend/windows/main.cpp | 14 ++-------- .../colorspacehandler/colorspacehandler.cpp | 28 +++++++++++++++---- 2 files changed, 25 insertions(+), 17 deletions(-) mode change 100644 => 100755 desmume/src/utils/colorspacehandler/colorspacehandler.cpp diff --git a/desmume/src/frontend/windows/main.cpp b/desmume/src/frontend/windows/main.cpp index 13702eab0..840112e23 100755 --- a/desmume/src/frontend/windows/main.cpp +++ b/desmume/src/frontend/windows/main.cpp @@ -1985,18 +1985,10 @@ static void DoDisplay(bool firstTime) if(ddhw || ddsw) { const NDSDisplayInfo &displayInfo = GPU->GetDisplayInfo(); + const size_t pixCount = displayInfo.customWidth * displayInfo.customHeight; - for(int screen=0;screen<2;screen++) - { - const GLfloat backlightIntensity = displayInfo.backlightIntensity[screen]; - if(backlightIntensity == 1.0f) continue; - - //abuse accelerated masterbrightness algorithm for this - const int factor = 16-backlightIntensity*16; - const u32 screenSize = 256*video.prescaleHD*192*video.prescaleHD; - u32* dst = video.buffer + screenSize*screen; - GPU->GetEngineMain()->ApplyMasterBrightness(dst,screenSize,GPUMasterBrightMode_Down,(u8)factor); - } + ColorspaceApplyIntensityToBuffer32(video.buffer, pixCount, displayInfo.backlightIntensity[NDSDisplayID_Main]); + ColorspaceApplyIntensityToBuffer32(video.buffer + pixCount, pixCount, displayInfo.backlightIntensity[NDSDisplayID_Touch]); } if(firstTime) diff --git a/desmume/src/utils/colorspacehandler/colorspacehandler.cpp b/desmume/src/utils/colorspacehandler/colorspacehandler.cpp old mode 100644 new mode 100755 index 42574d8a1..091df2454 --- a/desmume/src/utils/colorspacehandler/colorspacehandler.cpp +++ b/desmume/src/utils/colorspacehandler/colorspacehandler.cpp @@ -600,15 +600,16 @@ void ColorspaceApplyIntensityToBuffer16(u16 *dst, size_t pixCount, float intensi i = csh.ApplyIntensityToBuffer16(dst, pixCountVector, intensity); } } - -#pragma LOOPVECTORIZE_DISABLE - + #endif // USEMANUALVECTORIZATION if (intensity > 0.999f) { if (SWAP_RB) { +#ifdef USEMANUALVECTORIZATION +#pragma LOOPVECTORIZE_DISABLE +#endif for (; i < pixCount; i++) { dst[i] = COLOR5551_SWAP_RB(dst[i]); @@ -619,6 +620,9 @@ void ColorspaceApplyIntensityToBuffer16(u16 *dst, size_t pixCount, float intensi } else if (intensity < 0.001f) { +#ifdef USEMANUALVECTORIZATION +#pragma LOOPVECTORIZE_DISABLE +#endif for (; i < pixCount; i++) { dst[i] = dst[i] & 0x8000; @@ -628,7 +632,9 @@ void ColorspaceApplyIntensityToBuffer16(u16 *dst, size_t pixCount, float intensi } const u16 intensity_u16 = (u16)(intensity * (float)(0xFFFF)); - +#ifdef USEMANUALVECTORIZATION +#pragma LOOPVECTORIZE_DISABLE +#endif for (; i < pixCount; i++) { u16 outColor = (SWAP_RB) ? COLOR5551_SWAP_RB(dst[i]) : dst[i]; @@ -680,14 +686,15 @@ void ColorspaceApplyIntensityToBuffer32(u32 *dst, size_t pixCount, float intensi } } -#pragma LOOPVECTORIZE_DISABLE - #endif // USEMANUALVECTORIZATION if (intensity > 0.999f) { if (SWAP_RB) { +#ifdef USEMANUALVECTORIZATION +#pragma LOOPVECTORIZE_DISABLE +#endif for (; i < pixCount; i++) { FragmentColor dstColor; @@ -703,6 +710,9 @@ void ColorspaceApplyIntensityToBuffer32(u32 *dst, size_t pixCount, float intensi } else if (intensity < 0.001f) { +#ifdef USEMANUALVECTORIZATION +#pragma LOOPVECTORIZE_DISABLE +#endif for (; i < pixCount; i++) { dst[i] = dst[i] & 0xFF000000; @@ -715,6 +725,9 @@ void ColorspaceApplyIntensityToBuffer32(u32 *dst, size_t pixCount, float intensi if (SWAP_RB) { +#ifdef USEMANUALVECTORIZATION +#pragma LOOPVECTORIZE_DISABLE +#endif for (; i < pixCount; i++) { FragmentColor dstColor; @@ -728,6 +741,9 @@ void ColorspaceApplyIntensityToBuffer32(u32 *dst, size_t pixCount, float intensi } else { +#ifdef USEMANUALVECTORIZATION +#pragma LOOPVECTORIZE_DISABLE +#endif for (; i < pixCount; i++) { FragmentColor &outColor = (FragmentColor &)dst[i];