Compare commits
2 Commits
ba42f2d3bf
...
4a16dbfc9f
Author | SHA1 | Date |
---|---|---|
DaniTheSkunk | 4a16dbfc9f | |
DaniTheSkunk | ef937886cc |
|
@ -43,18 +43,35 @@ public class Image {
|
||||||
public Color getPixel(Vec2i pos) {
|
public Color getPixel(Vec2i pos) {
|
||||||
int i = pos.getX() * 4 + pos.getY() * 4 * size.getX();
|
int i = pos.getX() * 4 + pos.getY() * 4 * size.getX();
|
||||||
return new Color(
|
return new Color(
|
||||||
((int)data[i + 0]) & 0xFF,
|
((int) data[i + 0]) & 0xFF,
|
||||||
((int)data[i + 1]) & 0xFF,
|
((int) data[i + 1]) & 0xFF,
|
||||||
((int)data[i + 2]) & 0xFF,
|
((int) data[i + 2]) & 0xFF,
|
||||||
((int)data[i + 3]) & 0xFF
|
((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 * size.getX();
|
int i = pos.getX() * 4 + pos.getY() * 4 * size.getX();
|
||||||
data[i + 0] = (byte)(col.r & 0xFF);
|
data[i + 0] = (byte) (col.r & 0xFF);
|
||||||
data[i + 1] = (byte)(col.g & 0xFF);
|
data[i + 1] = (byte) (col.g & 0xFF);
|
||||||
data[i + 2] = (byte)(col.b & 0xFF);
|
data[i + 2] = (byte) (col.b & 0xFF);
|
||||||
data[i + 3] = (byte)(col.a & 0xFF);
|
data[i + 3] = (byte) (col.a & 0xFF);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawImage(Image srcImage, Vec2i destPos) {
|
||||||
|
drawImage(srcImage, destPos, new Recti(Vec2i.ZERO, srcImage.getSize()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawImage(Image srcImage, Vec2i destPos, Recti srcRect) {
|
||||||
|
//todo: check bounds
|
||||||
|
//todo: write in faster way than pixel stuff
|
||||||
|
for(int y = 0; y < srcRect.getHeight(); ++y) {
|
||||||
|
for(int x = 0; x < srcRect.getWidth(); ++x) {
|
||||||
|
var iterPos = new Vec2i(x, y);
|
||||||
|
var to = Vec2i.add(destPos, iterPos);
|
||||||
|
var from = Vec2i.add(srcRect.getPos(), iterPos);
|
||||||
|
setPixel(to, srcImage.getPixel(from));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,8 @@ package com.danitheskunk.skunkworks;
|
||||||
public final class Vec2i {
|
public final class Vec2i {
|
||||||
final int x, y;
|
final int x, y;
|
||||||
|
|
||||||
|
public final static Vec2i ZERO = new Vec2i(0, 0);
|
||||||
|
|
||||||
//constructors
|
//constructors
|
||||||
|
|
||||||
public Vec2i(int x, int y) {
|
public Vec2i(int x, int y) {
|
||||||
|
|
Loading…
Reference in New Issue