/** * 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; }
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); }
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));
normal = is(pfFlags, DDPF_NORMAL); if (is(pfFlags, DDPF_FOURCC)) { compressed = true; int fourcc = in.readInt(); case PF_DXT1: bpp = 4; if (is(pfFlags, DDPF_ALPHAPIXELS)) { pixelFormat = Image.Format.DXT1A; } else { break; default: throw new IOException("Unknown fourcc: " + string(fourcc) + ", " + Integer.toHexString(fourcc)); if (is(flags, DDSD_LINEARSIZE)) { if (pitchOrSize == 0) { logger.warning("Must use linear size with fourcc"); if (is(pfFlags, DDPF_RGB)) { if (is(pfFlags, DDPF_ALPHAPIXELS)) { if (bpp == 16) { pixelFormat = Format.RGB5A1; } else if (is(pfFlags, DDPF_GRAYSCALE) && is(pfFlags, DDPF_ALPHAPIXELS)) { switch (bpp) { case 16:
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 }
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 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(); } } }
normal = is(pfFlags, DDPF_NORMAL); if (is(pfFlags, DDPF_FOURCC)) { compressed = true; int fourcc = in.readInt(); case PF_DXT1: bpp = 4; if (is(pfFlags, DDPF_ALPHAPIXELS)) { pixelFormat = Image.Format.DXT1A; } else { throw new IOException("Unknown fourcc: " + string(fourcc) + ", " + Integer.toHexString(fourcc)); if (is(flags, DDSD_LINEARSIZE)) { if (pitchOrSize == 0) { logger.warning("Must use linear size with fourcc"); if (is(pfFlags, DDPF_RGB)) { if (is(pfFlags, DDPF_ALPHAPIXELS)) { pixelFormat = Format.RGBA8; } else { pixelFormat = Format.RGB8; } else if (is(pfFlags, DDPF_GRAYSCALE) && is(pfFlags, DDPF_ALPHAPIXELS)) { switch (bpp) { case 16: } else if (is(pfFlags, DDPF_GRAYSCALE)) {
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 }
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));
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)) { throw new IOException("File is not a texture"); 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); }
normal = is(pfFlags, DDPF_NORMAL); if (is(pfFlags, DDPF_FOURCC)) { compressed = true; int fourcc = in.readInt(); case PF_DXT1: bpp = 4; if (is(pfFlags, DDPF_ALPHAPIXELS)) { pixelFormat = Image.Format.DXT1A; } else { break; default: throw new IOException("Unknown fourcc: " + string(fourcc) + ", " + Integer.toHexString(fourcc)); if (is(flags, DDSD_LINEARSIZE)) { if (pitchOrSize == 0) { logger.warning("Must use linear size with fourcc"); if (is(pfFlags, DDPF_RGB)) { if (is(pfFlags, DDPF_ALPHAPIXELS)) { if (bpp == 16) { pixelFormat = Format.RGB5A1; } else if (is(pfFlags, DDPF_GRAYSCALE) && is(pfFlags, DDPF_ALPHAPIXELS)) { switch (bpp) { case 16:
/** * 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 readGrayscale3D(boolean flip, int totalSize) throws IOException { ByteBuffer buffer = BufferUtils.createByteBuffer(totalSize * depth); if (bpp == 8) { logger.finest("Source image format: R8"); } assert bpp == pixelFormat.getBitsPerPixel(); for (int i = 0; i < depth; i++) { 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); } } buffer.rewind(); return buffer; }
private void loadDX10Header() throws IOException { int dxgiFormat = in.readInt(); if (dxgiFormat != 83) { throw new IOException("Only DXGI_FORMAT_BC5_UNORM " + "is supported for DirectX10 DDS! Got: " + dxgiFormat); } pixelFormat = Format.LATC; bpp = 8; 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 }
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); }