Example #1
0
  @Override
  public void getRgb(
      int startX, int startY, int width, int height, int[] rgbArray, int offset, int scanSize) {
    Asserts.checkState(isReady(), "Cannot getRgb() a non-ready image");

    if (canvas == null) {
      canvas = img.getOwnerDocument().createCanvasElement();
      canvas.setHeight(img.getHeight());
      canvas.setWidth(img.getWidth());
      canvas.getContext2d().drawImage(img, 0, 0);
      // img.getOwnerDocument().getBody().appendChild(canvas);
    }

    Context2d ctx = canvas.getContext2d();
    ImageData imageData = ctx.getImageData(startX, startY, width, height);
    CanvasPixelArray pixelData = imageData.getData();
    int i = 0;
    int dst = offset;
    for (int y = 0; y < height; y++) {
      for (int x = 0; x < width; x++) {
        int r = pixelData.get(i++);
        int g = pixelData.get(i++);
        int b = pixelData.get(i++);
        int a = pixelData.get(i++);
        rgbArray[dst + x] = a << 24 | r << 16 | g << 8 | b;
      }
      dst += scanSize;
    }
  }
Example #2
0
 @Override
 public Pattern toPattern() {
   Asserts.checkState(isReady(), "Cannot generate a pattern from unready image.");
   Rectangle2D rect = new Rectangle2D.Float(0, 0, width(), height());
   return new JavaPattern(this, new TexturePaint(img, rect));
 }
Example #3
0
 @Override
 protected void updateTexture(int tex) {
   Asserts.checkState(img != null);
   ((JavaGLContext) ctx).updateTexture(tex, img);
 }
Example #4
0
 @Override
 public Surface restore() {
   Asserts.checkState(transformStack.size() > 1, "Unbalanced save/restore");
   transformStack.remove(transformStack.size() - 1);
   return this;
 }
Example #5
0
 @Override
 public Pattern toPattern() {
   Asserts.checkState(isReady(), "Cannot toPattern() a non-ready image");
   return new HtmlPattern(this, repeatX, repeatY);
 }