Don't know how I finished school not being able to solve that little problem...
Following code produces unexpected output:
public Color getPixel(int x, int y){
return img.getPixelReader().getColor(x, y);
}
public float colorToHeight(Color c){
int b =(int)(c.getBlue()*256);
int r =(int)(c.getRed()*256*256);
float h = (b+r)/2;
h-=10000;
return h;
}
public Color heightToColor(float h){
h+=10000;
h*=2;
double r= (int)(h/(256));
double b = h-(r*256);
return new Color(r/256,0,b/256,1f);
}
public void debugPixel(int x, int z){
System.out.println("test 424->Color: "+heightToColor(424f));
System.out.println("test Color->424: "+colorToHeight(heightToColor(424f)));
System.out.println("test Color->424->Color: "+heightToColor(colorToHeight(heightToColor(424f))));
System.out.println("check A: "+getPixel(x,z) + " Height: "+colorToHeight(getPixel(x,z)));
System.out.println("check B: "+heightToColor(colorToHeight(getPixel(x,z))));
System.out.println("check C: "+getPixel(x,z));
}
Output:
test 424->Color: 0x510070ff
test Color->424: 424.0
test Color->424->Color: 0x510070ff
check A: 0x5200cbff Height: 638.0
check B: 0x53001cff
check C: 0x5200cbff
I absolutely do not find the reason why [check B] != [check A]....Thanks!