Java/2D Graphics GUI/JAI
Версия от 18:01, 31 мая 2010; (обсуждение)
Содержание
Check Alignment Descriptor
/*
Java Media APIs: Cross-Platform Imaging, Media and Visualization
Alejandro Terrazas
Sams, Published November 2002,
ISBN 0672320940
*/
import javax.media.jai.OperationDescriptorImpl;
import javax.media.jai.registry.RenderedRegistryMode;
public class CheckAlignmentDescriptor extends OperationDescriptorImpl {
private static final String[] paramNames = { "samplingPeriod" };
private static final Object[] paramDefaults = { new Integer(1) };
private static final Class[] paramClasses = { Integer.class };
private static final int numSources = 2;
private static final String[] supportedModes = { "rendered" };
private static final Object[] validParamValues = { new javax.media.jai.util.Range(
Integer.class, new Integer(1), new Integer(Integer.MAX_VALUE)) };
private static final String[][] resources = {
{ "GlobalName", "CheckAlignment" },
{ "LocalName", "CheckAlignment" }, { "Vender", "Ostuni" },
{ "Description", "Provides Visual Alignment Check of Two Images" },
{ "DocURL", "none" }, { "Version", "Beta" }, };
public CheckAlignmentDescriptor() {
super(resources, supportedModes, numSources, paramNames, paramClasses,
paramDefaults, validParamValues);
}
}
Check AlignmentOpImage
/*
Java Media APIs: Cross-Platform Imaging, Media and Visualization
Alejandro Terrazas
Sams, Published November 2002,
ISBN 0672320940
*/
import javax.media.jai.ImageLayout;
import javax.media.jai.PointOpImage;
import java.awt.image.RenderedImage;
import java.awt.image.Raster;
import java.awt.image.WritableRaster;
public class CheckAlignmentOpImage extends PointOpImage {
public CheckAlignmentOpImage(RenderedImage s1, RenderedImage s2, int sp,
ImageLayout layout, java.util.Map configuration,
boolean cobbleSources) {
super(s1, s2, layout, configuration, cobbleSources);
source1 = s1;
source2 = s2;
samplingPeriod = sp;
}
public Raster computeTile(int x, int y) {
Raster r1 = source1.getTile(x, y);
Raster r2 = source2.getTile(x, y);
int xBounds = r1.getWidth();
if (r2.getWidth() < xBounds)
xBounds = r2.getWidth();
int yBounds = r1.getHeight();
if (r2.getHeight() < yBounds)
yBounds = r2.getHeight();
WritableRaster wr;
wr = r1.createCompatibleWritableRaster(xBounds, yBounds);
int tmpi;
int tmpj;
for (int i = 0; i < wr.getWidth(); i++)
for (int j = 0; j < wr.getHeight(); j++) {
tmpi = i / samplingPeriod;
tmpj = j / samplingPeriod;
if ((tmpi % 2 == 0) && (tmpj % 2 == 0))
wr.setDataElements(i, j, r2.getDataElements(i, j, null));
else if ((tmpi % 2 != 0) && (tmpj % 2 != 0))
wr.setDataElements(i, j, r2.getDataElements(i, j, null));
else
wr.setDataElements(i, j, r1.getDataElements(i, j, null));
}
return wr;
}
private RenderedImage source1, source2;
private int samplingPeriod;
}
Check Alignment RIF
import java.awt.image.RenderedImage;
import java.awt.image.renderable.ParameterBlock;
import java.awt.image.renderable.RenderedImageFactory;
import java.awt.RenderingHints;
import javax.media.jai.ImageLayout;
public class CheckAlignmentRIF implements RenderedImageFactory {
public CheckAlignmentRIF() {
}
public RenderedImage create(ParameterBlock paramBlock,
RenderingHints renderingHints) {
RenderedImage source1 = paramBlock.getRenderedSource(0);
RenderedImage source2 = paramBlock.getRenderedSource(1);
int samplingPeriod = paramBlock.getIntParameter(0);
ImageLayout layout = null;
return new CheckAlignmentOpImage(source1, source2, samplingPeriod,
layout, renderingHints, false);
}
}
Lists all allowable JAI operations
import javax.media.jai.JAI;
import javax.media.jai.OperationRegistry;
import javax.media.jai.RegistryMode;
public class ListRegistry {
public ListRegistry() {
or = JAI.getDefaultInstance().getOperationRegistry();
String[] modeNames = RegistryMode.getModeNames();
String[] descriptorNames;
for (int i = 0; i < modeNames.length; i++) {
System.out.println("For registry mode: " + modeNames[i]);
descriptorNames = or.getDescriptorNames(modeNames[i]);
for (int j = 0; j < descriptorNames.length; j++) {
System.out.print("\tRegistered Operator: ");
System.out.println(descriptorNames[j]);
}
}
}
public static void main(String[] args) {
new ListRegistry();
}
private OperationRegistry or;
}