Merge pull request #11 from LeoDJ/master

fix #10 alpha color issue for pixelwar
This commit is contained in:
Marcel Hellkamp 2018-04-19 11:43:50 +02:00 committed by GitHub
commit d698dca2ab
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 6 deletions

View file

@ -151,8 +151,8 @@ public class NetCanvas implements ComponentListener, KeyListener,
final BufferedImage img = pxBuffer; final BufferedImage img = pxBuffer;
if (x >= 0 && x < img.getWidth() && y >= 0 && y < img.getHeight()) { if (x >= 0 && x < img.getWidth() && y >= 0 && y < img.getHeight()) {
final int alpha = (argb >>> 24) % 256; final int alpha = argb & 0xff;
int rgb = argb & 0xffffff; int rgb = (argb & 0xffffff00) >>> 8;
if (alpha < 1) { if (alpha < 1) {
return; return;
@ -166,9 +166,9 @@ public class NetCanvas implements ComponentListener, KeyListener,
g = ((target >>> 8) & 0xff) * (255 - alpha); g = ((target >>> 8) & 0xff) * (255 - alpha);
b = ((target >>> 0) & 0xff) * (255 - alpha); b = ((target >>> 0) & 0xff) * (255 - alpha);
r += ((argb >>> 16) & 0xff) * alpha; r += ((rgb >>> 16) & 0xff) * alpha;
g += ((argb >>> 8) & 0xff) * alpha; g += ((rgb >>> 8) & 0xff) * alpha;
b += ((argb >>> 0) & 0xff) * alpha; b += ((rgb >>> 0) & 0xff) * alpha;
rgb = 0xff << 24; rgb = 0xff << 24;
rgb += (r / 255) << 16; rgb += (r / 255) << 16;

View file

@ -177,7 +177,8 @@ public class PixelClientHandler extends SimpleChannelInboundHandler<String> {
final int y = Integer.parseInt(args[1]); final int y = Integer.parseInt(args[1]);
int color = (int) Long.parseLong(args[2], 16); int color = (int) Long.parseLong(args[2], 16);
if (args[2].length() == 6) { if (args[2].length() == 6) {
color += 0xff000000; color = color << 8;
color += 0x000000ff;
} }
label.setPos(x, y); label.setPos(x, y);
canvas.setPixel(x, y, color); canvas.setPixel(x, y, color);