Search in sources :

Example 1 with ShortLookupTable

use of java.awt.image.ShortLookupTable in project ChatGameFontificator by GlitchCog.

the class Sprite method setupSwap.

private void setupSwap() {
    short[][] lookupArray = new short[4][256];
    for (int i = 0; i < lookupArray.length; i++) {
        for (short c = 0; c < lookupArray[i].length; c++) {
            lookupArray[i][c] = c;
        }
    }
    swapTable = new ShortLookupTable(0, lookupArray);
    swapOp = new LookupOp(swapTable, null);
}
Also used : ShortLookupTable(java.awt.image.ShortLookupTable) LookupOp(java.awt.image.LookupOp)

Example 2 with ShortLookupTable

use of java.awt.image.ShortLookupTable 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 3 with ShortLookupTable

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

ShortLookupTable (java.awt.image.ShortLookupTable)3 ByteLookupTable (java.awt.image.ByteLookupTable)2 LookupTable (java.awt.image.LookupTable)2 ColorModel (java.awt.image.ColorModel)1 IndexColorModel (java.awt.image.IndexColorModel)1 LookupOp (java.awt.image.LookupOp)1