下面列出了怎么用java.awt.image.LookupOp的API类实例代码及写法,或者点击链接到github查看源代码。
public static void main(String[] args) {
LookupTable tbl = createReverseTable();
LookupOp op = new LookupOp(tbl, null);
for (ImageType t : ImageType.values()) {
System.out.print(t);
BufferedImage src = createSourceImage(t);
BufferedImage dst = op.filter(src, null);
int rgb = dst.getRGB(0, 0);
System.out.printf(" Result: 0x%X ", rgb);
if (rgb != argbReverse) {
throw new RuntimeException("Test failed.");
}
System.out.println("Passed.");
}
}
private static BufferedImage getFilteredImage(URL url) {
BufferedImage image = Optional.ofNullable(url)
.map(u -> {
try {
return ImageIO.read(u);
} catch (IOException ex) {
return makeMissingImage();
}
}).orElseGet(MainPanel::makeMissingImage);
BufferedImage dest = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
byte[] b = new byte[256];
for (int i = 0; i < b.length; i++) {
b[i] = (byte) (i * .2f);
}
BufferedImageOp op = new LookupOp(new ByteLookupTable(0, b), null);
op.filter(image, dest);
return dest;
}
public static void main(String[] args) {
LookupTable tbl = createReverseTable();
LookupOp op = new LookupOp(tbl, null);
for (ImageType t : ImageType.values()) {
System.out.print(t);
BufferedImage src = createSourceImage(t);
BufferedImage dst = op.filter(src, null);
int rgb = dst.getRGB(0, 0);
System.out.printf(" Result: 0x%X ", rgb);
if (rgb != argbReverse) {
throw new RuntimeException("Test failed.");
}
System.out.println("Passed.");
}
}
public static BufferedImage getFilteredImage(URL url) {
BufferedImage image = Optional.ofNullable(url)
.map(u -> {
try {
return ImageIO.read(u);
} catch (IOException ex) {
return makeMissingImage();
}
}).orElseGet(ImageUtil::makeMissingImage);
BufferedImage dest = new BufferedImage(image.getWidth(), image.getHeight(), BufferedImage.TYPE_INT_RGB);
byte[] b = new byte[256];
IntStream.range(0, b.length).forEach(i -> b[i] = (byte) (i * .5));
BufferedImageOp op = new LookupOp(new ByteLookupTable(0, b), null);
op.filter(image, dest);
return dest;
}
public static void main(String[] args) {
LookupTable tbl = createReverseTable();
LookupOp op = new LookupOp(tbl, null);
for (ImageType t : ImageType.values()) {
System.out.print(t);
BufferedImage src = createSourceImage(t);
BufferedImage dst = op.filter(src, null);
int rgb = dst.getRGB(0, 0);
System.out.printf(" Result: 0x%X ", rgb);
if (rgb != argbReverse) {
throw new RuntimeException("Test failed.");
}
System.out.println("Passed.");
}
}
public static void main(String[] args) {
LookupTable tbl = createReverseTable();
LookupOp op = new LookupOp(tbl, null);
for (ImageType t : ImageType.values()) {
System.out.print(t);
BufferedImage src = createSourceImage(t);
BufferedImage dst = op.filter(src, null);
int rgb = dst.getRGB(0, 0);
System.out.printf(" Result: 0x%X ", rgb);
if (rgb != argbReverse) {
throw new RuntimeException("Test failed.");
}
System.out.println("Passed.");
}
}
public static void main(String[] args) {
byte[][] data = new byte[1][10];
ByteLookupTable lut = new ByteLookupTable(0, data);
RasterOp op = new LookupOp(lut, null);
int[] bandOffsets = {0};
Point location = new Point(0, 0);
DataBuffer db = new DataBufferByte(10 * 10);
SampleModel sm = new PixelInterleavedSampleModel(DataBuffer.TYPE_BYTE,
10, 10, 1, 10,
bandOffsets);
Raster src = Raster.createRaster(sm, db, location);
op.filter(src, null); // this used to result in NullPointerException
}
public static void main(String[] args) {
LookupTable tbl = createReverseTable();
LookupOp op = new LookupOp(tbl, null);
for (ImageType t : ImageType.values()) {
System.out.print(t);
BufferedImage src = createSourceImage(t);
BufferedImage dst = op.filter(src, null);
int rgb = dst.getRGB(0, 0);
System.out.printf(" Result: 0x%X ", rgb);
if (rgb != argbReverse) {
throw new RuntimeException("Test failed.");
}
System.out.println("Passed.");
}
}
public static void main(String[] args) {
LookupTable tbl = createReverseTable();
LookupOp op = new LookupOp(tbl, null);
for (ImageType t : ImageType.values()) {
System.out.print(t);
BufferedImage src = createSourceImage(t);
BufferedImage dst = op.filter(src, null);
int rgb = dst.getRGB(0, 0);
System.out.printf(" Result: 0x%X ", rgb);
if (rgb != argbReverse) {
throw new RuntimeException("Test failed.");
}
System.out.println("Passed.");
}
}
public static void enableBufImgOp(RenderQueue rq, SurfaceData srcData,
BufferedImage srcImg,
BufferedImageOp biop)
{
if (biop instanceof ConvolveOp) {
enableConvolveOp(rq, srcData, (ConvolveOp)biop);
} else if (biop instanceof RescaleOp) {
enableRescaleOp(rq, srcData, srcImg, (RescaleOp)biop);
} else if (biop instanceof LookupOp) {
enableLookupOp(rq, srcData, srcImg, (LookupOp)biop);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
public static void disableBufImgOp(RenderQueue rq, BufferedImageOp biop) {
if (biop instanceof ConvolveOp) {
disableConvolveOp(rq);
} else if (biop instanceof RescaleOp) {
disableRescaleOp(rq);
} else if (biop instanceof LookupOp) {
disableLookupOp(rq);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
public static void disableBufImgOp(RenderQueue rq, BufferedImageOp biop) {
if (biop instanceof ConvolveOp) {
disableConvolveOp(rq);
} else if (biop instanceof RescaleOp) {
disableRescaleOp(rq);
} else if (biop instanceof LookupOp) {
disableLookupOp(rq);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
public static void disableBufImgOp(RenderQueue rq, BufferedImageOp biop) {
if (biop instanceof ConvolveOp) {
disableConvolveOp(rq);
} else if (biop instanceof RescaleOp) {
disableRescaleOp(rq);
} else if (biop instanceof LookupOp) {
disableLookupOp(rq);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
public static void enableBufImgOp(RenderQueue rq, SurfaceData srcData,
BufferedImage srcImg,
BufferedImageOp biop)
{
if (biop instanceof ConvolveOp) {
enableConvolveOp(rq, srcData, (ConvolveOp)biop);
} else if (biop instanceof RescaleOp) {
enableRescaleOp(rq, srcData, srcImg, (RescaleOp)biop);
} else if (biop instanceof LookupOp) {
enableLookupOp(rq, srcData, srcImg, (LookupOp)biop);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
static void thresholding(BufferedImage bi) { // TODO Optimize
short[] threshold = new short[256];
for (short i = 0; i < 36; i++) {
threshold[i] = 0;
}
for (short i = 36; i < 256; i++) {
threshold[i] = i;
}
BufferedImageOp thresholdOp = new LookupOp(new ShortLookupTable(0, threshold), null);
thresholdOp.filter(bi, bi);
}
public static void disableBufImgOp(RenderQueue rq, BufferedImageOp biop) {
if (biop instanceof ConvolveOp) {
disableConvolveOp(rq);
} else if (biop instanceof RescaleOp) {
disableRescaleOp(rq);
} else if (biop instanceof LookupOp) {
disableLookupOp(rq);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
public static void enableBufImgOp(RenderQueue rq, SurfaceData srcData,
BufferedImage srcImg,
BufferedImageOp biop)
{
if (biop instanceof ConvolveOp) {
enableConvolveOp(rq, srcData, (ConvolveOp)biop);
} else if (biop instanceof RescaleOp) {
enableRescaleOp(rq, srcData, srcImg, (RescaleOp)biop);
} else if (biop instanceof LookupOp) {
enableLookupOp(rq, srcData, srcImg, (LookupOp)biop);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
public static void disableBufImgOp(RenderQueue rq, BufferedImageOp biop) {
if (biop instanceof ConvolveOp) {
disableConvolveOp(rq);
} else if (biop instanceof RescaleOp) {
disableRescaleOp(rq);
} else if (biop instanceof LookupOp) {
disableLookupOp(rq);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
public static void enableBufImgOp(RenderQueue rq, SurfaceData srcData,
BufferedImage srcImg,
BufferedImageOp biop)
{
if (biop instanceof ConvolveOp) {
enableConvolveOp(rq, srcData, (ConvolveOp)biop);
} else if (biop instanceof RescaleOp) {
enableRescaleOp(rq, srcData, srcImg, (RescaleOp)biop);
} else if (biop instanceof LookupOp) {
enableLookupOp(rq, srcData, srcImg, (LookupOp)biop);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
public static void disableBufImgOp(RenderQueue rq, BufferedImageOp biop) {
if (biop instanceof ConvolveOp) {
disableConvolveOp(rq);
} else if (biop instanceof RescaleOp) {
disableRescaleOp(rq);
} else if (biop instanceof LookupOp) {
disableLookupOp(rq);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
private static BufferedImageOp getLookupOp() {
byte[] inv = new byte[256];
for (int i = 0; i < 256; i++) {
inv[i] = (byte)(255 - i);
}
ByteLookupTable table = new ByteLookupTable(0, inv);
return new LookupOp(table, null);
}
public FilterPanelSeparator(int group) {
this.group = group;
jPanel = new JPanel();
GroupLayout layout = new GroupLayout(jPanel);
jPanel.setLayout(layout);
layout.setAutoCreateGaps(true);
layout.setAutoCreateContainerGaps(false);
BufferedImageOp lookup = new LookupOp(new ColorMapper(Color.WHITE, getColor("nimbusBlueGrey", "Separator.foreground")), null);
BufferedImage convertedImage = lookup.filter((BufferedImage)Images.MISC_AND.getImage(), null);
JLabel jIcon = new JLabel(new ImageIcon(convertedImage));
layout.setHorizontalGroup(
layout.createSequentialGroup()
.addGap(30)
.addComponent(jIcon, 12, 12, 12)
);
layout.setVerticalGroup(
layout.createSequentialGroup()
.addGap(1)
.addGroup(layout.createParallelGroup(GroupLayout.Alignment.CENTER)
.addComponent(jIcon, 4, 4, 4)
)
.addGap(1)
);
}
public SingleArrayTest() {
byte[] array = new byte[256];
for (int i = 0; i < 256; i++) {
array[i] = (byte)i;
}
ByteLookupTable table = new ByteLookupTable(0, array);
op = new LookupOp(table, null);
}
public static void enableBufImgOp(RenderQueue rq, SurfaceData srcData,
BufferedImage srcImg,
BufferedImageOp biop)
{
if (biop instanceof ConvolveOp) {
enableConvolveOp(rq, srcData, (ConvolveOp)biop);
} else if (biop instanceof RescaleOp) {
enableRescaleOp(rq, srcData, srcImg, (RescaleOp)biop);
} else if (biop instanceof LookupOp) {
enableLookupOp(rq, srcData, srcImg, (LookupOp)biop);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
public static void enableBufImgOp(RenderQueue rq, SurfaceData srcData,
BufferedImage srcImg,
BufferedImageOp biop)
{
if (biop instanceof ConvolveOp) {
enableConvolveOp(rq, srcData, (ConvolveOp)biop);
} else if (biop instanceof RescaleOp) {
enableRescaleOp(rq, srcData, srcImg, (RescaleOp)biop);
} else if (biop instanceof LookupOp) {
enableLookupOp(rq, srcData, srcImg, (LookupOp)biop);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}
public static void disableBufImgOp(RenderQueue rq, BufferedImageOp biop) {
if (biop instanceof ConvolveOp) {
disableConvolveOp(rq);
} else if (biop instanceof RescaleOp) {
disableRescaleOp(rq);
} else if (biop instanceof LookupOp) {
disableLookupOp(rq);
} else {
throw new InternalError("Unknown BufferedImageOp");
}
}