Search in sources :

Example 1 with LookupTable

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;
}
Also used : WritableRaster(java.awt.image.WritableRaster) ByteLookupTable(java.awt.image.ByteLookupTable) LookupTable(java.awt.image.LookupTable) ConvolveOp(java.awt.image.ConvolveOp) LookupOp(java.awt.image.LookupOp) ByteLookupTable(java.awt.image.ByteLookupTable) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 2 with LookupTable

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;
}
Also used : ByteLookupTable(java.awt.image.ByteLookupTable) LookupTable(java.awt.image.LookupTable) AffineTransform(java.awt.geom.AffineTransform) ConvolveOp(java.awt.image.ConvolveOp) LookupOp(java.awt.image.LookupOp) ByteLookupTable(java.awt.image.ByteLookupTable) BufferedImage(java.awt.image.BufferedImage) AffineTransformOp(java.awt.image.AffineTransformOp)

Example 3 with LookupTable

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;
}
Also used : ShortLookupTable(java.awt.image.ShortLookupTable) ColorModel(java.awt.image.ColorModel) IndexColorModel(java.awt.image.IndexColorModel) ByteLookupTable(java.awt.image.ByteLookupTable) LookupTable(java.awt.image.LookupTable) ShortLookupTable(java.awt.image.ShortLookupTable) ByteLookupTable(java.awt.image.ByteLookupTable) IndexColorModel(java.awt.image.IndexColorModel)

Example 4 with LookupTable

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);
    }
}
Also used : ShortLookupTable(java.awt.image.ShortLookupTable) ByteLookupTable(java.awt.image.ByteLookupTable) LookupTable(java.awt.image.LookupTable) ShortLookupTable(java.awt.image.ShortLookupTable) ByteLookupTable(java.awt.image.ByteLookupTable)

Example 5 with LookupTable

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.");
    }
}
Also used : LookupTable(java.awt.image.LookupTable) ByteLookupTable(java.awt.image.ByteLookupTable) LookupOp(java.awt.image.LookupOp) BufferedImage(java.awt.image.BufferedImage)

Aggregations

ByteLookupTable (java.awt.image.ByteLookupTable)5 LookupTable (java.awt.image.LookupTable)5 LookupOp (java.awt.image.LookupOp)3 AffineTransformOp (java.awt.image.AffineTransformOp)2 BufferedImage (java.awt.image.BufferedImage)2 ConvolveOp (java.awt.image.ConvolveOp)2 ShortLookupTable (java.awt.image.ShortLookupTable)2 AffineTransform (java.awt.geom.AffineTransform)1 ColorModel (java.awt.image.ColorModel)1 IndexColorModel (java.awt.image.IndexColorModel)1 WritableRaster (java.awt.image.WritableRaster)1