Beispiel #1
0
 @Override
 public Surface drawImage(Image image, float x, float y, float dw, float dh) {
   bindFramebuffer();
   ((ImageGL) image)
       .draw(shader, topTransform(), x, y, dw, dh, 0, 0, image.width(), image.height(), tint);
   return this;
 }
Beispiel #2
0
  @Override
  public boolean loadAsset() {
    logger.info("Loading image " + descriptor.getUri());
    loaded = false;
    if (image == null) {
      try {
        String path = assetHandler.getAbsolutePath(descriptor.getUri().getPath());
        image = PlayN.assets().getImage(path);
        if (image != null) {
          logger.info(
              "Image loaded OK: {} from {} width {}",
              new Object[] {descriptor.getUri(), path, image.width()});
          return image.isReady();
        } else {
          logger.error("Image NOT loaded: {}", descriptor.getUri());
          return true;
        }
      } catch (Exception e) {
        logger.error("Error loading image: {}", descriptor.getUri(), e);
        return false;
      }
    }
    image.addCallback(
        new ResourceCallback<Image>() {

          @Override
          public void done(Image resource) {
            loaded = true;
          }

          @Override
          public void error(Throwable err) {}
        });
    return loaded;
  }
 /**
  * Creates a new background using the given image. The image is assumed to be divided into a 3x1
  * grid of 3 equal pieces.
  *
  * <p>NOTE: the image must be preloaded since we need to determine the stretching factor. If this
  * cannot be arranged using the application resource strategy, callers may consider setting the
  * background style from the images callback.
  */
 public Scale3Background(Image image) {
   if (!image.isReady()) {
     // complain about this, we don't support asynch images
     PlayN.log().warn("Scale3 image not preloaded: " + image);
   }
   _image = image;
   _s3 = new Scale3(image.width(), image.height());
 }
Beispiel #4
0
  // used by GLContext.tex(Sub)Image2D impls
  protected static ByteBuffer getRgba(Image image) {
    int w = (int) image.width(), h = (int) image.height(), size = w * h;
    int[] rawPixels = new int[size];
    ByteBuffer pixels = ByteBuffer.allocateDirect(size * 4);
    pixels.order(ByteOrder.nativeOrder());
    IntBuffer rgba = pixels.asIntBuffer();
    image.getRgb(0, 0, w, h, rawPixels, 0, w);

    for (int i = 0; i < size; i++) {
      int argb = rawPixels[i];
      // Order is inverted because this is read as a byte array, and we store intel ints.
      rgba.put(i, ((argb >> 16) & 0x0ff) | (argb & 0x0ff00ff00) | ((argb & 0xff) << 16));
    }
    return pixels;
  }
 @Override
 public Surface drawImageCentered(Image img, float x, float y) {
   return drawImage(img, x - img.width() / 2, y - img.height() / 2);
 }
 @Override
 public Surface drawImage(Image image, float x, float y) {
   return drawImage(image, x, y, image.width(), image.height());
 }
Beispiel #7
0
 public int getWidth() {
   if (image != null) return image.width();
   return 1;
 }
Beispiel #8
0
 /**
  * Creates an instance with the supplied source image. The image is assumed to contain a complete
  * sheet of frames, each {@code width x height} in size.
  *
  * @param width the width of each frame.
  * @param height the width of each frame.
  */
 public SimpleFrames(Image source, float width, float height) {
   this(source, width, height, (int) (source.height() / height) * (int) (source.width() / width));
 }