Hello,
The JAI team forwards me to this list with a JAI-misbehaviour due to a JAVA2D
bug. The detailed reason :
>This is in fact a manifestation of a bug in
>java.awt.image.WritableRaster.setRect() wherein data stored as non-integral
>primitive types were being truncated. The same problem has been observed in
>TiledImage.setData(Raster). This bug has been fixed in the development code of
>JDK 1.3 (bud ID 4250270).
I have however downloaded and tried the JDK1.3beta, and none of the 2
manifestations disappear, so is it
possible that the bug is not solved or another is releated to ?
2 different program snippets are added;
- test2 will execute a PeriodicShift operator of JAI, but somewhere the road a
unintented casting from floats to ints occur (all kernelvalues smaller then 1
return a 0 in the shifted image).
- test3 will execute a clamping operator after a cropping operator, and also
here an unintentionally casting from
floats to integer values occur.
Thanks in advance for the investigation,
Luc
import java.awt.image.*;
import javax.media.jai.*;
public class test2 {
public static void main(String[] args)throws Exception {
float[] kernelData7 = {
0.00f, 0.31f, 0.79f, 0.96f, 0.79f, 0.31f, 0.00f,
0.31f, 0.99f, 1.00f, 1.00f, 1.00f, 0.99f, 0.31f,
0.79f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 0.79f,
0.96f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 0.96f,
0.79f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 0.79f,
0.31f, 0.99f, 1.00f, 1.00f, 1.00f, 0.99f, 0.31f,
0.00f, 0.31f, 0.79f, 0.96f, 0.79f, 0.31f, 0.00f
};
int convGrid = 7;
int imgWidth = 16;
int imgHeight = 16;
SampleModel sm =
RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT,imgWidth,i
mgHeight,1);
ColorModel cm = PlanarImage.createColorModel(sm);
TiledImage imgKernel = new TiledImage(0, 0, imgWidth, imgHeight, 0, 0, sm, cm);
WritableRaster wrKernel = imgKernel.getWritableTile(0,0);
// copy kernel in the middle of the TiledImage
int offsetX = (imgWidth - convGrid + 1)/2;
int offsetY = (imgHeight - convGrid + 1)/2;
wrKernel.setSamples(offsetX, offsetY, convGrid, convGrid, 0,kernelData7);
imgKernel.releaseWritableTile(0,0);
float[] imgKernelData = ((DataBufferFloat) wrKernel.getDataBuffer()).getData();
System.out.print(" half middle row of kernel = " );
for (int i = 0; i<4; i++) System.out.print(imgKernelData[136 + i] + " ");
System.out.println();
PlanarImage shiftedKernel = JAI.create("PeriodicShift",imgKernel);
float[] shiftKernelData = ((DataBufferFloat)
shiftedKernel.getData().getDataBuffer()).getData();
System.out.print("same values of Shifted kernel, are CASTED to int-values ! = "
);
for (int i = 0; i<4; i++) System.out.print(shiftKernelData[i] + " ");
System.out.println();
}//main
}//class test2
/*
********************************************************************************
******************************* */
import java.awt.image.*;
import javax.media.jai.*;
import java.awt.image.renderable.ParameterBlock;
import java.awt.RenderingHints;
public class test3 {
public static void main(String[] args)throws Exception {
float[] kernelData7 = {
0.00f, 0.31f, 0.79f, 1.00f, 0.79f, 0.31f, 0.00f,
0.31f, 0.99f, 1.00f, 1.00f, 1.00f, 0.99f, 0.31f,
0.79f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 0.79f,
0.96f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 0.96f,
0.79f, 1.00f, 1.00f, 1.00f, 1.00f, 1.00f, 0.79f,
0.31f, 0.99f, 1.00f, 1.00f, 1.00f, 0.99f, 0.31f,
0.00f, 0.31f, 0.79f, 1.00f, 0.79f, 0.31f, 0.00f
};
int imgWidth = 7;
int imgHeight = 7;
SampleModel sm =
RasterFactory.createPixelInterleavedSampleModel(DataBuffer.TYPE_FLOAT,imgWidth,i
mgHeight,1);
ColorModel cm = PlanarImage.createColorModel(sm);
TiledImage imgKernel = new TiledImage(0, 0, imgWidth, imgHeight, 0, 0, sm, cm);
WritableRaster wrKernel = imgKernel.getWritableTile(0,0);
// copy kernel in TiledImage
wrKernel.setSamples(0, 0, imgWidth, imgHeight, 0,kernelData7);
imgKernel.releaseWritableTile(0,0);
float[] imgKernelData = ((DataBufferFloat) wrKernel.getDataBuffer()).getData();
System.out.print(" first row before crop = " );
for (int i = 0; i<7; i++) System.out.print(imgKernelData[i] + " ");
System.out.println();
ParameterBlock pb1 = new ParameterBlock();
pb1.addSource(imgKernel);
pb1.add((float)0); //left offset
pb1.add((float)0); //top offset
pb1.add((float)(imgWidth)); //width
pb1.add((float)(imgHeight)); //height
PlanarImage img1 = JAI.create("crop",pb1);
float[] img1Data = ((DataBufferFloat)img1.getData().getDataBuffer()).getData();
System.out.print(" first row after crop = " );
for (int i = 0; i<7; i++) System.out.print(img1Data[i] + " ");
System.out.println();
ImageLayout il2 = new ImageLayout(); //needed to go around a bug in JAI 1.0
when origin <> 0,0
il2.setTileGridXOffset(il2.getMinX(img1));
il2.setTileGridYOffset(il2.getMinY(img1));
il2.setTileWidth(il2.getWidth(img1));
il2.setTileHeight(il2.getHeight(img1));
RenderingHints hint2 = new RenderingHints(JAI.KEY_IMAGE_LAYOUT,il2);
ParameterBlock pb2 = new ParameterBlock();
pb2.addSource(img1);
pb2.add(new double[] {0.0}); //low bound of clamping
pb2.add(new double[] {1.0}); //high bound of clamping
RenderedOp img2 = JAI.create("clamp",pb2, hint2);
float[] img2Data = ((DataBufferFloat)img2.getData().getDataBuffer()).getData();
System.out.print(" first row after clamp = " );
for (int i = 0; i<7; i++) System.out.print(img2Data[i] + " ");
System.out.println();
}//main
}//class test3
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA2D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".