Skip to content

Commit

Permalink
Fixes a bug in the TEXfile class that caused a NullpointerException w…
Browse files Browse the repository at this point in the history
…hen opening Tex-textures.
  • Loading branch information
Dahie committed Feb 9, 2012
1 parent 5e1a202 commit 1112d49
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
2 changes: 1 addition & 1 deletion DDSUtils/src/model/AbstractTextureImage.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ public void write() throws IOException {
*/ */
@Override @Override
public boolean isCompressed() { public boolean isCompressed() {
return DDSUtil.isDXTCompressed(pixelformat); return PixelFormats.isDXTCompressed(pixelformat);
} }


/** /**
Expand Down
25 changes: 16 additions & 9 deletions DDSUtils/src/model/MipMaps.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public MipMaps(final int numMipMaps) {
* @param topmost * @param topmost
*/ */
public void generateMipMaps(BufferedImage topmost) { public void generateMipMaps(BufferedImage topmost) {
this.mipmaps.add(topmost); getMipMaps().add(topmost);


if(!DDSFile.isPowerOfTwo(topmost.getWidth()) if(!DDSFile.isPowerOfTwo(topmost.getWidth())
&& !DDSFile.isPowerOfTwo(topmost.getHeight())) && !DDSFile.isPowerOfTwo(topmost.getHeight()))
throw new NonCubicDimensionException(); throw new NonCubicDimensionException();


this.mipmaps = generateMipMapArray(this.mipmaps); this.mipmaps = generateMipMapArray(getMipMaps());
} }


private Vector<BufferedImage> generateMipMapArray(Vector<BufferedImage> mipMapsVector) { private Vector<BufferedImage> generateMipMapArray(Vector<BufferedImage> mipMapsVector) {
Expand Down Expand Up @@ -122,23 +122,30 @@ public int getWidth() {
* @return * @return
*/ */
public BufferedImage getMipMap(final int index) { 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. * Set the given {@link BufferedImage} as MipMap in the index.
* @param mipmap * @param mipmapIndex
* @param image * @param image
*/ */
public void setMipMap(int mipmap, BufferedImage image) { public void setMipMap(int mipmapIndex, BufferedImage image) {
this.mipmaps.set(mipmap, image); if(getMipMaps().size() == mipmapIndex)
getMipMaps().add(mipmapIndex, image);
else
getMipMaps().set(mipmapIndex, image);
}

private Vector<BufferedImage> getMipMaps() {
return this.mipmaps;
} }


/** /**
* @param image * @param image
*/ */
public void addMipMap(final BufferedImage image) { public void addMipMap(final BufferedImage image) {
this.mipmaps.add(image); getMipMaps().add(image);
} }


/** /**
Expand All @@ -163,15 +170,15 @@ public ByteBuffer[] getDXTCompressedBuffer(final Squish.CompressionType compress
* @return * @return
*/ */
public Vector<BufferedImage> getAllMipMaps() { public Vector<BufferedImage> getAllMipMaps() {
return this.mipmaps; return getMipMaps();
} }


/** /**
* Returns an Array of {@link BufferedImage}s of MipMaps. * Returns an Array of {@link BufferedImage}s of MipMaps.
* @return * @return
*/ */
public BufferedImage[] getAllMipMapsArray() { public BufferedImage[] getAllMipMapsArray() {
return (BufferedImage[]) this.mipmaps.toArray(); return (BufferedImage[]) getMipMaps().toArray();
} }


/* (non-Javadoc) /* (non-Javadoc)
Expand Down
1 change: 1 addition & 0 deletions DDSUtils/src/model/TEXFile.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ protected void init(final TEXImage image) {
this.depth = image.getDepth(); this.depth = image.getDepth();
this.pixelformat = image.getPixelFormat(); this.pixelformat = image.getPixelFormat();
this.numMipMaps = image.getNumMipMaps(); this.numMipMaps = image.getNumMipMaps();
this.mipMaps = new MipMaps(this.numMipMaps);
this.hasMipMaps = (image.getNumMipMaps() > 1); // there is always at least the topmost MipMap this.hasMipMaps = (image.getNumMipMaps() > 1); // there is always at least the topmost MipMap
} }


Expand Down

0 comments on commit 1112d49

Please sign in to comment.