From 70484ba6128bec1010ff0546bacee915519bfdc5 Mon Sep 17 00:00:00 2001 From: Brandon Wright Date: Fri, 1 Mar 2019 19:57:38 -0600 Subject: [PATCH] GTK: Fix xBRZ scaler when multithreading enabled. --- gtk/src/filter_xbrz.cpp | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) diff --git a/gtk/src/filter_xbrz.cpp b/gtk/src/filter_xbrz.cpp index 1fa7d750..5de16156 100644 --- a/gtk/src/filter_xbrz.cpp +++ b/gtk/src/filter_xbrz.cpp @@ -4,7 +4,7 @@ For further information, consult the LICENSE file in the root directory. \*****************************************************************************/ -#include "snes9x.h" +#include "gtk_s9x.h" #include "../filter/xbrz.h" #include @@ -36,7 +36,6 @@ void copyImage16To32(const uint16_t* src, int width, int height, int srcPitch, } } - //stretch image and convert from ARGB to RGB565/555 inline void stretchImage32To16(const uint32_t* src, int srcWidth, int srcHeight, @@ -70,21 +69,38 @@ void xBRZ(uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int wi if (width <= 0 || height <= 0) return; - renderBuffer.resize(width * height); - - xbrzBuffer.resize(renderBuffer.size() * scalingFactor * scalingFactor ); - - int trgWidth = width * scalingFactor; + int trgWidth = width * scalingFactor; int trgHeight = height * scalingFactor; - copyImage16To32(reinterpret_cast(srcPtr), width, height, srcPitch, - &renderBuffer[0], 0, height); + if (gui_config->multithreading && gui_config->num_threads > 1) + { + renderBuffer.resize(width * (height + 4)); + xbrzBuffer.resize(renderBuffer.size() * scalingFactor * scalingFactor); - xbrz::scale(scalingFactor, &renderBuffer[0], &xbrzBuffer[0], width, height, xbrz::ColorFormat::RGB, xbrz::ScalerCfg(), 0, height); + copyImage16To32(reinterpret_cast(srcPtr - srcPitch * 2), + width, + height + 4, + srcPitch, + &renderBuffer[0], + 0, + height + 4); + xbrz::scale(scalingFactor, &renderBuffer[0], &xbrzBuffer[0], width, height + 4, xbrz::ColorFormat::RGB, xbrz::ScalerCfg(), 2, height + 2); - stretchImage32To16(&xbrzBuffer[0], width * scalingFactor, height * scalingFactor, - reinterpret_cast(dstPtr), trgWidth, trgHeight, dstPitch, 0, height * scalingFactor); + stretchImage32To16(&xbrzBuffer[trgWidth * 2 * scalingFactor], trgWidth, trgHeight, + reinterpret_cast(dstPtr), trgWidth, trgHeight, dstPitch, 0, height * scalingFactor); + } + else + { + renderBuffer.resize(width * height); + xbrzBuffer.resize(renderBuffer.size() * scalingFactor * scalingFactor); + copyImage16To32(reinterpret_cast(srcPtr), width, height, srcPitch, + &renderBuffer[0], 0, height); + + xbrz::scale(scalingFactor, &renderBuffer[0], &xbrzBuffer[0], width, height, xbrz::ColorFormat::RGB, xbrz::ScalerCfg(), 0, height); + stretchImage32To16(&xbrzBuffer[0], width * scalingFactor, height * scalingFactor, + reinterpret_cast(dstPtr), trgWidth, trgHeight, dstPitch, 0, height * scalingFactor); + } } void filter_2xBRZ(uint8 *srcPtr, uint32 srcPitch, uint8 *dstPtr, uint32 dstPitch, int width, int height)