JAIEffectpublic class JAIEffect extends BasicCodec implements Effect
Fields Summary |
---|
private BufferToImage | frameConverter | private PlanarImage | jaiImage | private boolean | debug | private Control[] | controls | private JAIControl | control | private static float[] | edge1Matrix | private static float[] | edge2Matrix | private static float[] | sharp1Matrix | private static float[] | sharp2Matrix | private static float[] | embossMatrix | private String[] | kernelNames | private float[] | matrices | private KernelJAI[] | kernels |
Constructors Summary |
---|
public JAIEffect()
matrices[0] = edge1Matrix;
matrices[1] = edge2Matrix;
matrices[2] = sharp1Matrix;
matrices[3] = sharp2Matrix;
matrices[4] = embossMatrix;
inputFormats = new Format[] {
new RGBFormat(null,
Format.NOT_SPECIFIED,
Format.byteArray,
Format.NOT_SPECIFIED,
24,
3, 2, 1,
3, Format.NOT_SPECIFIED,
Format.TRUE,
Format.NOT_SPECIFIED)
};
outputFormats = new Format[] {
new RGBFormat(null,
Format.NOT_SPECIFIED,
Format.byteArray,
Format.NOT_SPECIFIED,
24,
3, 2, 1,
3, Format.NOT_SPECIFIED,
Format.TRUE,
Format.NOT_SPECIFIED)
};
|
Methods Summary |
---|
public java.lang.Object | getControl(java.lang.String controlType)
// TODO: check if this right
if (controlType.equals("com.sun.media.effects.JAIControl")) {
return getControl();
} else
return null;
| private javax.media.Control | getControl()
if (control == null) {
control = new JAIControl();
control.setConvolutionChoices(kernelNames);
}
int index = control.getEffectIndex();
return control;
| public java.lang.Object[] | getControls()
if (controls == null) {
controls = new Control[1];
controls[0] = getControl();
}
return controls;
| public java.lang.String | getName()
return "Java Advanced Imaging Effects";
| public javax.media.Format[] | getSupportedOutputFormats(javax.media.Format input)
if (input == null) {
return outputFormats;
}
if (matches(input, inputFormats) != null) {
return new Format[] { outputFormats[0].intersects(input) };
} else {
return new Format[0];
}
| public int | process(javax.media.Buffer inBuffer, javax.media.Buffer outBuffer)
try {
if (frameConverter == null) {
frameConverter = new BufferToImage((VideoFormat) inBuffer.getFormat());
}
// Convert the Buffer to an AWT Image.
Image frameImage = frameConverter.createImage(inBuffer);
// Derive a JAI image from the AWT image.
PlanarImage jaiImage = JAI.create("AWTImage", frameImage);
int index;
boolean emboss = false;
if (control != null) {
index = control.getEffectIndex();
if (control.getEffectName().equals("None")) {
outBuffer.setData(inBuffer.getData());
outBuffer.setFormat(inBuffer.getFormat());
outBuffer.setFlags(inBuffer.getFlags());
outBuffer.setLength(inBuffer.getLength());
return BUFFER_PROCESSED_OK;
}
if (control.getEffectName().equals("Emboss")) {
emboss = true; // Special case
}
} else
index = 0;
if (kernels[index] == null) {
kernels[index] = new KernelJAI(3, 3, matrices[index]);
}
jaiImage = JAI.create("convolve", jaiImage, kernels[index]);
if (emboss) { // add 128 to make it brighter
double[] constants = new double[] {128., 128., 128.};
ParameterBlock pb = new ParameterBlock();
pb.addSource(jaiImage);
pb.add(constants);
jaiImage = JAI.create("addconst", pb, null);
}
// Now convert the image to a buffer
BufferedImage bim = jaiImage.getAsBufferedImage();
Buffer out = ImageToBuffer.createBuffer(bim, 15.F);
if (out == null) {
if (debug) {
System.out.println("ImageToBuffer returned null");
}
return BUFFER_PROCESSED_FAILED;
}
outBuffer.setData(out.getData());
outBuffer.setFormat(out.getFormat());
outBuffer.setFlags(out.getFlags());
outBuffer.setLength(out.getLength());
} catch (Exception e) {
System.err.println(e);
return BUFFER_PROCESSED_FAILED;
} catch (Error e) {
System.err.println(e);
return BUFFER_PROCESSED_FAILED;
}
return BUFFER_PROCESSED_OK;
| public javax.media.Format | setOutputFormat(javax.media.Format output)
if (output == null || matches(output, outputFormats) == null)
return null;
RGBFormat incoming = (RGBFormat) output;
Dimension size = incoming.getSize();
int maxDataLength = incoming.getMaxDataLength();
int lineStride = incoming.getLineStride();
float frameRate = incoming.getFrameRate();
int flipped = incoming.getFlipped();
int endian = incoming.getEndian();
if (size == null)
return null;
if (maxDataLength < size.width * size.height * 3)
maxDataLength = size.width * size.height * 3;
if (lineStride < size.width * 3)
lineStride = size.width * 3;
if (flipped != Format.FALSE)
flipped = Format.FALSE;
outputFormat = outputFormats[0].intersects(new RGBFormat(size,
maxDataLength,
null,
frameRate,
Format.NOT_SPECIFIED,
Format.NOT_SPECIFIED,
Format.NOT_SPECIFIED,
Format.NOT_SPECIFIED,
Format.NOT_SPECIFIED,
lineStride,
Format.NOT_SPECIFIED,
Format.NOT_SPECIFIED));
return outputFormat;
|
|