use of java.awt.image.LookupTable in project jdk8u_jdk by JetBrains.
the class ImagingLib method filter.
public static WritableRaster filter(RasterOp op, Raster src, WritableRaster dst) {
if (useLib == false) {
return null;
}
// Create the destination tile
if (dst == null) {
dst = op.createCompatibleDestRaster(src);
}
WritableRaster retRaster = null;
switch(getNativeOpIndex(op.getClass())) {
case LOOKUP_OP:
// REMIND: Fix this!
LookupTable table = ((LookupOp) op).getTable();
if (table.getOffset() != 0) {
// Right now the native code doesn't support offsets
return null;
}
if (table instanceof ByteLookupTable) {
ByteLookupTable bt = (ByteLookupTable) table;
if (lookupByteRaster(src, dst, bt.getTable()) > 0) {
retRaster = dst;
}
}
break;
case AFFINE_OP:
AffineTransformOp bOp = (AffineTransformOp) op;
double[] matrix = new double[6];
bOp.getTransform().getMatrix(matrix);
if (transformRaster(src, dst, matrix, bOp.getInterpolationType()) > 0) {
retRaster = dst;
}
break;
case CONVOLVE_OP:
ConvolveOp cOp = (ConvolveOp) op;
if (convolveRaster(src, dst, cOp.getKernel(), cOp.getEdgeCondition()) > 0) {
retRaster = dst;
}
break;
default:
break;
}
if (retRaster != null) {
SunWritableRaster.markDirty(retRaster);
}
return retRaster;
}
use of java.awt.image.LookupTable in project jdk8u_jdk by JetBrains.
the class ImagingLib method filter.
public static BufferedImage filter(BufferedImageOp op, BufferedImage src, BufferedImage dst) {
if (verbose) {
System.out.println("in filter and op is " + op + "bufimage is " + src + " and " + dst);
}
if (useLib == false) {
return null;
}
// Create the destination image
if (dst == null) {
dst = op.createCompatibleDestImage(src, null);
}
BufferedImage retBI = null;
switch(getNativeOpIndex(op.getClass())) {
case LOOKUP_OP:
// REMIND: Fix this!
LookupTable table = ((LookupOp) op).getTable();
if (table.getOffset() != 0) {
// Right now the native code doesn't support offsets
return null;
}
if (table instanceof ByteLookupTable) {
ByteLookupTable bt = (ByteLookupTable) table;
if (lookupByteBI(src, dst, bt.getTable()) > 0) {
retBI = dst;
}
}
break;
case AFFINE_OP:
AffineTransformOp bOp = (AffineTransformOp) op;
double[] matrix = new double[6];
AffineTransform xform = bOp.getTransform();
bOp.getTransform().getMatrix(matrix);
if (transformBI(src, dst, matrix, bOp.getInterpolationType()) > 0) {
retBI = dst;
}
break;
case CONVOLVE_OP:
ConvolveOp cOp = (ConvolveOp) op;
if (convolveBI(src, dst, cOp.getKernel(), cOp.getEdgeCondition()) > 0) {
retBI = dst;
}
break;
default:
break;
}
if (retBI != null) {
SunWritableRaster.markDirty(retBI);
}
return retBI;
}
use of java.awt.image.LookupTable in project jdk8u_jdk by JetBrains.
the class BufferedBufImgOps method isLookupOpValid.
/**************************** LookupOp support ******************************/
public static boolean isLookupOpValid(LookupOp lop, BufferedImage srcImg) {
LookupTable table = lop.getTable();
int numComps = table.getNumComponents();
ColorModel srcCM = srcImg.getColorModel();
if (srcCM instanceof IndexColorModel) {
throw new IllegalArgumentException("LookupOp cannot be " + "performed on an indexed image");
}
if (numComps != 1 && numComps != srcCM.getNumComponents() && numComps != srcCM.getNumColorComponents()) {
throw new IllegalArgumentException("Number of arrays in the " + " lookup table (" + numComps + ") is not compatible with" + " the src image: " + srcImg);
}
int csType = srcCM.getColorSpace().getType();
if (csType != ColorSpace.TYPE_RGB && csType != ColorSpace.TYPE_GRAY) {
// Not prepared to deal with other color spaces
return false;
}
if (numComps == 2 || numComps > 4) {
// Not really prepared to handle this at the native level, so...
return false;
}
// these restrictions here.
if (table instanceof ByteLookupTable) {
byte[][] data = ((ByteLookupTable) table).getTable();
for (int i = 1; i < data.length; i++) {
if (data[i].length > 256 || data[i].length != data[i - 1].length) {
return false;
}
}
} else if (table instanceof ShortLookupTable) {
short[][] data = ((ShortLookupTable) table).getTable();
for (int i = 1; i < data.length; i++) {
if (data[i].length > 256 || data[i].length != data[i - 1].length) {
return false;
}
}
} else {
return false;
}
return true;
}
use of java.awt.image.LookupTable in project jdk8u_jdk by JetBrains.
the class BufferedBufImgOps method enableLookupOp.
private static void enableLookupOp(RenderQueue rq, SurfaceData srcData, BufferedImage srcImg, LookupOp lop) {
// assert rq.lock.isHeldByCurrentThread();
boolean nonPremult = srcImg.getColorModel().hasAlpha() && srcImg.isAlphaPremultiplied();
LookupTable table = lop.getTable();
int numBands = table.getNumComponents();
int offset = table.getOffset();
int bandLength;
int bytesPerElem;
boolean shortData;
if (table instanceof ShortLookupTable) {
short[][] data = ((ShortLookupTable) table).getTable();
bandLength = data[0].length;
bytesPerElem = 2;
shortData = true;
} else {
// (table instanceof ByteLookupTable)
byte[][] data = ((ByteLookupTable) table).getTable();
bandLength = data[0].length;
bytesPerElem = 1;
shortData = false;
}
// Adjust the LUT length so that it ends on a 4-byte boundary
int totalLutBytes = numBands * bandLength * bytesPerElem;
int paddedLutBytes = (totalLutBytes + 3) & (~3);
int padding = paddedLutBytes - totalLutBytes;
int totalBytesRequired = 4 + 8 + 20 + paddedLutBytes;
RenderBuffer buf = rq.getBuffer();
rq.ensureCapacityAndAlignment(totalBytesRequired, 4);
buf.putInt(ENABLE_LOOKUP_OP);
buf.putLong(srcData.getNativeOps());
buf.putInt(nonPremult ? 1 : 0);
buf.putInt(shortData ? 1 : 0);
buf.putInt(numBands);
buf.putInt(bandLength);
buf.putInt(offset);
if (shortData) {
short[][] data = ((ShortLookupTable) table).getTable();
for (int i = 0; i < numBands; i++) {
buf.put(data[i]);
}
} else {
byte[][] data = ((ByteLookupTable) table).getTable();
for (int i = 0; i < numBands; i++) {
buf.put(data[i]);
}
}
if (padding != 0) {
buf.position(buf.position() + padding);
}
}
use of java.awt.image.LookupTable in project jdk8u_jdk by JetBrains.
the class IntImageReverseTest method main.
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.");
}
}
Aggregations