protected BufferedImage scaleImage(BufferedImage image, float viewImageRatio) { int swidth = MathUtil.iceil(viewImageRatio * image.getWidth()); int sheight = MathUtil.iceil(viewImageRatio * image.getHeight()); BufferedImage scaled = new BufferedImage(swidth, sheight, BufferedImage.TYPE_INT_ARGB_PRE); Graphics2D gfx = scaled.createGraphics(); gfx.drawImage(image.getScaledInstance(swidth, sheight, java.awt.Image.SCALE_SMOOTH), 0, 0, null); gfx.dispose(); return scaled; }
protected BufferedImage scaleImage(BufferedImage image, float viewImageRatio) { int swidth = MathUtil.iceil(viewImageRatio * image.getWidth()); int sheight = MathUtil.iceil(viewImageRatio * image.getHeight()); BufferedImage scaled = new BufferedImage(swidth, sheight, BufferedImage.TYPE_INT_ARGB_PRE); Graphics2D gfx = scaled.createGraphics(); gfx.drawImage(image.getScaledInstance(swidth, sheight, java.awt.Image.SCALE_SMOOTH), 0, 0, null); gfx.dispose(); return scaled; }
protected BufferedImage scaleImage(BufferedImage image, float viewImageRatio) { int swidth = MathUtil.iceil(viewImageRatio * image.getWidth()); int sheight = MathUtil.iceil(viewImageRatio * image.getHeight()); BufferedImage scaled = new BufferedImage(swidth, sheight, BufferedImage.TYPE_INT_ARGB_PRE); Graphics2D gfx = scaled.createGraphics(); gfx.drawImage(image.getScaledInstance(swidth, sheight, java.awt.Image.SCALE_SMOOTH), 0, 0, null); gfx.dispose(); return scaled; }
@Override protected Pattern toSubPattern(AbstractImageGL<?> image, boolean repeatX, boolean repeatY, float x, float y, float width, float height) { int ix = MathUtil.ifloor(x), iy = MathUtil.ifloor(y); int iw = MathUtil.iceil(width), ih = MathUtil.iceil(height); return new AndroidPattern(image, repeatX, repeatY, Bitmap.createBitmap(bitmap, ix, iy, iw, ih)); }
@Override public Canvas clipRect(float x, float y, float width, final float height) { final int cx = MathUtil.ifloor(x), cy = MathUtil.ifloor(y); final int cwidth = MathUtil.iceil(width), cheight = MathUtil.iceil(height); currentState().clipper = new JavaCanvasState.Clipper() { public void setClip(Graphics2D g2d) { g2d.setClip(cx, cy, cwidth, cheight); } }; return this; }
@Override public Canvas clipRect(float x, float y, float width, final float height) { final int cx = MathUtil.ifloor(x), cy = MathUtil.ifloor(y); final int cwidth = MathUtil.iceil(width), cheight = MathUtil.iceil(height); currentState().clipper = new JavaCanvasState.Clipper() { public void setClip(Graphics2D gfx) { gfx.clipRect(cx, cy, cwidth, cheight); } }; return this; }
@Override public Canvas clipRect(float x, float y, float width, final float height) { final int cx = MathUtil.ifloor(x), cy = MathUtil.ifloor(y); final int cwidth = MathUtil.iceil(width), cheight = MathUtil.iceil(height); currentState().clipper = new JavaCanvasState.Clipper() { public void setClip(Graphics2D g2d) { g2d.setClip(cx, cy, cwidth, cheight); } }; return this; }
@Override public Canvas clipRect(float x, float y, float width, final float height) { final int cx = MathUtil.ifloor(x), cy = MathUtil.ifloor(y); final int cwidth = MathUtil.iceil(width), cheight = MathUtil.iceil(height); currentState().clipper = new JavaCanvasState.Clipper() { public void setClip(Graphics2D gfx) { gfx.clipRect(cx, cy, cwidth, cheight); } }; return this; }
HtmlGLContext(HtmlPlatform platform, float scaleFactor, WebGLRenderingContext gl, CanvasElement canvas) { super(platform, new HtmlGL20(gl), scaleFactor, HtmlUrlParameters.checkGLErrors); this.glc = gl; // try basic GL operations to detect failure cases early tryBasicGLCalls(); setSize(MathUtil.iceil(canvas.getWidth() / scaleFactor), MathUtil.iceil(canvas.getHeight() / scaleFactor)); init(); glc.pixelStorei(UNPACK_PREMULTIPLY_ALPHA_WEBGL, ONE); }
@Override protected Image createErrorImage(Throwable cause, float width, float height) { ImageElement img = Document.get().createImageElement(); img.setWidth(MathUtil.iceil(width)); img.setHeight(MathUtil.iceil(height)); // TODO: proper error image that reports failure to callbacks return new HtmlImage(platform.graphics().ctx(), Scale.ONE, img); }
@Override protected Pattern toSubPattern(AbstractImageGL<?> image, boolean repeatX, boolean repeatY, float x, float y, float width, float height) { CanvasElement canvas = Document.get().createElement("canvas").<CanvasElement>cast(); canvas.setWidth(MathUtil.iceil(width)); canvas.setHeight(MathUtil.iceil(height)); canvas.getContext2d().drawImage(img, x, y, width, height, 0, 0, width, height); ImageElement subelem = canvas.cast(); return new HtmlPattern(image, subelem, repeatX, repeatY); }