예제 #1
0
  /**
   * 将LImage转化为LTextureData
   *
   * @param image
   * @return
   */
  private void create(LImage image) {
    if (image == null) {
      return;
    }
    int srcWidth = image.getWidth();
    int srcHeight = image.getHeight();

    this.hasAlpha = image.hasAlpha();

    if (GLEx.isPowerOfTwo(srcWidth) && GLEx.isPowerOfTwo(srcHeight)) {
      this.width = srcWidth;
      this.height = srcHeight;
      this.texHeight = srcHeight;
      this.texWidth = srcWidth;
      this.source = image.getByteBuffer();
      this.pixels = image.getPixels();

      if (image.isAutoDispose()) {
        image.dispose();
        image = null;
      }
      return;
    }

    int texWidth = GLEx.toPowerOfTwo(srcWidth);
    int texHeight = GLEx.toPowerOfTwo(srcHeight);

    this.width = srcWidth;
    this.height = srcHeight;
    this.texHeight = texHeight;
    this.texWidth = texWidth;

    LImage texImage = new LImage(texWidth, texHeight, hasAlpha);

    LGraphics g = texImage.getLGraphics();

    g.drawImage(image, 0, 0);

    if (this.height < texHeight - 1) {
      copyArea(texImage, g, 0, 0, width, 1, 0, texHeight - 1);
      copyArea(texImage, g, 0, height - 1, width, 1, 0, 1);
    }
    if (this.width < texWidth - 1) {
      copyArea(texImage, g, 0, 0, 1, height, texWidth - 1, 0);
      copyArea(texImage, g, width - 1, 0, 1, height, 1, 0);
    }

    this.source = texImage.getByteBuffer();
    this.pixels = texImage.getPixels();

    if (image.isAutoDispose()) {
      image.dispose();
      image = null;
    }
  }
예제 #2
0
 /**
  * 复制指定的LImage图像区域
  *
  * @param image
  * @param g
  * @param x
  * @param y
  * @param width
  * @param height
  * @param dx
  * @param dy
  */
 public static void copyArea(
     LImage image, LGraphics g, int x, int y, int width, int height, int dx, int dy) {
   LImage tmp = image.getSubImage(x, y, width, height);
   g.drawImage(tmp, x + dx, y + dy);
   tmp.dispose();
   tmp = null;
 }