Search in sources :

Example 6 with ByteLookupTable

use of java.awt.image.ByteLookupTable 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)

Aggregations

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