diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/ColorController.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/ColorController.java index 3bbbde820..6b9d6a0ca 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/ColorController.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/ColorController.java @@ -9,7 +9,6 @@ import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; import javax.swing.JColorChooser; import javax.swing.JComponent; -import javax.swing.JFrame; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -31,13 +30,13 @@ public class ColorController { int w3 = getWidth() / 3; int h3 = getHeight() / 3; g.setColor(ColorController.this.getBackground()); - g.fillRect(w3, h3, 2*w3, 2*h3); + g.fillRect(w3, h3, 2 * w3, 2 * h3); g.setColor(Color.BLACK); - g.drawRect(w3, h3, 2*w3, 2*h3); + g.drawRect(w3, h3, 2 * w3, 2 * h3); g.setColor(ColorController.this.getForeground()); - g.fillRect(0, 0, 2*w3, 2*h3); + g.fillRect(0, 0, 2 * w3, 2 * h3); g.setColor(Color.BLACK); - g.drawRect(0, 0, 2*w3, 2*h3); + g.drawRect(0, 0, 2 * w3, 2 * h3); } }; display.addMouseListener(new MouseAdapter() { @@ -46,9 +45,9 @@ public class ColorController { public void mouseReleased(MouseEvent e) { int w3 = display.getWidth() / 3; int h3 = display.getHeight() / 3; - if(new Rectangle(0, 0, 2*w3, 2*h3).contains(e.getPoint())) { + if (new Rectangle(0, 0, 2 * w3, 2 * h3).contains(e.getPoint())) { chooseColor(foreground); - } else if(new Rectangle(w3, h3, 2*w3, 2*h3).contains(e.getPoint())) { + } else if (new Rectangle(w3, h3, 2 * w3, 2 * h3).contains(e.getPoint())) { chooseColor(background); } } @@ -87,8 +86,8 @@ public class ColorController { String title = source == foreground ? "Foreground Color" : "Background Color"; Frame parent = JOptionPane.getFrameForComponent(COMPONENT); Color choice = JColorChooser.showDialog(parent, title, initial); - if(choice != null) { - if(source == foreground) { + if (choice != null) { + if (source == foreground) { setForeground(choice); } else { setBackground(choice); diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/EditorToolTarget.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/EditorToolTarget.java index 9303ed7d3..8594b4ecb 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/EditorToolTarget.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/EditorToolTarget.java @@ -9,7 +9,9 @@ public interface EditorToolTarget { JComponent getImageCanvas(); float getScaleX(); + float getScaleY(); + BufferedImage getCurrentImage(); public void setForeground(Color picked); diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/IOModule.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/IOModule.java index e50c4e64d..dd3e535f9 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/IOModule.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/IOModule.java @@ -35,7 +35,7 @@ public class IOModule { } public BufferedImage load(FileObject file) throws IOException, URISyntaxException { - if(file.getExt().equalsIgnoreCase("tga")) { + if (file.getExt().equalsIgnoreCase("tga")) { ImageInputStream in = new FileImageInputStream(new File(file.getURL().toURI())); TGAImageReaderSpi spi = new TGAImageReaderSpi(); TGAImageReader rea = new TGAImageReader(spi); diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/ImageEditorComponent.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/ImageEditorComponent.java index 1d29d7a9e..13449a4b9 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/ImageEditorComponent.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/ImageEditorComponent.java @@ -39,6 +39,7 @@ import com.jme3.gde.textureeditor.filters.GrayscaleFilter; import com.jme3.gde.textureeditor.filters.MirrorFilter; import com.jme3.gde.textureeditor.filters.ResizeFilter; import com.jme3.gde.textureeditor.filters.RotateLeftFilter; +import com.jme3.gde.textureeditor.filters.SphereMappedFilter; import com.jme3.gde.textureeditor.tools.ColorPicker; import com.jme3.gde.textureeditor.tools.CropTool; import java.io.IOException; @@ -169,6 +170,7 @@ public class ImageEditorComponent implements EditorToolTarget { scroller.setViewportView(imageContainer); } + @SuppressWarnings("unchecked") private void createToolBar() { final JButton zoomIn = new JButton(Icon("zoom-in-2.png")); final JButton zoomOut = new JButton(Icon("zoom-out-2.png")); @@ -259,8 +261,8 @@ public class ImageEditorComponent implements EditorToolTarget { builder.addFileFilter(FileFilters.TGA); builder.addFileFilter(FileFilters.PNG); - JFileChooser fc= builder.createFileChooser(); - fc.setFileSelectionMode(fc.SAVE_DIALOG); + JFileChooser fc = builder.createFileChooser(); + fc.setFileSelectionMode(JFileChooser.SAVE_DIALOG); fc.setAcceptAllFileFilterUsed(false); int a = fc.showOpenDialog(COMPONENT); @@ -275,7 +277,7 @@ public class ImageEditorComponent implements EditorToolTarget { } else if (name.endsWith(".bmp")) { type = "bmp"; } else if (name.endsWith(".tga")) { - type ="tga"; + type = "tga"; } else { ExtensionFileFilter filter = (ExtensionFileFilter) fc.getFileFilter(); file = new File(file.getParentFile(), file.getName() + filter.getExtension()); @@ -351,6 +353,7 @@ public class ImageEditorComponent implements EditorToolTarget { final JMenuItem gray = filters.add("Grayscale"); final JMenuItem bright = filters.add("Brightness"); + final JMenuItem spheremap = filters.add("SphereMapped"); ActionListener al = new ActionListener() { @@ -366,11 +369,13 @@ public class ImageEditorComponent implements EditorToolTarget { spawnEditor(GrayscaleFilter.create().filter(editedImage)); } else if (source == bright) { spawnEditor(BrightFilter.create().filter(editedImage, ImageEditorComponent.this)); + } else if (source == spheremap) { + spawnEditor(SphereMappedFilter.create().filter(editedImage)); } } }; - for (AbstractButton b : Arrays.asList(bumpSoft, bumpMedium, bumpStrong, gray, bright)) { + for (AbstractButton b : Arrays.asList(bumpSoft, bumpMedium, bumpStrong, gray, bright, spheremap)) { b.addActionListener(al); } } diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/JmeTextureDataObject.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/JmeTextureDataObject.java index 4dc118c69..9988288f5 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/JmeTextureDataObject.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/JmeTextureDataObject.java @@ -10,7 +10,6 @@ import org.openide.loaders.DataNode; import org.openide.loaders.DataObjectExistsException; import org.openide.loaders.MultiDataObject; import org.openide.loaders.MultiFileLoader; -import org.openide.nodes.CookieSet; import org.openide.nodes.Node; import org.openide.nodes.Children; import org.openide.util.Lookup; diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BrightFilter.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BrightFilter.java index 27780a6d8..4673239a9 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BrightFilter.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BrightFilter.java @@ -20,7 +20,6 @@ public class BrightFilter implements BufferedImageFilter { public static BrightFilter create() { return new BrightFilter(); } - private final int[] lookup; protected BrightFilter() { @@ -39,7 +38,7 @@ public class BrightFilter implements BufferedImageFilter { slider.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent e) { - if(!slider.getValueIsAdjusting()) { + if (!slider.getValueIsAdjusting()) { label.setIcon(new ImageIcon(doFilter(sourceIcon, slider.getValue() / 100f))); } } @@ -49,7 +48,8 @@ public class BrightFilter implements BufferedImageFilter { sliderContainer.setBorder(BorderFactory.createTitledBorder("Brightness value")); sliderContainer.add(slider); JPanel labelContainer = new JPanel(new GridBagLayout()); - GridBagConstraints lim = new GridBagConstraints(); lim.gridx = lim.gridy = 0; + GridBagConstraints lim = new GridBagConstraints(); + lim.gridx = lim.gridy = 0; labelContainer.add(label, lim); labelContainer.setBorder(BorderFactory.createTitledBorder("Preview")); JPanel container = new JPanel(new BorderLayout()); @@ -57,7 +57,7 @@ public class BrightFilter implements BufferedImageFilter { container.add(sliderContainer, BorderLayout.SOUTH); int choice = JOptionPane.showConfirmDialog(parent.getComponent(), container, "Brightness Filter", JOptionPane.OK_CANCEL_OPTION, JOptionPane.PLAIN_MESSAGE, null); - if(choice == JOptionPane.OK_OPTION) { + if (choice == JOptionPane.OK_OPTION) { return doFilter(source, slider.getValue() / 100f); } else { return null; diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BufferedImageFilter.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BufferedImageFilter.java index ce106d1cd..a9ee6baec 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BufferedImageFilter.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BufferedImageFilter.java @@ -4,5 +4,5 @@ import java.awt.image.BufferedImage; public interface BufferedImageFilter { - BufferedImage filter(BufferedImage source, Object...args); + BufferedImage filter(BufferedImage source, Object... args); } diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BumpMapFilter.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BumpMapFilter.java index f9a1e7768..d7f73b3af 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BumpMapFilter.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/BumpMapFilter.java @@ -3,10 +3,11 @@ package com.jme3.gde.textureeditor.filters; import java.awt.color.ColorSpace; import java.awt.image.BufferedImage; import java.awt.image.ColorConvertOp; -import com.jme3.gde.textureeditor.ImageEditorComponent; public class BumpMapFilter implements BufferedImageFilter { + private static class Vec3f { + float x, y, z; void divideLocal(float d) { @@ -29,8 +30,8 @@ public class BumpMapFilter implements BufferedImageFilter { BufferedImage bumpMap = new BufferedImage(sourceImage.getWidth(), sourceImage.getHeight(), BufferedImage.TYPE_INT_ARGB); ColorConvertOp gscale = new ColorConvertOp(ColorSpace.getInstance(ColorSpace.CS_GRAY), null); gscale.filter(sourceImage, heightMap); - for(int x = 0; x < bumpMap.getWidth(); x++) { - for(int y = 0; y < bumpMap.getHeight(); y++) { + for (int x = 0; x < bumpMap.getWidth(); x++) { + for (int y = 0; y < bumpMap.getHeight(); y++) { bumpMap.setRGB(x, y, generateBumpPixel(heightMap, x, y, a)); } } @@ -41,13 +42,13 @@ public class BumpMapFilter implements BufferedImageFilter { Vec3f S = new Vec3f(); Vec3f T = new Vec3f(); Vec3f N = new Vec3f(); - Vec3f ST = new Vec3f(); + S.x = 1; S.y = 0; S.z = a * getHeight(image, x + 1, y) - a * getHeight(image, x - 1, y); T.x = 0; T.y = 1; - T.z = a * getHeight(image, x, y + 1) - a * getHeight(image, x, y - 1); + T.z = a * getHeight(image, x, y + 1) - a * getHeight(image, x, y - 1); float den = (float) Math.sqrt(S.z * S.z + T.z * T.z + 1); N.x = -S.z; @@ -58,14 +59,14 @@ public class BumpMapFilter implements BufferedImageFilter { } private float getHeight(BufferedImage image, int x, int y) { - if(x < 0) { + if (x < 0) { x = 0; - } else if(x >= image.getWidth()) { + } else if (x >= image.getWidth()) { x = image.getWidth() - 1; } - if(y < 0) { + if (y < 0) { y = 0; - } else if(y >= image.getHeight()) { + } else if (y >= image.getHeight()) { y = image.getHeight() - 1; } return image.getRGB(x, y) & 0xff; diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/MirrorFilter.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/MirrorFilter.java index a7fef7388..5ebc23311 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/MirrorFilter.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/MirrorFilter.java @@ -5,6 +5,7 @@ import java.awt.image.AffineTransformOp; import java.awt.image.BufferedImage; public class MirrorFilter implements BufferedImageFilter { + public static final Integer X = 0; public static final Integer Y = 1; @@ -12,14 +13,15 @@ public class MirrorFilter implements BufferedImageFilter { return new MirrorFilter(); } - protected MirrorFilter() {} + protected MirrorFilter() { + } public BufferedImage filter(BufferedImage source, Object... args) { - if(args[0] == Y) { + if (args[0] == Y) { AffineTransform op = AffineTransform.getScaleInstance(1, -1); op.translate(0, -source.getHeight(null)); return new AffineTransformOp(op, null).filter(source, null); - } else if(args[0] == X) { + } else if (args[0] == X) { AffineTransform op = AffineTransform.getScaleInstance(-1, 1); op.translate(-source.getWidth(null), 0); return new AffineTransformOp(op, null).filter(source, null); diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/ResizeFilter.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/ResizeFilter.java index 932e3bea4..3ae2a2bc8 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/ResizeFilter.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/ResizeFilter.java @@ -9,7 +9,8 @@ public class ResizeFilter implements BufferedImageFilter { return new ResizeFilter(); } - protected ResizeFilter() {} + protected ResizeFilter() { + } public BufferedImage filter(BufferedImage source, Object... args) { int newWidth = (Integer) args[0]; diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/RotateLeftFilter.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/RotateLeftFilter.java index 67c954619..89fb4b842 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/RotateLeftFilter.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/RotateLeftFilter.java @@ -11,17 +11,18 @@ public class RotateLeftFilter implements BufferedImageFilter { return new RotateLeftFilter(); } - protected RotateLeftFilter() {} + protected RotateLeftFilter() { + } public BufferedImage filter(BufferedImage source, Object... args) { int type = source.getType(); - if(type == BufferedImage.TYPE_CUSTOM) { + if (type == BufferedImage.TYPE_CUSTOM) { type = BufferedImage.TYPE_INT_ARGB; } // BufferedImage dest = new BufferedImage(source.getHeight(), source.getWidth(), type); AffineTransform rot = AffineTransform.getRotateInstance( - Math.PI / 2, source.getWidth() / 2, - source.getHeight() / 2); + Math.PI / 2, source.getWidth() / 2, + source.getHeight() / 2); Point2D p0 = new Point2D.Double(); Point2D p1 = rot.transform(p0, null); double dy = p1.getY(); diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/SphereMappedFilter.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/SphereMappedFilter.java new file mode 100644 index 000000000..2662fbdf8 --- /dev/null +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/filters/SphereMappedFilter.java @@ -0,0 +1,56 @@ +package com.jme3.gde.textureeditor.filters; + +import java.awt.image.BufferedImage; + +/** + * Texture Mapper + * + * This class will take a texture and will map it to a spherical + * adaptation so no, at least no visible, distortion is apparent. + * + * @author MadJack + * @created 06/18/2011 + */ +public class SphereMappedFilter implements BufferedImageFilter { + + public static SphereMappedFilter create() { + return new SphereMappedFilter(); + } + + protected SphereMappedFilter() { + } + + /* + * The following algorithm is heavily based on + * Paul Bourke's pseudo code available at: + * http://paulbourke.net/texture_colour/texturemap/ + * + */ + @Override + public BufferedImage filter(BufferedImage sourceImg, Object... args) { + + BufferedImage imageOut = new BufferedImage(sourceImg.getWidth(), sourceImg.getHeight(), BufferedImage.TYPE_INT_ARGB); + + double theta, phi, phi2; + int i, i2, j; + + for (j = 0; j < sourceImg.getHeight(); j++) { + theta = Math.PI * (j - (sourceImg.getHeight() - 1) / 2.0f) / (sourceImg.getHeight() - 1); + for (i = 0; i < sourceImg.getWidth(); i++) { + phi = Math.PI * 2 * (i - sourceImg.getWidth() / 2.0f) / sourceImg.getWidth(); + phi2 = phi * Math.cos(theta); + i2 = (int) Math.round(phi2 * sourceImg.getWidth() / (Math.PI * 2) + sourceImg.getWidth() / 2); + + int newpixel = 0; + if (i2 < 0 || i2 > sourceImg.getWidth() - 1) { + /* Should not happen, make that a red pixel */ + newpixel = 100; + } else { + newpixel = sourceImg.getRGB(i2, j); + } + imageOut.setRGB(i, j, newpixel); + } + } + return imageOut; + } +} diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/tools/ColorPicker.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/tools/ColorPicker.java index b81b0d8f6..9a144e343 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/tools/ColorPicker.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/tools/ColorPicker.java @@ -16,7 +16,8 @@ public class ColorPicker extends MouseAdapter implements EditorTool { } private EditorToolTarget target; - protected ColorPicker() {} + protected ColorPicker() { + } public void install(EditorToolTarget t) { target = t; @@ -36,9 +37,9 @@ public class ColorPicker extends MouseAdapter implements EditorTool { p.x /= target.getScaleX(); p.y /= target.getScaleY(); Color picked = new Color(target.getCurrentImage().getRGB(p.x, p.y)); - if(SwingUtilities.isLeftMouseButton(e)) { + if (SwingUtilities.isLeftMouseButton(e)) { target.setForeground(picked); - } else if(SwingUtilities.isRightMouseButton(e)) { + } else if (SwingUtilities.isRightMouseButton(e)) { target.setBackground(picked); } } diff --git a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/tools/CropTool.java b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/tools/CropTool.java index e79928c94..0b9d5441c 100644 --- a/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/tools/CropTool.java +++ b/sdk/jme3-texture-editor/src/com/jme3/gde/textureeditor/tools/CropTool.java @@ -18,11 +18,12 @@ public class CropTool extends MouseInputAdapter implements EditorTool { return new CropTool(); } private EditorToolTarget target; - private Stroke stroke = new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0, new float[] { 4, 4 }, 0); + private Stroke stroke = new BasicStroke(1, BasicStroke.CAP_SQUARE, BasicStroke.JOIN_BEVEL, 0, new float[]{4, 4}, 0); private Rectangle track; private Point last; - protected CropTool() {} + protected CropTool() { + } public void install(EditorToolTarget t) { target = t; @@ -44,13 +45,13 @@ public class CropTool extends MouseInputAdapter implements EditorTool { @Override public void mouseReleased(MouseEvent e) { - int x = (int)(track.x / target.getScaleX()); - int y = (int)(track.y / target.getScaleY()); - int w = (int)(track.width / target.getScaleX()); - int h = (int)(track.height / target.getScaleY()); + int x = (int) (track.x / target.getScaleX()); + int y = (int) (track.y / target.getScaleY()); + int w = (int) (track.width / target.getScaleX()); + int h = (int) (track.height / target.getScaleY()); BufferedImage source = target.getCurrentImage(); int type = source.getType(); - if(type == BufferedImage.TYPE_CUSTOM) { + if (type == BufferedImage.TYPE_CUSTOM) { type = BufferedImage.TYPE_INT_ARGB; } BufferedImage dest = new BufferedImage(w, h, type); @@ -73,7 +74,7 @@ public class CropTool extends MouseInputAdapter implements EditorTool { } public void drawTrack(Graphics2D g, int width, int height, float scaleX, float scaleY) { - if(track != null) { + if (track != null) { g.setPaint(Color.GREEN); g.setStroke(stroke); g.draw(track);