From 2ed584541b4e9e194332ff470118d2bd9303f10b Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 10 Jun 2024 08:57:47 -0300 Subject: [PATCH] [msvc] Use a workaround to fix compiler bug (fix #4526) Reported in https://developercommunity.visualstudio.com/t/Invalid-optimized-x64-codegen-with-inlin/10678815 possible duplicated of https://developercommunity.visualstudio.com/t/Optimisation-of-right-bit-shift-switches/10453852 not yet available in official VS release. Here we changed signed ints to unsigned ints to avoid this bug. --- src/doc/rgbmap_rgb5a3.h | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/doc/rgbmap_rgb5a3.h b/src/doc/rgbmap_rgb5a3.h index 25ead6445..e17ab4ab3 100644 --- a/src/doc/rgbmap_rgb5a3.h +++ b/src/doc/rgbmap_rgb5a3.h @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2020-2022 Igara Studio S.A. +// Copyright (c) 2020-2024 Igara Studio S.A. // Copyright (c) 2001-2016 David Capello // // This file is released under the terms of the MIT license. @@ -11,6 +11,7 @@ #include "base/debug.h" #include "base/disable_copying.h" +#include "base/ints.h" #include "doc/object.h" #include "doc/rgbmap.h" @@ -23,7 +24,7 @@ namespace doc { // It acts like a cache for Palette:findBestfit() calls. class RgbMapRGB5A3 : public RgbMap { // Bit activated on m_map entries that aren't yet calculated. - const int INVALID = 256; + const uint16_t INVALID = 256; public: RgbMapRGB5A3(); @@ -31,13 +32,13 @@ namespace doc { // RgbMap impl void regenerateMap(const Palette* palette, int maskIndex) override; int mapColor(const color_t rgba) const override { - const int r = rgba_getr(rgba); - const int g = rgba_getg(rgba); - const int b = rgba_getb(rgba); - const int a = rgba_geta(rgba); + const uint8_t r = rgba_getr(rgba); + const uint8_t g = rgba_getg(rgba); + const uint8_t b = rgba_getb(rgba); + const uint8_t a = rgba_geta(rgba); // bits -> bbbbbgggggrrrrraaa - const int i = (a>>5) | ((b>>3) << 3) | ((g>>3) << 8) | ((r>>3) << 13); - const int v = m_map[i]; + const uint32_t i = (a>>5) | ((b>>3) << 3) | ((g>>3) << 8) | ((r>>3) << 13); + const uint16_t v = m_map[i]; return (v & INVALID) ? generateEntry(i, r, g, b, a): v; }