private boolean decodeScanlineUncompressed(InputStream in, int width) throws IOException{ byte[] rgbe = new byte[4]; for (int i = 0; i < width; i+=3){ if (in.read(rgbe) < 1) return false; writeRGBE(rgbe); } return true; }
n = writeCode5(n, 0, 0, readCode5(l, 0, 1)); n = writeCode5(n, 1, 0, readCode5(l, 1, 1)); n = writeCode5(n, 2, 0, readCode5(l, 2, 1)); n = writeCode5(n, 3, 0, readCode5(l, 3, 1)); n = writeCode5(n, 0, 1, readCode5(l, 0, 0)); n = writeCode5(n, 1, 1, readCode5(l, 1, 0)); n = writeCode5(n, 2, 1, readCode5(l, 2, 0)); n = writeCode5(n, 3, 1, readCode5(l, 3, 0)); }else{ n = writeCode5(n, 0, 0, readCode5(l, 0, 3)); n = writeCode5(n, 1, 0, readCode5(l, 1, 3)); n = writeCode5(n, 2, 0, readCode5(l, 2, 3)); n = writeCode5(n, 3, 0, readCode5(l, 3, 3)); n = writeCode5(n, 0, 1, readCode5(l, 0, 2)); n = writeCode5(n, 1, 1, readCode5(l, 1, 2)); n = writeCode5(n, 2, 1, readCode5(l, 2, 2)); n = writeCode5(n, 3, 1, readCode5(l, 3, 2)); n = writeCode5(n, 0, 2, readCode5(l, 0, 1)); n = writeCode5(n, 1, 2, readCode5(l, 1, 1)); n = writeCode5(n, 2, 2, readCode5(l, 2, 1)); n = writeCode5(n, 3, 2, readCode5(l, 3, 1)); n = writeCode5(n, 0, 3, readCode5(l, 0, 0)); n = writeCode5(n, 1, 3, readCode5(l, 1, 0)); n = writeCode5(n, 2, 3, readCode5(l, 2, 0)); n = writeCode5(n, 3, 3, readCode5(l, 3, 0));
private void decodeScanline(InputStream in, int width) throws IOException{ if (width < 8 || width > 0x7fff){ // too short/long for RLE compression decodeScanlineUncompressed(in, width); } // check format byte[] data = new byte[4]; in.read(data); if (data[0] != 0x02 || data[1] != 0x02 || (data[2] & 0x80) != 0){ // not RLE data decodeScanlineUncompressed(in, width-1); }else{ // check scanline width int readWidth = (data[2] & 0xFF) << 8 | (data[3] & 0xFF); if (readWidth != width) throw new IOException("Illegal scanline width in HDR file: "+width+" != "+readWidth); // RLE data decodeScanlineRLE(in, width); } }
for (int i = 0; i < depth; i++) { if (compressed) { allMaps.add(readDXT2D(flip, totalSize)); } else if (grayscaleOrAlpha) { allMaps.add(readGrayscale2D(flip, totalSize)); } else { allMaps.add(readRGB2D(flip, totalSize)); allMaps.add(readDXT3D(flip, totalSize)); } else if (grayscaleOrAlpha) { allMaps.add(readGrayscale3D(flip, totalSize)); } else { allMaps.add(readRGB3D(flip, totalSize)); allMaps.add(readDXT2D(flip, totalSize)); } else if (grayscaleOrAlpha) { allMaps.add(readGrayscale2D(flip, totalSize)); } else { allMaps.add(readRGB2D(flip, totalSize));
public static void resizeToPowerOf2(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); int potSize = Math.max(potWidth, potHeight); BufferedImage scaled = scaleDown(original, potSize, potSize); AWTLoader loader = new AWTLoader(); Image output = loader.load(scaled, false); image.setWidth(potSize); image.setHeight(potSize); image.setDepth(0); image.setData(output.getData(0)); image.setFormat(output.getFormat()); image.setMipMapSizes(null); }
public Image load(InputStream in, boolean flipY) throws IOException{ ImageIO.setUseCache(false); BufferedImage img = ImageIO.read(in); if (img == null){ return null; } return load(img, flipY); }
if (!is(flags, DDSD_MANDATORY) && !is(flags, DDSD_MANDATORY_DX10)) { throw new IOException("Mandatory flags missing"); pixelFormat = null; directx10 = false; readPixelFormat(); caps1 = in.readInt(); caps2 = in.readInt(); if (!is(caps1, DDSCAPS_TEXTURE)) { logger.warning("Texture is missing the DDSCAPS_TEXTURE-flag"); if (is(caps2, DDSCAPS2_CUBEMAP)) { depth = 6; // somewhat of a hack, force loading 6 textures if a cubemap if (is(caps2, DDSCAPS2_VOLUME)) { texture3D = true; if (is(caps1, DDSCAPS_MIPMAP)) { if (!is(flags, DDSD_MIPMAPCOUNT)) { mipMapCount = expectedMipmaps; } else if (mipMapCount != expectedMipmaps) { loadDX10Header(); loadSizes();
public Image load(InputStream stream) throws IOException { in = new LittleEndien(stream); loadHeader(); ArrayList<ByteBuffer> data = readData(false); return new Image(pixelFormat, width, height, depth, data, sizes, ColorSpace.sRGB); }
ByteBuffer wrapped = ByteBuffer.wrap(data); wrapped.rewind(); ByteBuffer flipped = DXTFlipper.flipDXT(wrapped, mipWidth, mipHeight, pixelFormat); buffer.put(flipped); } else {
private void loadDX10Header() throws IOException { int dxgiFormat = in.readInt(); if (dxgiFormat == 0) { pixelFormat = Format.ETC1; bpp = 4; } else { throw new IOException("Unsupported DX10 format: " + dxgiFormat); } compressed = true; int resDim = in.readInt(); if (resDim == DX10DIM_TEXTURE3D) { texture3D = true; } int miscFlag = in.readInt(); int arraySize = in.readInt(); if (is(miscFlag, DX10MISC_TEXTURECUBE)) { // mark texture as cube if (arraySize != 6) { throw new IOException("Cubemaps should consist of 6 images!"); } } in.skipBytes(4); // skip reserved value }
private void writeRGBE(byte[] rgbe){ if (writeRGBE){ dataStore.put(rgbe); }else{ convertRGBEtoFloat(rgbe, tempF); dataStore.putShort(FastMath.convertFloatToHalf(tempF[0])) .putShort(FastMath.convertFloatToHalf(tempF[1])). putShort(FastMath.convertFloatToHalf(tempF[2])); } }
public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof TextureKey)) throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); InputStream in = null; try { in = info.openStream(); return load(in, ((TextureKey)info.getKey()).isFlipY()); } finally { if (in != null){ in.close(); } } }
public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof TextureKey)) throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); boolean flip = ((TextureKey) info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); return img; } finally { if (in != null){ in.close(); } } }
/** * Reads a grayscale image with mipmaps from the InputStream * @param flip Flip the loaded image by Y axis * @param totalSize Total size of the image in bytes including the mipmaps * @return A ByteBuffer containing the grayscale image data with mips. * @throws java.io.IOException If an error occured while reading from InputStream */ public ByteBuffer readGrayscale2D(boolean flip, int totalSize) throws IOException { ByteBuffer buffer = BufferUtils.createByteBuffer(totalSize); if (bpp == 8) { logger.finest("Source image format: R8"); } assert bpp == pixelFormat.getBitsPerPixel(); int mipWidth = width; int mipHeight = height; for (int mip = 0; mip < mipMapCount; mip++) { byte[] data = new byte[sizes[mip]]; in.readFully(data); if (flip) { data = flipData(data, mipWidth * bpp / 8, mipHeight); } buffer.put(data); mipWidth = Math.max(mipWidth / 2, 1); mipHeight = Math.max(mipHeight / 2, 1); } return buffer; }
public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof TextureKey)) { throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); } boolean flip = ((TextureKey) info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); return img; } finally { if (in != null) { in.close(); } } }
public Image load(AssetInfo info) throws IOException { boolean flip = ((TextureKey) info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); return load(info.openStream(), flip, tmpArray); } finally { if (in != null){ in.close(); } } } }
public Object load(AssetInfo info) throws IOException { if (ImageIO.getImageReadersBySuffix(info.getKey().getExtension()) != null){ boolean flip = ((TextureKey) info.getKey()).isFlipY(); InputStream in = null; try { in = info.openStream(); Image img = load(in, flip); if (img == null){ throw new AssetLoadException("The given image cannot be loaded " + info.getKey()); } return img; } finally { if (in != null){ in.close(); } } }else{ throw new AssetLoadException("The extension " + info.getKey().getExtension() + " is not supported"); } } }
public Object load(AssetInfo info) throws IOException { if (!(info.getKey() instanceof TextureKey)) { throw new IllegalArgumentException("Texture assets must be loaded using a TextureKey"); } InputStream stream = null; try { stream = info.openStream(); in = new LittleEndien(stream); loadHeader(); if (texture3D) { ((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.ThreeDimensional); } else if (depth > 1) { ((TextureKey) info.getKey()).setTextureTypeHint(Texture.Type.CubeMap); } ArrayList<ByteBuffer> data = readData(((TextureKey) info.getKey()).isFlipY()); return new Image(pixelFormat, width, height, depth, data, sizes, ColorSpace.sRGB); } finally { if (stream != null){ stream.close(); } } }
ByteBuffer wrapped = ByteBuffer.wrap(data); wrapped.rewind(); ByteBuffer flipped = DXTFlipper.flipDXT(wrapped, mipWidth, mipHeight, pixelFormat); flipped.rewind(); buffer.put(flipped);