From 2910d62be36ef75f826760aac3ce33d476cc0874 Mon Sep 17 00:00:00 2001 From: Melvyn Linke Date: Thu, 18 Apr 2024 22:16:24 +0200 Subject: [PATCH 1/2] Cleans up warnings in jme3-desktop --- .../main/java/com/jme3/app/AppletHarness.java | 4 +- .../jme3/app/state/AWTComponentAppState.java | 2 - .../jme3/cursors/plugins/CursorLoader.java | 8 +- .../main/java/com/jme3/input/AWTInput.java | 2 - .../com/jme3/system/AWTComponentRenderer.java | 6 +- .../com/jme3/system/AWTFrameProcessor.java | 138 +++++++++++------- .../main/java/com/jme3/system/AWTUtils.java | 25 ++++ .../com/jme3/system/JmeDesktopSystem.java | 12 +- .../com/jme3/system/NativeLibraryLoader.java | 29 +--- .../com/jme3/texture/plugins/AWTLoader.java | 13 -- .../java/jme3tools/converters/ImageToAwt.java | 19 ++- .../jme3tools/converters/MipMapGenerator.java | 4 +- 12 files changed, 144 insertions(+), 118 deletions(-) create mode 100644 jme3-desktop/src/main/java/com/jme3/system/AWTUtils.java diff --git a/jme3-desktop/src/main/java/com/jme3/app/AppletHarness.java b/jme3-desktop/src/main/java/com/jme3/app/AppletHarness.java index eddf09b333..d36eecee9f 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/AppletHarness.java +++ b/jme3-desktop/src/main/java/com/jme3/app/AppletHarness.java @@ -68,7 +68,7 @@ public static Applet getApplet(Application app){ return appToApplet.get(app); } - @SuppressWarnings("unchecked") + private void createCanvas(){ AppSettings settings = new AppSettings(true); @@ -107,7 +107,7 @@ private void createCanvas(){ JmeSystem.setLowPermissions(true); try{ - Class clazz = Class.forName(appClass); + Class clazz = Class.forName(appClass); app = (LegacyApplication) clazz.getDeclaredConstructor().newInstance(); } catch (ClassNotFoundException | InstantiationException diff --git a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java index db42f9050a..c4a5589cad 100644 --- a/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java +++ b/jme3-desktop/src/main/java/com/jme3/app/state/AWTComponentAppState.java @@ -34,8 +34,6 @@ import java.awt.Component; import com.jme3.app.Application; -import com.jme3.app.state.AbstractAppState; -import com.jme3.app.state.AppStateManager; import com.jme3.system.AWTFrameProcessor; import com.jme3.system.AWTTaskExecutor; diff --git a/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java b/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java index f5411bf479..44c17235a4 100644 --- a/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java +++ b/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java @@ -95,6 +95,8 @@ public JmeCursor load(AssetInfo info) throws IOException { } } + + // @SuppressWarnings("resource") private JmeCursor loadCursor(InputStream inStream) throws IOException { byte[] icoimages = new byte[0]; // new byte [0] facilitates read() @@ -107,7 +109,7 @@ private JmeCursor loadCursor(InputStream inStream) throws IOException { int steps = 0; int width = 0; int height = 0; - int flag = 0; // we don't use that. + //int flag = 0; // we don't use that. int[] rate = null; int[] animSeq = null; ArrayList icons; @@ -135,7 +137,7 @@ private JmeCursor loadCursor(InputStream inStream) throws IOException { height = leIn.readInt(); leIn.skipBytes(8); jiffy = leIn.readInt(); - flag = leIn.readInt(); + leIn.readInt(); // flag nextInt = leIn.readInt(); } else if (nextInt == 0x65746172) { // found a 'rate' of animation // System.out.println("we have 'rate'."); @@ -207,8 +209,10 @@ private JmeCursor loadCursor(InputStream inStream) throws IOException { return setJmeCursor(ciDat); } else if (riff == 0x58464952) { + ((LittleEndien) leIn).close(); throw new IllegalArgumentException("Big-Endian RIFX is not supported. Sorry."); } else { + ((LittleEndien) leIn).close(); throw new IllegalArgumentException("Unknown format."); } } else if (isCur || isIco) { diff --git a/jme3-desktop/src/main/java/com/jme3/input/AWTInput.java b/jme3-desktop/src/main/java/com/jme3/input/AWTInput.java index be3c9f5de5..3eb64d8ca7 100644 --- a/jme3-desktop/src/main/java/com/jme3/input/AWTInput.java +++ b/jme3-desktop/src/main/java/com/jme3/input/AWTInput.java @@ -35,8 +35,6 @@ import java.util.Objects; import com.jme3.app.Application; -import com.jme3.input.Input; -import com.jme3.input.RawInputListener; import com.jme3.system.AWTContext; import com.jme3.system.AWTTaskExecutor; diff --git a/jme3-desktop/src/main/java/com/jme3/system/AWTComponentRenderer.java b/jme3-desktop/src/main/java/com/jme3/system/AWTComponentRenderer.java index bfb0e85e31..a72b9d6c27 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/AWTComponentRenderer.java +++ b/jme3-desktop/src/main/java/com/jme3/system/AWTComponentRenderer.java @@ -185,10 +185,7 @@ public AWTComponentRenderer(Component destination, TransferMode transferMode, Fr if (frameBuffer != null) { this.frameBuffer = frameBuffer; } else { - this.frameBuffer = new FrameBuffer(width, height, 1); - this.frameBuffer.setDepthBuffer(Image.Format.Depth); - this.frameBuffer.setColorBuffer(Image.Format.RGBA8); - this.frameBuffer.setSrgb(true); + this.frameBuffer = AWTUtils.getFrameBuffer(width, height, 1); } colorModel = ColorModel.getRGBdefault(); @@ -203,6 +200,7 @@ public AWTComponentRenderer(Component destination, TransferMode transferMode, Fr } + /** * Initialize the component renderer. * @param renderer the JMonkey {@link Renderer renderer} to use. diff --git a/jme3-desktop/src/main/java/com/jme3/system/AWTFrameProcessor.java b/jme3-desktop/src/main/java/com/jme3/system/AWTFrameProcessor.java index 111e856973..845ce3d984 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/AWTFrameProcessor.java +++ b/jme3-desktop/src/main/java/com/jme3/system/AWTFrameProcessor.java @@ -49,13 +49,15 @@ import com.jme3.renderer.ViewPort; import com.jme3.renderer.queue.RenderQueue; import com.jme3.texture.FrameBuffer; -import com.jme3.texture.Image; /** * A frame processor that enables to render JMonkey frame buffer onto an AWT component. *

- * This class is based on the JavaFX original code provided by Alexander Brui (see JME3-FX) + * This class is based on the + * JavaFX + * original code provided by Alexander Brui (see JME3-FX) *

+ * * @author Julien Seinturier - COMEX SA - http://www.seinturier.fr * @author Alexander Brui (JavaSaBr) * @@ -63,8 +65,7 @@ public class AWTFrameProcessor implements SceneProcessor, PropertyChangeListener { public enum TransferMode { - ALWAYS, - ON_CHANGES + ALWAYS, ON_CHANGES } private Application application = null; @@ -186,12 +187,13 @@ public void cleanup() { @Override public void setProfiler(AppProfiler profiler) { - // not implemented + // not implemented } @Override public void propertyChange(PropertyChangeEvent evt) { - System.out.println("Property changed: "+evt.getPropertyName()+" "+evt.getOldValue()+" -> "+evt.getNewValue()); + System.out.println("Property changed: " + evt.getPropertyName() + " " + evt.getOldValue() + " -> " + + evt.getNewValue()); } public AWTFrameProcessor() { @@ -199,13 +201,14 @@ public AWTFrameProcessor() { askWidth = 1; askHeight = 1; main = true; - reshapeNeeded = new AtomicInteger(2); + reshapeNeeded = new AtomicInteger(2); } /** * Notify about that the ratio was changed. * - * @param newValue the new value of the ratio. + * @param newValue + * the new value of the ratio. */ protected void notifyChangedRatio(Boolean newValue) { notifyComponentResized(destination.getWidth(), destination.getHeight(), newValue); @@ -214,7 +217,8 @@ protected void notifyChangedRatio(Boolean newValue) { /** * Notify about that the height was changed. * - * @param newValue the new value of the height. + * @param newValue + * the new value of the height. */ protected void notifyChangedHeight(Number newValue) { notifyComponentResized(destination.getWidth(), newValue.intValue(), isPreserveRatio()); @@ -223,7 +227,8 @@ protected void notifyChangedHeight(Number newValue) { /** * Notify about that the width was changed. * - * @param newValue the new value of the width. + * @param newValue + * the new value of the width. */ protected void notifyChangedWidth(Number newValue) { notifyComponentResized(newValue.intValue(), destination.getHeight(), isPreserveRatio()); @@ -241,7 +246,8 @@ protected Application getApplication() { /** * Sets the application. * - * @param application the application. + * @param application + * the application. */ protected void setApplication(Application application) { this.application = application; @@ -259,7 +265,8 @@ protected Component getDestination() { /** * Sets the destination. * - * @param destination the destination. + * @param destination + * the destination. */ protected void setDestination(Component destination) { this.destination = destination; @@ -267,6 +274,7 @@ protected void setDestination(Component destination) { /** * Checks of existing destination. + * * @return true if destination is exists. */ protected boolean hasDestination() { @@ -275,15 +283,16 @@ protected boolean hasDestination() { /** * Checks of existing application. + * * @return true if destination is exists. */ protected boolean hasApplication() { return application != null; } - /** * Gets the frame transfer. + * * @return the file transfer. */ protected AWTComponentRenderer getFrameTransfer() { @@ -293,7 +302,8 @@ protected AWTComponentRenderer getFrameTransfer() { /** * Sets the frame transfer. * - * @param frameTransfer the file transfer. + * @param frameTransfer + * the file transfer. */ protected void setFrameTransfer(AWTComponentRenderer frameTransfer) { this.frameTransfer = frameTransfer; @@ -332,9 +342,12 @@ public void setEnabled(final boolean enabled) { /** * Handle resizing. * - * @param newWidth the new width. - * @param newHeight the new height. - * @param fixAspect true to fix the aspect ratio. + * @param newWidth + * the new width. + * @param newHeight + * the new height. + * @param fixAspect + * true to fix the aspect ratio. */ protected void notifyComponentResized(int newWidth, int newHeight, boolean fixAspect) { @@ -385,8 +398,10 @@ protected int getDestinationHeight() { /** * Bind this processor. * - * @param destination the destination. - * @param application the application. + * @param destination + * the destination. + * @param application + * the application. */ public void bind(Component destination, Application application) { final RenderManager renderManager = application.getRenderManager(); @@ -406,9 +421,12 @@ public void bind(Component destination, Application application) { /** * Bind this processor. * - * @param destination the destination. - * @param application the application. - * @param viewPort the view port. + * @param destination + * the destination. + * @param application + * the application. + * @param viewPort + * the view port. */ public void bind(Component destination, Application application, ViewPort viewPort) { bind(destination, application, viewPort, true); @@ -417,12 +435,17 @@ public void bind(Component destination, Application application, ViewPort viewPo /** * Bind this processor. * - * @param destination the destination. - * @param application the application. - * @param viewPort the view port. - * @param main true if this processor is main. - */ - public void bind(final Component destination, final Application application, ViewPort viewPort, boolean main) { + * @param destination + * the destination. + * @param application + * the application. + * @param viewPort + * the view port. + * @param main + * true if this processor is main. + */ + public void bind(final Component destination, final Application application, ViewPort viewPort, + boolean main) { if (hasApplication()) { throw new RuntimeException("This process is already bonded."); @@ -443,7 +466,8 @@ public void bind(final Component destination, final Application application, Vie @Override public void run() { bindDestination(application, destination); - }}); + } + }); } } @@ -465,7 +489,8 @@ public void unbind() { @Override public void run() { unbindDestination(); - }}); + } + }); } } @@ -473,8 +498,10 @@ public void run() { /** * Bind this processor. * - * @param application the application. - * @param destination the destination. + * @param application + * the application. + * @param destination + * the destination. */ protected void bindDestination(Application application, Component destination) { @@ -498,10 +525,13 @@ protected void bindDestination(Application application, Component destination) { notifyComponentResized(getDestinationWidth(), getDestinationHeight(), isPreserveRatio()); } else { - throw new IllegalArgumentException("Underlying application has to use AWTContext (actually using "+application.getContext().getClass().getSimpleName()+")"); + throw new IllegalArgumentException( + "Underlying application has to use AWTContext (actually using " + + application.getContext().getClass().getSimpleName() + ")"); } } else { - throw new IllegalArgumentException("Underlying application has to use a valid AWTContext (context is null)"); + throw new IllegalArgumentException( + "Underlying application has to use a valid AWTContext (context is null)"); } } } @@ -531,14 +561,12 @@ protected void unbindDestination() { } } - protected void bindListeners() { Component destination = getDestination(); destination.addPropertyChangeListener(this); destination.addPropertyChangeListener(this); } - protected void unbindListeners() { Component destination = getDestination(); destination.removePropertyChangeListener(this); @@ -548,12 +576,16 @@ protected void unbindListeners() { /** * Reshape the current frame transfer for the new size. * - * @param width the width. - * @param height the height. - * @param fixAspect true to fix the aspect ratio. + * @param width + * the width. + * @param height + * the height. + * @param fixAspect + * true to fix the aspect ratio. * @return the new frame transfer. */ - protected AWTComponentRenderer reshapeInThread(final int width, final int height, final boolean fixAspect) { + protected AWTComponentRenderer reshapeInThread(final int width, final int height, + final boolean fixAspect) { reshapeCurrentViewPort(width, height); @@ -576,20 +608,26 @@ protected AWTComponentRenderer reshapeInThread(final int width, final int height /** * Create a new frame transfer. * - * @param frameBuffer the frame buffer. - * @param width the width. - * @param height the height. + * @param frameBuffer + * the frame buffer. + * @param width + * the width. + * @param height + * the height. * @return the new frame transfer. */ protected AWTComponentRenderer createFrameTransfer(FrameBuffer frameBuffer, int width, int height) { - return new AWTComponentRenderer(getDestination(), getTransferMode(), isMain() ? null : frameBuffer, width, height); + return new AWTComponentRenderer(getDestination(), getTransferMode(), isMain() ? null : frameBuffer, + width, height); } /** * Reshape the current view port. * - * @param width the width. - * @param height the height. + * @param width + * the width. + * @param height + * the height. */ protected void reshapeCurrentViewPort(int width, int height) { @@ -611,7 +649,7 @@ protected void reshapeCurrentViewPort(int width, int height) { boolean found = false; Iterator iter = processors.iterator(); - while(!found && iter.hasNext()) { + while (!found && iter.hasNext()) { if (!(iter.next() instanceof AWTFrameProcessor)) { found = true; } @@ -619,11 +657,7 @@ protected void reshapeCurrentViewPort(int width, int height) { if (found) { - FrameBuffer frameBuffer = new FrameBuffer(width, height, 1); - frameBuffer.setDepthBuffer(Image.Format.Depth); - frameBuffer.setColorBuffer(Image.Format.RGBA8); - frameBuffer.setSrgb(true); - + FrameBuffer frameBuffer = AWTUtils.getFrameBuffer(width, height, 1); viewPort.setOutputFrameBuffer(frameBuffer); } diff --git a/jme3-desktop/src/main/java/com/jme3/system/AWTUtils.java b/jme3-desktop/src/main/java/com/jme3/system/AWTUtils.java new file mode 100644 index 0000000000..86730cc589 --- /dev/null +++ b/jme3-desktop/src/main/java/com/jme3/system/AWTUtils.java @@ -0,0 +1,25 @@ +package com.jme3.system; + +import com.jme3.texture.FrameBuffer; +import com.jme3.texture.Image; + +public class AWTUtils { + /** + * This should be a Temporary solution. FrameBuffer functions and Image-Formats are deprecated. + * + * @param width + * @param height + * @param samples + * @return + */ + @SuppressWarnings("deprecation") + public static FrameBuffer getFrameBuffer(int width, int height, int samples) { + FrameBuffer frameBuffer = new FrameBuffer(width, height, samples); + frameBuffer.setDepthBuffer(Image.Format.Depth); + frameBuffer.setColorBuffer(Image.Format.RGBA8); + frameBuffer.setSrgb(true); + + return frameBuffer; + } + +} diff --git a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java index 81c197a3c5..86304557fb 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java +++ b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java @@ -127,10 +127,10 @@ public void writeImageFile(OutputStream outStream, String format, ByteBuffer ima } } - @SuppressWarnings("unchecked") + //@SuppressWarnings("unchecked") private JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) { try { - Class ctxClazz = null; + Class ctxClazz = null; switch (type) { case Canvas: ctxClazz = Class.forName("com.jme3.system.lwjgl.LwjglCanvas"); @@ -158,10 +158,10 @@ private JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) { return null; } - @SuppressWarnings("unchecked") + //@SuppressWarnings("unchecked") private JmeContext newContextJogl(AppSettings settings, JmeContext.Type type) { try { - Class ctxClazz = null; + Class ctxClazz = null; switch (type) { case Display: ctxClazz = Class.forName("com.jme3.system.jogl.JoglNewtDisplay"); @@ -194,8 +194,8 @@ private JmeContext newContextCustom(AppSettings settings, JmeContext.Type type) try { String className = settings.getRenderer().substring("CUSTOM".length()); - Class ctxClazz = Class.forName(className); - return (JmeContext) ctxClazz.getDeclaredConstructor().newInstance(); + Class ctxClazz = (Class) Class.forName(className); + return ctxClazz.getDeclaredConstructor().newInstance(); } catch (InstantiationException | IllegalAccessException | IllegalArgumentException | InvocationTargetException | NoSuchMethodException | SecurityException ex) { diff --git a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java index c0eb8613e6..72d79e0301 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java +++ b/jme3-desktop/src/main/java/com/jme3/system/NativeLibraryLoader.java @@ -150,7 +150,7 @@ private NativeLibraryLoader() { */ public static boolean isUsingNativeBullet() { try { - Class clazz = Class.forName("com.jme3.bullet.util.NativeMeshUtil"); + Class clazz = Class.forName("com.jme3.bullet.util.NativeMeshUtil"); return clazz != null; } catch (ClassNotFoundException ex) { return false; @@ -245,6 +245,8 @@ private static File getJmeUserCacheFolder() { case Windows: userCacheFolder = new File(new File(userHomeFolder, "AppData"), "Local"); break; + default: + break; } if (userCacheFolder == null || !userCacheFolder.exists()) { @@ -329,31 +331,6 @@ public static void extractNativeLibraries(Platform platform, File targetDir) thr } } - /** - * Removes platform-specific portions of a library file name so - * that it can be accepted by {@link System#loadLibrary(java.lang.String) }. - *

- * E.g.
- *

    - *
  • jinput-dx8_64.dll => jinput-dx8_64
  • - *
  • liblwjgl64.so => lwjgl64
  • - *
  • libopenal.so => openal
  • - *
- * - * @param filename The filename to strip platform-specific parts - * @return The stripped library name - */ - private static String unmapLibraryName(String filename) { - StringBuilder sb = new StringBuilder(filename); - if (sb.indexOf("lib") == 0 && !filename.toLowerCase().endsWith(".dll")) { - sb.delete(0, 3); - } - int dot = sb.lastIndexOf("."); - if (dot > 0) { - sb.delete(dot, sb.length()); - } - return sb.toString(); - } public static File getJarForNativeLibrary(Platform platform, String name) { NativeLibrary library = nativeLibraryMap.get(new NativeLibrary.Key(name, platform)); diff --git a/jme3-desktop/src/main/java/com/jme3/texture/plugins/AWTLoader.java b/jme3-desktop/src/main/java/com/jme3/texture/plugins/AWTLoader.java index 926e7305af..16c9bb3e09 100644 --- a/jme3-desktop/src/main/java/com/jme3/texture/plugins/AWTLoader.java +++ b/jme3-desktop/src/main/java/com/jme3/texture/plugins/AWTLoader.java @@ -87,19 +87,6 @@ private void flipImage(byte[] img, int width, int height, int bpp){ System.arraycopy(sln, 0, img, y2 * scSz, scSz); } } - - private void flipImage(short[] img, int width, int height, int bpp){ - int scSz = (width * bpp) / 8; - scSz /= 2; // Because shorts are 2 bytes - short[] sln = new short[scSz]; - int y2 = 0; - for (int y1 = 0; y1 < height / 2; y1++){ - y2 = height - y1 - 1; - System.arraycopy(img, y1 * scSz, sln, 0, scSz); - System.arraycopy(img, y2 * scSz, img, y1 * scSz, scSz); - System.arraycopy(sln, 0, img, y2 * scSz, scSz); - } - } public Image load(BufferedImage img, boolean flipY){ int width = img.getWidth(); diff --git a/jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java b/jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java index 82f03a410d..a25e934ec7 100644 --- a/jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java +++ b/jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java @@ -87,9 +87,9 @@ public DecodeParams(int bpp, int rm, int rs, int im, int is, boolean alpha){ this.is = is; } - public DecodeParams(int bpp, int rm, int rs, int im, int is){ - this(bpp, rm, rs, im, is, false); - } + /* + * public DecodeParams(int bpp, int rm, int rs, int im, int is){ this(bpp, rm, rs, im, is, false); } + */ } static { @@ -104,13 +104,21 @@ public DecodeParams(int bpp, int rm, int rs, int im, int is){ final int mxxxx = 0xffffffff; final int sxxxx = 0; + @SuppressWarnings("unused") final int m4x___ = 0xf000; + @SuppressWarnings("unused") final int m4_x__ = 0x0f00; + @SuppressWarnings("unused") final int m4__x_ = 0x00f0; + @SuppressWarnings("unused") final int m4___x = 0x000f; + @SuppressWarnings("unused") final int s4x___ = 12; + @SuppressWarnings("unused") final int s4_x__ = 8; + @SuppressWarnings("unused") final int s4__x_ = 4; + @SuppressWarnings("unused") final int s4___x = 0; final int m5___ = 0xf800; @@ -326,15 +334,12 @@ public static void convert(Image input, Image output){ boolean inAlpha = false; boolean inLum = false; - boolean inRGB = false; if (inParams.am != 0) { inAlpha = true; } if (inParams.rm != 0 && inParams.gm == 0 && inParams.bm == 0) { inLum = true; - } else if (inParams.rm != 0 && inParams.gm != 0 && inParams.bm != 0) { - inRGB = true; } int expansionA = 8 - Integer.bitCount(inParams.am); @@ -377,7 +382,7 @@ public static void convert(Image input, Image output){ public static BufferedImage convert(Image image, boolean do16bit, boolean fullAlpha, int mipLevel){ Format format = image.getFormat(); - DecodeParams p = params.get(image.getFormat()); + DecodeParams p = params.get(format); if (p == null) throw new UnsupportedOperationException(); diff --git a/jme3-desktop/src/main/java/jme3tools/converters/MipMapGenerator.java b/jme3-desktop/src/main/java/jme3tools/converters/MipMapGenerator.java index 24378647e6..b887331e54 100644 --- a/jme3-desktop/src/main/java/jme3tools/converters/MipMapGenerator.java +++ b/jme3-desktop/src/main/java/jme3tools/converters/MipMapGenerator.java @@ -87,7 +87,7 @@ public static void generateMipMaps(Image image){ BufferedImage original = ImageToAwt.convert(image, false, true, 0); int width = original.getWidth(); int height = original.getHeight(); - int level = 0; + // int level = 0; BufferedImage current = original; AWTLoader loader = new AWTLoader(); @@ -105,7 +105,7 @@ public static void generateMipMaps(Image image){ break; } - level++; + // level++; height /= 2; width /= 2; From 354d1e23e2fcb4459a13c8e5e2cc10ca536781ef Mon Sep 17 00:00:00 2001 From: Melvyn Linke Date: Sun, 16 Jun 2024 12:04:56 +0200 Subject: [PATCH 2/2] Removes comments Fixes buffer creation Auto format --- .../jme3/cursors/plugins/CursorLoader.java | 182 +++++------- .../com/jme3/system/AWTFrameProcessor.java | 10 +- .../main/java/com/jme3/system/AWTUtils.java | 9 +- .../com/jme3/system/JmeDesktopSystem.java | 55 ++-- .../java/jme3tools/converters/ImageToAwt.java | 281 +++++++++--------- .../jme3tools/converters/MipMapGenerator.java | 19 +- 6 files changed, 253 insertions(+), 303 deletions(-) diff --git a/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java b/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java index 44c17235a4..cebe237f12 100644 --- a/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java +++ b/jme3-desktop/src/main/java/com/jme3/cursors/plugins/CursorLoader.java @@ -51,6 +51,7 @@ /** * Created Jun 5, 2012 9:45:58 AM + * * @author MadJack */ public class CursorLoader implements AssetLoader { @@ -62,9 +63,12 @@ public class CursorLoader implements AssetLoader { /** * Loads and return a cursor file of one of the following format: .ani, .cur and .ico. - * @param info The {@link AssetInfo} describing the cursor file. + * + * @param info + * The {@link AssetInfo} describing the cursor file. * @return A JmeCursor representation of the LWJGL's Cursor. - * @throws IOException if the file is not found. + * @throws IOException + * if the file is not found. */ @Override public JmeCursor load(AssetInfo info) throws IOException { @@ -95,7 +99,6 @@ public JmeCursor load(AssetInfo info) throws IOException { } } - // @SuppressWarnings("resource") private JmeCursor loadCursor(InputStream inStream) throws IOException { @@ -109,7 +112,6 @@ private JmeCursor loadCursor(InputStream inStream) throws IOException { int steps = 0; int width = 0; int height = 0; - //int flag = 0; // we don't use that. int[] rate = null; int[] animSeq = null; ArrayList icons; @@ -125,11 +127,11 @@ private JmeCursor loadCursor(InputStream inStream) throws IOException { nextInt = getNext(leIn); if (nextInt == 0x4e4f4341) { // We have ACON, we do nothing -// System.out.println("We have ACON. Next!"); + // System.out.println("We have ACON. Next!"); nextInt = getNext(leIn); while (nextInt >= 0) { if (nextInt == 0x68696e61) { -// System.out.println("we have 'anih' header"); + // System.out.println("we have 'anih' header"); leIn.skipBytes(8); // internal struct length (always 36) numIcons = leIn.readInt(); steps = leIn.readInt(); // number of blits for ani cycles @@ -137,10 +139,10 @@ private JmeCursor loadCursor(InputStream inStream) throws IOException { height = leIn.readInt(); leIn.skipBytes(8); jiffy = leIn.readInt(); - leIn.readInt(); // flag + leIn.readInt(); // flag nextInt = leIn.readInt(); } else if (nextInt == 0x65746172) { // found a 'rate' of animation -// System.out.println("we have 'rate'."); + // System.out.println("we have 'rate'."); // Fill rate here. // Rate is synchronous with frames. int length = leIn.readInt(); @@ -150,7 +152,7 @@ private JmeCursor loadCursor(InputStream inStream) throws IOException { } nextInt = leIn.readInt(); } else if (nextInt == 0x20716573) { // found a 'seq ' of animation -// System.out.println("we have 'seq '."); + // System.out.println("we have 'seq '."); // Fill animation sequence here int length = leIn.readInt(); animSeq = new int[length / 4]; @@ -159,16 +161,16 @@ private JmeCursor loadCursor(InputStream inStream) throws IOException { } nextInt = leIn.readInt(); } else if (nextInt == 0x5453494c) { // Found a LIST -// System.out.println("we have 'LIST'."); + // System.out.println("we have 'LIST'."); int length = leIn.readInt(); nextInt = leIn.readInt(); if (nextInt == 0x4f464e49) { // Got an INFO, skip its length - // this part consist of Author, title, etc + // this part consist of Author, title, etc leIn.skipBytes(length - 4); -// System.out.println(" Discarding INFO (skipped = " + skipped + ")"); + // System.out.println(" Discarding INFO (skipped = " + skipped + ")"); nextInt = leIn.readInt(); } else if (nextInt == 0x6d617266) { // found a 'fram' for animation -// System.out.println("we have 'fram'."); + // System.out.println("we have 'fram'."); if (leIn.readInt() == 0x6e6f6369) { // we have 'icon' // We have an icon and from this point on // the rest is only icons. @@ -232,13 +234,11 @@ private JmeCursor loadCursor(InputStream inStream) throws IOException { CursorLoader.CursorImageData cid = new CursorLoader.CursorImageData(bi, 0, hotSpotX, hotSpotY, 0); if (isCur) { /* - * Per http://msdn.microsoft.com/en-us/library/ms997538.aspx - * every .cur file should provide hotspot coordinates. + * Per http://msdn.microsoft.com/en-us/library/ms997538.aspx every .cur file should provide + * hotspot coordinates. */ - hotSpotX = icoimages[FDE_OFFSET + 4] - + icoimages[FDE_OFFSET + 5] * 255; - hotSpotY = icoimages[FDE_OFFSET + 6] - + icoimages[FDE_OFFSET + 7] * 255; + hotSpotX = icoimages[FDE_OFFSET + 4] + icoimages[FDE_OFFSET + 5] * 255; + hotSpotY = icoimages[FDE_OFFSET + 6] + icoimages[FDE_OFFSET + 7] * 255; cid.xHotSpot = hotSpotX; /* * Flip the Y-coordinate. @@ -261,11 +261,11 @@ private JmeCursor setJmeCursor(CursorLoader.CursorImageData cid) { jmeCursor.setNumImages(cid.numImages); jmeCursor.setImagesDelay(cid.imgDelay); jmeCursor.setImagesData(cid.data); -// System.out.println("Width = " + cid.width); -// System.out.println("Height = " + cid.height); -// System.out.println("HSx = " + cid.xHotSpot); -// System.out.println("HSy = " + cid.yHotSpot); -// System.out.println("# img = " + cid.numImages); + // System.out.println("Width = " + cid.width); + // System.out.println("Height = " + cid.height); + // System.out.println("HSx = " + cid.xHotSpot); + // System.out.println("HSy = " + cid.yHotSpot); + // System.out.println("# img = " + cid.numImages); return jmeCursor; } @@ -282,7 +282,8 @@ private BufferedImage[] parseICOImage(byte[] icoImage) throws IOException { int BMIH_LENGTH = 40; // BITMAPINFOHEADER length if (icoImage[2] != 1 && icoImage[2] != 2 || icoImage[3] != 0) { - throw new IllegalArgumentException("Bad data in ICO/CUR file. ImageType has to be either 1 or 2."); + throw new IllegalArgumentException( + "Bad data in ICO/CUR file. ImageType has to be either 1 or 2."); } int numImages = ubyte(icoImage[5]); @@ -314,10 +315,8 @@ private BufferedImage[] parseICOImage(byte[] icoImage) throws IOException { imageOffset <<= 8; imageOffset |= ubyte(icoImage[FDE_OFFSET + i * DE_LENGTH + 12]); - if (icoImage[imageOffset] == 40 - && icoImage[imageOffset + 1] == 0 - && icoImage[imageOffset + 2] == 0 - && icoImage[imageOffset + 3] == 0) { + if (icoImage[imageOffset] == 40 && icoImage[imageOffset + 1] == 0 + && icoImage[imageOffset + 2] == 0 && icoImage[imageOffset + 3] == 0) { // BITMAPINFOHEADER detected int _width = ubyte(icoImage[imageOffset + 7]); @@ -390,14 +389,13 @@ private BufferedImage[] parseICOImage(byte[] icoImage) throws IOException { int scanlineBytes = calcScanlineBytes(width, 1); int andImageOffset = xorImageOffset + scanlineBytes * height; - int[] masks = {128, 64, 32, 16, 8, 4, 2, 1}; + int[] masks = { 128, 64, 32, 16, 8, 4, 2, 1 }; for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { int index; - if ((ubyte(icoImage[xorImageOffset + row - * scanlineBytes + col / 8]) + if ((ubyte(icoImage[xorImageOffset + row * scanlineBytes + col / 8]) & masks[col % 8]) != 0) { index = 1; } else { @@ -405,22 +403,17 @@ private BufferedImage[] parseICOImage(byte[] icoImage) throws IOException { } int rgb = 0; - rgb |= (ubyte(icoImage[colorTableOffset + index * 4 - + 2])); + rgb |= (ubyte(icoImage[colorTableOffset + index * 4 + 2])); rgb <<= 8; - rgb |= (ubyte(icoImage[colorTableOffset + index * 4 - + 1])); + rgb |= (ubyte(icoImage[colorTableOffset + index * 4 + 1])); rgb <<= 8; - rgb |= (ubyte(icoImage[colorTableOffset + index - * 4])); + rgb |= (ubyte(icoImage[colorTableOffset + index * 4])); - if ((ubyte(icoImage[andImageOffset + row - * scanlineBytes + col / 8]) + if ((ubyte(icoImage[andImageOffset + row * scanlineBytes + col / 8]) & masks[col % 8]) != 0) { bi[i].setRGB(col, height - 1 - row, rgb); } else { - bi[i].setRGB(col, height - 1 - row, - 0xff000000 | rgb); + bi[i].setRGB(col, height - 1 - row, 0xff000000 | rgb); } } } @@ -430,40 +423,31 @@ private BufferedImage[] parseICOImage(byte[] icoImage) throws IOException { int scanlineBytes = calcScanlineBytes(width, 4); int andImageOffset = xorImageOffset + scanlineBytes * height; - int[] masks = {128, 64, 32, 16, 8, 4, 2, 1}; + int[] masks = { 128, 64, 32, 16, 8, 4, 2, 1 }; for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { int index; if ((col & 1) == 0) // even { - index = ubyte(icoImage[xorImageOffset + row - * scanlineBytes + col / 2]); + index = ubyte(icoImage[xorImageOffset + row * scanlineBytes + col / 2]); index >>= 4; } else { - index = ubyte(icoImage[xorImageOffset + row - * scanlineBytes + col / 2]) - & 15; + index = ubyte(icoImage[xorImageOffset + row * scanlineBytes + col / 2]) & 15; } int rgb = 0; - rgb |= (ubyte(icoImage[colorTableOffset + index * 4 - + 2])); + rgb |= (ubyte(icoImage[colorTableOffset + index * 4 + 2])); rgb <<= 8; - rgb |= (ubyte(icoImage[colorTableOffset + index * 4 - + 1])); + rgb |= (ubyte(icoImage[colorTableOffset + index * 4 + 1])); rgb <<= 8; - rgb |= (ubyte(icoImage[colorTableOffset + index - * 4])); + rgb |= (ubyte(icoImage[colorTableOffset + index * 4])); - if ((ubyte(icoImage[andImageOffset + row - * calcScanlineBytes(width, 1) - + col / 8]) & masks[col % 8]) - != 0) { + if ((ubyte(icoImage[andImageOffset + row * calcScanlineBytes(width, 1) + col / 8]) + & masks[col % 8]) != 0) { bi[i].setRGB(col, height - 1 - row, rgb); } else { - bi[i].setRGB(col, height - 1 - row, - 0xff000000 | rgb); + bi[i].setRGB(col, height - 1 - row, 0xff000000 | rgb); } } } @@ -473,31 +457,25 @@ private BufferedImage[] parseICOImage(byte[] icoImage) throws IOException { int scanlineBytes = calcScanlineBytes(width, 8); int andImageOffset = xorImageOffset + scanlineBytes * height; - int[] masks = {128, 64, 32, 16, 8, 4, 2, 1}; + int[] masks = { 128, 64, 32, 16, 8, 4, 2, 1 }; for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { int index; - index = ubyte(icoImage[xorImageOffset + row - * scanlineBytes + col]); + index = ubyte(icoImage[xorImageOffset + row * scanlineBytes + col]); int rgb = 0; - rgb |= (ubyte(icoImage[colorTableOffset + index * 4 - + 2])); + rgb |= (ubyte(icoImage[colorTableOffset + index * 4 + 2])); rgb <<= 8; - rgb |= (ubyte(icoImage[colorTableOffset + index * 4 - + 1])); + rgb |= (ubyte(icoImage[colorTableOffset + index * 4 + 1])); rgb <<= 8; rgb |= (ubyte(icoImage[colorTableOffset + index * 4])); - if ((ubyte(icoImage[andImageOffset + row - * calcScanlineBytes(width, 1) - + col / 8]) & masks[col % 8]) - != 0) { + if ((ubyte(icoImage[andImageOffset + row * calcScanlineBytes(width, 1) + col / 8]) + & masks[col % 8]) != 0) { bi[i].setRGB(col, height - 1 - row, rgb); } else { - bi[i].setRGB(col, height - 1 - row, - 0xff000000 | rgb); + bi[i].setRGB(col, height - 1 - row, 0xff000000 | rgb); } } } @@ -506,40 +484,31 @@ private BufferedImage[] parseICOImage(byte[] icoImage) throws IOException { for (int row = 0; row < height; row++) { for (int col = 0; col < width; col++) { - int rgb = ubyte(icoImage[colorTableOffset + row - * scanlineBytes + col * 4 + 3]); + int rgb = ubyte(icoImage[colorTableOffset + row * scanlineBytes + col * 4 + 3]); rgb <<= 8; - rgb |= ubyte(icoImage[colorTableOffset + row - * scanlineBytes + col * 4 + 2]); + rgb |= ubyte(icoImage[colorTableOffset + row * scanlineBytes + col * 4 + 2]); rgb <<= 8; - rgb |= ubyte(icoImage[colorTableOffset + row - * scanlineBytes + col * 4 + 1]); + rgb |= ubyte(icoImage[colorTableOffset + row * scanlineBytes + col * 4 + 1]); rgb <<= 8; - rgb |= ubyte(icoImage[colorTableOffset + row - * scanlineBytes + col * 4]); + rgb |= ubyte(icoImage[colorTableOffset + row * scanlineBytes + col * 4]); bi[i].setRGB(col, height - 1 - row, rgb); } } } - } else if (ubyte(icoImage[imageOffset]) == 0x89 - && icoImage[imageOffset + 1] == 0x50 - && icoImage[imageOffset + 2] == 0x4e - && icoImage[imageOffset + 3] == 0x47 - && icoImage[imageOffset + 4] == 0x0d - && icoImage[imageOffset + 5] == 0x0a - && icoImage[imageOffset + 6] == 0x1a - && icoImage[imageOffset + 7] == 0x0a) { - // PNG detected - - ByteArrayInputStream bais; - bais = new ByteArrayInputStream(icoImage, imageOffset, - bytesInRes); - bi[i] = ImageIO.read(bais); - } else { - throw new IllegalArgumentException("Bad data in ICO/CUR file. BITMAPINFOHEADER or PNG " - + "expected"); - } + } else if (ubyte(icoImage[imageOffset]) == 0x89 && icoImage[imageOffset + 1] == 0x50 + && icoImage[imageOffset + 2] == 0x4e && icoImage[imageOffset + 3] == 0x47 + && icoImage[imageOffset + 4] == 0x0d && icoImage[imageOffset + 5] == 0x0a + && icoImage[imageOffset + 6] == 0x1a && icoImage[imageOffset + 7] == 0x0a) { + // PNG detected + + ByteArrayInputStream bais; + bais = new ByteArrayInputStream(icoImage, imageOffset, bytesInRes); + bi[i] = ImageIO.read(bais); + } else { + throw new IllegalArgumentException( + "Bad data in ICO/CUR file. BITMAPINFOHEADER or PNG " + "expected"); + } } icoImage = null; // This array can now be garbage collected. @@ -656,7 +625,8 @@ public CursorImageData() { } } - private void addFrame(byte[] imgData, int rate, int jiffy, int width, int height, int numSeq) throws IOException { + private void addFrame(byte[] imgData, int rate, int jiffy, int width, int height, int numSeq) + throws IOException { BufferedImage bi[] = parseICOImage(imgData); int hotspotx = 0; int hotspoty = 0; @@ -671,11 +641,12 @@ private void addFrame(byte[] imgData, int rate, int jiffy, int width, int height hotspotx = 0; hotspoty = height - 1; } -// System.out.println("Image type = " + (type == 1 ? "CUR" : "ICO")); + // System.out.println("Image type = " + (type == 1 ? "CUR" : "ICO")); if (rate == 0) { rate = jiffy; } - CursorLoader.CursorImageData cid = new CursorLoader.CursorImageData(bi, rate, hotspotx, hotspoty, type); + CursorLoader.CursorImageData cid = new CursorLoader.CursorImageData(bi, rate, hotspotx, hotspoty, + type); if (width == 0) { this.width = cid.width; } else { @@ -711,7 +682,8 @@ private void addFrame(byte[] imgData, int rate, int jiffy, int width, int height cid = null; } - void assembleCursor(ArrayList icons, int[] rate, int[] animSeq, int jiffy, int steps, int width, int height) throws IOException { + void assembleCursor(ArrayList icons, int[] rate, int[] animSeq, int jiffy, int steps, + int width, int height) throws IOException { // Jiffy multiplier for LWJGL's delay, which is in milliseconds. final int MULT = 17; numImages = icons.size(); @@ -731,7 +703,7 @@ void assembleCursor(ArrayList icons, int[] rate, int[] animSeq, int jiff // the frame # is the one in the animation sequence frame = icons.get(animSeq[i]); addFrame(frame, frRate, jiffy, width, height, animSeq.length); -// System.out.println("delay of " + frRate); + // System.out.println("delay of " + frRate); } } else { for (int i = 0; i < icons.size(); i++) { @@ -742,7 +714,7 @@ void assembleCursor(ArrayList icons, int[] rate, int[] animSeq, int jiff frRate = rate[i] * MULT; } addFrame(frame, frRate, jiffy, width, height, 0); -// System.out.println("delay of " + frRate); + // System.out.println("delay of " + frRate); } } } diff --git a/jme3-desktop/src/main/java/com/jme3/system/AWTFrameProcessor.java b/jme3-desktop/src/main/java/com/jme3/system/AWTFrameProcessor.java index 845ce3d984..94538682e5 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/AWTFrameProcessor.java +++ b/jme3-desktop/src/main/java/com/jme3/system/AWTFrameProcessor.java @@ -335,7 +335,7 @@ public boolean isEnabled() { return enabled; } - public void setEnabled(final boolean enabled) { + public void setEnabled(boolean enabled) { this.enabled = enabled; } @@ -444,8 +444,7 @@ public void bind(Component destination, Application application, ViewPort viewPo * @param main * true if this processor is main. */ - public void bind(final Component destination, final Application application, ViewPort viewPort, - boolean main) { + public void bind(Component destination, Application application, ViewPort viewPort, boolean main) { if (hasApplication()) { throw new RuntimeException("This process is already bonded."); @@ -584,8 +583,7 @@ protected void unbindListeners() { * true to fix the aspect ratio. * @return the new frame transfer. */ - protected AWTComponentRenderer reshapeInThread(final int width, final int height, - final boolean fixAspect) { + protected AWTComponentRenderer reshapeInThread(int width, int height, boolean fixAspect) { reshapeCurrentViewPort(width, height); @@ -661,7 +659,7 @@ protected void reshapeCurrentViewPort(int width, int height) { viewPort.setOutputFrameBuffer(frameBuffer); } - for (final SceneProcessor sceneProcessor : processors) { + for (SceneProcessor sceneProcessor : processors) { if (!sceneProcessor.isInitialized()) { sceneProcessor.initialize(renderManager, viewPort); } else { diff --git a/jme3-desktop/src/main/java/com/jme3/system/AWTUtils.java b/jme3-desktop/src/main/java/com/jme3/system/AWTUtils.java index 86730cc589..41a27e559f 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/AWTUtils.java +++ b/jme3-desktop/src/main/java/com/jme3/system/AWTUtils.java @@ -2,21 +2,22 @@ import com.jme3.texture.FrameBuffer; import com.jme3.texture.Image; +import com.jme3.texture.FrameBuffer.FrameBufferTarget; public class AWTUtils { /** - * This should be a Temporary solution. FrameBuffer functions and Image-Formats are deprecated. + * Returns a Frame buffer. * * @param width * @param height * @param samples * @return */ - @SuppressWarnings("deprecation") public static FrameBuffer getFrameBuffer(int width, int height, int samples) { FrameBuffer frameBuffer = new FrameBuffer(width, height, samples); - frameBuffer.setDepthBuffer(Image.Format.Depth); - frameBuffer.setColorBuffer(Image.Format.RGBA8); + + frameBuffer.addColorTarget(FrameBufferTarget.newTarget(Image.Format.RGBA8)); + frameBuffer.setDepthTarget(FrameBufferTarget.newTarget(Image.Format.Depth)); frameBuffer.setSrgb(true); return frameBuffer; diff --git a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java index 86304557fb..d494f79d2d 100644 --- a/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java +++ b/jme3-desktop/src/main/java/com/jme3/system/JmeDesktopSystem.java @@ -74,23 +74,22 @@ public JmeDesktopSystem() { public URL getPlatformAssetConfigURL() { return Resources.getResource("com/jme3/asset/Desktop.cfg"); } - + private static BufferedImage verticalFlip(BufferedImage original) { AffineTransform tx = AffineTransform.getScaleInstance(1, -1); tx.translate(0, -original.getHeight()); AffineTransformOp transformOp = new AffineTransformOp(tx, AffineTransformOp.TYPE_NEAREST_NEIGHBOR); - BufferedImage awtImage = new BufferedImage(original.getWidth(), original.getHeight(), original.getType()); + BufferedImage awtImage = new BufferedImage(original.getWidth(), original.getHeight(), + original.getType()); Graphics2D g2d = awtImage.createGraphics(); - g2d.setRenderingHint(RenderingHints.KEY_RENDERING, - RenderingHints.VALUE_RENDER_SPEED); + g2d.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_SPEED); g2d.drawImage(original, transformOp, 0, 0); g2d.dispose(); return awtImage; } private static BufferedImage ensureOpaque(BufferedImage original) { - if (original.getTransparency() == BufferedImage.OPAQUE) - return original; + if (original.getTransparency() == BufferedImage.OPAQUE) return original; int w = original.getWidth(); int h = original.getHeight(); int[] pixels = new int[w * h]; @@ -101,8 +100,11 @@ private static BufferedImage ensureOpaque(BufferedImage original) { } @Override - public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, int height) throws IOException { - BufferedImage awtImage = ImageToAwt.convert(new Image(Image.Format.RGBA8, width, height, imageData.duplicate(), ColorSpace.Linear), false, true, 0); + public void writeImageFile(OutputStream outStream, String format, ByteBuffer imageData, int width, + int height) throws IOException { + BufferedImage awtImage = ImageToAwt.convert( + new Image(Image.Format.RGBA8, width, height, imageData.duplicate(), ColorSpace.Linear), false, + true, 0); awtImage = verticalFlip(awtImage); ImageWriter writer = ImageIO.getImageWritersByFormatName(format).next(); @@ -115,7 +117,7 @@ public void writeImageFile(OutputStream outStream, String format, ByteBuffer ima jpegParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT); jpegParam.setCompressionQuality(0.95f); } - + ImageOutputStream imgOut = new MemoryCacheImageOutputStream(outStream); writer.setOutput(imgOut); IIOImage outputImage = new IIOImage(awtImage, null, null); @@ -127,7 +129,6 @@ public void writeImageFile(OutputStream outStream, String format, ByteBuffer ima } } - //@SuppressWarnings("unchecked") private JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) { try { Class ctxClazz = null; @@ -146,9 +147,8 @@ private JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) { } return (JmeContext) ctxClazz.getDeclaredConstructor().newInstance(); - } catch (InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException ex) { + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException ex) { logger.log(Level.SEVERE, "Failed to create context", ex); } catch (ClassNotFoundException ex) { logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!\n" @@ -158,7 +158,6 @@ private JmeContext newContextLwjgl(AppSettings settings, JmeContext.Type type) { return null; } - //@SuppressWarnings("unchecked") private JmeContext newContextJogl(AppSettings settings, JmeContext.Type type) { try { Class ctxClazz = null; @@ -177,9 +176,8 @@ private JmeContext newContextJogl(AppSettings settings, JmeContext.Type type) { } return (JmeContext) ctxClazz.getDeclaredConstructor().newInstance(); - } catch (InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException ex) { + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException ex) { logger.log(Level.SEVERE, "Failed to create context", ex); } catch (ClassNotFoundException ex) { logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!\n" @@ -196,9 +194,8 @@ private JmeContext newContextCustom(AppSettings settings, JmeContext.Type type) Class ctxClazz = (Class) Class.forName(className); return ctxClazz.getDeclaredConstructor().newInstance(); - } catch (InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException ex) { + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException ex) { logger.log(Level.SEVERE, "Failed to create context", ex); } catch (ClassNotFoundException ex) { logger.log(Level.SEVERE, "CRITICAL ERROR: Context class is missing!", ex); @@ -211,8 +208,7 @@ private JmeContext newContextCustom(AppSettings settings, JmeContext.Type type) public JmeContext newContext(AppSettings settings, Type contextType) { initialize(settings); JmeContext ctx; - if (settings.getRenderer() == null - || settings.getRenderer().equals("NULL") + if (settings.getRenderer() == null || settings.getRenderer().equals("NULL") || contextType == JmeContext.Type.Headless) { ctx = new NullContext(); ctx.setSettings(settings); @@ -227,8 +223,7 @@ public JmeContext newContext(AppSettings settings, Type contextType) { ctx.setSettings(settings); } else { throw new UnsupportedOperationException( - "Unrecognizable renderer specified: " - + settings.getRenderer()); + "Unrecognizable renderer specified: " + settings.getRenderer()); } return ctx; } @@ -239,11 +234,10 @@ private T newObject(String className) { Class clazz = (Class) Class.forName(className); return clazz.getDeclaredConstructor().newInstance(); } catch (ClassNotFoundException ex) { - logger.log(Level.SEVERE, "CRITICAL ERROR: Audio implementation class " - + className + " is missing!\n", ex); - } catch (InstantiationException | IllegalAccessException - | IllegalArgumentException | InvocationTargetException - | NoSuchMethodException | SecurityException ex) { + logger.log(Level.SEVERE, + "CRITICAL ERROR: Audio implementation class " + className + " is missing!\n", ex); + } catch (InstantiationException | IllegalAccessException | IllegalArgumentException + | InvocationTargetException | NoSuchMethodException | SecurityException ex) { logger.log(Level.SEVERE, "Failed to create context", ex); } @@ -267,8 +261,7 @@ public AudioRenderer newAudioRenderer(AppSettings settings) { efx = newObject("com.jme3.audio.joal.JoalEFX"); } else { throw new UnsupportedOperationException( - "Unrecognizable audio renderer specified: " - + settings.getAudioRenderer()); + "Unrecognizable audio renderer specified: " + settings.getAudioRenderer()); } if (al == null || alc == null || efx == null) { diff --git a/jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java b/jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java index a25e934ec7..a26871a0ef 100644 --- a/jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java +++ b/jme3-desktop/src/main/java/jme3tools/converters/ImageToAwt.java @@ -44,14 +44,15 @@ public class ImageToAwt { - private static final EnumMap params - = new EnumMap(Format.class); + private static final EnumMap params = new EnumMap( + Format.class); private static class DecodeParams { final int bpp, am, rm, gm, bm, as, rs, gs, bs, im, is; - public DecodeParams(int bpp, int am, int rm, int gm, int bm, int as, int rs, int gs, int bs, int im, int is) { + public DecodeParams(int bpp, int am, int rm, int gm, int bm, int as, int rs, int gs, int bs, int im, + int is) { this.bpp = bpp; this.am = am; this.rm = rm; @@ -65,20 +66,20 @@ public DecodeParams(int bpp, int am, int rm, int gm, int bm, int as, int rs, int this.is = is; } - public DecodeParams(int bpp, int rm, int rs, int im, int is, boolean alpha){ + public DecodeParams(int bpp, int rm, int rs, int im, int is, boolean alpha) { this.bpp = bpp; - if (alpha){ + if (alpha) { this.am = rm; this.as = rs; this.rm = 0; this.rs = 0; - }else{ + } else { this.rm = rm; this.rs = rs; this.am = 0; this.as = 0; } - + this.gm = 0; this.bm = 0; this.gs = 0; @@ -87,12 +88,19 @@ public DecodeParams(int bpp, int rm, int rs, int im, int is, boolean alpha){ this.is = is; } - /* - * public DecodeParams(int bpp, int rm, int rs, int im, int is){ this(bpp, rm, rs, im, is, false); } - */ + @SuppressWarnings("unused") + public DecodeParams(int bpp, int rm, int rs, int im, int is) { + this(bpp, rm, rs, im, is, false); + } + } static { + /* + * Masks and shift operations. "m" stands for mask and "s" for shift. After that the mask-/shift- + * pattern is shown by "x" for used byte, "_" for unused byte or a number to mark a specific bit. "m4" + * and "s4" are for two byte nibble mask and shift. + */ final int mx___ = 0xff000000; final int m_x__ = 0x00ff0000; final int m__x_ = 0x0000ff00; @@ -121,68 +129,59 @@ public DecodeParams(int bpp, int rm, int rs, int im, int is, boolean alpha){ @SuppressWarnings("unused") final int s4___x = 0; - final int m5___ = 0xf800; - final int m_5__ = 0x07c0; - final int m__5_ = 0x003e; - final int m___1 = 0x0001; + final int m5___ = 0xf800; + final int m_5__ = 0x07c0; + final int m__5_ = 0x003e; + final int m___1 = 0x0001; - final int s5___ = 11; - final int s_5__ = 6; - final int s__5_ = 1; - final int s___1 = 0; + final int s5___ = 11; + final int s_5__ = 6; + final int s__5_ = 1; + final int s___1 = 0; - final int m5__ = 0xf800; - final int m_6_ = 0x07e0; - final int m__5 = 0x001f; + final int m5__ = 0xf800; + final int m_6_ = 0x07e0; + final int m__5 = 0x001f; - final int s5__ = 11; - final int s_6_ = 5; - final int s__5 = 0; + final int s5__ = 11; + final int s_6_ = 5; + final int s__5 = 0; - final int mxx__ = 0xffff0000; - final int sxx__ = 32; - final int m__xx = 0x0000ffff; - final int s__xx = 0; + final int mxx__ = 0xffff0000; + final int sxx__ = 32; + final int m__xx = 0x0000ffff; + final int s__xx = 0; // Note: compressed, depth, and floating-point formats are not included here. - - params.put(Format.ABGR8, new DecodeParams(4, mx___, m___x, m__x_, m_x__, - sx___, s___x, s__x_, s_x__, - mxxxx, sxxxx)); - - params.put(Format.Alpha8, new DecodeParams(1, mxxxx, sxxxx, mxxxx, sxxxx, true)); - params.put(Format.BGR8, new DecodeParams(3, 0, m___x, m__x_, m_x__, - 0, s___x, s__x_, s_x__, - mxxxx, sxxxx)); - - params.put(Format.Luminance8, new DecodeParams(1, mxxxx, sxxxx, mxxxx, sxxxx, false)); + + params.put(Format.ABGR8, + new DecodeParams(4, mx___, m___x, m__x_, m_x__, sx___, s___x, s__x_, s_x__, mxxxx, sxxxx)); + + params.put(Format.Alpha8, new DecodeParams(1, mxxxx, sxxxx, mxxxx, sxxxx, true)); + params.put(Format.BGR8, + new DecodeParams(3, 0, m___x, m__x_, m_x__, 0, s___x, s__x_, s_x__, mxxxx, sxxxx)); + + params.put(Format.Luminance8, new DecodeParams(1, mxxxx, sxxxx, mxxxx, sxxxx, false)); params.put(Format.Luminance16F, new DecodeParams(2, mxxxx, sxxxx, mxxxx, sxxxx, false)); - params.put(Format.Luminance16FAlpha16F, new DecodeParams(4, m__xx, mxx__, 0, 0, - s__xx, sxx__, 0, 0, - mxxxx, sxxxx)); + params.put(Format.Luminance16FAlpha16F, + new DecodeParams(4, m__xx, mxx__, 0, 0, s__xx, sxx__, 0, 0, mxxxx, sxxxx)); params.put(Format.Luminance32F, new DecodeParams(4, mxxxx, sxxxx, mxxxx, sxxxx, false)); - params.put(Format.Luminance8, new DecodeParams(1, mxxxx, sxxxx, mxxxx, sxxxx, false)); - params.put(Format.RGB5A1, new DecodeParams(2, m___1, m5___, m_5__, m__5_, - s___1, s5___, s_5__, s__5_, - mxxxx, sxxxx)); - params.put(Format.RGB565, new DecodeParams(2, 0, m5__ , m_6_ , m__5, - 0, s5__ , s_6_ , s__5, - mxxxx, sxxxx)); - params.put(Format.RGB8, new DecodeParams(3, 0, m_x__, m__x_, m___x, - 0, s_x__, s__x_, s___x, - mxxxx, sxxxx)); - params.put(Format.RGBA8, new DecodeParams(4, m___x, mx___, m_x__, m__x_, - s___x, sx___, s_x__, s__x_, - mxxxx, sxxxx)); - params.put(Format.BGRA8, new DecodeParams(4, m___x, m__x_, m_x__, mx___, - s___x, s__x_, s_x__, sx___, - mxxxx, sxxxx)); - - params.put(Format.ARGB8, new DecodeParams(4, mx___, m_x__, m__x_, m___x, - sx___, s_x__, s__x_, s___x, - mxxxx, sxxxx)); - + params.put(Format.Luminance8, new DecodeParams(1, mxxxx, sxxxx, mxxxx, sxxxx, false)); + params.put(Format.RGB5A1, + new DecodeParams(2, m___1, m5___, m_5__, m__5_, s___1, s5___, s_5__, s__5_, mxxxx, sxxxx)); + params.put(Format.RGB565, + new DecodeParams(2, 0, m5__, m_6_, m__5, 0, s5__, s_6_, s__5, mxxxx, sxxxx)); + params.put(Format.RGB8, + new DecodeParams(3, 0, m_x__, m__x_, m___x, 0, s_x__, s__x_, s___x, mxxxx, sxxxx)); + params.put(Format.RGBA8, + new DecodeParams(4, m___x, mx___, m_x__, m__x_, s___x, sx___, s_x__, s__x_, mxxxx, sxxxx)); + params.put(Format.BGRA8, + new DecodeParams(4, m___x, m__x_, m_x__, mx___, s___x, s__x_, s_x__, sx___, mxxxx, sxxxx)); + + params.put(Format.ARGB8, + new DecodeParams(4, mx___, m_x__, m__x_, m___x, sx___, s_x__, s__x_, s___x, mxxxx, sxxxx)); + } /** @@ -191,25 +190,25 @@ public DecodeParams(int bpp, int rm, int rs, int im, int is, boolean alpha){ private ImageToAwt() { } - private static int Ix(int x, int y, int w){ + private static int Ix(int x, int y, int w) { return y * w + x; } - private static int readPixel(ByteBuffer buf, int idx, int bpp){ + private static int readPixel(ByteBuffer buf, int idx, int bpp) { buf.position(idx); int original = buf.get() & 0xff; - while ((--bpp) > 0){ + while ((--bpp) > 0) { original = (original << 8) | (buf.get() & 0xff); } return original; } - private static void writePixel(ByteBuffer buf, int idx, int pixel, int bpp){ + private static void writePixel(ByteBuffer buf, int idx, int pixel, int bpp) { buf.position(idx); - while ((--bpp) >= 0){ -// pixel = pixel >> 8; + while ((--bpp) >= 0) { + // pixel = pixel >> 8; byte bt = (byte) ((pixel >> (bpp * 8)) & 0xff); -// buf.put( (byte) (pixel & 0xff) ); + // buf.put( (byte) (pixel & 0xff) ); buf.put(bt); } } @@ -217,9 +216,12 @@ private static void writePixel(ByteBuffer buf, int idx, int pixel, int bpp){ /** * Convert an AWT image to jME image. XXX not implemented yet! * - * @param image the input image (not null, unaffected) - * @param format the data format - * @param buf the output buffer (not null, modified) + * @param image + * the input image (not null, unaffected) + * @param format + * the data format + * @param buf + * the output buffer (not null, modified) */ public static void convert(BufferedImage image, Format format, ByteBuffer buf) { DecodeParams p = params.get(format); @@ -238,8 +240,8 @@ public static void convert(BufferedImage image, Format format, ByteBuffer buf) { int reductionB = 8 - Integer.bitCount(p.bm); int initialPos = buf.position(); - for (int y = 0; y < height; y++){ - for (int x = 0; x < width; x++){ + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { // Get ARGB int argb = image.getRGB(x, y); @@ -256,12 +258,11 @@ public static void convert(BufferedImage image, Format format, ByteBuffer buf) { b = b & 0xff; // Set full alpha if target image has no alpha - if (!alpha) - a = 0xff; + if (!alpha) a = 0xff; // Convert color to luminance if target // image is in luminance format - if (luminance){ + if (luminance) { // convert RGB to luminance } @@ -271,7 +272,7 @@ public static void convert(BufferedImage image, Format format, ByteBuffer buf) { r = r >> reductionR; g = g >> reductionG; b = b >> reductionB; - + // Put components into appropriate positions a = (a << p.as) & p.am; r = (r << p.rs) & p.rm; @@ -279,7 +280,7 @@ public static void convert(BufferedImage image, Format format, ByteBuffer buf) { b = (b << p.bs) & p.bm; int outputPixel = ((a | r | g | b) << p.is) & p.im; - int i = initialPos + (Ix(x,y,width) * p.bpp); + int i = initialPos + (Ix(x, y, width) * p.bpp); writePixel(buf, i, outputPixel, p.bpp); } } @@ -287,18 +288,18 @@ public static void convert(BufferedImage image, Format format, ByteBuffer buf) { private static final double LOG2 = Math.log(2); - public static void createData(Image image, boolean mipmaps){ + public static void createData(Image image, boolean mipmaps) { int bpp = image.getFormat().getBitsPerPixel(); int w = image.getWidth(); int h = image.getHeight(); - if (!mipmaps){ - image.setData(BufferUtils.createByteBuffer(w*h*bpp/8)); + if (!mipmaps) { + image.setData(BufferUtils.createByteBuffer(w * h * bpp / 8)); return; } int expectedMipmaps = 1 + (int) Math.ceil(Math.log(Math.max(h, w)) / LOG2); int[] mipMapSizes = new int[expectedMipmaps]; int total = 0; - for (int i = 0; i < mipMapSizes.length; i++){ + for (int i = 0; i < mipMapSizes.length; i++) { int size = (w * h * bpp) / 8; total += size; mipMapSizes[i] = size; @@ -310,25 +311,24 @@ public static void createData(Image image, boolean mipmaps){ } /** - * Convert the image from the given format to the output format. - * It is assumed that both images have buffers with the appropriate - * number of elements and that both have the same dimensions. + * Convert the image from the given format to the output format. It is assumed that both images have + * buffers with the appropriate number of elements and that both have the same dimensions. * - * @param input the input image (not null, unaffected) - * @param output the output image (not null, modified) + * @param input + * the input image (not null, unaffected) + * @param output + * the output image (not null, modified) */ - public static void convert(Image input, Image output){ - DecodeParams inParams = params.get(input.getFormat()); + public static void convert(Image input, Image output) { + DecodeParams inParams = params.get(input.getFormat()); DecodeParams outParams = params.get(output.getFormat()); - if (inParams == null || outParams == null) - throw new UnsupportedOperationException(); + if (inParams == null || outParams == null) throw new UnsupportedOperationException(); - int width = input.getWidth(); + int width = input.getWidth(); int height = input.getHeight(); - if (width != output.getWidth() || height != output.getHeight()) - throw new IllegalArgumentException(); + if (width != output.getWidth() || height != output.getHeight()) throw new IllegalArgumentException(); ByteBuffer inData = input.getData(0); @@ -348,11 +348,11 @@ public static void convert(Image input, Image output){ int expansionB = 8 - Integer.bitCount(inParams.bm); int inputPixel; - for (int y = 0; y < height; y++){ - for (int x = 0; x < width; x++){ + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { int i = Ix(x, y, width) * inParams.bpp; inputPixel = (readPixel(inData, i, inParams.bpp) & inParams.im) >> inParams.is; - + int a = (inputPixel & inParams.am) >> inParams.as; int r = (inputPixel & inParams.rm) >> inParams.rs; int g = (inputPixel & inParams.gm) >> inParams.gs; @@ -368,30 +368,27 @@ public static void convert(Image input, Image output){ g = g << expansionG; b = b << expansionB; - if (inLum) - b = g = r; + if (inLum) b = g = r; - if (!inAlpha) - a = 0xff; + if (!inAlpha) a = 0xff; -// int argb = (a << 24) | (r << 16) | (g << 8) | b; -// out.setRGB(x, y, argb); + // int argb = (a << 24) | (r << 16) | (g << 8) | b; + // out.setRGB(x, y, argb); } } } - public static BufferedImage convert(Image image, boolean do16bit, boolean fullAlpha, int mipLevel){ + public static BufferedImage convert(Image image, boolean do16bit, boolean fullAlpha, int mipLevel) { Format format = image.getFormat(); DecodeParams p = params.get(format); - if (p == null) - throw new UnsupportedOperationException(); + if (p == null) throw new UnsupportedOperationException(); int width = image.getWidth(); int height = image.getHeight(); int level = mipLevel; - while (--level >= 0){ - width /= 2; + while (--level >= 0) { + width /= 2; height /= 2; } @@ -403,44 +400,38 @@ public static BufferedImage convert(Image image, boolean do16bit, boolean fullAl boolean alpha = false; boolean luminance = false; boolean rgb = false; - if (p.am != 0) - alpha = true; + if (p.am != 0) alpha = true; - if (p.rm != 0 && p.gm == 0 && p.bm == 0) - luminance = true; - else if (p.rm != 0 && p.gm != 0 && p.bm != 0) - rgb = true; + if (p.rm != 0 && p.gm == 0 && p.bm == 0) luminance = true; + else if (p.rm != 0 && p.gm != 0 && p.bm != 0) rgb = true; // alpha OR luminance but not both - if ( (alpha && !rgb && !luminance) || (luminance && !alpha && !rgb) ){ + if ((alpha && !rgb && !luminance) || (luminance && !alpha && !rgb)) { out = new BufferedImage(width, height, BufferedImage.TYPE_BYTE_GRAY); - }else if ( (rgb && alpha) || (luminance && alpha) ){ - if (do16bit){ - if (fullAlpha){ + } else if ((rgb && alpha) || (luminance && alpha)) { + if (do16bit) { + if (fullAlpha) { ColorModel model = AWTLoader.AWT_RGBA4444; WritableRaster raster = model.createCompatibleWritableRaster(width, width); out = new BufferedImage(model, raster, false, null); - }else{ + } else { // RGB5_A1 ColorSpace cs = ColorSpace.getInstance(ColorSpace.CS_sRGB); - int[] nBits = {5, 5, 5, 1}; - int[] bOffs = {0, 1, 2, 3}; + int[] nBits = { 5, 5, 5, 1 }; + int[] bOffs = { 0, 1, 2, 3 }; ColorModel colorModel = new ComponentColorModel(cs, nBits, true, false, - Transparency.BITMASK, - DataBuffer.TYPE_BYTE); - WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, - width, height, - width*2, 2, - bOffs, null); + Transparency.BITMASK, DataBuffer.TYPE_BYTE); + WritableRaster raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, width, + height, width * 2, 2, bOffs, null); out = new BufferedImage(colorModel, raster, false, null); } - }else{ + } else { out = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); } - }else{ - if (do16bit){ + } else { + if (do16bit) { out = new BufferedImage(width, height, BufferedImage.TYPE_USHORT_565_RGB); - }else{ + } else { out = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); } } @@ -449,20 +440,20 @@ else if (p.rm != 0 && p.gm != 0 && p.bm != 0) int expansionR = 8 - Integer.bitCount(p.rm); int expansionG = 8 - Integer.bitCount(p.gm); int expansionB = 8 - Integer.bitCount(p.bm); - - if (expansionR < 0){ + + if (expansionR < 0) { expansionR = 0; } - + int mipPos = 0; - for (int i = 0; i < mipLevel; i++){ + for (int i = 0; i < mipLevel; i++) { mipPos += image.getMipMapSizes()[i]; } int inputPixel; - for (int y = 0; y < height; y++){ - for (int x = 0; x < width; x++){ - int i = mipPos + (Ix(x,y,width) * p.bpp); - inputPixel = (readPixel(buf,i,p.bpp) & p.im) >> p.is; + for (int y = 0; y < height; y++) { + for (int x = 0; x < width; x++) { + int i = mipPos + (Ix(x, y, width) * p.bpp); + inputPixel = (readPixel(buf, i, p.bpp) & p.im) >> p.is; int a = (inputPixel & p.am) >> p.as; int r = (inputPixel & p.rm) >> p.rs; int g = (inputPixel & p.gm) >> p.gs; @@ -477,12 +468,10 @@ else if (p.rm != 0 && p.gm != 0 && p.bm != 0) r = r << expansionR; g = g << expansionG; b = b << expansionB; - - if (luminance) - b = g = r; - if (!alpha) - a = 0xff; + if (luminance) b = g = r; + + if (!alpha) a = 0xff; int argb = (a << 24) | (r << 16) | (g << 8) | b; out.setRGB(x, y, argb); diff --git a/jme3-desktop/src/main/java/jme3tools/converters/MipMapGenerator.java b/jme3-desktop/src/main/java/jme3tools/converters/MipMapGenerator.java index b887331e54..a3181c4872 100644 --- a/jme3-desktop/src/main/java/jme3tools/converters/MipMapGenerator.java +++ b/jme3-desktop/src/main/java/jme3tools/converters/MipMapGenerator.java @@ -51,7 +51,7 @@ private MipMapGenerator() { } private static BufferedImage scaleDown(BufferedImage sourceImage, int targetWidth, int targetHeight) { - int sourceWidth = sourceImage.getWidth(); + int sourceWidth = sourceImage.getWidth(); int sourceHeight = sourceImage.getHeight(); BufferedImage targetImage = new BufferedImage(targetWidth, targetHeight, sourceImage.getType()); @@ -64,7 +64,7 @@ private static BufferedImage scaleDown(BufferedImage sourceImage, int targetWidt return targetImage; } - public static void resizeToPowerOf2(Image image){ + public static void resizeToPowerOf2(Image image) { BufferedImage original = ImageToAwt.convert(image, false, true, 0); int potWidth = FastMath.nearestPowerOfTwo(image.getWidth()); int potHeight = FastMath.nearestPowerOfTwo(image.getHeight()); @@ -83,30 +83,27 @@ public static void resizeToPowerOf2(Image image){ image.setMipMapSizes(null); } - public static void generateMipMaps(Image image){ + public static void generateMipMaps(Image image) { BufferedImage original = ImageToAwt.convert(image, false, true, 0); int width = original.getWidth(); int height = original.getHeight(); - // int level = 0; BufferedImage current = original; AWTLoader loader = new AWTLoader(); ArrayList output = new ArrayList<>(); int totalSize = 0; Format format = null; - - while (height >= 1 || width >= 1){ + + while (height >= 1 || width >= 1) { Image converted = loader.load(current, false); format = converted.getFormat(); output.add(converted.getData(0)); totalSize += converted.getData(0).capacity(); - if(height == 1 || width == 1) { - break; + if (height == 1 || width == 1) { + break; } - // level++; - height /= 2; width /= 2; @@ -115,7 +112,7 @@ public static void generateMipMaps(Image image){ ByteBuffer combinedData = BufferUtils.createByteBuffer(totalSize); int[] mipSizes = new int[output.size()]; - for (int i = 0; i < output.size(); i++){ + for (int i = 0; i < output.size(); i++) { ByteBuffer data = output.get(i); data.clear(); combinedData.put(data);