diff options
Diffstat (limited to 'src/jogl/classes/com/jogamp/opengl/util/texture')
18 files changed, 624 insertions, 621 deletions
diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java b/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java index a2d202d11..f5ef5672f 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/ImageSequence.java @@ -77,7 +77,7 @@ public class ImageSequence implements TextureSequence { } public final void addFrame(final GL gl, final Class<?> context, final String imageResourcePath, final String imageSuffix) throws IOException { - URLConnection urlConn = IOUtil.getResource(context, imageResourcePath); + final URLConnection urlConn = IOUtil.getResource(context, imageResourcePath); if(null != urlConn) { final TextureData texData = TextureIO.newTextureData(GLProfile.getGL2ES2(), urlConn.getInputStream(), false, imageSuffix); final Texture tex = new Texture(getTextureTarget()); @@ -97,7 +97,7 @@ public class ImageSequence implements TextureSequence { public final boolean getManualStepping() { return manualStepping; } public final TextureSequence.TextureFrame getFrame(final int idx) { return frames.get(idx); } - public void destroy(GL gl) throws GLException { + public void destroy(final GL gl) throws GLException { for(int i=frames.size()-1; i>=0; i--) { frames.get(i).getTexture().destroy(gl); } @@ -133,7 +133,7 @@ public class ImageSequence implements TextureSequence { } @Override - public TextureSequence.TextureFrame getNextTexture(GL gl) throws IllegalStateException { + public TextureSequence.TextureFrame getNextTexture(final GL gl) throws IllegalStateException { if( !manualStepping ) { frameIdx = ( frameIdx + 1 ) % frames.size(); } @@ -153,7 +153,7 @@ public class ImageSequence implements TextureSequence { private String textureLookupFunctionName = "myTexture2D"; @Override - public String getTextureLookupFunctionName(String desiredFuncName) throws IllegalStateException { + public String getTextureLookupFunctionName(final String desiredFuncName) throws IllegalStateException { if(useBuildInTexLookup) { return "texture2D"; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java index 47be0714e..e7693f4a6 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/Texture.java @@ -205,7 +205,7 @@ public class Texture { private static final boolean disableNPOT = Debug.isPropertyDefined("jogl.texture.nonpot", true); private static final boolean disableTexRect = Debug.isPropertyDefined("jogl.texture.notexrect", true); - public Texture(GL gl, TextureData data) throws GLException { + public Texture(final GL gl, final TextureData data) throws GLException { texID = 0; updateImage(gl, data); } @@ -216,7 +216,7 @@ public class Texture { * @param target the OpenGL texture target, eg GL.GL_TEXTURE_2D, * GL2.GL_TEXTURE_RECTANGLE */ - public Texture(int target) { + public Texture(final int target) { texID = 0; this.target = target; } @@ -278,7 +278,7 @@ public class Texture { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void enable(GL gl) throws GLException { + public void enable(final GL gl) throws GLException { if( !gl.isGLcore() && GLES2.GL_TEXTURE_EXTERNAL_OES != target) { gl.glEnable(target); } @@ -305,7 +305,7 @@ public class Texture { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void disable(GL gl) throws GLException { + public void disable(final GL gl) throws GLException { if( !gl.isGLcore() && GLES2.GL_TEXTURE_EXTERNAL_OES != target ) { gl.glDisable(target); } @@ -325,7 +325,7 @@ public class Texture { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void bind(GL gl) throws GLException { + public void bind(final GL gl) throws GLException { validateTexID(gl, true); gl.glBindTexture(target, texID); } @@ -335,7 +335,7 @@ public class Texture { * * @throws GLException if any OpenGL-related errors occurred */ - public void destroy(GL gl) throws GLException { + public void destroy(final GL gl) throws GLException { if(0!=texID) { gl.glDeleteTextures(1, new int[] {texID}, 0); texID = 0; @@ -437,7 +437,7 @@ public class Texture { * * @return the texture coordinates corresponding to the specified sub-image */ - public TextureCoords getSubImageTexCoords(int x1, int y1, int x2, int y2) { + public TextureCoords getSubImageTexCoords(final int x1, final int y1, final int x2, final int y2) { if (target == GL2.GL_TEXTURE_RECTANGLE_ARB) { if (mustFlipVertically) { return new TextureCoords(x1, texHeight - y1, x2, texHeight - y2); @@ -445,12 +445,12 @@ public class Texture { return new TextureCoords(x1, y1, x2, y2); } } else { - float tx1 = (float)x1 / (float)texWidth; - float ty1 = (float)y1 / (float)texHeight; - float tx2 = (float)x2 / (float)texWidth; - float ty2 = (float)y2 / (float)texHeight; + final float tx1 = (float)x1 / (float)texWidth; + final float ty1 = (float)y1 / (float)texHeight; + final float tx2 = (float)x2 / (float)texWidth; + final float ty2 = (float)y2 / (float)texHeight; if (mustFlipVertically) { - float yMax = (float) imgHeight / (float) texHeight; + final float yMax = (float) imgHeight / (float) texHeight; return new TextureCoords(tx1, yMax - ty1, tx2, yMax - ty2); } else { return new TextureCoords(tx1, ty1, tx2, ty2); @@ -464,7 +464,7 @@ public class Texture { * * @throws GLException if any OpenGL-related errors occurred */ - public void updateImage(GL gl, TextureData data) throws GLException { + public void updateImage(final GL gl, final TextureData data) throws GLException { updateImage(gl, data, 0); } @@ -487,7 +487,7 @@ public class Texture { * No-op if no change, otherwise generates new {@link TextureCoords}. * </p> */ - public void setMustFlipVertically(boolean v) { + public void setMustFlipVertically(final boolean v) { if( v != mustFlipVertically ) { mustFlipVertically = v; updateTexCoords(); @@ -501,7 +501,7 @@ public class Texture { * * @throws GLException if any OpenGL-related errors occurred */ - public void updateImage(GL gl, TextureData data, int targetOverride) throws GLException { + public void updateImage(final GL gl, final TextureData data, final int targetOverride) throws GLException { validateTexID(gl, true); imgWidth = data.getWidth(); @@ -522,7 +522,7 @@ public class Texture { data.setHaveGL12(gl.isExtensionAvailable(GLExtensions.VERSION_1_2)); // Indicates whether both width and height are power of two - boolean isPOT = isPowerOfTwo(imgWidth) && isPowerOfTwo(imgHeight); + final boolean isPOT = isPowerOfTwo(imgWidth) && isPowerOfTwo(imgHeight); // Note that automatic mipmap generation doesn't work for // GL_ARB_texture_rectangle @@ -634,7 +634,7 @@ public class Texture { } if (data.getMipmap() && !haveAutoMipmapGeneration) { - int[] align = new int[1]; + final int[] align = new int[1]; gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, align, 0); // save alignment gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, data.getAlignment()); @@ -644,7 +644,7 @@ public class Texture { try { // FIXME: may need check for GLUnsupportedException - GLU glu = GLU.createGLU(gl); + final GLU glu = GLU.createGLU(gl); glu.gluBuild2DMipmaps(texTarget, data.getInternalFormat(), data.getWidth(), data.getHeight(), data.getPixelFormat(), data.getPixelType(), data.getBuffer()); @@ -653,7 +653,7 @@ public class Texture { } } else { checkCompressedTextureExtensions(gl, data); - Buffer[] mipmapData = data.getMipmapData(); + final Buffer[] mipmapData = data.getMipmapData(); if (mipmapData != null) { int width = texWidth; int height = texHeight; @@ -684,7 +684,7 @@ public class Texture { texWidth, texHeight, data.getBorder(), data.getBuffer().capacity(), data.getBuffer()); } else { - ByteBuffer buf = DDSImage.allocateBlankBuffer(texWidth, + final ByteBuffer buf = DDSImage.allocateBlankBuffer(texWidth, texHeight, data.getInternalFormat()); gl.glCompressedTexImage2D(texTarget, 0, data.getInternalFormat(), @@ -710,9 +710,9 @@ public class Texture { } } - int minFilter = (data.getMipmap() ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR); - int magFilter = GL.GL_LINEAR; - int wrapMode = (gl.isExtensionAvailable(GLExtensions.VERSION_1_2) || !gl.isGL2()) ? GL.GL_CLAMP_TO_EDGE : GL2.GL_CLAMP; + final int minFilter = (data.getMipmap() ? GL.GL_LINEAR_MIPMAP_LINEAR : GL.GL_LINEAR); + final int magFilter = GL.GL_LINEAR; + final int wrapMode = (gl.isExtensionAvailable(GLExtensions.VERSION_1_2) || !gl.isGL2()) ? GL.GL_CLAMP_TO_EDGE : GL2.GL_CLAMP; // REMIND: figure out what to do for GL_TEXTURE_RECTANGLE_ARB if (texTarget != GL2.GL_TEXTURE_RECTANGLE_ARB) { @@ -720,8 +720,8 @@ public class Texture { gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_MAG_FILTER, magFilter); gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_WRAP_S, wrapMode); gl.glTexParameteri(texParamTarget, GL.GL_TEXTURE_WRAP_T, wrapMode); - if (this.target == GL2.GL_TEXTURE_CUBE_MAP) { - gl.glTexParameteri(texParamTarget, GL2.GL_TEXTURE_WRAP_R, wrapMode); + if (this.target == GL.GL_TEXTURE_CUBE_MAP) { + gl.glTexParameteri(texParamTarget, GL2ES2.GL_TEXTURE_WRAP_R, wrapMode); } } @@ -758,7 +758,7 @@ public class Texture { * * @throws GLException if any OpenGL-related errors occurred */ - public void updateSubImage(GL gl, TextureData data, int mipmapLevel, int x, int y) throws GLException { + public void updateSubImage(final GL gl, final TextureData data, final int mipmapLevel, final int x, final int y) throws GLException { if (usingAutoMipmapGeneration && mipmapLevel != 0) { // When we're using mipmap generation via GL_GENERATE_MIPMAP, we // don't need to update other mipmap levels @@ -798,10 +798,10 @@ public class Texture { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void updateSubImage(GL gl, TextureData data, int mipmapLevel, - int dstx, int dsty, - int srcx, int srcy, - int width, int height) throws GLException { + public void updateSubImage(final GL gl, final TextureData data, final int mipmapLevel, + final int dstx, final int dsty, + final int srcx, final int srcy, + final int width, final int height) throws GLException { if (data.isDataCompressed()) { throw new GLException("updateSubImage specifying a sub-rectangle is not supported for compressed TextureData"); } @@ -823,8 +823,8 @@ public class Texture { * @throws GLException if no OpenGL context was current or if any * OpenGL-related errors occurred */ - public void setTexParameterf(GL gl, int parameterName, - float value) { + public void setTexParameterf(final GL gl, final int parameterName, + final float value) { bind(gl); gl.glTexParameterf(target, parameterName, value); } @@ -836,8 +836,8 @@ public class Texture { * * @throws GLException if any OpenGL-related errors occurred */ - public void setTexParameterfv(GL gl, int parameterName, - FloatBuffer params) { + public void setTexParameterfv(final GL gl, final int parameterName, + final FloatBuffer params) { bind(gl); gl.glTexParameterfv(target, parameterName, params); } @@ -849,8 +849,8 @@ public class Texture { * * @throws GLException if any OpenGL-related errors occurred */ - public void setTexParameterfv(GL gl, int parameterName, - float[] params, int params_offset) { + public void setTexParameterfv(final GL gl, final int parameterName, + final float[] params, final int params_offset) { bind(gl); gl.glTexParameterfv(target, parameterName, params, params_offset); } @@ -865,8 +865,8 @@ public class Texture { * * @throws GLException if any OpenGL-related errors occurred */ - public void setTexParameteri(GL gl, int parameterName, - int value) { + public void setTexParameteri(final GL gl, final int parameterName, + final int value) { bind(gl); gl.glTexParameteri(target, parameterName, value); } @@ -878,8 +878,8 @@ public class Texture { * * @throws GLException if any OpenGL-related errors occurred */ - public void setTexParameteriv(GL gl, int parameterName, - IntBuffer params) { + public void setTexParameteriv(final GL gl, final int parameterName, + final IntBuffer params) { bind(gl); gl.glTexParameteriv(target, parameterName, params); } @@ -891,8 +891,8 @@ public class Texture { * * @throws GLException if any OpenGL-related errors occurred */ - public void setTexParameteriv(GL gl, int parameterName, - int[] params, int params_offset) { + public void setTexParameteriv(final GL gl, final int parameterName, + final int[] params, final int params_offset) { bind(gl); gl.glTexParameteriv(target, parameterName, params, params_offset); } @@ -908,7 +908,7 @@ public class Texture { * otherwise it may be <code>null</code>. * @see #getTextureObject() */ - public int getTextureObject(GL gl) { + public int getTextureObject(final GL gl) { validateTexID(gl, false); return texID; } @@ -957,7 +957,7 @@ public class Texture { * * @return true if the given value is a power of two, false otherwise */ - private static boolean isPowerOfTwo(int val) { + private static boolean isPowerOfTwo(final int val) { return ((val & (val - 1)) == 0); } @@ -969,7 +969,7 @@ public class Texture { * @param val the value * @return the next power of two */ - private static int nextPowerOfTwo(int val) { + private static int nextPowerOfTwo(final int val) { int ret = 1; while (ret < val) { ret <<= 1; @@ -981,7 +981,7 @@ public class Texture { * Updates the actual image dimensions; usually only called from * <code>updateImage</code>. */ - private void setImageSize(int width, int height, int target) { + private void setImageSize(final int width, final int height, final int target) { imgWidth = width; imgHeight = height; updateTexCoords(); @@ -1010,7 +1010,7 @@ public class Texture { } } - private void updateSubImageImpl(GL gl, TextureData data, int newTarget, int mipmapLevel, + private void updateSubImageImpl(final GL gl, final TextureData data, final int newTarget, final int mipmapLevel, int dstx, int dsty, int srcx, int srcy, int width, int height) throws GLException { data.setHaveEXTABGR(gl.isExtensionAvailable(GLExtensions.EXT_abgr)); @@ -1081,15 +1081,15 @@ public class Texture { data.getInternalFormat(), buffer.remaining(), buffer); } else { - int[] align = { 0 }; - int[] rowLength = { 0 }; - int[] skipRows = { 0 }; - int[] skipPixels = { 0 }; + final int[] align = { 0 }; + final int[] rowLength = { 0 }; + final int[] skipRows = { 0 }; + final int[] skipPixels = { 0 }; gl.glGetIntegerv(GL.GL_UNPACK_ALIGNMENT, align, 0); // save alignment if(gl.isGL2GL3()) { - gl.glGetIntegerv(GL2GL3.GL_UNPACK_ROW_LENGTH, rowLength, 0); // save row length - gl.glGetIntegerv(GL2GL3.GL_UNPACK_SKIP_ROWS, skipRows, 0); // save skipped rows - gl.glGetIntegerv(GL2GL3.GL_UNPACK_SKIP_PIXELS, skipPixels, 0); // save skipped pixels + gl.glGetIntegerv(GL2ES2.GL_UNPACK_ROW_LENGTH, rowLength, 0); // save row length + gl.glGetIntegerv(GL2ES2.GL_UNPACK_SKIP_ROWS, skipRows, 0); // save skipped rows + gl.glGetIntegerv(GL2ES2.GL_UNPACK_SKIP_PIXELS, skipPixels, 0); // save skipped pixels } gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, data.getAlignment()); if (DEBUG && VERBOSE) { @@ -1102,9 +1102,9 @@ public class Texture { System.out.println("height = " + height); } if(gl.isGL2GL3()) { - gl.glPixelStorei(GL2GL3.GL_UNPACK_ROW_LENGTH, rowlen); - gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_ROWS, srcy); - gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_PIXELS, srcx); + gl.glPixelStorei(GL2ES2.GL_UNPACK_ROW_LENGTH, rowlen); + gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_ROWS, srcy); + gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_PIXELS, srcx); } else { if ( rowlen!=0 && rowlen!=width && srcy!=0 && srcx!=0 ) { @@ -1118,14 +1118,14 @@ public class Texture { buffer); gl.glPixelStorei(GL.GL_UNPACK_ALIGNMENT, align[0]); // restore alignment if(gl.isGL2GL3()) { - gl.glPixelStorei(GL2GL3.GL_UNPACK_ROW_LENGTH, rowLength[0]); // restore row length - gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_ROWS, skipRows[0]); // restore skipped rows - gl.glPixelStorei(GL2GL3.GL_UNPACK_SKIP_PIXELS, skipPixels[0]); // restore skipped pixels + gl.glPixelStorei(GL2ES2.GL_UNPACK_ROW_LENGTH, rowLength[0]); // restore row length + gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_ROWS, skipRows[0]); // restore skipped rows + gl.glPixelStorei(GL2ES2.GL_UNPACK_SKIP_PIXELS, skipPixels[0]); // restore skipped pixels } } } - private void checkCompressedTextureExtensions(GL gl, TextureData data) { + private void checkCompressedTextureExtensions(final GL gl, final TextureData data) { if (data.isDataCompressed()) { switch (data.getInternalFormat()) { case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT: @@ -1145,10 +1145,10 @@ public class Texture { } } - private boolean validateTexID(GL gl, boolean throwException) { + private boolean validateTexID(final GL gl, final boolean throwException) { if( 0 == texID ) { if( null != gl ) { - int[] tmp = new int[1]; + final int[] tmp = new int[1]; gl.glGenTextures(1, tmp, 0); texID = tmp[0]; if ( 0 == texID && throwException ) { @@ -1162,22 +1162,22 @@ public class Texture { } // Helper routines for disabling certain codepaths - private static boolean haveNPOT(GL gl) { + private static boolean haveNPOT(final GL gl) { return !disableNPOT && gl.isNPOTTextureAvailable(); } - private static boolean haveTexRect(GL gl) { + private static boolean haveTexRect(final GL gl) { return (!disableTexRect && TextureIO.isTexRectEnabled() && gl.isExtensionAvailable(GLExtensions.ARB_texture_rectangle)); } - private static boolean preferTexRect(GL gl) { + private static boolean preferTexRect(final GL gl) { // Prefer GL_ARB_texture_rectangle on ATI hardware on Mac OS X // due to software fallbacks if (NativeWindowFactory.TYPE_MACOSX == NativeWindowFactory.getNativeWindowType(false)) { - String vendor = gl.glGetString(GL.GL_VENDOR); + final String vendor = gl.glGetString(GL.GL_VENDOR); if (vendor != null && vendor.startsWith("ATI")) { return true; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java index ba59f89c5..17fcc7016 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureCoords.java @@ -48,14 +48,14 @@ package com.jogamp.opengl.util.texture; public class TextureCoords { // These represent the lower-left point - private float left; - private float bottom; + private final float left; + private final float bottom; // These represent the upper-right point - private float right; - private float top; + private final float right; + private final float top; - public TextureCoords(float left, float bottom, - float right, float top) { + public TextureCoords(final float left, final float bottom, + final float right, final float top) { this.left = left; this.bottom = bottom; this.right = right; @@ -70,7 +70,7 @@ public class TextureCoords { * right top * </pre> */ - public float[] getST_LB_RB_LT_RT(float[] d, int d_off, float ss, float ts) { + public float[] getST_LB_RB_LT_RT(final float[] d, final int d_off, final float ss, final float ts) { d[0+d_off] = left *ss; d[1+d_off] = bottom*ts; d[2+d_off] = right *ss; d[3+d_off] = bottom*ts; d[4+d_off] = left *ss; d[5+d_off] = top *ts; diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java index 5d88a76c0..5b2e4fc00 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureData.java @@ -41,6 +41,7 @@ import java.nio.Buffer; import javax.media.opengl.GLProfile; +import com.jogamp.common.nio.Buffers; import com.jogamp.opengl.util.GLBuffers; import com.jogamp.opengl.util.GLPixelBuffer.GLPixelAttributes; @@ -123,18 +124,18 @@ public class TextureData { * data were invalid, such as requesting mipmap generation for a * compressed texture */ - public TextureData(GLProfile glp, - int internalFormat, - int width, - int height, - int border, - int pixelFormat, - int pixelType, - boolean mipmap, - boolean dataIsCompressed, - boolean mustFlipVertically, - Buffer buffer, - Flusher flusher) throws IllegalArgumentException { + public TextureData(final GLProfile glp, + final int internalFormat, + final int width, + final int height, + final int border, + final int pixelFormat, + final int pixelType, + final boolean mipmap, + final boolean dataIsCompressed, + final boolean mustFlipVertically, + final Buffer buffer, + final Flusher flusher) throws IllegalArgumentException { this(glp, internalFormat, width, height, border, new GLPixelAttributes(pixelFormat, pixelType), mipmap, dataIsCompressed, mustFlipVertically, buffer, flusher); } @@ -178,17 +179,17 @@ public class TextureData { * data were invalid, such as requesting mipmap generation for a * compressed texture */ - public TextureData(GLProfile glp, - int internalFormat, - int width, - int height, - int border, - GLPixelAttributes pixelAttributes, - boolean mipmap, - boolean dataIsCompressed, - boolean mustFlipVertically, - Buffer buffer, - Flusher flusher) throws IllegalArgumentException { + public TextureData(final GLProfile glp, + final int internalFormat, + final int width, + final int height, + final int border, + final GLPixelAttributes pixelAttributes, + final boolean mipmap, + final boolean dataIsCompressed, + final boolean mustFlipVertically, + final Buffer buffer, + final Flusher flusher) throws IllegalArgumentException { if (mipmap && dataIsCompressed) { throw new IllegalArgumentException("Can not generate mipmaps for compressed textures"); } @@ -247,17 +248,17 @@ public class TextureData { * data were invalid, such as requesting mipmap generation for a * compressed texture */ - public TextureData(GLProfile glp, - int internalFormat, - int width, - int height, - int border, - int pixelFormat, - int pixelType, - boolean dataIsCompressed, - boolean mustFlipVertically, - Buffer[] mipmapData, - Flusher flusher) throws IllegalArgumentException { + public TextureData(final GLProfile glp, + final int internalFormat, + final int width, + final int height, + final int border, + final int pixelFormat, + final int pixelType, + final boolean dataIsCompressed, + final boolean mustFlipVertically, + final Buffer[] mipmapData, + final Flusher flusher) throws IllegalArgumentException { this(glp, internalFormat, width, height, border, new GLPixelAttributes(pixelFormat, pixelType), dataIsCompressed, mustFlipVertically, mipmapData, flusher); } @@ -300,16 +301,16 @@ public class TextureData { * data were invalid, such as requesting mipmap generation for a * compressed texture */ - public TextureData(GLProfile glp, - int internalFormat, - int width, - int height, - int border, - GLPixelAttributes pixelAttributes, - boolean dataIsCompressed, - boolean mustFlipVertically, - Buffer[] mipmapData, - Flusher flusher) throws IllegalArgumentException { + public TextureData(final GLProfile glp, + final int internalFormat, + final int width, + final int height, + final int border, + final GLPixelAttributes pixelAttributes, + final boolean dataIsCompressed, + final boolean mustFlipVertically, + final Buffer[] mipmapData, + final Flusher flusher) throws IllegalArgumentException { this.glProfile = glp; this.width = width; this.height = height; @@ -318,7 +319,7 @@ public class TextureData { this.internalFormat = internalFormat; this.dataIsCompressed = dataIsCompressed; this.mustFlipVertically = mustFlipVertically; - this.mipmapData = (Buffer[]) mipmapData.clone(); + this.mipmapData = mipmapData.clone(); this.flusher = flusher; alignment = 1; // FIXME: is this correct enough in all situations? for (int i = 0; i < mipmapData.length; i++) { @@ -336,10 +337,10 @@ public class TextureData { * Set the color space of the pixel data, which defaults to {@link ColorSpace#RGB}. * @see #getColorSpace() */ - public void setColorSpace(ColorSpace cs) { pixelCS = cs; } + public void setColorSpace(final ColorSpace cs) { pixelCS = cs; } /** Used only by subclasses */ - protected TextureData(GLProfile glp) { this.glProfile = glp; this.pixelAttributes = GLPixelAttributes.UNDEF; } + protected TextureData(final GLProfile glp) { this.glProfile = glp; this.pixelAttributes = GLPixelAttributes.UNDEF; } /** Returns the width in pixels of the texture data. */ public int getWidth() { return width; } @@ -399,20 +400,20 @@ public class TextureData { } /** Sets the width in pixels of the texture data. */ - public void setWidth(int width) { this.width = width; } + public void setWidth(final int width) { this.width = width; } /** Sets the height in pixels of the texture data. */ - public void setHeight(int height) { this.height = height; } + public void setHeight(final int height) { this.height = height; } /** Sets the border in pixels of the texture data. */ - public void setBorder(int border) { this.border = border; } + public void setBorder(final int border) { this.border = border; } /** Sets the intended OpenGL pixel format of the texture data. */ - public void setPixelAttributes(GLPixelAttributes pixelAttributes) { this.pixelAttributes = pixelAttributes; } + public void setPixelAttributes(final GLPixelAttributes pixelAttributes) { this.pixelAttributes = pixelAttributes; } /** * Sets the intended OpenGL pixel format component of {@link GLPixelAttributes} of the texture data. * <p> * Use {@link #setPixelAttributes(GLPixelAttributes)}, if setting format and type. * </p> */ - public void setPixelFormat(int pixelFormat) { + public void setPixelFormat(final int pixelFormat) { if( pixelAttributes.format != pixelFormat ) { pixelAttributes = new GLPixelAttributes(pixelFormat, pixelAttributes.type); } @@ -423,42 +424,42 @@ public class TextureData { * Use {@link #setPixelAttributes(GLPixelAttributes)}, if setting format and type. * </p> */ - public void setPixelType(int pixelType) { + public void setPixelType(final int pixelType) { if( pixelAttributes.type != pixelType) { pixelAttributes = new GLPixelAttributes(pixelAttributes.format, pixelType); } } /** Sets the intended OpenGL internal format of the texture data. */ - public void setInternalFormat(int internalFormat) { this.internalFormat = internalFormat; } + public void setInternalFormat(final int internalFormat) { this.internalFormat = internalFormat; } /** Sets whether mipmaps should be generated for the texture data. */ - public void setMipmap(boolean mipmap) { this.mipmap = mipmap; } + public void setMipmap(final boolean mipmap) { this.mipmap = mipmap; } /** Sets whether the texture data is in compressed form. */ - public void setIsDataCompressed(boolean compressed) { this.dataIsCompressed = compressed; } + public void setIsDataCompressed(final boolean compressed) { this.dataIsCompressed = compressed; } /** Sets whether the texture coordinates must be flipped vertically for proper display. */ - public void setMustFlipVertically(boolean mustFlipVertically) { this.mustFlipVertically = mustFlipVertically; } + public void setMustFlipVertically(final boolean mustFlipVertically) { this.mustFlipVertically = mustFlipVertically; } /** Sets the texture data. */ - public void setBuffer(Buffer buffer) { + public void setBuffer(final Buffer buffer) { this.buffer = buffer; estimatedMemorySize = estimatedMemorySize(buffer); } /** Sets the required byte alignment for the texture data. */ - public void setAlignment(int alignment) { this.alignment = alignment; } + public void setAlignment(final int alignment) { this.alignment = alignment; } /** Sets the row length needed for correct GL_UNPACK_ROW_LENGTH specification. This is currently only supported for non-mipmapped, non-compressed textures. */ - public void setRowLength(int rowLength) { this.rowLength = rowLength; } + public void setRowLength(final int rowLength) { this.rowLength = rowLength; } /** Indicates to this TextureData whether the GL_EXT_abgr extension is available. Used for optimization along some code paths to avoid data copies. */ - public void setHaveEXTABGR(boolean haveEXTABGR) { + public void setHaveEXTABGR(final boolean haveEXTABGR) { this.haveEXTABGR = haveEXTABGR; } /** Indicates to this TextureData whether OpenGL version 1.2 is available. If not, falls back to relatively inefficient code paths for several input data types (several kinds of packed pixel formats, in particular). */ - public void setHaveGL12(boolean haveGL12) { + public void setHaveGL12(final boolean haveGL12) { this.haveGL12 = haveGL12; } @@ -509,10 +510,10 @@ public class TextureData { // Internals only below this point // - protected static int estimatedMemorySize(Buffer buffer) { + protected static int estimatedMemorySize(final Buffer buffer) { if (buffer == null) { return 0; } - return buffer.capacity() * GLBuffers.sizeOfBufferElem(buffer); + return buffer.capacity() * Buffers.sizeOfBufferElem(buffer); } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java index b2bcd0de3..19f2fc05b 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureIO.java @@ -60,6 +60,7 @@ import javax.media.nativewindow.util.DimensionImmutable; import javax.media.nativewindow.util.PixelFormat; import javax.media.opengl.GL; import javax.media.opengl.GL2; +import javax.media.opengl.GL2ES3; import javax.media.opengl.GL2GL3; import javax.media.opengl.GLContext; import javax.media.opengl.GLException; @@ -209,8 +210,8 @@ public class TextureIO { * registered texture providers could read the file * @throws IOException if an error occurred while reading the file */ - public static TextureData newTextureData(GLProfile glp, File file, - boolean mipmap, + public static TextureData newTextureData(final GLProfile glp, final File file, + final boolean mipmap, String fileSuffix) throws IOException { if (fileSuffix == null) { fileSuffix = IOUtil.getFileSuffix(file); @@ -239,9 +240,9 @@ public class TextureIO { * registered texture providers could read the stream * @throws IOException if an error occurred while reading the stream */ - public static TextureData newTextureData(GLProfile glp, InputStream stream, - boolean mipmap, - String fileSuffix) throws IOException { + public static TextureData newTextureData(final GLProfile glp, final InputStream stream, + final boolean mipmap, + final String fileSuffix) throws IOException { return newTextureDataImpl(glp, stream, 0, 0, mipmap, fileSuffix); } @@ -266,8 +267,8 @@ public class TextureIO { * registered texture providers could read the URL * @throws IOException if an error occurred while reading the URL */ - public static TextureData newTextureData(GLProfile glp, URL url, - boolean mipmap, + public static TextureData newTextureData(final GLProfile glp, final URL url, + final boolean mipmap, String fileSuffix) throws IOException { if (fileSuffix == null) { fileSuffix = IOUtil.getFileSuffix(url.getPath()); @@ -314,10 +315,10 @@ public class TextureIO { * pixelFormat was 0 * @throws IOException if an error occurred while reading the file */ - public static TextureData newTextureData(GLProfile glp, File file, - int internalFormat, - int pixelFormat, - boolean mipmap, + public static TextureData newTextureData(final GLProfile glp, final File file, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, String fileSuffix) throws IOException, IllegalArgumentException { if ((internalFormat == 0) || (pixelFormat == 0)) { throw new IllegalArgumentException("internalFormat and pixelFormat must be non-zero"); @@ -362,11 +363,11 @@ public class TextureIO { * pixelFormat was 0 * @throws IOException if an error occurred while reading the stream */ - public static TextureData newTextureData(GLProfile glp, InputStream stream, - int internalFormat, - int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException, IllegalArgumentException { + public static TextureData newTextureData(final GLProfile glp, final InputStream stream, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, + final String fileSuffix) throws IOException, IllegalArgumentException { if ((internalFormat == 0) || (pixelFormat == 0)) { throw new IllegalArgumentException("internalFormat and pixelFormat must be non-zero"); } @@ -406,10 +407,10 @@ public class TextureIO { * pixelFormat was 0 * @throws IOException if an error occurred while reading the URL */ - public static TextureData newTextureData(GLProfile glp, URL url, - int internalFormat, - int pixelFormat, - boolean mipmap, + public static TextureData newTextureData(final GLProfile glp, final URL url, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, String fileSuffix) throws IOException, IllegalArgumentException { if ((internalFormat == 0) || (pixelFormat == 0)) { throw new IllegalArgumentException("internalFormat and pixelFormat must be non-zero"); @@ -435,7 +436,7 @@ public class TextureIO { * OpenGL error occurred * @throws IllegalArgumentException if the passed TextureData was null */ - public static Texture newTexture(TextureData data) throws GLException, IllegalArgumentException { + public static Texture newTexture(final TextureData data) throws GLException, IllegalArgumentException { return newTexture(GLContext.getCurrentGL(), data); } @@ -448,7 +449,7 @@ public class TextureIO { * OpenGL error occurred * @throws IllegalArgumentException if the passed TextureData was null */ - public static Texture newTexture(GL gl, TextureData data) throws GLException, IllegalArgumentException { + public static Texture newTexture(final GL gl, final TextureData data) throws GLException, IllegalArgumentException { if (data == null) { throw new IllegalArgumentException("Null TextureData"); } @@ -470,11 +471,11 @@ public class TextureIO { * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ - public static Texture newTexture(File file, boolean mipmap) throws IOException, GLException { - GL gl = GLContext.getCurrentGL(); - GLProfile glp = gl.getGLProfile(); - TextureData data = newTextureData(glp, file, mipmap, IOUtil.getFileSuffix(file)); - Texture texture = newTexture(gl, data); + public static Texture newTexture(final File file, final boolean mipmap) throws IOException, GLException { + final GL gl = GLContext.getCurrentGL(); + final GLProfile glp = gl.getGLProfile(); + final TextureData data = newTextureData(glp, file, mipmap, IOUtil.getFileSuffix(file)); + final Texture texture = newTexture(gl, data); data.flush(); return texture; } @@ -499,11 +500,11 @@ public class TextureIO { * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ - public static Texture newTexture(InputStream stream, boolean mipmap, String fileSuffix) throws IOException, GLException { - GL gl = GLContext.getCurrentGL(); - GLProfile glp = gl.getGLProfile(); - TextureData data = newTextureData(glp, stream, mipmap, fileSuffix); - Texture texture = newTexture(gl, data); + public static Texture newTexture(final InputStream stream, final boolean mipmap, final String fileSuffix) throws IOException, GLException { + final GL gl = GLContext.getCurrentGL(); + final GLProfile glp = gl.getGLProfile(); + final TextureData data = newTextureData(glp, stream, mipmap, fileSuffix); + final Texture texture = newTexture(gl, data); data.flush(); return texture; } @@ -528,14 +529,14 @@ public class TextureIO { * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ - public static Texture newTexture(URL url, boolean mipmap, String fileSuffix) throws IOException, GLException { + public static Texture newTexture(final URL url, final boolean mipmap, String fileSuffix) throws IOException, GLException { if (fileSuffix == null) { fileSuffix = IOUtil.getFileSuffix(url.getPath()); } - GL gl = GLContext.getCurrentGL(); - GLProfile glp = gl.getGLProfile(); - TextureData data = newTextureData(glp, url, mipmap, fileSuffix); - Texture texture = newTexture(gl, data); + final GL gl = GLContext.getCurrentGL(); + final GLProfile glp = gl.getGLProfile(); + final TextureData data = newTextureData(glp, url, mipmap, fileSuffix); + final Texture texture = newTexture(gl, data); data.flush(); return texture; } @@ -549,7 +550,7 @@ public class TextureIO { * @param target the OpenGL target type, eg GL.GL_TEXTURE_2D, * GL.GL_TEXTURE_RECTANGLE_ARB */ - public static Texture newTexture(int target) { + public static Texture newTexture(final int target) { return new Texture(target); } @@ -579,31 +580,31 @@ public class TextureIO { * @throws GLException if no OpenGL context was current or an * OpenGL-related error occurred */ - public static void write(Texture texture, File file) throws IOException, GLException { + public static void write(final Texture texture, final File file) throws IOException, GLException { if (texture.getTarget() != GL.GL_TEXTURE_2D) { throw new GLException("Only GL_TEXTURE_2D textures are supported"); } // First fetch the texture data - GL _gl = GLContext.getCurrentGL(); + final GL _gl = GLContext.getCurrentGL(); if (!_gl.isGL2GL3()) { throw new GLException("Implementation only supports GL2GL3 (Use GLReadBufferUtil and the TextureData variant), have: " + _gl); } - GL2GL3 gl = _gl.getGL2(); + final GL2GL3 gl = _gl.getGL2(); texture.bind(gl); - int internalFormat = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_INTERNAL_FORMAT); - int width = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_WIDTH); - int height = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_HEIGHT); - int border = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_BORDER); + final int internalFormat = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2GL3.GL_TEXTURE_INTERNAL_FORMAT); + final int width = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2GL3.GL_TEXTURE_WIDTH); + final int height = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2GL3.GL_TEXTURE_HEIGHT); + final int border = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_BORDER); TextureData data = null; if (internalFormat == GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT || internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT1_EXT || internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT3_EXT || internalFormat == GL.GL_COMPRESSED_RGBA_S3TC_DXT5_EXT) { // Fetch using glGetCompressedTexImage - int size = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2.GL_TEXTURE_COMPRESSED_IMAGE_SIZE); - ByteBuffer res = ByteBuffer.allocate(size); + final int size = glGetTexLevelParameteri(gl, GL.GL_TEXTURE_2D, 0, GL2GL3.GL_TEXTURE_COMPRESSED_IMAGE_SIZE); + final ByteBuffer res = ByteBuffer.allocate(size); gl.glGetCompressedTexImage(GL.GL_TEXTURE_2D, 0, res); data = new TextureData(gl.getGLProfile(), internalFormat, width, height, border, internalFormat, GL.GL_UNSIGNED_BYTE, false, true, true, res, null); @@ -612,7 +613,7 @@ public class TextureIO { int fetchedFormat = 0; switch (internalFormat) { case GL.GL_RGB: - case GL2.GL_BGR: + case GL2GL3.GL_BGR: case GL.GL_RGB8: bytesPerPixel = 3; fetchedFormat = GL.GL_RGB; @@ -629,19 +630,19 @@ public class TextureIO { } // Fetch using glGetTexImage - int packAlignment = glGetInteger(gl, GL.GL_PACK_ALIGNMENT); - int packRowLength = glGetInteger(gl, GL2.GL_PACK_ROW_LENGTH); - int packSkipRows = glGetInteger(gl, GL2.GL_PACK_SKIP_ROWS); - int packSkipPixels = glGetInteger(gl, GL2.GL_PACK_SKIP_PIXELS); - int packSwapBytes = glGetInteger(gl, GL2.GL_PACK_SWAP_BYTES); + final int packAlignment = glGetInteger(gl, GL.GL_PACK_ALIGNMENT); + final int packRowLength = glGetInteger(gl, GL2ES3.GL_PACK_ROW_LENGTH); + final int packSkipRows = glGetInteger(gl, GL2ES3.GL_PACK_SKIP_ROWS); + final int packSkipPixels = glGetInteger(gl, GL2ES3.GL_PACK_SKIP_PIXELS); + final int packSwapBytes = glGetInteger(gl, GL2GL3.GL_PACK_SWAP_BYTES); gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, 1); - gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, 0); - gl.glPixelStorei(GL2.GL_PACK_SKIP_ROWS, 0); - gl.glPixelStorei(GL2.GL_PACK_SKIP_PIXELS, 0); - gl.glPixelStorei(GL2.GL_PACK_SWAP_BYTES, 0); + gl.glPixelStorei(GL2ES3.GL_PACK_ROW_LENGTH, 0); + gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_ROWS, 0); + gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_PIXELS, 0); + gl.glPixelStorei(GL2GL3.GL_PACK_SWAP_BYTES, 0); - ByteBuffer res = ByteBuffer.allocate((width + (2 * border)) * + final ByteBuffer res = ByteBuffer.allocate((width + (2 * border)) * (height + (2 * border)) * bytesPerPixel); if (DEBUG) { @@ -651,10 +652,10 @@ public class TextureIO { gl.glGetTexImage(GL.GL_TEXTURE_2D, 0, fetchedFormat, GL.GL_UNSIGNED_BYTE, res); gl.glPixelStorei(GL.GL_PACK_ALIGNMENT, packAlignment); - gl.glPixelStorei(GL2.GL_PACK_ROW_LENGTH, packRowLength); - gl.glPixelStorei(GL2.GL_PACK_SKIP_ROWS, packSkipRows); - gl.glPixelStorei(GL2.GL_PACK_SKIP_PIXELS, packSkipPixels); - gl.glPixelStorei(GL2.GL_PACK_SWAP_BYTES, packSwapBytes); + gl.glPixelStorei(GL2ES3.GL_PACK_ROW_LENGTH, packRowLength); + gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_ROWS, packSkipRows); + gl.glPixelStorei(GL2ES3.GL_PACK_SKIP_PIXELS, packSkipPixels); + gl.glPixelStorei(GL2GL3.GL_PACK_SWAP_BYTES, packSwapBytes); data = new TextureData(gl.getGLProfile(), internalFormat, width, height, border, fetchedFormat, GL.GL_UNSIGNED_BYTE, false, false, false, res, null); @@ -668,9 +669,9 @@ public class TextureIO { write(data, file); } - public static void write(TextureData data, File file) throws IOException, GLException { - for (Iterator<TextureWriter> iter = textureWriters.iterator(); iter.hasNext(); ) { - TextureWriter writer = iter.next(); + public static void write(final TextureData data, final File file) throws IOException, GLException { + for (final Iterator<TextureWriter> iter = textureWriters.iterator(); iter.hasNext(); ) { + final TextureWriter writer = iter.next(); if (writer.write(file, data)) { return; } @@ -689,7 +690,7 @@ public class TextureIO { * The last provider added, will be the first provider to be tested. * </p> */ - public static void addTextureProvider(TextureProvider provider) { + public static void addTextureProvider(final TextureProvider provider) { // Must always add at the front so the ImageIO provider is last, // so we don't accidentally use it instead of a user's possibly // more optimal provider @@ -702,7 +703,7 @@ public class TextureIO { * The last provider added, will be the first provider to be tested. * </p> */ - public static void addTextureWriter(TextureWriter writer) { + public static void addTextureWriter(final TextureWriter writer) { // Must always add at the front so the ImageIO writer is last, // so we don't accidentally use it instead of a user's possibly // more optimal writer @@ -727,7 +728,7 @@ public class TextureIO { the GL_ARB_texture_rectangle extension to be turned off globally for this purpose. The default is that the use of the extension is enabled. */ - public static void setTexRectEnabled(boolean enabled) { + public static void setTexRectEnabled(final boolean enabled) { texRectEnabled = enabled; } @@ -750,10 +751,10 @@ public class TextureIO { if(GLProfile.isAWTAvailable()) { try { // Use reflection to avoid compile-time dependencies on AWT-related classes - TextureProvider provider = (TextureProvider) + final TextureProvider provider = (TextureProvider) Class.forName("com.jogamp.opengl.util.texture.spi.awt.IIOTextureProvider").newInstance(); addTextureProvider(provider); - } catch (Exception e) { + } catch (final Exception e) { if (DEBUG) { e.printStackTrace(); } @@ -771,14 +772,14 @@ public class TextureIO { if(GLProfile.isAWTAvailable()) { try { // Use reflection to avoid compile-time dependencies on AWT-related classes - TextureWriter writer = (TextureWriter) + final TextureWriter writer = (TextureWriter) Class.forName("com.jogamp.opengl.util.texture.spi.awt.IIOTextureWriter").newInstance(); addTextureWriter(writer); - } catch (Exception e) { + } catch (final Exception e) { if (DEBUG) { e.printStackTrace(); } - } catch (Error e) { + } catch (final Error e) { if (DEBUG) { e.printStackTrace(); } @@ -794,10 +795,10 @@ public class TextureIO { } // Implementation methods - private static TextureData newTextureDataImpl(GLProfile glp, File file, - int internalFormat, - int pixelFormat, - boolean mipmap, + private static TextureData newTextureDataImpl(final GLProfile glp, final File file, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, String fileSuffix) throws IOException { if (file == null) { throw new IOException("File was null"); @@ -805,9 +806,9 @@ public class TextureIO { fileSuffix = toLowerCase(fileSuffix); - for (Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { - TextureProvider provider = iter.next(); - TextureData data = provider.newTextureData(glp, file, + for (final Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { + final TextureProvider provider = iter.next(); + final TextureData data = provider.newTextureData(glp, file, internalFormat, pixelFormat, mipmap, @@ -820,10 +821,10 @@ public class TextureIO { throw new IOException("No suitable reader for given file "+file.getAbsolutePath()); } - private static TextureData newTextureDataImpl(GLProfile glp, InputStream stream, - int internalFormat, - int pixelFormat, - boolean mipmap, + private static TextureData newTextureDataImpl(final GLProfile glp, InputStream stream, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, String fileSuffix) throws IOException { if (stream == null) { throw new IOException("Stream was null"); @@ -836,9 +837,9 @@ public class TextureIO { stream = new BufferedInputStream(stream); } - for (Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { - TextureProvider provider = iter.next(); - TextureData data = provider.newTextureData(glp, stream, + for (final Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { + final TextureProvider provider = iter.next(); + final TextureData data = provider.newTextureData(glp, stream, internalFormat, pixelFormat, mipmap, @@ -851,10 +852,10 @@ public class TextureIO { throw new IOException("No suitable reader for given stream"); } - private static TextureData newTextureDataImpl(GLProfile glp, URL url, - int internalFormat, - int pixelFormat, - boolean mipmap, + private static TextureData newTextureDataImpl(final GLProfile glp, final URL url, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, String fileSuffix) throws IOException { if (url == null) { throw new IOException("URL was null"); @@ -862,9 +863,9 @@ public class TextureIO { fileSuffix = toLowerCase(fileSuffix); - for (Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { - TextureProvider provider = iter.next(); - TextureData data = provider.newTextureData(glp, url, + for (final Iterator<TextureProvider> iter = textureProviders.iterator(); iter.hasNext(); ) { + final TextureProvider provider = iter.next(); + final TextureData data = provider.newTextureData(glp, url, internalFormat, pixelFormat, mipmap, @@ -881,14 +882,14 @@ public class TextureIO { // DDS provider -- supports files only for now static class DDSTextureProvider implements TextureProvider { @Override - public TextureData newTextureData(GLProfile glp, File file, - int internalFormat, - int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { + public TextureData newTextureData(final GLProfile glp, final File file, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, + final String fileSuffix) throws IOException { if (DDS.equals(fileSuffix) || DDS.equals(IOUtil.getFileSuffix(file))) { - DDSImage image = DDSImage.read(file); + final DDSImage image = DDSImage.read(file); return newTextureData(glp, image, internalFormat, pixelFormat, mipmap); } @@ -896,16 +897,16 @@ public class TextureIO { } @Override - public TextureData newTextureData(GLProfile glp, InputStream stream, - int internalFormat, - int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { + public TextureData newTextureData(final GLProfile glp, final InputStream stream, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, + final String fileSuffix) throws IOException { if (DDS.equals(fileSuffix) || DDSImage.isDDSImage(stream)) { - byte[] data = IOUtil.copyStream2ByteArray(stream); - ByteBuffer buf = ByteBuffer.wrap(data); - DDSImage image = DDSImage.read(buf); + final byte[] data = IOUtil.copyStream2ByteArray(stream); + final ByteBuffer buf = ByteBuffer.wrap(data); + final DDSImage image = DDSImage.read(buf); return newTextureData(glp, image, internalFormat, pixelFormat, mipmap); } @@ -913,12 +914,12 @@ public class TextureIO { } @Override - public TextureData newTextureData(GLProfile glp, URL url, - int internalFormat, - int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { - InputStream stream = new BufferedInputStream(url.openStream()); + public TextureData newTextureData(final GLProfile glp, final URL url, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, + final String fileSuffix) throws IOException { + final InputStream stream = new BufferedInputStream(url.openStream()); try { return newTextureData(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix); } finally { @@ -926,11 +927,11 @@ public class TextureIO { } } - private TextureData newTextureData(GLProfile glp, final DDSImage image, + private TextureData newTextureData(final GLProfile glp, final DDSImage image, int internalFormat, int pixelFormat, boolean mipmap) { - DDSImage.ImageInfo info = image.getMipMap(0); + final DDSImage.ImageInfo info = image.getMipMap(0); if (pixelFormat == 0) { switch (image.getPixelFormat()) { case DDSImage.D3DFMT_R8G8B8: @@ -967,7 +968,7 @@ public class TextureIO { break; } } - TextureData.Flusher flusher = new TextureData.Flusher() { + final TextureData.Flusher flusher = new TextureData.Flusher() { @Override public void flush() { image.close(); @@ -975,7 +976,7 @@ public class TextureIO { }; TextureData data; if (mipmap && image.getNumMipMaps() > 0) { - Buffer[] mipmapData = new Buffer[image.getNumMipMaps()]; + final Buffer[] mipmapData = new Buffer[image.getNumMipMaps()]; for (int i = 0; i < image.getNumMipMaps(); i++) { mipmapData[i] = image.getMipMap(i).getData(); } @@ -1013,12 +1014,12 @@ public class TextureIO { // Base class for SGI RGB and TGA image providers static abstract class StreamBasedTextureProvider implements TextureProvider { @Override - public TextureData newTextureData(GLProfile glp, File file, - int internalFormat, - int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { - InputStream inStream = new BufferedInputStream(new FileInputStream(file)); + public TextureData newTextureData(final GLProfile glp, final File file, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, + final String fileSuffix) throws IOException { + final InputStream inStream = new BufferedInputStream(new FileInputStream(file)); try { // The SGIImage and TGAImage implementations use InputStreams // anyway so there isn't much point in having a separate code @@ -1034,12 +1035,12 @@ public class TextureIO { } @Override - public TextureData newTextureData(GLProfile glp, URL url, - int internalFormat, - int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { - InputStream stream = new BufferedInputStream(url.openStream()); + public TextureData newTextureData(final GLProfile glp, final URL url, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, + final String fileSuffix) throws IOException { + final InputStream stream = new BufferedInputStream(url.openStream()); try { return newTextureData(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix); } finally { @@ -1052,15 +1053,15 @@ public class TextureIO { // SGI RGB image provider static class SGITextureProvider extends StreamBasedTextureProvider { @Override - public TextureData newTextureData(GLProfile glp, InputStream stream, + public TextureData newTextureData(final GLProfile glp, final InputStream stream, int internalFormat, int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { + final boolean mipmap, + final String fileSuffix) throws IOException { if (SGI.equals(fileSuffix) || SGI_RGB.equals(fileSuffix) || SGIImage.isSGIImage(stream)) { - SGIImage image = SGIImage.read(stream); + final SGIImage image = SGIImage.read(stream); if (pixelFormat == 0) { pixelFormat = image.getFormat(); } @@ -1088,13 +1089,13 @@ public class TextureIO { // TGA (Targa) image provider static class TGATextureProvider extends StreamBasedTextureProvider { @Override - public TextureData newTextureData(GLProfile glp, InputStream stream, + public TextureData newTextureData(final GLProfile glp, final InputStream stream, int internalFormat, int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { + final boolean mipmap, + final String fileSuffix) throws IOException { if (TGA.equals(fileSuffix)) { - TGAImage image = TGAImage.read(glp, stream); + final TGAImage image = TGAImage.read(glp, stream); if (pixelFormat == 0) { pixelFormat = image.getGLFormat(); } @@ -1126,11 +1127,11 @@ public class TextureIO { // PNG image provider static class PNGTextureProvider extends StreamBasedTextureProvider { @Override - public TextureData newTextureData(GLProfile glp, InputStream stream, + public TextureData newTextureData(final GLProfile glp, final InputStream stream, int internalFormat, int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { + final boolean mipmap, + final String fileSuffix) throws IOException { if (PNG.equals(fileSuffix)) { final PNGPixelRect image = PNGPixelRect.read(stream, null, true /* directBuffer */, 0 /* destMinStrideInBytes */, true /* destIsGLOriented */); final GLPixelAttributes glpa = GLPixelAttributes.convert(image.getPixelformat(), glp); @@ -1166,13 +1167,13 @@ public class TextureIO { // JPEG image provider static class JPGTextureProvider extends StreamBasedTextureProvider { @Override - public TextureData newTextureData(GLProfile glp, InputStream stream, + public TextureData newTextureData(final GLProfile glp, final InputStream stream, int internalFormat, int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { + final boolean mipmap, + final String fileSuffix) throws IOException { if (JPG.equals(fileSuffix)) { - JPEGImage image = JPEGImage.read(/*glp, */ stream); + final JPEGImage image = JPEGImage.read(/*glp, */ stream); if (pixelFormat == 0) { pixelFormat = image.getGLFormat(); } @@ -1205,8 +1206,8 @@ public class TextureIO { // static class DDSTextureWriter implements TextureWriter { @Override - public boolean write(File file, - TextureData data) throws IOException { + public boolean write(final File file, + final TextureData data) throws IOException { if (DDS.equals(IOUtil.getFileSuffix(file))) { // See whether the DDS writer can handle this TextureData final GLPixelAttributes pixelAttribs = data.getPixelAttributes(); @@ -1239,7 +1240,7 @@ public class TextureIO { mipmaps = new ByteBuffer[] { (ByteBuffer) data.getBuffer() }; } - DDSImage image = DDSImage.createFromData(d3dFormat, + final DDSImage image = DDSImage.createFromData(d3dFormat, data.getWidth(), data.getHeight(), mipmaps); @@ -1256,9 +1257,9 @@ public class TextureIO { // static class SGITextureWriter implements TextureWriter { @Override - public boolean write(File file, - TextureData data) throws IOException { - String fileSuffix = IOUtil.getFileSuffix(file); + public boolean write(final File file, + final TextureData data) throws IOException { + final String fileSuffix = IOUtil.getFileSuffix(file); if (SGI.equals(fileSuffix) || SGI_RGB.equals(fileSuffix)) { // See whether the SGI writer can handle this TextureData @@ -1269,7 +1270,7 @@ public class TextureIO { pixelFormat == GL.GL_RGBA) && (pixelType == GL.GL_BYTE || pixelType == GL.GL_UNSIGNED_BYTE)) { - ByteBuffer buf = ((data.getBuffer() != null) ? + final ByteBuffer buf = ((data.getBuffer() != null) ? (ByteBuffer) data.getBuffer() : (ByteBuffer) data.getMipmapData()[0]); byte[] bytes; @@ -1282,7 +1283,7 @@ public class TextureIO { buf.rewind(); } - SGIImage image = SGIImage.createFromData(data.getWidth(), + final SGIImage image = SGIImage.createFromData(data.getWidth(), data.getHeight(), (pixelFormat == GL.GL_RGBA), bytes); @@ -1302,8 +1303,8 @@ public class TextureIO { static class TGATextureWriter implements TextureWriter { @Override - public boolean write(File file, - TextureData data) throws IOException { + public boolean write(final File file, + final TextureData data) throws IOException { if (TGA.equals(IOUtil.getFileSuffix(file))) { // See whether the TGA writer can handle this TextureData final GLPixelAttributes pixelAttribs = data.getPixelAttributes(); @@ -1311,7 +1312,7 @@ public class TextureIO { final int pixelType = pixelAttribs.type; if ((pixelFormat == GL.GL_RGB || pixelFormat == GL.GL_RGBA || - pixelFormat == GL2.GL_BGR || + pixelFormat == GL2GL3.GL_BGR || pixelFormat == GL.GL_BGRA ) && (pixelType == GL.GL_BYTE || pixelType == GL.GL_UNSIGNED_BYTE)) { @@ -1324,16 +1325,16 @@ public class TextureIO { if( pixelFormat == GL.GL_RGB || pixelFormat == GL.GL_RGBA ) { // Must reverse order of red and blue channels to get correct results - int skip = ((pixelFormat == GL.GL_RGB) ? 3 : 4); + final int skip = ((pixelFormat == GL.GL_RGB) ? 3 : 4); for (int i = 0; i < buf.remaining(); i += skip) { - byte red = buf.get(i + 0); - byte blue = buf.get(i + 2); + final byte red = buf.get(i + 0); + final byte blue = buf.get(i + 2); buf.put(i + 0, blue); buf.put(i + 2, red); } } - TGAImage image = TGAImage.createFromData(data.getWidth(), + final TGAImage image = TGAImage.createFromData(data.getWidth(), data.getHeight(), (pixelFormat == GL.GL_RGBA || pixelFormat == GL.GL_BGRA), false, buf); @@ -1353,7 +1354,7 @@ public class TextureIO { static class PNGTextureWriter implements TextureWriter { @Override - public boolean write(File file, TextureData data) throws IOException { + public boolean write(final File file, final TextureData data) throws IOException { if (PNG.equals(IOUtil.getFileSuffix(file))) { // See whether the PNG writer can handle this TextureData final GLPixelAttributes pixelAttribs = data.getPixelAttributes(); @@ -1403,19 +1404,19 @@ public class TextureIO { // Helper routines // - private static int glGetInteger(GL gl, int pname) { - int[] tmp = new int[1]; + private static int glGetInteger(final GL gl, final int pname) { + final int[] tmp = new int[1]; gl.glGetIntegerv(pname, tmp, 0); return tmp[0]; } - private static int glGetTexLevelParameteri(GL2GL3 gl, int target, int level, int pname) { - int[] tmp = new int[1]; + private static int glGetTexLevelParameteri(final GL2GL3 gl, final int target, final int level, final int pname) { + final int[] tmp = new int[1]; gl.glGetTexLevelParameteriv(target, 0, pname, tmp, 0); return tmp[0]; } - private static String toLowerCase(String arg) { + private static String toLowerCase(final String arg) { if (arg == null) { return null; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java index ee3b600a5..5add4f695 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureSequence.java @@ -114,11 +114,11 @@ public interface TextureSequence { * to associated related data. */ public static class TextureFrame extends TimeFrameI { - public TextureFrame(Texture t, int pts, int duration) { + public TextureFrame(final Texture t, final int pts, final int duration) { super(pts, duration); texture = t; } - public TextureFrame(Texture t) { + public TextureFrame(final Texture t) { texture = t; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureState.java b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureState.java index d8320c690..467ab41c5 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/TextureState.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/TextureState.java @@ -53,7 +53,7 @@ public class TextureState { * Returns <code>0</code> is <code>textureTarget</code> is not supported. * </p> */ - public static final int getTextureTargetQueryName(int textureTarget) { + public static final int getTextureTargetQueryName(final int textureTarget) { final int texBindQName; switch(textureTarget) { case GL.GL_TEXTURE_2D: texBindQName = GL.GL_TEXTURE_BINDING_2D; break; @@ -61,7 +61,7 @@ public class TextureState { case GL2ES2.GL_TEXTURE_3D: texBindQName = GL2ES2.GL_TEXTURE_BINDING_3D; break; case GL2GL3.GL_TEXTURE_1D: texBindQName = GL2GL3.GL_TEXTURE_BINDING_1D; break; case GL2GL3.GL_TEXTURE_1D_ARRAY: texBindQName = GL2GL3.GL_TEXTURE_BINDING_1D_ARRAY; break; - case GL2GL3.GL_TEXTURE_2D_ARRAY: texBindQName = GL2GL3.GL_TEXTURE_BINDING_2D_ARRAY; break; + case GL.GL_TEXTURE_2D_ARRAY: texBindQName = GL.GL_TEXTURE_BINDING_2D_ARRAY; break; case GL2GL3.GL_TEXTURE_RECTANGLE: texBindQName = GL2GL3.GL_TEXTURE_BINDING_RECTANGLE; break; case GL2GL3.GL_TEXTURE_BUFFER: texBindQName = GL2GL3.GL_TEXTURE_BINDING_BUFFER; break; case GL3.GL_TEXTURE_2D_MULTISAMPLE: texBindQName = GL3.GL_TEXTURE_BINDING_2D_MULTISAMPLE; break; @@ -84,9 +84,9 @@ public class TextureState { */ private final int[] state = new int[] { 0, 0, 0, 0, 0, 0 }; - private static final String toHexString(int i) { return "0x"+Integer.toHexString(i); } + private static final String toHexString(final int i) { return "0x"+Integer.toHexString(i); } - private static final int activeTexture(GL gl) { + private static final int activeTexture(final GL gl) { final int[] vi = { 0 }; gl.glGetIntegerv(GL.GL_ACTIVE_TEXTURE, vi, 0); return vi[0]; @@ -99,7 +99,7 @@ public class TextureState { * @param textureTarget * @throws GLException if textureTarget is not supported */ - public TextureState(GL gl, int textureTarget) throws GLException { + public TextureState(final GL gl, final int textureTarget) throws GLException { this(gl, activeTexture(gl), textureTarget); } @@ -111,7 +111,7 @@ public class TextureState { * @param textureTarget * @throws GLException if textureTarget is not supported */ - public TextureState(GL gl, int textureUnit, int textureTarget) throws GLException { + public TextureState(final GL gl, final int textureUnit, final int textureTarget) throws GLException { target = textureTarget; state[0] = textureUnit; final int texBindQName = getTextureTargetQueryName(textureTarget); @@ -132,7 +132,7 @@ public class TextureState { * </p> * @param gl current GL context's GL object */ - public final void restore(GL gl) { + public final void restore(final GL gl) { gl.glActiveTexture(state[0]); gl.glBindTexture(target, state[1]); gl.glTexParameteri(target, GL.GL_TEXTURE_MAG_FILTER, state[2]); diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java b/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java index 202c08e4e..ccb3ecc3c 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureData.java @@ -113,11 +113,11 @@ public class AWTTextureData extends TextureData { * texture * @param image the image containing the texture data */ - public AWTTextureData(GLProfile glp, - int internalFormat, - int pixelFormat, - boolean mipmap, - BufferedImage image) { + public AWTTextureData(final GLProfile glp, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, + final BufferedImage image) { super(glp); if (internalFormat == 0) { this.internalFormat = image.getColorModel().hasAlpha() ? GL.GL_RGBA : GL.GL_RGB; @@ -176,7 +176,7 @@ public class AWTTextureData extends TextureData { return buffer; } - private void createFromImage(GLProfile glp, BufferedImage image) { + private void createFromImage(final GLProfile glp, final BufferedImage image) { pixelAttributes = GLPixelAttributes.UNDEF; // Determine from image mustFlipVertically = true; @@ -185,7 +185,7 @@ public class AWTTextureData extends TextureData { int scanlineStride; - SampleModel sm = image.getRaster().getSampleModel(); + final SampleModel sm = image.getRaster().getSampleModel(); if (sm instanceof SinglePixelPackedSampleModel) { scanlineStride = ((SinglePixelPackedSampleModel)sm).getScanlineStride(); @@ -300,7 +300,7 @@ public class AWTTextureData extends TextureData { case BufferedImage.TYPE_BYTE_INDEXED: case BufferedImage.TYPE_CUSTOM: default: - java.awt.image.ColorModel cm = image.getColorModel(); + final java.awt.image.ColorModel cm = image.getColorModel(); if (cm.equals(rgbColorModel)) { pixelAttributes = new GLPixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_BYTE); rowLength = scanlineStride / 3; @@ -362,7 +362,7 @@ public class AWTTextureData extends TextureData { case BufferedImage.TYPE_BYTE_INDEXED: case BufferedImage.TYPE_CUSTOM: default: - java.awt.image.ColorModel cm = image.getColorModel(); + final java.awt.image.ColorModel cm = image.getColorModel(); if (cm.equals(rgbColorModel)) { pixelAttributes = new GLPixelAttributes(GL.GL_RGB, GL.GL_UNSIGNED_BYTE); rowLength = scanlineStride / 3; @@ -382,9 +382,9 @@ public class AWTTextureData extends TextureData { createNIOBufferFromImage(image); } - private void setupLazyCustomConversion(BufferedImage image) { + private void setupLazyCustomConversion(final BufferedImage image) { imageForLazyCustomConversion = image; - boolean hasAlpha = image.getColorModel().hasAlpha(); + final boolean hasAlpha = image.getColorModel().hasAlpha(); int pixelFormat = pixelAttributes.format; int pixelType = pixelAttributes.type; if (pixelFormat == 0) { @@ -395,7 +395,7 @@ public class AWTTextureData extends TextureData { // Allow previously-selected pixelType (if any) to override that // we can infer from the DataBuffer - DataBuffer data = image.getRaster().getDataBuffer(); + final DataBuffer data = image.getRaster().getDataBuffer(); if (data instanceof DataBufferByte || isPackedInt(image)) { // Don't use GL_UNSIGNED_INT for BufferedImage packed int images if (pixelType == 0) pixelType = GL.GL_UNSIGNED_BYTE; @@ -405,7 +405,7 @@ public class AWTTextureData extends TextureData { if (pixelType == 0) pixelType = GL.GL_FLOAT; } else if (data instanceof DataBufferInt) { // FIXME: should we support signed ints? - if (pixelType == 0) pixelType = GL2GL3.GL_UNSIGNED_INT; + if (pixelType == 0) pixelType = GL.GL_UNSIGNED_INT; } else if (data instanceof DataBufferShort) { if (pixelType == 0) pixelType = GL.GL_SHORT; } else if (data instanceof DataBufferUShort) { @@ -416,12 +416,12 @@ public class AWTTextureData extends TextureData { pixelAttributes = new GLPixelAttributes(pixelFormat, pixelType); } - private void createFromCustom(BufferedImage image) { - int width = image.getWidth(); - int height = image.getHeight(); + private void createFromCustom(final BufferedImage image) { + final int width = image.getWidth(); + final int height = image.getHeight(); // create a temporary image that is compatible with OpenGL - boolean hasAlpha = image.getColorModel().hasAlpha(); + final boolean hasAlpha = image.getColorModel().hasAlpha(); java.awt.image.ColorModel cm = null; int dataBufferType = image.getRaster().getDataBuffer().getDataType(); // Don't use integer components for packed int images @@ -444,13 +444,13 @@ public class AWTTextureData extends TextureData { } } - boolean premult = cm.isAlphaPremultiplied(); - WritableRaster raster = + final boolean premult = cm.isAlphaPremultiplied(); + final WritableRaster raster = cm.createCompatibleWritableRaster(width, height); - BufferedImage texImage = new BufferedImage(cm, raster, premult, null); + final BufferedImage texImage = new BufferedImage(cm, raster, premult, null); // copy the source image into the temporary image - Graphics2D g = texImage.createGraphics(); + final Graphics2D g = texImage.createGraphics(); g.setComposite(AlphaComposite.Src); g.drawImage(image, 0, 0, null); g.dispose(); @@ -459,8 +459,8 @@ public class AWTTextureData extends TextureData { createNIOBufferFromImage(texImage); } - private boolean isPackedInt(BufferedImage image) { - int imgType = image.getType(); + private boolean isPackedInt(final BufferedImage image) { + final int imgType = image.getType(); return (imgType == BufferedImage.TYPE_INT_RGB || imgType == BufferedImage.TYPE_INT_BGR || imgType == BufferedImage.TYPE_INT_ARGB || @@ -476,11 +476,11 @@ public class AWTTextureData extends TextureData { setupLazyCustomConversion(imageForLazyCustomConversion); } - private void createNIOBufferFromImage(BufferedImage image) { + private void createNIOBufferFromImage(final BufferedImage image) { buffer = wrapImageDataBuffer(image); } - private Buffer wrapImageDataBuffer(BufferedImage image) { + private Buffer wrapImageDataBuffer(final BufferedImage image) { // // Note: Grabbing the DataBuffer will defeat Java2D's image // management mechanism (as of JDK 5/6, at least). This shouldn't @@ -490,7 +490,7 @@ public class AWTTextureData extends TextureData { // it could be. // - DataBuffer data = image.getRaster().getDataBuffer(); + final DataBuffer data = image.getRaster().getDataBuffer(); if (data instanceof DataBufferByte) { return ByteBuffer.wrap(((DataBufferByte) data).getData()); } else if (data instanceof DataBufferDouble) { diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureIO.java b/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureIO.java index c70f5d0f3..c3b3adc75 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureIO.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/awt/AWTTextureIO.java @@ -59,8 +59,8 @@ public class AWTTextureIO extends TextureIO { * * @see #newTextureData(GLProfile, BufferedImage, boolean) */ - public static TextureData newTextureData(GLProfile glp, BufferedImage image, - boolean mipmap) { + public static TextureData newTextureData(final GLProfile glp, final BufferedImage image, + final boolean mipmap) { return newTextureDataImpl(glp, image, 0, 0, mipmap); } @@ -89,10 +89,10 @@ public class AWTTextureIO extends TextureIO { * @throws IllegalArgumentException if either internalFormat or * pixelFormat was 0 */ - public static TextureData newTextureData(GLProfile glp, BufferedImage image, - int internalFormat, - int pixelFormat, - boolean mipmap) throws IllegalArgumentException { + public static TextureData newTextureData(final GLProfile glp, final BufferedImage image, + final int internalFormat, + final int pixelFormat, + final boolean mipmap) throws IllegalArgumentException { if ((internalFormat == 0) || (pixelFormat == 0)) { throw new IllegalArgumentException("internalFormat and pixelFormat must be non-zero"); } @@ -112,18 +112,18 @@ public class AWTTextureIO extends TextureIO { * @throws GLException if no OpenGL context is current or if an * OpenGL error occurred */ - public static Texture newTexture(GLProfile glp, BufferedImage image, boolean mipmap) throws GLException { - TextureData data = newTextureData(glp, image, mipmap); - Texture texture = newTexture(data); + public static Texture newTexture(final GLProfile glp, final BufferedImage image, final boolean mipmap) throws GLException { + final TextureData data = newTextureData(glp, image, mipmap); + final Texture texture = newTexture(data); data.flush(); return texture; } - private static TextureData newTextureDataImpl(GLProfile glp, - BufferedImage image, - int internalFormat, - int pixelFormat, - boolean mipmap) { + private static TextureData newTextureDataImpl(final GLProfile glp, + final BufferedImage image, + final int internalFormat, + final int pixelFormat, + final boolean mipmap) { return new AWTTextureData(glp, internalFormat, pixelFormat, mipmap, image); } } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java index 7311f20b3..20fc92819 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/DDSImage.java @@ -52,6 +52,7 @@ import java.nio.channels.FileChannel; import javax.media.opengl.GL; +import com.jogamp.common.nio.Buffers; import com.jogamp.common.util.IOUtil; import com.jogamp.opengl.util.GLBuffers; @@ -67,13 +68,13 @@ public class DDSImage { that information in another way. */ public static class ImageInfo { - private ByteBuffer data; - private int width; - private int height; - private boolean isCompressed; - private int compressionFormat; + private final ByteBuffer data; + private final int width; + private final int height; + private final boolean isCompressed; + private final int compressionFormat; - public ImageInfo(ByteBuffer data, int width, int height, boolean compressed, int compressionFormat) { + public ImageInfo(final ByteBuffer data, final int width, final int height, final boolean compressed, final int compressionFormat) { this.data = data; this.width = width; this.height = height; this.isCompressed = compressed; this.compressionFormat = compressionFormat; } @@ -163,7 +164,7 @@ public class DDSImage { @return DDS image object @throws java.io.IOException if an I/O exception occurred */ - public static DDSImage read(String filename) throws IOException { + public static DDSImage read(final String filename) throws IOException { return read(new File(filename)); } @@ -174,8 +175,8 @@ public class DDSImage { @return DDS image object @throws java.io.IOException if an I/O exception occurred */ - public static DDSImage read(File file) throws IOException { - DDSImage image = new DDSImage(); + public static DDSImage read(final File file) throws IOException { + final DDSImage image = new DDSImage(); image.readFromFile(file); return image; } @@ -187,8 +188,8 @@ public class DDSImage { @return DDS image object @throws java.io.IOException if an I/O exception occurred */ - public static DDSImage read(ByteBuffer buf) throws IOException { - DDSImage image = new DDSImage(); + public static DDSImage read(final ByteBuffer buf) throws IOException { + final DDSImage image = new DDSImage(); image.readFromBuffer(buf); return image; } @@ -207,7 +208,7 @@ public class DDSImage { fis = null; } buf = null; - } catch (IOException e) { + } catch (final IOException e) { e.printStackTrace(); } } @@ -228,11 +229,11 @@ public class DDSImage { * specified arguments * @return DDS image object */ - public static DDSImage createFromData(int d3dFormat, - int width, - int height, - ByteBuffer[] mipmapData) throws IllegalArgumentException { - DDSImage image = new DDSImage(); + public static DDSImage createFromData(final int d3dFormat, + final int width, + final int height, + final ByteBuffer[] mipmapData) throws IllegalArgumentException { + final DDSImage image = new DDSImage(); image.initFromData(d3dFormat, width, height, mipmapData); return image; } @@ -256,7 +257,7 @@ public class DDSImage { in.mark(4); int magic = 0; for (int i = 0; i < 4; i++) { - int tmp = in.read(); + final int tmp = in.read(); if (tmp < 0) { in.reset(); return false; @@ -272,7 +273,7 @@ public class DDSImage { * @param filename File name to write to * @throws java.io.IOException if an I/O exception occurred */ - public void write(String filename) throws IOException { + public void write(final String filename) throws IOException { write(new File(filename)); } @@ -281,12 +282,12 @@ public class DDSImage { * @param file File object to write to * @throws java.io.IOException if an I/O exception occurred */ - public void write(File file) throws IOException { - FileOutputStream stream = IOUtil.getFileOutputStream(file, true); - FileChannel chan = stream.getChannel(); + public void write(final File file) throws IOException { + final FileOutputStream stream = IOUtil.getFileOutputStream(file, true); + final FileChannel chan = stream.getChannel(); // Create ByteBuffer for header in case the start of our // ByteBuffer isn't actually memory-mapped - ByteBuffer hdr = ByteBuffer.allocate(Header.writtenSize()); + final ByteBuffer hdr = ByteBuffer.allocate(Header.writtenSize()); hdr.order(ByteOrder.LITTLE_ENDIAN); header.write(hdr); hdr.rewind(); @@ -302,12 +303,12 @@ public class DDSImage { * @param flag DDSD_* flags set to test * @return true if flag present or false otherwise */ - public boolean isSurfaceDescFlagSet(int flag) { + public boolean isSurfaceDescFlagSet(final int flag) { return ((header.flags & flag) != 0); } /** Test for presence/absence of pixel format flags (DDPF_*) */ - public boolean isPixelFormatFlagSet(int flag) { + public boolean isPixelFormatFlagSet(final int flag) { return ((header.pfFlags & flag) != 0); } @@ -357,7 +358,7 @@ public class DDSImage { * @param side Side to test * @return true if side present or false otherwise */ - public boolean isCubemapSidePresent(int side) { + public boolean isCubemapSidePresent(final int side) { return isCubemap() && (header.ddsCaps2 & side) != 0; } @@ -402,7 +403,7 @@ public class DDSImage { * @param map Mipmap index * @return Image object */ - public ImageInfo getMipMap(int map) { + public ImageInfo getMipMap(final int map) { return getMipMap( 0, map ); } @@ -412,7 +413,7 @@ public class DDSImage { * @param map Mipmap index * @return Image object */ - public ImageInfo getMipMap(int side, int map) { + public ImageInfo getMipMap(final int side, final int map) { if (!isCubemap() && (side != 0)) { throw new RuntimeException( "Illegal side for 2D texture: " + side ); } @@ -434,7 +435,7 @@ public class DDSImage { } buf.limit(seek + mipMapSizeInBytes(map)); buf.position(seek); - ByteBuffer next = buf.slice(); + final ByteBuffer next = buf.slice(); buf.position(0); buf.limit(buf.capacity()); return new ImageInfo(next, mipMapWidth(map), mipMapHeight(map), isCompressed(), getCompressionFormat()); @@ -454,12 +455,12 @@ public class DDSImage { * @param side Cubemap side or 0 for 2D texture * @return Mipmap image objects set */ - public ImageInfo[] getAllMipMaps( int side ) { + public ImageInfo[] getAllMipMaps( final int side ) { int numLevels = getNumMipMaps(); if (numLevels == 0) { numLevels = 1; } - ImageInfo[] result = new ImageInfo[numLevels]; + final ImageInfo[] result = new ImageInfo[numLevels]; for (int i = 0; i < numLevels; i++) { result[i] = getMipMap(side, i); } @@ -472,9 +473,9 @@ public class DDSImage { @return String format code */ public static String getCompressionFormatName(int compressionFormat) { - StringBuilder buf = new StringBuilder(); + final StringBuilder buf = new StringBuilder(); for (int i = 0; i < 4; i++) { - char c = (char) (compressionFormat & 0xFF); + final char c = (char) (compressionFormat & 0xFF); buf.append(c); compressionFormat = compressionFormat >> 8; } @@ -491,9 +492,9 @@ public class DDSImage { GL_COMPRESSED_RGBA_S3TC_DXT3_EXT, or GL_COMPRESSED_RGBA_S3TC_DXT5_EXT. */ - public static ByteBuffer allocateBlankBuffer(int width, - int height, - int openGLInternalFormat) { + public static ByteBuffer allocateBlankBuffer(final int width, + final int height, + final int openGLInternalFormat) { int size = width * height; switch (openGLInternalFormat) { case GL.GL_COMPRESSED_RGB_S3TC_DXT1_EXT: @@ -511,15 +512,15 @@ public class DDSImage { } if (size == 0) size = 1; - return GLBuffers.newDirectByteBuffer(size); + return Buffers.newDirectByteBuffer(size); } public void debugPrint() { - PrintStream tty = System.err; + final PrintStream tty = System.err; tty.println("Compressed texture: " + isCompressed()); if (isCompressed()) { - int fmt = getCompressionFormat(); - String name = getCompressionFormatName(fmt); + final int fmt = getCompressionFormat(); + final String name = getCompressionFormatName(fmt); tty.println("Compression format: 0x" + Integer.toHexString(fmt) + " (" + name + ")"); } tty.println("Width: " + header.width + " Height: " + header.height); @@ -567,7 +568,7 @@ public class DDSImage { tty.println("Raw pixel format flags: 0x" + Integer.toHexString(header.pfFlags)); tty.println("Depth: " + getDepth()); tty.println("Number of mip maps: " + getNumMipMaps()); - int fmt = getPixelFormat(); + final int fmt = getPixelFormat(); tty.print("Pixel format: "); switch (fmt) { case D3DFMT_R8G8B8: tty.println("D3DFMT_R8G8B8"); break; @@ -629,8 +630,8 @@ public class DDSImage { int ddsCapsReserved2; int textureStage; // stage in multitexture cascade - void read(ByteBuffer buf) throws IOException { - int magic = buf.getInt(); + void read(final ByteBuffer buf) throws IOException { + final int magic = buf.getInt(); if (magic != MAGIC) { throw new IOException("Incorrect magic number 0x" + Integer.toHexString(magic) + @@ -671,7 +672,7 @@ public class DDSImage { } // buf must be in little-endian byte order - void write(ByteBuffer buf) { + void write(final ByteBuffer buf) { buf.putInt(MAGIC); buf.putInt(size); buf.putInt(flags); @@ -722,15 +723,15 @@ public class DDSImage { private DDSImage() { } - private void readFromFile(File file) throws IOException { + private void readFromFile(final File file) throws IOException { fis = new FileInputStream(file); chan = fis.getChannel(); - ByteBuffer buf = chan.map(FileChannel.MapMode.READ_ONLY, + final ByteBuffer buf = chan.map(FileChannel.MapMode.READ_ONLY, 0, (int) file.length()); readFromBuffer(buf); } - private void readFromBuffer(ByteBuffer buf) throws IOException { + private void readFromBuffer(final ByteBuffer buf) throws IOException { this.buf = buf; buf.order(ByteOrder.LITTLE_ENDIAN); header = new Header(); @@ -738,10 +739,10 @@ public class DDSImage { fixupHeader(); } - private void initFromData(int d3dFormat, - int width, - int height, - ByteBuffer[] mipmapData) throws IllegalArgumentException { + private void initFromData(final int d3dFormat, + final int width, + final int height, + final ByteBuffer[] mipmapData) throws IllegalArgumentException { // Check size of mipmap data compared against format, width and // height int topmostMipmapSize = width * height; @@ -784,7 +785,7 @@ public class DDSImage { // OK, create one large ByteBuffer to hold all of the mipmap data totalSize += Header.writtenSize(); - ByteBuffer buf = ByteBuffer.allocate(totalSize); + final ByteBuffer buf = ByteBuffer.allocate(totalSize); buf.position(Header.writtenSize()); for (int i = 0; i < mipmapData.length; i++) { buf.put(mipmapData[i]); @@ -845,10 +846,10 @@ public class DDSImage { } } - private static int computeCompressedBlockSize(int width, - int height, - int depth, - int compressionFormat) { + private static int computeCompressedBlockSize(final int width, + final int height, + final int depth, + final int compressionFormat) { int blockSize = ((width + 3)/4) * ((height + 3)/4) * ((depth + 3)/4); switch (compressionFormat) { case D3DFMT_DXT1: blockSize *= 8; break; @@ -857,10 +858,10 @@ public class DDSImage { return blockSize; } - private static int computeBlockSize(int width, - int height, - int depth, - int pixelFormat) { + private static int computeBlockSize(final int width, + final int height, + final int depth, + final int pixelFormat) { int blocksize; switch (pixelFormat) { case D3DFMT_R8G8B8: @@ -883,7 +884,7 @@ public class DDSImage { return blocksize; } - private int mipMapWidth(int map) { + private int mipMapWidth(final int map) { int width = getWidth(); for (int i = 0; i < map; i++) { width >>= 1; @@ -891,7 +892,7 @@ public class DDSImage { return Math.max(width, 1); } - private int mipMapHeight(int map) { + private int mipMapHeight(final int map) { int height = getHeight(); for (int i = 0; i < map; i++) { height >>= 1; @@ -899,11 +900,11 @@ public class DDSImage { return Math.max(height, 1); } - private int mipMapSizeInBytes(int map) { - int width = mipMapWidth(map); - int height = mipMapHeight(map); + private int mipMapSizeInBytes(final int map) { + final int width = mipMapWidth(map); + final int height = mipMapHeight(map); if (isCompressed()) { - int blockSize = (getCompressionFormat() == D3DFMT_DXT1 ? 8 : 16); + final int blockSize = (getCompressionFormat() == D3DFMT_DXT1 ? 8 : 16); return ((width+3)/4)*((height+3)/4)*blockSize; } else { return width * height * (getDepth() / 8); @@ -924,8 +925,8 @@ public class DDSImage { return size; } - private int sideShiftInBytes(int side) { - int[] sides = { + private int sideShiftInBytes(final int side) { + final int[] sides = { DDSCAPS2_CUBEMAP_POSITIVEX, DDSCAPS2_CUBEMAP_NEGATIVEX, DDSCAPS2_CUBEMAP_POSITIVEY, @@ -935,9 +936,9 @@ public class DDSImage { }; int shift = 0; - int sideSize = sideSizeInBytes(); + final int sideSize = sideSizeInBytes(); for (int i = 0; i < sides.length; i++) { - int temp = sides[i]; + final int temp = sides[i]; if ((temp & side) != 0) { return shift; } @@ -948,7 +949,7 @@ public class DDSImage { throw new RuntimeException("Illegal side: " + side); } - private boolean printIfRecognized(PrintStream tty, int flags, int flag, String what) { + private boolean printIfRecognized(final PrintStream tty, final int flags, final int flag, final String what) { if ((flags & flag) != 0) { tty.println(what); return true; diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/JPEGImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/JPEGImage.java index 2081788ba..66a486f9b 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/JPEGImage.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/JPEGImage.java @@ -51,12 +51,12 @@ public class JPEGImage { * @return * @throws IOException */ - public static JPEGImage read(InputStream in, ColorSpace cs) throws IOException { + public static JPEGImage read(final InputStream in, final ColorSpace cs) throws IOException { return new JPEGImage(in, cs); } /** Reads a JPEG image from the specified InputStream, using the {@link ColorSpace#RGB}. */ - public static JPEGImage read(InputStream in) throws IOException { + public static JPEGImage read(final InputStream in) throws IOException { return new JPEGImage(in, ColorSpace.RGB); } @@ -68,7 +68,7 @@ public class JPEGImage { final ColorSpace storageCS; ByteBuffer data = null; - JPEGColorSink(ColorSpace storageCM) { + JPEGColorSink(final ColorSpace storageCM) { this.storageCS = storageCM; switch(storageCS) { case RGB: @@ -81,7 +81,7 @@ public class JPEGImage { } @Override - public final ColorSpace allocate(int width, int height, ColorSpace sourceCM, int sourceComponents) throws RuntimeException { + public final ColorSpace allocate(final int width, final int height, final ColorSpace sourceCM, final int sourceComponents) throws RuntimeException { this.width = width; this.height = height; this.sourceComponents = sourceComponents; @@ -91,7 +91,7 @@ public class JPEGImage { } @Override - public final void storeRGB(int x, int y, byte r, byte g, byte b) { + public final void storeRGB(final int x, final int y, final byte r, final byte g, final byte b) { int i = ( ( height - y - 1 ) * width + x ) * storageComponents; data.put(i++, r); data.put(i++, g); @@ -100,12 +100,12 @@ public class JPEGImage { } @Override - public final void store2(int x, int y, byte c1, byte c2) { + public final void store2(final int x, final int y, final byte c1, final byte c2) { throw new RuntimeException("not supported yet"); } @Override - public final void storeYCbCr(int x, int y, byte Y, byte Cb, byte Cr) { + public final void storeYCbCr(final int x, final int y, final byte Y, final byte Cb, final byte Cr) { int i = ( ( height - y - 1 ) * width + x ) * storageComponents; data.put(i++, Y); data.put(i++, Cb); @@ -118,7 +118,7 @@ public class JPEGImage { } }; - private JPEGImage(InputStream in, ColorSpace cs) throws IOException { + private JPEGImage(final InputStream in, final ColorSpace cs) throws IOException { pixelStorage = new JPEGColorSink(cs); final JPEGDecoder decoder = new JPEGDecoder(); decoder.parse(in); @@ -139,9 +139,9 @@ public class JPEGImage { } decoder.clear(null); } - private JPEGColorSink pixelStorage; + private final JPEGColorSink pixelStorage; private final int pixelWidth, pixelHeight, glFormat, bytesPerPixel; - private boolean reversedChannels; + private final boolean reversedChannels; private final ByteBuffer data; /** Returns the color space of the pixel data */ diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataInputStream.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataInputStream.java index 3c90d96e4..f121478e7 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataInputStream.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataInputStream.java @@ -76,7 +76,7 @@ public class LEDataInputStream extends FilterInputStream implements DataInput */ DataInputStream dataIn; - public LEDataInputStream(InputStream in) + public LEDataInputStream(final InputStream in) { super(in); dataIn = new DataInputStream(in); @@ -90,32 +90,32 @@ public class LEDataInputStream extends FilterInputStream implements DataInput } @Override - public synchronized final int read(byte b[]) throws IOException + public synchronized final int read(final byte b[]) throws IOException { return dataIn.read(b, 0, b.length); } @Override - public synchronized final int read(byte b[], int off, int len) throws IOException + public synchronized final int read(final byte b[], final int off, final int len) throws IOException { - int rl = dataIn.read(b, off, len); + final int rl = dataIn.read(b, off, len); return rl; } @Override - public final void readFully(byte b[]) throws IOException + public final void readFully(final byte b[]) throws IOException { dataIn.readFully(b, 0, b.length); } @Override - public final void readFully(byte b[], int off, int len) throws IOException + public final void readFully(final byte b[], final int off, final int len) throws IOException { dataIn.readFully(b, off, len); } @Override - public final int skipBytes(int n) throws IOException + public final int skipBytes(final int n) throws IOException { return dataIn.skipBytes(n); } @@ -123,7 +123,7 @@ public class LEDataInputStream extends FilterInputStream implements DataInput @Override public final boolean readBoolean() throws IOException { - int ch = dataIn.read(); + final int ch = dataIn.read(); if (ch < 0) throw new EOFException(); return (ch != 0); @@ -132,7 +132,7 @@ public class LEDataInputStream extends FilterInputStream implements DataInput @Override public final byte readByte() throws IOException { - int ch = dataIn.read(); + final int ch = dataIn.read(); if (ch < 0) throw new EOFException(); return (byte)(ch); @@ -141,7 +141,7 @@ public class LEDataInputStream extends FilterInputStream implements DataInput @Override public final int readUnsignedByte() throws IOException { - int ch = dataIn.read(); + final int ch = dataIn.read(); if (ch < 0) throw new EOFException(); return ch; @@ -150,8 +150,8 @@ public class LEDataInputStream extends FilterInputStream implements DataInput @Override public final short readShort() throws IOException { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); + final int ch1 = dataIn.read(); + final int ch2 = dataIn.read(); if ((ch1 | ch2) < 0) throw new EOFException(); return (short)((ch1 << 0) + (ch2 << 8)); @@ -160,8 +160,8 @@ public class LEDataInputStream extends FilterInputStream implements DataInput @Override public final int readUnsignedShort() throws IOException { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); + final int ch1 = dataIn.read(); + final int ch2 = dataIn.read(); if ((ch1 | ch2) < 0) throw new EOFException(); return (ch1 << 0) + (ch2 << 8); @@ -170,8 +170,8 @@ public class LEDataInputStream extends FilterInputStream implements DataInput @Override public final char readChar() throws IOException { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); + final int ch1 = dataIn.read(); + final int ch2 = dataIn.read(); if ((ch1 | ch2) < 0) throw new EOFException(); return (char)((ch1 << 0) + (ch2 << 8)); @@ -180,10 +180,10 @@ public class LEDataInputStream extends FilterInputStream implements DataInput @Override public final int readInt() throws IOException { - int ch1 = dataIn.read(); - int ch2 = dataIn.read(); - int ch3 = dataIn.read(); - int ch4 = dataIn.read(); + final int ch1 = dataIn.read(); + final int ch2 = dataIn.read(); + final int ch3 = dataIn.read(); + final int ch4 = dataIn.read(); if ((ch1 | ch2 | ch3 | ch4) < 0) throw new EOFException(); return ((ch1 << 0) + (ch2 << 8) + (ch3 << 16) + (ch4 << 24)); @@ -192,9 +192,9 @@ public class LEDataInputStream extends FilterInputStream implements DataInput @Override public final long readLong() throws IOException { - int i1 = readInt(); - int i2 = readInt(); - return ((long)i1 & 0xFFFFFFFFL) + ((long)i2 << 32); + final int i1 = readInt(); + final int i2 = readInt(); + return (i1 & 0xFFFFFFFFL) + ((long)i2 << 32); } @Override @@ -233,7 +233,7 @@ public class LEDataInputStream extends FilterInputStream implements DataInput * dont call this it is not implemented * @return empty new string **/ - public final static String readUTF(DataInput in) throws IOException + public final static String readUTF(final DataInput in) throws IOException { return new String(); } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataOutputStream.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataOutputStream.java index 93b097500..add177546 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataOutputStream.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/LEDataOutputStream.java @@ -72,7 +72,7 @@ public class LEDataOutputStream extends FilterOutputStream implements DataOutput */ DataOutputStream dataOut; - public LEDataOutputStream(OutputStream out) + public LEDataOutputStream(final OutputStream out) { super(out); dataOut = new DataOutputStream(out); @@ -86,44 +86,44 @@ public class LEDataOutputStream extends FilterOutputStream implements DataOutput } @Override - public synchronized final void write(byte b[]) throws IOException + public synchronized final void write(final byte b[]) throws IOException { dataOut.write(b, 0, b.length); } @Override - public synchronized final void write(byte b[], int off, int len) throws IOException + public synchronized final void write(final byte b[], final int off, final int len) throws IOException { dataOut.write(b, off, len); } @Override - public final void write(int b) throws IOException + public final void write(final int b) throws IOException { dataOut.write(b); } @Override - public final void writeBoolean(boolean v) throws IOException + public final void writeBoolean(final boolean v) throws IOException { dataOut.writeBoolean(v); } @Override - public final void writeByte(int v) throws IOException + public final void writeByte(final int v) throws IOException { dataOut.writeByte(v); } /** Don't call this -- not implemented */ @Override - public final void writeBytes(String s) throws IOException + public final void writeBytes(final String s) throws IOException { throw new UnsupportedOperationException(); } @Override - public final void writeChar(int v) throws IOException + public final void writeChar(final int v) throws IOException { dataOut.writeChar(((v >> 8) & 0xff) | ((v & 0xff) << 8)); @@ -131,25 +131,25 @@ public class LEDataOutputStream extends FilterOutputStream implements DataOutput /** Don't call this -- not implemented */ @Override - public final void writeChars(String s) throws IOException + public final void writeChars(final String s) throws IOException { throw new UnsupportedOperationException(); } @Override - public final void writeDouble(double v) throws IOException + public final void writeDouble(final double v) throws IOException { writeLong(Double.doubleToRawLongBits(v)); } @Override - public final void writeFloat(float v) throws IOException + public final void writeFloat(final float v) throws IOException { writeInt(Float.floatToRawIntBits(v)); } @Override - public final void writeInt(int v) throws IOException + public final void writeInt(final int v) throws IOException { dataOut.writeInt((v >>> 24) | ((v >>> 8) & 0xff00) | @@ -158,14 +158,14 @@ public class LEDataOutputStream extends FilterOutputStream implements DataOutput } @Override - public final void writeLong(long v) throws IOException + public final void writeLong(final long v) throws IOException { writeInt((int) v); writeInt((int) (v >>> 32)); } @Override - public final void writeShort(int v) throws IOException + public final void writeShort(final int v) throws IOException { dataOut.writeShort(((v >> 8) & 0xff) | ((v & 0xff) << 8)); @@ -173,7 +173,7 @@ public class LEDataOutputStream extends FilterOutputStream implements DataOutput /** Don't call this -- not implemented */ @Override - public final void writeUTF(String s) throws IOException + public final void writeUTF(final String s) throws IOException { throw new UnsupportedOperationException(); } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java index cabf4ebc5..461ddceb8 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/NetPbmTextureWriter.java @@ -63,7 +63,7 @@ public class NetPbmTextureWriter implements TextureWriter { * magic 7 - PAM binary RGB or RGBA * </pre> */ - public NetPbmTextureWriter(int magic) { + public NetPbmTextureWriter(final int magic) { switch(magic) { case 0: case 6: @@ -85,7 +85,7 @@ public class NetPbmTextureWriter implements TextureWriter { public String getSuffix() { return (magic==6)?PPM:PAM; } @Override - public boolean write(File file, TextureData data) throws IOException { + public boolean write(final File file, final TextureData data) throws IOException { boolean res; final int magic_old = magic; @@ -107,12 +107,12 @@ public class NetPbmTextureWriter implements TextureWriter { return res; } - private boolean writeImpl(File file, TextureData data) throws IOException { + private boolean writeImpl(final File file, final TextureData data) throws IOException { int pixelFormat = data.getPixelFormat(); final int pixelType = data.getPixelType(); if ((pixelFormat == GL.GL_RGB || pixelFormat == GL.GL_RGBA || - pixelFormat == GL2.GL_BGR || + pixelFormat == GL2GL3.GL_BGR || pixelFormat == GL.GL_BGRA ) && (pixelType == GL.GL_BYTE || pixelType == GL.GL_UNSIGNED_BYTE)) { @@ -123,13 +123,13 @@ public class NetPbmTextureWriter implements TextureWriter { } buf.rewind(); - int comps = ( pixelFormat == GL.GL_RGBA || pixelFormat == GL.GL_BGRA ) ? 4 : 3 ; + final int comps = ( pixelFormat == GL.GL_RGBA || pixelFormat == GL.GL_BGRA ) ? 4 : 3 ; - if( pixelFormat == GL2.GL_BGR || pixelFormat == GL.GL_BGRA ) { + if( pixelFormat == GL2GL3.GL_BGR || pixelFormat == GL.GL_BGRA ) { // Must reverse order of red and blue channels to get correct results for (int i = 0; i < buf.remaining(); i += comps) { - byte red = buf.get(i + 0); - byte blue = buf.get(i + 2); + final byte red = buf.get(i + 0); + final byte blue = buf.get(i + 2); buf.put(i + 0, blue); buf.put(i + 2, red); } @@ -141,9 +141,9 @@ public class NetPbmTextureWriter implements TextureWriter { throw new IOException("NetPbmTextureWriter magic 6 (PPM) doesn't RGBA pixel format, use magic 7 (PAM)"); } - FileOutputStream fos = IOUtil.getFileOutputStream(file, true); + final FileOutputStream fos = IOUtil.getFileOutputStream(file, true); - StringBuilder header = new StringBuilder(); + final StringBuilder header = new StringBuilder(); header.append("P"); header.append(magic); header.append("\n"); @@ -173,7 +173,7 @@ public class NetPbmTextureWriter implements TextureWriter { fos.write(header.toString().getBytes()); - FileChannel fosc = fos.getChannel(); + final FileChannel fosc = fos.getChannel(); fosc.write(buf); fosc.force(true); fosc.close(); diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/SGIImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/SGIImage.java index cbc8e652f..27549dfe3 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/SGIImage.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/SGIImage.java @@ -54,7 +54,7 @@ import com.jogamp.common.util.IOUtil; */ public class SGIImage { - private Header header; + private final Header header; private int format; private byte[] data; // Used for decoding RLE-compressed images @@ -105,7 +105,7 @@ public class SGIImage { magic = MAGIC; } - Header(DataInputStream in) throws IOException { + Header(final DataInputStream in) throws IOException { magic = in.readShort(); storage = in.readByte(); bpc = in.readByte(); @@ -116,13 +116,13 @@ public class SGIImage { pixmin = in.readInt(); pixmax = in.readInt(); dummy = in.readInt(); - byte[] tmpname = new byte[80]; + final byte[] tmpname = new byte[80]; in.read(tmpname); int numChars = 0; while (tmpname[numChars++] != 0); imagename = new String(tmpname, 0, numChars); colormap = in.readInt(); - byte[] tmp = new byte[404]; + final byte[] tmp = new byte[404]; in.read(tmp); } @@ -142,21 +142,21 @@ public class SGIImage { } } - private SGIImage(Header header) { + private SGIImage(final Header header) { this.header = header; } /** Reads an SGI image from the specified file. */ - public static SGIImage read(String filename) throws IOException { + public static SGIImage read(final String filename) throws IOException { return read(new FileInputStream(filename)); } /** Reads an SGI image from the specified InputStream. */ - public static SGIImage read(InputStream in) throws IOException { - DataInputStream dIn = new DataInputStream(new BufferedInputStream(in)); + public static SGIImage read(final InputStream in) throws IOException { + final DataInputStream dIn = new DataInputStream(new BufferedInputStream(in)); - Header header = new Header(dIn); - SGIImage res = new SGIImage(header); + final Header header = new Header(dIn); + final SGIImage res = new SGIImage(header); res.decodeImage(dIn); return res; } @@ -164,28 +164,28 @@ public class SGIImage { /** Writes this SGIImage to the specified file name. If flipVertically is set, outputs the scanlines from top to bottom rather than the default bottom to top order. */ - public void write(String filename, boolean flipVertically) throws IOException { + public void write(final String filename, final boolean flipVertically) throws IOException { write(new File(filename), flipVertically); } /** Writes this SGIImage to the specified file. If flipVertically is set, outputs the scanlines from top to bottom rather than the default bottom to top order. */ - public void write(File file, boolean flipVertically) throws IOException { + public void write(final File file, final boolean flipVertically) throws IOException { writeImage(file, data, header.xsize, header.ysize, header.zsize, flipVertically); } /** Creates an SGIImage from the specified data in either RGB or RGBA format. */ - public static SGIImage createFromData(int width, - int height, - boolean hasAlpha, - byte[] data) { - Header header = new Header(); + public static SGIImage createFromData(final int width, + final int height, + final boolean hasAlpha, + final byte[] data) { + final Header header = new Header(); header.xsize = (short) width; header.ysize = (short) height; header.zsize = (short) (hasAlpha ? 4 : 3); - SGIImage image = new SGIImage(header); + final SGIImage image = new SGIImage(header); image.data = data; return image; } @@ -201,9 +201,9 @@ public class SGIImage { if (!in.markSupported()) { throw new IOException("Can not test non-destructively whether given InputStream is an SGI RGB image"); } - DataInputStream dIn = new DataInputStream(in); + final DataInputStream dIn = new DataInputStream(in); dIn.mark(4); - short magic = dIn.readShort(); + final short magic = dIn.readShort(); dIn.reset(); return (magic == MAGIC); } @@ -236,10 +236,10 @@ public class SGIImage { // Internals only below this point // - private void decodeImage(DataInputStream in) throws IOException { + private void decodeImage(final DataInputStream in) throws IOException { if (header.storage == 1) { // Read RLE compression data; row starts and sizes - int x = header.ysize * header.zsize; + final int x = header.ysize * header.zsize; rowStart = new int[x]; rowSize = new int[x]; rleEnd = 4 * 2 * x + 512; @@ -253,16 +253,16 @@ public class SGIImage { } tmpData = readAll(in); - int xsize = header.xsize; - int ysize = header.ysize; - int zsize = header.zsize; + final int xsize = header.xsize; + final int ysize = header.ysize; + final int zsize = header.zsize; int lptr = 0; data = new byte[xsize * ysize * 4]; - byte[] rbuf = new byte[xsize]; - byte[] gbuf = new byte[xsize]; - byte[] bbuf = new byte[xsize]; - byte[] abuf = new byte[xsize]; + final byte[] rbuf = new byte[xsize]; + final byte[] gbuf = new byte[xsize]; + final byte[] bbuf = new byte[xsize]; + final byte[] abuf = new byte[xsize]; for (int y = 0; y < ysize; y++) { if (zsize >= 4) { getRow(rbuf, y, 0); @@ -293,15 +293,15 @@ public class SGIImage { header.zsize = 4; } - private void getRow(byte[] buf, int y, int z) { + private void getRow(final byte[] buf, final int y, final int z) { if (header.storage == 1) { - int offs = rowStart[y + z * header.ysize] - rleEnd; + final int offs = rowStart[y + z * header.ysize] - rleEnd; System.arraycopy(tmpData, offs, tmpRead, 0, rowSize[y + z * header.ysize]); int iPtr = 0; int oPtr = 0; for (;;) { byte pixel = tmpRead[iPtr++]; - int count = (int) (pixel & 0x7F); + int count = pixel & 0x7F; if (count == 0) { return; } @@ -317,12 +317,12 @@ public class SGIImage { } } } else { - int offs = (y * header.xsize) + (z * header.xsize * header.ysize); + final int offs = (y * header.xsize) + (z * header.xsize * header.ysize); System.arraycopy(tmpData, offs, buf, 0, header.xsize); } } - private void bwtorgba(byte[] b, byte[] dest, int lptr) { + private void bwtorgba(final byte[] b, final byte[] dest, final int lptr) { for (int i = 0; i < b.length; i++) { dest[4 * i + lptr + 0] = b[i]; dest[4 * i + lptr + 1] = b[i]; @@ -331,7 +331,7 @@ public class SGIImage { } } - private void latorgba(byte[] b, byte[] a, byte[] dest, int lptr) { + private void latorgba(final byte[] b, final byte[] a, final byte[] dest, final int lptr) { for (int i = 0; i < b.length; i++) { dest[4 * i + lptr + 0] = b[i]; dest[4 * i + lptr + 1] = b[i]; @@ -340,7 +340,7 @@ public class SGIImage { } } - private void rgbtorgba(byte[] r, byte[] g, byte[] b, byte[] dest, int lptr) { + private void rgbtorgba(final byte[] r, final byte[] g, final byte[] b, final byte[] dest, final int lptr) { for (int i = 0; i < b.length; i++) { dest[4 * i + lptr + 0] = r[i]; dest[4 * i + lptr + 1] = g[i]; @@ -349,7 +349,7 @@ public class SGIImage { } } - private void rgbatorgba(byte[] r, byte[] g, byte[] b, byte[] a, byte[] dest, int lptr) { + private void rgbatorgba(final byte[] r, final byte[] g, final byte[] b, final byte[] a, final byte[] dest, final int lptr) { for (int i = 0; i < b.length; i++) { dest[4 * i + lptr + 0] = r[i]; dest[4 * i + lptr + 1] = g[i]; @@ -358,19 +358,19 @@ public class SGIImage { } } - private static byte imgref(byte[] i, - int x, - int y, - int z, - int xs, - int ys, - int zs) { + private static byte imgref(final byte[] i, + final int x, + final int y, + final int z, + final int xs, + final int ys, + final int zs) { return i[(xs*ys*z)+(xs*y)+x]; } - private void writeHeader(DataOutputStream stream, - int xsize, int ysize, int zsize, boolean rle) throws IOException { + private void writeHeader(final DataOutputStream stream, + final int xsize, final int ysize, final int zsize, final boolean rle) throws IOException { // effects: outputs the 512-byte IRIS RGB header to STREAM, using xsize, // ysize, and depth as the dimensions of the image. NOTE that // the following defaults are used: @@ -415,14 +415,14 @@ public class SGIImage { stream.write(0); } - private void writeImage(File file, + private void writeImage(final File file, byte[] data, - int xsize, - int ysize, - int zsize, - boolean yflip) throws IOException { + final int xsize, + final int ysize, + final int zsize, + final boolean yflip) throws IOException { // Input data is in RGBRGBRGB or RGBARGBARGBA format; first unswizzle it - byte[] tmpData = new byte[xsize * ysize * zsize]; + final byte[] tmpData = new byte[xsize * ysize * zsize]; int dest = 0; for (int i = 0; i < zsize; i++) { for (int j = i; j < (xsize * ysize * zsize); j += zsize) { @@ -447,8 +447,8 @@ public class SGIImage { // x axis). // Build the offset tables - int[] starttab = new int[ysize * zsize]; - int[] lengthtab = new int[ysize * zsize]; + final int[] starttab = new int[ysize * zsize]; + final int[] lengthtab = new int[ysize * zsize]; // Temporary buffer for holding RLE data. // Note that this makes the assumption that RLE-compressed data will @@ -459,8 +459,8 @@ public class SGIImage { // empirical evidence here; the break-even point seems to be a look- // ahead of 3. (That is, if the three values following this one are all // the same as the current value, switch to repeat mode.) - int lookahead = 3; - byte[] rlebuf = new byte[2 * xsize * ysize * zsize]; + final int lookahead = 3; + final byte[] rlebuf = new byte[2 * xsize * ysize * zsize]; int cur_loc = 0; // current offset location. int ptr = 0; @@ -475,7 +475,7 @@ public class SGIImage { yincr = -1; } - boolean DEBUG = false; + final boolean DEBUG = false; for (int z = 0; z < zsize; z++) { for (int y = ystart; y != yend; y += yincr) { @@ -485,7 +485,7 @@ public class SGIImage { byte count = 0; boolean repeat_mode = false; boolean should_switch = false; - int start_ptr = ptr; + final int start_ptr = ptr; int num_ptr = ptr++; byte repeat_val = 0; @@ -566,7 +566,7 @@ public class SGIImage { x++; } // output this row's length into the length table - int rowlen = ptr - start_ptr; + final int rowlen = ptr - start_ptr; if (yflip) lengthtab[ysize*z+(ysize-y-1)] = rowlen; else @@ -587,11 +587,11 @@ public class SGIImage { if (DEBUG) System.err.println("total_size was " + total_size); - DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(IOUtil.getFileOutputStream(file, true))); + final DataOutputStream stream = new DataOutputStream(new BufferedOutputStream(IOUtil.getFileOutputStream(file, true))); writeHeader(stream, xsize, ysize, zsize, true); - int SIZEOF_INT = 4; + final int SIZEOF_INT = 4; for (int i = 0; i < (ysize * zsize); i++) stream.writeInt(starttab[i] + 512 + (2 * ysize * zsize * SIZEOF_INT)); for (int i = 0; i < (ysize * zsize); i++) @@ -602,7 +602,7 @@ public class SGIImage { stream.close(); } - private byte[] readAll(DataInputStream in) throws IOException { + private byte[] readAll(final DataInputStream in) throws IOException { byte[] dest = new byte[16384]; int pos = 0; int numRead = 0; @@ -613,7 +613,7 @@ public class SGIImage { numRead = in.read(dest, pos, dest.length - pos); if (pos == dest.length) { // Resize destination buffer - byte[] newDest = new byte[2 * dest.length]; + final byte[] newDest = new byte[2 * dest.length]; System.arraycopy(dest, 0, newDest, 0, pos); dest = newDest; } @@ -626,7 +626,7 @@ public class SGIImage { // Trim destination buffer if (pos != dest.length) { - byte[] finalDest = new byte[pos]; + final byte[] finalDest = new byte[pos]; System.arraycopy(dest, 0, finalDest, 0, pos); dest = finalDest; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java index 15cd63eb3..28823abb3 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/TGAImage.java @@ -71,12 +71,12 @@ import com.jogamp.common.util.IOUtil; */ public class TGAImage { - private Header header; + private final Header header; private int format; private int bpp; private ByteBuffer data; - private TGAImage(Header header) { + private TGAImage(final Header header) { this.header = header; } @@ -114,7 +114,7 @@ public class TGAImage { public final static int I_FOURWAY = 2; /** Type of this TGA file format */ - private int tgaType; + private final int tgaType; /** initial TGA image data fields */ private int idLength; // byte value @@ -142,7 +142,7 @@ public class TGAImage { tgaType = TYPE_OLD; // dont try and get footer. } - Header(LEDataInputStream in) throws IOException { + Header(final LEDataInputStream in) throws IOException { tgaType = TYPE_OLD; // dont try and get footer. // initial header fields @@ -220,24 +220,24 @@ public class TGAImage { public int size() { return 18 + idLength; } // buf must be in little-endian byte order - private void write(ByteBuffer buf) { + private void write(final ByteBuffer buf) { buf.put((byte) idLength); buf.put((byte) colorMapType); buf.put((byte) imageType); buf.putShort((short) firstEntryIndex); buf.putShort((short) colorMapLength); - buf.put((byte) colorMapEntrySize); + buf.put(colorMapEntrySize); buf.putShort((short) xOrigin); buf.putShort((short) yOrigin); buf.putShort((short) width); buf.putShort((short) height); - buf.put((byte) pixelDepth); - buf.put((byte) imageDescriptor); + buf.put(pixelDepth); + buf.put(imageDescriptor); if (idLength > 0) { try { - byte[] chars = imageID.getBytes("US-ASCII"); + final byte[] chars = imageID.getBytes("US-ASCII"); buf.put(chars); - } catch (UnsupportedEncodingException e) { + } catch (final UnsupportedEncodingException e) { throw new RuntimeException(e); } } @@ -250,7 +250,7 @@ public class TGAImage { * it into the JimiImage structure. This was taken from the * prototype and modified for the new Jimi structure */ - private void decodeImage(GLProfile glp, LEDataInputStream dIn) throws IOException { + private void decodeImage(final GLProfile glp, final LEDataInputStream dIn) throws IOException { switch (header.imageType()) { case Header.UCOLORMAPPED: throw new IOException("TGADecoder Uncompressed Colormapped images not supported"); @@ -294,14 +294,14 @@ public class TGAImage { * This assumes that the body is for a 24 bit or 32 bit for a * RGB or ARGB image respectively. */ - private void decodeRGBImageU24_32(GLProfile glp, LEDataInputStream dIn) throws IOException { + private void decodeRGBImageU24_32(final GLProfile glp, final LEDataInputStream dIn) throws IOException { setupImage24_32(glp); int i; // row index int y; // output row index - int rawWidth = header.width() * bpp; - byte[] rawBuf = new byte[rawWidth]; - byte[] tmpData = new byte[rawWidth * header.height()]; + final int rawWidth = header.width() * bpp; + final byte[] rawBuf = new byte[rawWidth]; + final byte[] tmpData = new byte[rawWidth * header.height()]; for (i = 0; i < header.height(); ++i) { dIn.readFully(rawBuf, 0, rawWidth); @@ -323,12 +323,12 @@ public class TGAImage { * This assumes that the body is for a 24 bit or 32 bit for a * RGB or ARGB image respectively. */ - private void decodeRGBImageRLE24_32(GLProfile glp, LEDataInputStream dIn) throws IOException { + private void decodeRGBImageRLE24_32(final GLProfile glp, final LEDataInputStream dIn) throws IOException { setupImage24_32(glp); - byte[] pixel = new byte[bpp]; - int rawWidth = header.width() * bpp; - byte[] tmpData = new byte[rawWidth * header.height()]; + final byte[] pixel = new byte[bpp]; + final int rawWidth = header.width() * bpp; + final byte[] tmpData = new byte[rawWidth * header.height()]; int i = 0, j; int packet, len; while (i < tmpData.length) { @@ -348,7 +348,7 @@ public class TGAImage { data = ByteBuffer.wrap(tmpData); } - private void setupImage24_32(GLProfile glp) { + private void setupImage24_32(final GLProfile glp) { bpp = header.pixelDepth / 8; switch (header.pixelDepth) { case 24: @@ -367,7 +367,7 @@ public class TGAImage { } } - private static void swapBGR(byte[] data, int bWidth, int height, int bpp) { + private static void swapBGR(final byte[] data, final int bWidth, final int height, final int bpp) { byte r,b; int k; for(int i=0; i<height; ++i) { @@ -398,30 +398,30 @@ public class TGAImage { public ByteBuffer getData() { return data; } /** Reads a Targa image from the specified file. */ - public static TGAImage read(GLProfile glp, String filename) throws IOException { + public static TGAImage read(final GLProfile glp, final String filename) throws IOException { return read(glp, new FileInputStream(filename)); } /** Reads a Targa image from the specified InputStream. */ - public static TGAImage read(GLProfile glp, InputStream in) throws IOException { - LEDataInputStream dIn = new LEDataInputStream(new BufferedInputStream(in)); + public static TGAImage read(final GLProfile glp, final InputStream in) throws IOException { + final LEDataInputStream dIn = new LEDataInputStream(new BufferedInputStream(in)); - Header header = new Header(dIn); - TGAImage res = new TGAImage(header); + final Header header = new Header(dIn); + final TGAImage res = new TGAImage(header); res.decodeImage(glp, dIn); return res; } /** Writes the image in Targa format to the specified file name. */ - public void write(String filename) throws IOException { + public void write(final String filename) throws IOException { write(new File(filename)); } /** Writes the image in Targa format to the specified file. */ - public void write(File file) throws IOException { - FileOutputStream stream = IOUtil.getFileOutputStream(file, true); - FileChannel chan = stream.getChannel(); - ByteBuffer buf = ByteBuffer.allocate(header.size()); + public void write(final File file) throws IOException { + final FileOutputStream stream = IOUtil.getFileOutputStream(file, true); + final FileChannel chan = stream.getChannel(); + final ByteBuffer buf = ByteBuffer.allocate(header.size()); buf.order(ByteOrder.LITTLE_ENDIAN); header.write(buf); buf.rewind(); @@ -437,19 +437,19 @@ public class TGAImage { data with the passed ByteBuffer. Assumes the data is already in the correct byte order for writing to disk, i.e., BGR or BGRA. */ - public static TGAImage createFromData(int width, - int height, - boolean hasAlpha, - boolean topToBottom, - ByteBuffer data) { - Header header = new Header(); + public static TGAImage createFromData(final int width, + final int height, + final boolean hasAlpha, + final boolean topToBottom, + final ByteBuffer data) { + final Header header = new Header(); header.imageType = Header.UTRUECOLOR; header.width = width; header.height = height; header.pixelDepth = (byte) (hasAlpha ? 32 : 24); header.imageDescriptor = (byte) (topToBottom ? Header.ID_TOPTOBOTTOM : 0); // Note ID not supported - TGAImage ret = new TGAImage(header); + final TGAImage ret = new TGAImage(header); ret.data = data; return ret; } diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureProvider.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureProvider.java index 18ad429d2..4174adf52 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureProvider.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureProvider.java @@ -55,12 +55,12 @@ public class IIOTextureProvider implements TextureProvider { private static final boolean DEBUG = Debug.debug("TextureIO"); @Override - public TextureData newTextureData(GLProfile glp, File file, - int internalFormat, - int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { - BufferedImage img = ImageIO.read(file); + public TextureData newTextureData(final GLProfile glp, final File file, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, + final String fileSuffix) throws IOException { + final BufferedImage img = ImageIO.read(file); if (img == null) { return null; } @@ -72,12 +72,12 @@ public class IIOTextureProvider implements TextureProvider { } @Override - public TextureData newTextureData(GLProfile glp, InputStream stream, - int internalFormat, - int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { - BufferedImage img = ImageIO.read(stream); + public TextureData newTextureData(final GLProfile glp, final InputStream stream, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, + final String fileSuffix) throws IOException { + final BufferedImage img = ImageIO.read(stream); if (img == null) { return null; } @@ -89,12 +89,12 @@ public class IIOTextureProvider implements TextureProvider { } @Override - public TextureData newTextureData(GLProfile glp, URL url, - int internalFormat, - int pixelFormat, - boolean mipmap, - String fileSuffix) throws IOException { - InputStream stream = url.openStream(); + public TextureData newTextureData(final GLProfile glp, final URL url, + final int internalFormat, + final int pixelFormat, + final boolean mipmap, + final String fileSuffix) throws IOException { + final InputStream stream = url.openStream(); try { return newTextureData(glp, stream, internalFormat, pixelFormat, mipmap, fileSuffix); } finally { diff --git a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java index be82e4fb8..60ac5680e 100644 --- a/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java +++ b/src/jogl/classes/com/jogamp/opengl/util/texture/spi/awt/IIOTextureWriter.java @@ -54,10 +54,10 @@ import com.jogamp.opengl.util.texture.spi.*; public class IIOTextureWriter implements TextureWriter { @Override - public boolean write(File file, - TextureData data) throws IOException { - int pixelFormat = data.getPixelFormat(); - int pixelType = data.getPixelType(); + public boolean write(final File file, + final TextureData data) throws IOException { + final int pixelFormat = data.getPixelFormat(); + final int pixelType = data.getPixelType(); if ((pixelFormat == GL.GL_RGB || pixelFormat == GL.GL_RGBA) && (pixelType == GL.GL_BYTE || @@ -68,7 +68,7 @@ public class IIOTextureWriter implements TextureWriter { (pixelFormat == GL.GL_RGB) ? BufferedImage.TYPE_3BYTE_BGR : BufferedImage.TYPE_4BYTE_ABGR); - byte[] imageData = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); + final byte[] imageData = ((DataBufferByte) image.getRaster().getDataBuffer()).getData(); ByteBuffer buf = (ByteBuffer) data.getBuffer(); if (buf == null) { buf = (ByteBuffer) data.getMipmapData()[0]; @@ -80,17 +80,17 @@ public class IIOTextureWriter implements TextureWriter { // Swizzle image components to be correct if (pixelFormat == GL.GL_RGB) { for (int i = 0; i < imageData.length; i += 3) { - byte red = imageData[i + 0]; - byte blue = imageData[i + 2]; + final byte red = imageData[i + 0]; + final byte blue = imageData[i + 2]; imageData[i + 0] = blue; imageData[i + 2] = red; } } else { for (int i = 0; i < imageData.length; i += 4) { - byte red = imageData[i + 0]; - byte green = imageData[i + 1]; - byte blue = imageData[i + 2]; - byte alpha = imageData[i + 3]; + final byte red = imageData[i + 0]; + final byte green = imageData[i + 1]; + final byte blue = imageData[i + 2]; + final byte alpha = imageData[i + 3]; imageData[i + 0] = alpha; imageData[i + 1] = blue; imageData[i + 2] = green; @@ -104,9 +104,9 @@ public class IIOTextureWriter implements TextureWriter { // Happened to notice that writing RGBA images to JPEGS is broken if (TextureIO.JPG.equals(IOUtil.getFileSuffix(file)) && image.getType() == BufferedImage.TYPE_4BYTE_ABGR) { - BufferedImage tmpImage = new BufferedImage(image.getWidth(), image.getHeight(), + final BufferedImage tmpImage = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_3BYTE_BGR); - Graphics g = tmpImage.getGraphics(); + final Graphics g = tmpImage.getGraphics(); g.drawImage(image, 0, 0, null); g.dispose(); image = tmpImage; |