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);
}
}
Aggregations