diff --git a/desmume/src/filter/xbrz.cpp b/desmume/src/filter/xbrz.cpp index 16dd3923d..997855a8f 100644 --- a/desmume/src/filter/xbrz.cpp +++ b/desmume/src/filter/xbrz.cpp @@ -105,10 +105,8 @@ uint32_t gradientARGB(uint32_t pixFront, uint32_t pixBack) //find intermediate c } template inline -uint32_t gradientARGB_1bitAlpha(uint32_t pixFront, uint32_t pixBack) //find intermediate color between two colors with alpha channels (=> NO alpha blending!!!) +uint32_t gradientARGB_1bitAlpha(uint32_t pixFront, uint32_t pixBack) //special blending mode for NDS textures -- assumes that the alpha component value is either 0x00 or 0xFF { - //static_assert(0 < M && M < N && N <= 1000, ""); - const unsigned int weightFront = getAlpha(pixFront) * M; const unsigned int weightBack = getAlpha(pixBack) * (N - M); const unsigned int weightSum = weightFront + weightBack; @@ -126,16 +124,11 @@ uint32_t gradientARGB_1bitAlpha(uint32_t pixFront, uint32_t pixBack) //find inte return pixFront; } - /* - auto calcColor = [=](unsigned char colFront, unsigned char colBack) - { - return static_cast((colFront * weightFront + colBack * weightBack) / weightSum); - }; - */ - return makePixel(static_cast(weightSum / N), - gradientARGB_calcColor(getRed (pixFront), getRed (pixBack), weightFront, weightBack, weightSum), - gradientARGB_calcColor(getGreen(pixFront), getGreen(pixBack), weightFront, weightBack, weightSum), - gradientARGB_calcColor(getBlue (pixFront), getBlue (pixBack), weightFront, weightBack, weightSum)); + // At this point, we know that both pixels must be opaque, so treat them as such. + return makePixel(0xFF, + gradientRGB_calcColor(getRed (pixFront), getRed (pixBack)), + gradientRGB_calcColor(getGreen(pixFront), getGreen(pixBack)), + gradientRGB_calcColor(getBlue (pixFront), getBlue (pixBack))); } //inline @@ -1219,15 +1212,15 @@ void xbrz::scale(const uint32_t* src, uint32_t* trg, int srcWidth, int srcHeight switch (SCALEFACTOR) { case 2: - return scaleImage, ColorDistanceRGB>(src, trg, srcWidth, srcHeight, cfg, yFirst, yLast); + return scaleImage, ColorDistanceARGB>(src, trg, srcWidth, srcHeight, cfg, yFirst, yLast); case 3: - return scaleImage, ColorDistanceRGB>(src, trg, srcWidth, srcHeight, cfg, yFirst, yLast); + return scaleImage, ColorDistanceARGB>(src, trg, srcWidth, srcHeight, cfg, yFirst, yLast); case 4: - return scaleImage, ColorDistanceRGB>(src, trg, srcWidth, srcHeight, cfg, yFirst, yLast); + return scaleImage, ColorDistanceARGB>(src, trg, srcWidth, srcHeight, cfg, yFirst, yLast); case 5: - return scaleImage, ColorDistanceRGB>(src, trg, srcWidth, srcHeight, cfg, yFirst, yLast); + return scaleImage, ColorDistanceARGB>(src, trg, srcWidth, srcHeight, cfg, yFirst, yLast); case 6: - return scaleImage, ColorDistanceRGB>(src, trg, srcWidth, srcHeight, cfg, yFirst, yLast); + return scaleImage, ColorDistanceARGB>(src, trg, srcWidth, srcHeight, cfg, yFirst, yLast); } break; @@ -1272,6 +1265,7 @@ bool xbrz::equalColorTest(uint32_t col1, uint32_t col2, ColorFormat colFmt, doub switch (colFmt) { case ColorFormatARGB: + case ColorFormatARGB_1bitAlpha: return ColorDistanceARGB::dist(col1, col2, luminanceWeight) < equalColorTolerance; case ColorFormatRGB: