SDK:
- add invert filter (thanks to @jmaasing) git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9756 75d07b2b-3a1a-0410-a2c5-0572b91ccdca
This commit is contained in:
parent
c31c7a406b
commit
1a2b56121b
@ -36,6 +36,7 @@ import org.openide.windows.TopComponent;
|
||||
import com.jme3.gde.textureeditor.filters.BrightFilter;
|
||||
import com.jme3.gde.textureeditor.filters.BumpMapFilter;
|
||||
import com.jme3.gde.textureeditor.filters.GrayscaleFilter;
|
||||
import com.jme3.gde.textureeditor.filters.InvertFilter;
|
||||
import com.jme3.gde.textureeditor.filters.MirrorFilter;
|
||||
import com.jme3.gde.textureeditor.filters.ResizeFilter;
|
||||
import com.jme3.gde.textureeditor.filters.RotateLeftFilter;
|
||||
@ -47,7 +48,6 @@ import org.openide.DialogDisplayer;
|
||||
import org.openide.NotifyDescriptor;
|
||||
import org.openide.NotifyDescriptor.Confirmation;
|
||||
import org.openide.NotifyDescriptor.Message;
|
||||
import org.openide.awt.UndoRedo;
|
||||
import org.openide.cookies.SaveCookie;
|
||||
import org.openide.filesystems.FileChooserBuilder;
|
||||
import org.openide.filesystems.FileObject;
|
||||
@ -369,6 +369,13 @@ public class ImageEditorComponent implements EditorToolTarget {
|
||||
final JMenuItem gray = filters.add("Grayscale");
|
||||
final JMenuItem bright = filters.add("Brightness");
|
||||
final JMenuItem spheremap = filters.add("SphereMapped");
|
||||
final JMenu invertMenu = new JMenu("Invert") ;
|
||||
final JMenuItem invertAll = invertMenu.add("All") ;
|
||||
final JMenuItem invertAlpha = invertMenu.add("Alpha") ;
|
||||
final JMenuItem invertRed = invertMenu.add("Red") ;
|
||||
final JMenuItem invertGreen = invertMenu.add("Green") ;
|
||||
final JMenuItem invertBlue = invertMenu.add("Blue") ;
|
||||
filters.add(invertMenu) ;
|
||||
|
||||
ActionListener al = new ActionListener() {
|
||||
|
||||
@ -386,8 +393,17 @@ public class ImageEditorComponent implements EditorToolTarget {
|
||||
spawnEditor(BrightFilter.create().filter(editedImage, ImageEditorComponent.this));
|
||||
} else if (source == spheremap) {
|
||||
spawnEditor(SphereMappedFilter.create().filter(editedImage));
|
||||
} else if (source == invertAll) {
|
||||
spawnEditor(new InvertFilter().filter(editedImage, InvertFilter.Channel.All));
|
||||
} else if (source == invertAlpha) {
|
||||
spawnEditor(new InvertFilter().filter(editedImage, InvertFilter.Channel.Alpha));
|
||||
} else if (source == invertRed) {
|
||||
spawnEditor(new InvertFilter().filter(editedImage, InvertFilter.Channel.Red));
|
||||
} else if (source == invertGreen) {
|
||||
spawnEditor(new InvertFilter().filter(editedImage, InvertFilter.Channel.Green));
|
||||
} else if (source == invertBlue) {
|
||||
spawnEditor(new InvertFilter().filter(editedImage, InvertFilter.Channel.Blue));
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -0,0 +1,73 @@
|
||||
package com.jme3.gde.textureeditor.filters;
|
||||
|
||||
import java.awt.image.BufferedImage;
|
||||
|
||||
/**
|
||||
* Invert channels in an image. It takes the ARGB color component and set it to 255 - value.
|
||||
*/
|
||||
public class InvertFilter implements BufferedImageFilter {
|
||||
|
||||
public enum Channel {
|
||||
|
||||
All, Red, Green, Blue, Alpha;
|
||||
}
|
||||
|
||||
public BufferedImage filter(BufferedImage source, Object... args) {
|
||||
final Channel channel;
|
||||
if ((args == null) || (args.length < 1) || (!(args[0] instanceof Channel))) {
|
||||
channel = Channel.All;
|
||||
} else {
|
||||
channel = (Channel) args[0];
|
||||
}
|
||||
BufferedImage result = new BufferedImage(
|
||||
source.getWidth(),
|
||||
source.getHeight(),
|
||||
BufferedImage.TYPE_INT_ARGB);
|
||||
final int height = source.getHeight();
|
||||
final int width = source.getWidth();
|
||||
for (int y = 0; y < height; y++) {
|
||||
for (int x = 0; x < width; x++) {
|
||||
final int sourceARGB = source.getRGB(x, y);
|
||||
final int targetARGB = invert(sourceARGB, channel);
|
||||
result.setRGB(x, y, targetARGB);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private int invert(final int sourceARGB, final Channel channel) {
|
||||
int a = (sourceARGB >> 24) & 0xff;
|
||||
int r = (sourceARGB >> 16) & 0xff;
|
||||
int g = (sourceARGB >> 8) & 0xff;
|
||||
int b = sourceARGB & 0xff;
|
||||
|
||||
switch (channel) {
|
||||
case Alpha:
|
||||
a = 255 - a;
|
||||
break;
|
||||
case Red:
|
||||
r = 255 - r;
|
||||
break;
|
||||
case Green:
|
||||
g = 255 - g;
|
||||
break;
|
||||
case Blue:
|
||||
b = 255 - b;
|
||||
break;
|
||||
default:
|
||||
a = 255 - a;
|
||||
r = 255 - r;
|
||||
g = 255 - g;
|
||||
b = 255 - b;
|
||||
}
|
||||
return packPixel(a, r, g, b);
|
||||
}
|
||||
|
||||
private int packPixel(int alpha, int red, int green, int blue) {
|
||||
final int argb = ((alpha << 24) & 0xff000000)
|
||||
| ((red << 16) & 0x00ff0000)
|
||||
| ((green << 8) & 0x0000ff00)
|
||||
| (blue & 0x000000ff);
|
||||
return argb;
|
||||
}
|
||||
}
|
Binary file not shown.
After Width: | Height: | Size: 228 B |
Loading…
x
Reference in New Issue
Block a user