MTrop / DoomStruct

Reads Doom Engine and Doom Engine-derivative structures.
https://mtrop.github.io/DoomStruct/
GNU Lesser General Public License v2.1
16 stars 3 forks source link

Palette.getColor() -> Color parameter outside of expected range #18

Closed tmgeorge2 closed 10 months ago

tmgeorge2 commented 10 months ago

Hi, 1st I am new to Java and I hope I didn't screwed this up. I actually want to use some sprites from doom.wad in libGDX as texture. Currently I read from Picture pixel by pixel and call Palette.getColor() which sometimes throws an error.

I tried to debug it but only got hold of java.awt.Color(int r, int g, int b) and for this index the r-component is -93.

(BTW eclipse just told me: Unable to install breakpoints in net.mtrop... due to missing line number attributes. Modify compiler options to generate line number attributes")

public class Test {
    public static void main(String[] args) {
        try {
            WadFile wad = new WadFile("doom.wad");

            final Palette pal = wad.getDataAs("playpal", Palette.class);

            var c2 = pal.getColor(67);
        } catch (Exception e) {
            System.out.println(e);
        }
    }
}
MTrop commented 10 months ago

You're right - getColor() did not convert the byte components correctly.

If you can, you can get the int ARGB value of a palette color using getColorARGB(). That way, you save a step by not creating a Color object.

Fixed in commit 3af399b0a9714e139578d0f80afea53980770366.