Ejemplo n.º 1
0
  @Override
  public ILegibleImage readAsset(IAsset asset, DataInputStream in) throws Throwable {
    PNGDecoder dec = new PNGDecoder(in);

    int width = dec.getWidth();
    int height = dec.getHeight();

    ByteBuffer buf = BufferHelper.createByteBuffer(width * height * 4);

    dec.decode(buf, width * 4, PNGDecoder.Format.RGBA);

    buf.flip();

    return new LegibleByteImage(ColorFormat.RGBA, width, height, buf);
  }
Ejemplo n.º 2
0
  private TextureData decodeTextureFile(String fileName) {
    int width = 0;
    int height = 0;
    ByteBuffer buffer = null;
    try {

      String path = "Skyboxes/" + fileName + ".png";
      InputStream source = this.getClass().getClassLoader().getResourceAsStream(path);
      PNGDecoder decoder = new PNGDecoder(source);
      width = decoder.getWidth();
      height = decoder.getHeight();
      buffer = ByteBuffer.allocateDirect(4 * width * height);
      decoder.decode(buffer, width * 4, Format.RGBA);
      buffer.flip();
      source.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
    return new TextureData(buffer, width, height);
  }
Ejemplo n.º 3
0
 private TextureData decodeTextureFile(String fileName) {
   int width = 0;
   int height = 0;
   ByteBuffer buffer = null;
   try {
     FileInputStream in = new FileInputStream(fileName);
     PNGDecoder decoder = new PNGDecoder(in);
     width = decoder.getWidth();
     height = decoder.getHeight();
     buffer = ByteBuffer.allocateDirect(4 * width * height);
     decoder.decode(buffer, width * 4, Format.RGBA);
     buffer.flip();
     in.close();
   } catch (Exception e) {
     e.printStackTrace();
     System.err.println("Tried to load texture " + fileName + ", didn't work");
     System.exit(-1);
   }
   return new TextureData(buffer, width, height);
 }
Ejemplo n.º 4
0
  private void fetchPNGTexture() throws IOException {

    InputStream in = this.getClass().getResourceAsStream(pngLocation);
    // Link the PNG decoder to this stream
    PNGDecoder decoder = new PNGDecoder(in);

    // Get the width and height of the texture
    tWidth = decoder.getWidth();
    tHeight = decoder.getHeight();

    // Decode the PNG file in a ByteBuffer
    textureBuffer = ByteBuffer.allocateDirect(4 * decoder.getWidth() * decoder.getHeight());
    decoder.decode(textureBuffer, decoder.getWidth() * 4, PNGDecoder.Format.RGBA);
    textureBuffer.flip();

    in.close();
    if (Log.logger.getLevel() == Level.DEBUG)
      Log.logger.debug(
          "Texture {} decoded successfully. Width is {}. Height is {}.",
          pngLocation,
          tWidth,
          tHeight);
  }