/** Takes ETC1 compressed image data and converts it to a {@link Format#RGB565} or {@link Format#RGB888} {@link Pixmap}. Does * not modify the ByteBuffer's position or limit. * @param etc1Data the {@link ETC1Data} instance * @param format either {@link Format#RGB565} or {@link Format#RGB888} * @return the Pixmap */ public static Pixmap decodeImage (ETC1Data etc1Data, Format format) { int dataOffset = 0; int width = 0; int height = 0; if (etc1Data.hasPKMHeader()) { dataOffset = 16; width = ETC1.getWidthPKM(etc1Data.compressedData, 0); height = ETC1.getHeightPKM(etc1Data.compressedData, 0); } else { dataOffset = 0; width = etc1Data.width; height = etc1Data.height; } int pixelSize = getPixelSize(format); Pixmap pixmap = new Pixmap(width, height, format); decodeImage(etc1Data.compressedData, dataOffset, pixmap.getPixels(), 0, width, height, pixelSize); return pixmap; }
/** Encodes the image via the ETC1 compression scheme. Only {@link Format#RGB565} and {@link Format#RGB888} are supported. Adds * a PKM header in front of the compressed image data. * @param pixmap the {@link Pixmap} * @return the {@link ETC1Data} */ public static ETC1Data encodeImagePKM (Pixmap pixmap) { int pixelSize = getPixelSize(pixmap.getFormat()); ByteBuffer compressedData = encodeImagePKM(pixmap.getPixels(), 0, pixmap.getWidth(), pixmap.getHeight(), pixelSize); BufferUtils.newUnsafeByteBuffer(compressedData); return new ETC1Data(pixmap.getWidth(), pixmap.getHeight(), compressedData, 16); }
/** Encodes the image via the ETC1 compression scheme. Only {@link Format#RGB565} and {@link Format#RGB888} are supported. * @param pixmap the {@link Pixmap} * @return the {@link ETC1Data} */ public static ETC1Data encodeImage (Pixmap pixmap) { int pixelSize = getPixelSize(pixmap.getFormat()); ByteBuffer compressedData = encodeImage(pixmap.getPixels(), 0, pixmap.getWidth(), pixmap.getHeight(), pixelSize); BufferUtils.newUnsafeByteBuffer(compressedData); return new ETC1Data(pixmap.getWidth(), pixmap.getHeight(), compressedData, 0); }
public String toString () { if (hasPKMHeader()) { return (ETC1.isValidPKM(compressedData, 0) ? "valid" : "invalid") + " pkm [" + ETC1.getWidthPKM(compressedData, 0) + "x" + ETC1.getHeightPKM(compressedData, 0) + "], compressed: " + (compressedData.capacity() - ETC1.PKM_HEADER_SIZE); } else { return "raw [" + width + "x" + height + "], compressed: " + (compressedData.capacity() - ETC1.PKM_HEADER_SIZE); } } }
public ETC1Data (FileHandle pkmFile) { byte[] buffer = new byte[1024 * 10]; DataInputStream in = null; try { in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(pkmFile.read()))); int fileSize = in.readInt(); compressedData = BufferUtils.newUnsafeByteBuffer(fileSize); int readBytes = 0; while ((readBytes = in.read(buffer)) != -1) { compressedData.put(buffer, 0, readBytes); } compressedData.position(0); compressedData.limit(compressedData.capacity()); } catch (Exception e) { throw new GdxRuntimeException("Couldn't load pkm file '" + pkmFile + "'", e); } finally { StreamUtils.closeQuietly(in); } width = getWidthPKM(compressedData, 0); height = getHeightPKM(compressedData, 0); dataOffset = PKM_HEADER_SIZE; compressedData.position(dataOffset); checkNPOT(); }
ByteBuffer ktxData = ktx.getData(0, ktxFace); if (ktxData != null && ktx.getGlInternalFormat() == ETC1.ETC1_RGB8_OES) facePixmap = ETC1.decodeImage(new ETC1Data(levelWidth, levelHeight, ktxData, 0), Format.RGB888); facePixmap = ETC1.decodeImage(etc1, Format.RGB888); if (levelPixmap == null) levelPixmap = ETC1.decodeImage(levelETCData, Format.RGB888); int w = levelPixmap.getWidth(), h = levelPixmap.getHeight(); Pixmap pm = new Pixmap(w, h * 2, levelPixmap.getFormat()); levelETCData = ETC1.encodeImagePKM(levelPixmap); levelPixmap.dispose(); levelPixmap = null;
if (!Gdx.graphics.supportsExtension("GL_OES_compressed_ETC1_RGB8_texture")) { ETC1Data etcData = new ETC1Data(pixelWidth, pixelHeight, data, 0); Pixmap pixmap = ETC1.decodeImage(etcData, Format.RGB888); Gdx.gl.glTexImage2D(target + face, level, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());
@Override protected void processFile (Entry entry) throws Exception { System.out.println("Processing " + entry.inputFile); Pixmap pixmap = new Pixmap(new FileHandle(entry.inputFile)); if (pixmap.getFormat() != Format.RGB888 && pixmap.getFormat() != Format.RGB565) { System.out.println("Converting from " + pixmap.getFormat() + " to RGB888!"); Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Format.RGB888); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); pixmap = tmp; } ETC1.encodeImagePKM(pixmap).write(new FileHandle(entry.outputFile)); pixmap.dispose(); }
ByteBuffer ktxData = ktx.getData(0, ktxFace); if (ktxData != null && ktx.getGlInternalFormat() == ETC1.ETC1_RGB8_OES) facePixmap = ETC1.decodeImage(new ETC1Data(levelWidth, levelHeight, ktxData, 0), Format.RGB888); facePixmap = ETC1.decodeImage(etc1, Format.RGB888); if (levelPixmap == null) levelPixmap = ETC1.decodeImage(levelETCData, Format.RGB888); int w = levelPixmap.getWidth(), h = levelPixmap.getHeight(); Pixmap pm = new Pixmap(w, h * 2, levelPixmap.getFormat()); levelETCData = ETC1.encodeImagePKM(levelPixmap); levelPixmap.dispose(); levelPixmap = null;
if (!Gdx.graphics.supportsExtension("GL_OES_compressed_ETC1_RGB8_texture")) { ETC1Data etcData = new ETC1Data(pixelWidth, pixelHeight, data, 0); Pixmap pixmap = ETC1.decodeImage(etcData, Format.RGB888); Gdx.gl.glTexImage2D(target + face, level, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels());
@Override protected void processFile (Entry entry) throws Exception { System.out.println("Processing " + entry.inputFile); Pixmap pixmap = new Pixmap(new FileHandle(entry.inputFile)); if (pixmap.getFormat() != Format.RGB888 && pixmap.getFormat() != Format.RGB565) { System.out.println("Converting from " + pixmap.getFormat() + " to RGB888!"); Pixmap tmp = new Pixmap(pixmap.getWidth(), pixmap.getHeight(), Format.RGB888); tmp.drawPixmap(pixmap, 0, 0, 0, 0, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); pixmap = tmp; } ETC1.encodeImagePKM(pixmap).write(new FileHandle(entry.outputFile)); pixmap.dispose(); }
public String toString () { if (hasPKMHeader()) { return (ETC1.isValidPKM(compressedData, 0) ? "valid" : "invalid") + " pkm [" + ETC1.getWidthPKM(compressedData, 0) + "x" + ETC1.getHeightPKM(compressedData, 0) + "], compressed: " + (compressedData.capacity() - ETC1.PKM_HEADER_SIZE); } else { return "raw [" + width + "x" + height + "], compressed: " + (compressedData.capacity() - ETC1.PKM_HEADER_SIZE); } } }
public ETC1Data (FileHandle pkmFile) { byte[] buffer = new byte[1024 * 10]; DataInputStream in = null; try { in = new DataInputStream(new BufferedInputStream(new GZIPInputStream(pkmFile.read()))); int fileSize = in.readInt(); compressedData = BufferUtils.newUnsafeByteBuffer(fileSize); int readBytes = 0; while ((readBytes = in.read(buffer)) != -1) { compressedData.put(buffer, 0, readBytes); } compressedData.position(0); compressedData.limit(compressedData.capacity()); } catch (Exception e) { throw new GdxRuntimeException("Couldn't load pkm file '" + pkmFile + "'", e); } finally { StreamUtils.closeQuietly(in); } width = getWidthPKM(compressedData, 0); height = getHeightPKM(compressedData, 0); dataOffset = PKM_HEADER_SIZE; compressedData.position(dataOffset); checkNPOT(); }
@Override public void create () { font = new BitmapFont(); camera = new OrthographicCamera(Gdx.graphics.getWidth(), Gdx.graphics.getHeight()); controller = new OrthoCamController(camera); Gdx.input.setInputProcessor(controller); Pixmap pixmap = new Pixmap(32, 32, Format.RGB565); pixmap.setColor(1, 0, 0, 1); pixmap.fill(); pixmap.setColor(0, 1, 0, 1); pixmap.drawLine(0, 0, 32, 32); pixmap.drawLine(0, 32, 32, 0); ETC1Data encodedImage = ETC1.encodeImagePKM(pixmap); pixmap.dispose(); pixmap = ETC1.decodeImage(encodedImage, Format.RGB565); encodedImage.dispose(); img1 = new Texture(pixmap); img2 = new Texture("data/test.etc1"); batch = new SpriteBatch(); pixmap.dispose(); }
/** Takes ETC1 compressed image data and converts it to a {@link Format#RGB565} or {@link Format#RGB888} {@link Pixmap}. Does * not modify the ByteBuffer's position or limit. * @param etc1Data the {@link ETC1Data} instance * @param format either {@link Format#RGB565} or {@link Format#RGB888} * @return the Pixmap */ public static Pixmap decodeImage (ETC1Data etc1Data, Format format) { int dataOffset = 0; int width = 0; int height = 0; if (etc1Data.hasPKMHeader()) { dataOffset = 16; width = ETC1.getWidthPKM(etc1Data.compressedData, 0); height = ETC1.getHeightPKM(etc1Data.compressedData, 0); } else { dataOffset = 0; width = etc1Data.width; height = etc1Data.height; } int pixelSize = getPixelSize(format); Pixmap pixmap = new Pixmap(width, height, format); decodeImage(etc1Data.compressedData, dataOffset, pixmap.getPixels(), 0, width, height, pixelSize); return pixmap; }
@Override public void consumeCustomData (int target) { if (!isPrepared) throw new GdxRuntimeException("Call prepare() before calling consumeCompressedData()"); if (!Gdx.graphics.supportsExtension("GL_OES_compressed_ETC1_RGB8_texture")) { Pixmap pixmap = ETC1.decodeImage(data, Format.RGB565); Gdx.gl.glTexImage2D(target, 0, pixmap.getGLInternalFormat(), pixmap.getWidth(), pixmap.getHeight(), 0, pixmap.getGLFormat(), pixmap.getGLType(), pixmap.getPixels()); if (useMipMaps) MipMapGenerator.generateMipMap(target, pixmap, pixmap.getWidth(), pixmap.getHeight()); pixmap.dispose(); useMipMaps = false; } else { Gdx.gl.glCompressedTexImage2D(target, 0, ETC1.ETC1_RGB8_OES, width, height, 0, data.compressedData.capacity() - data.dataOffset, data.compressedData); if (useMipMaps()) Gdx.gl20.glGenerateMipmap(GL20.GL_TEXTURE_2D); } data.dispose(); data = null; isPrepared = false; }
/** Encodes the image via the ETC1 compression scheme. Only {@link Format#RGB565} and {@link Format#RGB888} are supported. Adds * a PKM header in front of the compressed image data. * @param pixmap the {@link Pixmap} * @return the {@link ETC1Data} */ public static ETC1Data encodeImagePKM (Pixmap pixmap) { int pixelSize = getPixelSize(pixmap.getFormat()); ByteBuffer compressedData = encodeImagePKM(pixmap.getPixels(), 0, pixmap.getWidth(), pixmap.getHeight(), pixelSize); BufferUtils.newUnsafeByteBuffer(compressedData); return new ETC1Data(pixmap.getWidth(), pixmap.getHeight(), compressedData, 16); }
etcData = ETC1.encodeImagePKM(imagePixmap); imagePixmap.dispose(); imagePixmap = null;
public String toString () { if (hasPKMHeader()) { return (ETC1.isValidPKM(compressedData, 0) ? "valid" : "invalid") + " pkm [" + ETC1.getWidthPKM(compressedData, 0) + "x" + ETC1.getHeightPKM(compressedData, 0) + "], compressed: " + (compressedData.capacity() - ETC1.PKM_HEADER_SIZE); } else { return "raw [" + width + "x" + height + "], compressed: " + (compressedData.capacity() - ETC1.PKM_HEADER_SIZE); } } }
/** Encodes the image via the ETC1 compression scheme. Only {@link Format#RGB565} and {@link Format#RGB888} are supported. * @param pixmap the {@link Pixmap} * @return the {@link ETC1Data} */ public static ETC1Data encodeImage (Pixmap pixmap) { int pixelSize = getPixelSize(pixmap.getFormat()); ByteBuffer compressedData = encodeImage(pixmap.getPixels(), 0, pixmap.getWidth(), pixmap.getHeight(), pixelSize); BufferUtils.newUnsafeByteBuffer(compressedData); return new ETC1Data(pixmap.getWidth(), pixmap.getHeight(), compressedData, 0); }