Skip to content

Commit

Permalink
Merge pull request #11 from LeoDJ/master
Browse files Browse the repository at this point in the history
fix #10 alpha color issue for pixelwar
  • Loading branch information
defnull authored Apr 19, 2018
2 parents 056f992 + 640b23e commit d698dca
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
10 changes: 5 additions & 5 deletions pixelwar/src/main/java/de/paws/pixelwar/NetCanvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,8 @@ public void setPixel(final int x, final int y, final int argb) {
final BufferedImage img = pxBuffer;

if (x >= 0 && x < img.getWidth() && y >= 0 && y < img.getHeight()) {
final int alpha = (argb >>> 24) % 256;
int rgb = argb & 0xffffff;
final int alpha = argb & 0xff;
int rgb = (argb & 0xffffff00) >>> 8;

if (alpha < 1) {
return;
Expand All @@ -166,9 +166,9 @@ public void setPixel(final int x, final int y, final int argb) {
g = ((target >>> 8) & 0xff) * (255 - alpha);
b = ((target >>> 0) & 0xff) * (255 - alpha);

r += ((argb >>> 16) & 0xff) * alpha;
g += ((argb >>> 8) & 0xff) * alpha;
b += ((argb >>> 0) & 0xff) * alpha;
r += ((rgb >>> 16) & 0xff) * alpha;
g += ((rgb >>> 8) & 0xff) * alpha;
b += ((rgb >>> 0) & 0xff) * alpha;

rgb = 0xff << 24;
rgb += (r / 255) << 16;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,8 @@ private void handle_PX(final ChannelHandlerContext ctx, final String data) {
final int y = Integer.parseInt(args[1]);
int color = (int) Long.parseLong(args[2], 16);
if (args[2].length() == 6) {
color += 0xff000000;
color = color << 8;
color += 0x000000ff;
}
label.setPos(x, y);
canvas.setPixel(x, y, color);
Expand Down

0 comments on commit d698dca

Please sign in to comment.