Permalink
Browse files

Fixes a bug in the TEXfile class that caused a NullpointerException w…

…hen opening Tex-textures.
  • Loading branch information...
1 parent 5e1a202 commit 1112d49543d565c47972cbaee75fb384ebbf1520 @Dahie committed Feb 9, 2012
Showing with 18 additions and 10 deletions.
  1. +1 −1 DDSUtils/src/model/AbstractTextureImage.java
  2. +16 −9 DDSUtils/src/model/MipMaps.java
  3. +1 −0 DDSUtils/src/model/TEXFile.java
View
2 DDSUtils/src/model/AbstractTextureImage.java
@@ -161,7 +161,7 @@ public void write() throws IOException {
*/
@Override
public boolean isCompressed() {
- return DDSUtil.isDXTCompressed(pixelformat);
+ return PixelFormats.isDXTCompressed(pixelformat);
}
/**
View
25 DDSUtils/src/model/MipMaps.java
@@ -57,13 +57,13 @@ public MipMaps(final int numMipMaps) {
* @param topmost
*/
public void generateMipMaps(BufferedImage topmost) {
- this.mipmaps.add(topmost);
+ getMipMaps().add(topmost);
if(!DDSFile.isPowerOfTwo(topmost.getWidth())
&& !DDSFile.isPowerOfTwo(topmost.getHeight()))
throw new NonCubicDimensionException();
- this.mipmaps = generateMipMapArray(this.mipmaps);
+ this.mipmaps = generateMipMapArray(getMipMaps());
}
private Vector<BufferedImage> generateMipMapArray(Vector<BufferedImage> mipMapsVector) {
@@ -122,23 +122,30 @@ public int getWidth() {
* @return
*/
public BufferedImage getMipMap(final int index) {
- return this.mipmaps.get(index);
+ return getMipMaps().get(index);
}
/**
* Set the given {@link BufferedImage} as MipMap in the index.
- * @param mipmap
+ * @param mipmapIndex
* @param image
*/
- public void setMipMap(int mipmap, BufferedImage image) {
- this.mipmaps.set(mipmap, image);
+ public void setMipMap(int mipmapIndex, BufferedImage image) {
+ if(getMipMaps().size() == mipmapIndex)
+ getMipMaps().add(mipmapIndex, image);
+ else
+ getMipMaps().set(mipmapIndex, image);
+ }
+
+ private Vector<BufferedImage> getMipMaps() {
+ return this.mipmaps;
}
/**
* @param image
*/
public void addMipMap(final BufferedImage image) {
- this.mipmaps.add(image);
+ getMipMaps().add(image);
}
/**
@@ -163,15 +170,15 @@ public void addMipMap(final BufferedImage image) {
* @return
*/
public Vector<BufferedImage> getAllMipMaps() {
- return this.mipmaps;
+ return getMipMaps();
}
/**
* Returns an Array of {@link BufferedImage}s of MipMaps.
* @return
*/
public BufferedImage[] getAllMipMapsArray() {
- return (BufferedImage[]) this.mipmaps.toArray();
+ return (BufferedImage[]) getMipMaps().toArray();
}
/* (non-Javadoc)
View
1 DDSUtils/src/model/TEXFile.java
@@ -58,6 +58,7 @@ protected void init(final TEXImage image) {
this.depth = image.getDepth();
this.pixelformat = image.getPixelFormat();
this.numMipMaps = image.getNumMipMaps();
+ this.mipMaps = new MipMaps(this.numMipMaps);
this.hasMipMaps = (image.getNumMipMaps() > 1); // there is always at least the topmost MipMap
}

0 comments on commit 1112d49

Please sign in to comment.