texHeight = ktx.getHeight(); } else if (file.name().toLowerCase().endsWith(".etc1")) { etc1 = new ETC1Data(file); nLevels = 1; texWidth = etc1.width; ByteBuffer ktxData = ktx.getData(level, ktxFace); if (ktxData != null && ktx.getGlInternalFormat() == ETC1.ETC1_RGB8_OES) levelETCData = new ETC1Data(levelWidth, levelHeight, ktxData, 0); facePixmap = ETC1.decodeImage(new ETC1Data(levelWidth, levelHeight, ktxData, 0), Format.RGB888); etc1.dispose(); etc1 = null;
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(); }
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); } } }
texHeight = ktx.getHeight(); } else if (file.name().toLowerCase().endsWith(".etc1")) { etc1 = new ETC1Data(file); nLevels = 1; texWidth = etc1.width; ByteBuffer ktxData = ktx.getData(level, ktxFace); if (ktxData != null && ktx.getGlInternalFormat() == ETC1.ETC1_RGB8_OES) levelETCData = new ETC1Data(levelWidth, levelHeight, ktxData, 0); facePixmap = ETC1.decodeImage(new ETC1Data(levelWidth, levelHeight, ktxData, 0), Format.RGB888); etc1.dispose(); etc1 = null;
texHeight = ktx.getHeight(); } else if (file.name().toLowerCase().endsWith(".etc1")) { etc1 = new ETC1Data(file); nLevels = 1; texWidth = etc1.width; ByteBuffer ktxData = ktx.getData(level, ktxFace); if (ktxData != null && ktx.getGlInternalFormat() == ETC1.ETC1_RGB8_OES) levelETCData = new ETC1Data(levelWidth, levelHeight, ktxData, 0); facePixmap = ETC1.decodeImage(new ETC1Data(levelWidth, levelHeight, ktxData, 0), Format.RGB888); etc1.dispose(); etc1 = null;
if (glInternalFormat == ETC1.ETC1_RGB8_OES) { 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(),
/** 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; }
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 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; }
@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(); }
@Override public void prepare () { if (isPrepared) throw new GdxRuntimeException("Already prepared"); if (file == null && data == null) throw new GdxRuntimeException("Can only load once from ETC1Data"); if (file != null) { data = new ETC1Data(file); } width = data.width; height = data.height; isPrepared = true; }
/** 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 (int width, int height, ByteBuffer compressedData, int dataOffset) { this.width = width; this.height = height; this.compressedData = compressedData; this.dataOffset = dataOffset; checkNPOT(); }
texHeight = ktx.getHeight(); } else if (file.name().toLowerCase().endsWith(".etc1")) { etc1 = new ETC1Data(file); nLevels = 1; texWidth = etc1.width; ByteBuffer ktxData = ktx.getData(level, ktxFace); if (ktxData != null && ktx.getGlInternalFormat() == ETC1.ETC1_RGB8_OES) levelETCData = new ETC1Data(levelWidth, levelHeight, ktxData, 0); facePixmap = ETC1.decodeImage(new ETC1Data(levelWidth, levelHeight, ktxData, 0), Format.RGB888); etc1.dispose(); etc1 = null;
if (glInternalFormat == ETC1.ETC1_RGB8_OES) { 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(),
if (glInternalFormat == ETC1.ETC1_RGB8_OES) { 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(),
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(); }
/** 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; }