use of java.awt.image.RasterFormatException in project Railcraft by Railcraft.
the class TextureAtlasSheet method load.
@Override
public boolean load(IResourceManager manager, ResourceLocation location) {
// Remove the index from the resource path so we can find the original texture.
location = new ResourceLocation(location.getResourceDomain(), location.getResourcePath().replace("_" + index, ""));
BufferedImage image;
IResource resource = null;
try {
resource = manager.getResource(location);
image = ImageIO.read(resource.getInputStream());
} catch (IOException ex) {
Game.log(Level.WARN, "Failed to load sub-texture from {0}: {1}", location.getResourcePath(), ex.getLocalizedMessage());
return true;
} finally {
if (resource != null)
try {
resource.getInputStream().close();
} catch (IOException ignored) {
}
}
int mipmapLevels = Minecraft.getMinecraft().gameSettings.mipmapLevels;
int size = image.getHeight() / rows;
int x = index % columns;
int y = index / columns;
BufferedImage subImage;
try {
subImage = image.getSubimage(x * size, y * size, size, size);
} catch (RasterFormatException ex) {
Game.log(Level.WARN, "Failed to load sub-texture from {0} - {1}x{2}: {3}", location.getResourcePath(), image.getWidth(), image.getHeight(), ex.getLocalizedMessage());
return true;
}
this.height = subImage.getHeight();
this.width = subImage.getWidth();
int[] rgbaData = new int[height * width];
subImage.getRGB(0, 0, width, height, rgbaData, 0, width);
int[][] imageData = new int[1 + mipmapLevels][];
imageData[0] = rgbaData;
framesTextureData.add(imageData);
return false;
}
use of java.awt.image.RasterFormatException in project jdk8u_jdk by JetBrains.
the class ByteInterleavedRaster method createWritableChild.
/**
* Creates a Writable subRaster given a region of the Raster. The x and y
* coordinates specify the horizontal and vertical offsets
* from the upper-left corner of this Raster to the upper-left corner
* of the subRaster. A subset of the bands of the parent Raster may
* be specified. If this is null, then all the bands are present in the
* subRaster. A translation to the subRaster may also be specified.
* Note that the subRaster will reference the same
* DataBuffer as the parent Raster, but using different offsets.
* @param x X offset.
* @param y Y offset.
* @param width Width (in pixels) of the subraster.
* @param height Height (in pixels) of the subraster.
* @param x0 Translated X origin of the subraster.
* @param y0 Translated Y origin of the subraster.
* @param bandList Array of band indices.
* @exception RasterFormatException
* if the specified bounding box is outside of the parent Raster.
*/
public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) {
if (x < this.minX) {
throw new RasterFormatException("x lies outside the raster");
}
if (y < this.minY) {
throw new RasterFormatException("y lies outside the raster");
}
if ((x + width < x) || (x + width > this.minX + this.width)) {
throw new RasterFormatException("(x + width) is outside of Raster");
}
if ((y + height < y) || (y + height > this.minY + this.height)) {
throw new RasterFormatException("(y + height) is outside of Raster");
}
SampleModel sm;
if (bandList != null)
sm = sampleModel.createSubsetSampleModel(bandList);
else
sm = sampleModel;
int deltaX = x0 - x;
int deltaY = y0 - y;
return new ByteInterleavedRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX + deltaX, sampleModelTranslateY + deltaY), this);
}
use of java.awt.image.RasterFormatException in project jdk8u_jdk by JetBrains.
the class ByteComponentRaster method createWritableChild.
/**
* Creates a Writable subRaster given a region of the Raster. The x and y
* coordinates specify the horizontal and vertical offsets
* from the upper-left corner of this Raster to the upper-left corner
* of the subRaster. A subset of the bands of the parent Raster may
* be specified. If this is null, then all the bands are present in the
* subRaster. A translation to the subRaster may also be specified.
* Note that the subRaster will reference the same
* DataBuffer as the parent Raster, but using different offsets.
* @param x X offset.
* @param y Y offset.
* @param width Width (in pixels) of the subraster.
* @param height Height (in pixels) of the subraster.
* @param x0 Translated X origin of the subraster.
* @param y0 Translated Y origin of the subraster.
* @param bandList Array of band indices.
* @exception RasterFormatException
* if the specified bounding box is outside of the parent Raster.
*/
public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) {
if (x < this.minX) {
throw new RasterFormatException("x lies outside the raster");
}
if (y < this.minY) {
throw new RasterFormatException("y lies outside the raster");
}
if ((x + width < x) || (x + width > this.minX + this.width)) {
throw new RasterFormatException("(x + width) is outside of Raster");
}
if ((y + height < y) || (y + height > this.minY + this.height)) {
throw new RasterFormatException("(y + height) is outside of Raster");
}
SampleModel sm;
if (bandList != null)
sm = sampleModel.createSubsetSampleModel(bandList);
else
sm = sampleModel;
int deltaX = x0 - x;
int deltaY = y0 - y;
return new ByteComponentRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX + deltaX, sampleModelTranslateY + deltaY), this);
}
use of java.awt.image.RasterFormatException in project jdk8u_jdk by JetBrains.
the class ShortBandedRaster method verify.
/**
* Verify that the layout parameters are consistent with the data.
* Verifies whether the data buffer has enough data for the raster,
* taking into account offsets, after ensuring all offsets are >=0.
* @throws RasterFormatException if a problem is detected.
*/
private void verify() {
/* Need to re-verify the dimensions since a sample model may be
* specified to the constructor
*/
if (width <= 0 || height <= 0 || height > (Integer.MAX_VALUE / width)) {
throw new RasterFormatException("Invalid raster dimension");
}
if (scanlineStride < 0 || scanlineStride > (Integer.MAX_VALUE / height)) {
// integer overflow
throw new RasterFormatException("Incorrect scanline stride: " + scanlineStride);
}
if ((long) minX - sampleModelTranslateX < 0 || (long) minY - sampleModelTranslateY < 0) {
throw new RasterFormatException("Incorrect origin/translate: (" + minX + ", " + minY + ") / (" + sampleModelTranslateX + ", " + sampleModelTranslateY + ")");
}
if (height > 1 || minY - sampleModelTranslateY > 0) {
// buffer should contain at least one scanline
for (int i = 0; i < data.length; i++) {
if (scanlineStride > data[i].length) {
throw new RasterFormatException("Incorrect scanline stride: " + scanlineStride);
}
}
}
// Make sure data for Raster is in a legal range
for (int i = 0; i < dataOffsets.length; i++) {
if (dataOffsets[i] < 0) {
throw new RasterFormatException("Data offsets for band " + i + "(" + dataOffsets[i] + ") must be >= 0");
}
}
int lastScanOffset = (height - 1) * scanlineStride;
if ((width - 1) > (Integer.MAX_VALUE - lastScanOffset)) {
throw new RasterFormatException("Invalid raster dimension");
}
int lastPixelOffset = lastScanOffset + (width - 1);
int maxIndex = 0;
int index;
for (int i = 0; i < numDataElements; i++) {
if (dataOffsets[i] > (Integer.MAX_VALUE - lastPixelOffset)) {
throw new RasterFormatException("Invalid raster dimension");
}
index = lastPixelOffset + dataOffsets[i];
if (index > maxIndex) {
maxIndex = index;
}
}
for (int i = 0; i < numDataElements; i++) {
if (data[i].length <= maxIndex) {
throw new RasterFormatException("Data array too small " + "(should be > " + maxIndex + " )");
}
}
}
use of java.awt.image.RasterFormatException in project jdk8u_jdk by JetBrains.
the class ShortComponentRaster method createWritableChild.
/**
* Creates a Writable subRaster given a region of the Raster. The x and y
* coordinates specify the horizontal and vertical offsets
* from the upper-left corner of this Raster to the upper-left corner
* of the subRaster. A subset of the bands of the parent Raster may
* be specified. If this is null, then all the bands are present in the
* subRaster. A translation to the subRaster may also be specified.
* Note that the subRaster will reference the same
* DataBuffers as the parent Raster, but using different offsets.
* @param x X offset.
* @param y Y offset.
* @param width Width (in pixels) of the subraster.
* @param height Height (in pixels) of the subraster.
* @param x0 Translated X origin of the subraster.
* @param y0 Translated Y origin of the subraster.
* @param bandList Array of band indices.
* @exception RasterFormatException
* if the specified bounding box is outside of the parent Raster.
*/
public WritableRaster createWritableChild(int x, int y, int width, int height, int x0, int y0, int[] bandList) {
if (x < this.minX) {
throw new RasterFormatException("x lies outside the raster");
}
if (y < this.minY) {
throw new RasterFormatException("y lies outside the raster");
}
if ((x + width < x) || (x + width > this.minX + this.width)) {
throw new RasterFormatException("(x + width) is outside of Raster");
}
if ((y + height < y) || (y + height > this.minY + this.height)) {
throw new RasterFormatException("(y + height) is outside of Raster");
}
SampleModel sm;
if (bandList != null)
sm = sampleModel.createSubsetSampleModel(bandList);
else
sm = sampleModel;
int deltaX = x0 - x;
int deltaY = y0 - y;
return new ShortComponentRaster(sm, dataBuffer, new Rectangle(x0, y0, width, height), new Point(sampleModelTranslateX + deltaX, sampleModelTranslateY + deltaY), this);
}
Aggregations