Graphics API #328 improvements

This commit is contained in:
Emux
2017-03-07 14:18:48 +02:00
parent e562ebdff6
commit 5818edc228
3 changed files with 20 additions and 13 deletions

View File

@@ -1,6 +1,6 @@
/*
* Copyright 2013 Hannes Janetzek
* Copyright 2016 devemux86
* Copyright 2016-2017 devemux86
* Copyright 2016-2017 Longri
*
* This file is part of the OpenScienceMap project (http://www.opensciencemap.org).
@@ -47,7 +47,7 @@ public class AwtBitmap implements Bitmap {
boolean internal;
public AwtBitmap(int width, int height, int format) {
bitmap = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB_PRE);
bitmap = new BufferedImage(width, height, format != 0 ? format : BufferedImage.TYPE_INT_ARGB);
this.width = width;
this.height = height;

View File

@@ -129,17 +129,21 @@ public class AwtCanvas implements Canvas {
@Override
public void drawBitmap(Bitmap bitmap, float x, float y) {
int intX = (int) x;
int intY = (int) y;
BufferedImage src = ((AwtBitmap) bitmap).bitmap;
int[] srcbuf = ((DataBufferInt) src.getRaster().getDataBuffer()).getData();
int[] dstbuf = ((DataBufferInt) this.bitmap.getRaster().getDataBuffer()).getData();
int width = intX + src.getWidth() > this.bitmap.getWidth() ? this.getWidth() - intX : src.getWidth();
int height = intY + src.getHeight() > this.bitmap.getHeight() ? this.getHeight() - intY : src.getHeight();
int dstoffs = intX + intY * this.bitmap.getWidth();
int srcoffs = 0;
for (int i = 0; i < height; i++, dstoffs += this.bitmap.getWidth(), srcoffs += width)
System.arraycopy(srcbuf, srcoffs, dstbuf, dstoffs, width);
// TODO Need better check
if (src.isAlphaPremultiplied()) {
int intX = (int) x;
int intY = (int) y;
int[] srcbuf = ((DataBufferInt) src.getRaster().getDataBuffer()).getData();
int[] dstbuf = ((DataBufferInt) this.bitmap.getRaster().getDataBuffer()).getData();
int width = intX + src.getWidth() > this.bitmap.getWidth() ? this.getWidth() - intX : src.getWidth();
int height = intY + src.getHeight() > this.bitmap.getHeight() ? this.getHeight() - intY : src.getHeight();
int dstoffs = intX + intY * this.bitmap.getWidth();
int srcoffs = 0;
for (int i = 0; i < height; i++, dstoffs += this.bitmap.getWidth(), srcoffs += width)
System.arraycopy(srcbuf, srcoffs, dstbuf, dstoffs, width);
} else
this.canvas.drawImage(src, (int) x, (int) y, null);
}
@Override