changed Color to int, because of lack of unsigned byte

This commit is contained in:
Dani The Skunk 2022-09-14 06:59:14 +02:00
parent 7fbb1cbc7e
commit a3733090d3
2 changed files with 16 additions and 16 deletions

View File

@ -1,35 +1,35 @@
package com.danitheskunk.skunkworks; package com.danitheskunk.skunkworks;
public final class Color { public final class Color {
final byte r, g, b, a; final int r, g, b, a;
public Color(byte r, byte g, byte b) { public Color(int r, int g, int b) {
this.r = r; this.r = r;
this.g = g; this.g = g;
this.b = b; this.b = b;
this.a = (byte)0xff; this.a = 0xff;
} }
public Color(byte r, byte g, byte b, byte a) { public Color(int r, int g, int b, int a) {
this.r = r; this.r = r;
this.g = g; this.g = g;
this.b = b; this.b = b;
this.a = a; this.a = a;
} }
public byte getR() { public int getR() {
return r; return r;
} }
public byte getG() { public int getG() {
return g; return g;
} }
public byte getB() { public int getB() {
return b; return b;
} }
public byte getA() { public int getA() {
return a; return a;
} }

View File

@ -24,18 +24,18 @@ public class Image {
public Color getPixel(Vec2i pos) { public Color getPixel(Vec2i pos) {
int i = pos.getX() * 4 + pos.getY() * 4 * width; int i = pos.getX() * 4 + pos.getY() * 4 * width;
return new Color( return new Color(
data[i + 0], ((int)data[i + 0]) & 0xFF,
data[i + 1], ((int)data[i + 1]) & 0xFF,
data[i + 2], ((int)data[i + 2]) & 0xFF,
data[i + 3] ((int)data[i + 3]) & 0xFF
); );
} }
public void setPixel(Vec2i pos, Color col) { public void setPixel(Vec2i pos, Color col) {
int i = pos.getX() * 4 + pos.getY() * 4 * width; int i = pos.getX() * 4 + pos.getY() * 4 * width;
data[i + 0] = col.r; data[i + 0] = (byte)(col.r & 0xFF);
data[i + 1] = col.g; data[i + 1] = (byte)(col.g & 0xFF);
data[i + 2] = col.b; data[i + 2] = (byte)(col.b & 0xFF);
data[i + 3] = col.a; data[i + 3] = (byte)(col.a & 0xFF);
} }
} }