Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-7124

MapPalette.getColor(0) returns the wrong color

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: Minor Minor
    • None
    • None
    • /

    • 1.8, 1.9, 1.10, 1.11, 1.12, 1.13, 1.14, 1.15, 1.16, 1.17, 1.18, 1.19
    • Yes

      Since commit https://hub.spigotmc.org/stash/projects/SPIGOT/repos/bukkit/diff/src/main/java/org/bukkit/map/MapPalette.java?until=78af97dbe303df77eb9443074ee0494cd80e0ac9

      the first 4 index of the private field MapPalette$colors are incorrect. (or at least for index 0, i don't really know if index 1, 2 and 3 should be the same or not than 0)

      Prior to this commit, they would return the transparent color, and in fact the index of byte 0 sent to the client will not show any color (transparent)

      Now, index 0 returns color of RGB: (0,0,0), opaque black.

      It is problematic because now, byte MapPalette$matchColor(Color color) is no longer bijective with Color MapPalette$getColor(byte) in the definition domain of colors of the palette.

       

      Example:

      Color transparent = new Color(0,0,0,0);

      transparent.getAlpha(); //returns 0

      byte index = MapPalette.matchColor(transparent); //returns the byte 0

      Color paletteTransparent = MapPalette.getColor(index); //returns Color(R:0, G:0, B:0);

      paletteTransparent.getAlpha(); //returns 255, aka opaque

       

      How have I spotted this issue?

      I was working on a dithering algorithm, which basically goes through each pixel, retrieves its original RGBA value, compares it to the nearest color of the palette, and accordingly adjusts the neighbor pixels. I was surprised to see that my transparent background transformed to black, so i thought that it was due to MapPalette.matchColor(color) which was checking for the alpha channel but it does, in fact the function will return the transparent pixel if the alpha channel is <= 127, which is logical because maps only show fully opaque pixels (or the fully transparent one). I then found out about the issue I described above. For now I will add a check myself, in case index is 0 then don't try to MapPalette.getColor it, instead chose directly transparent.

       

            DerFrZocker Marvin Rieple
            Alexis Alexis B
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: