use of java.awt.image.IndexColorModel in project jdk8u_jdk by JetBrains.
the class ShortHistogramTest method gethISTNode.
private IIOMetadataNode gethISTNode(BufferedImage bi) {
IndexColorModel icm = (IndexColorModel) bi.getColorModel();
int mapSize = icm.getMapSize();
int[] hist = new int[mapSize];
Arrays.fill(hist, 0);
Raster r = bi.getData();
for (int y = 0; y < bi.getHeight(); y++) {
for (int x = 0; x < bi.getWidth(); x++) {
int s = r.getSample(x, y, 0);
hist[s]++;
}
}
IIOMetadataNode hIST = new IIOMetadataNode("hIST");
for (int i = 0; i < hist.length; i++) {
IIOMetadataNode n = new IIOMetadataNode("hISTEntry");
n.setAttribute("index", "" + i);
n.setAttribute("value", "" + hist[i]);
hIST.appendChild(n);
}
return hIST;
}
use of java.awt.image.IndexColorModel in project cloudstack by apache.
the class ServerPaletteUpdate method handleData.
@Override
public void handleData(ByteBuffer buf, Link link) {
if (verbose)
System.out.println("[" + this + "] INFO: Data received: " + buf + ".");
// (2 bytes): A 16-bit, unsigned integer. The update type. This field MUST
// be set to UPDATETYPE_PALETTE (0x0002).
int updateType = buf.readUnsignedShortLE();
if (updateType != UPDATETYPE_PALETTE)
throw new RuntimeException("Unexpected update type. Expected type: UPDATETYPE_PALETTE (0x0002), actual value: " + updateType + ", data: " + buf + ".");
// pad2Octets (2 bytes): A 16-bit, unsigned integer. Padding. Values in this
// field MUST be ignored.
buf.skipBytes(2);
// (4 bytes): A 32-bit, unsigned integer. The number of RGB triplets in the
// paletteData field. This field MUST be set to 256 (the number of entries
// in an 8 bpp palette).
int numberColors = (int) buf.readUnsignedIntLE();
if (numberColors != 256)
throw new RuntimeException("Unexpected value for number of color field in server Palette Update packet. Expected value: 256 colors, actual value: " + numberColors + ", data: " + buf + ".");
// (variable): An array of palette entries in RGB triplet format packed on
// byte boundaries. The number of triplet entries is given by the
// numberColors field.
ByteBuffer paletteEntries = buf.readBytes(numberColors * 3);
// In the case of a Palette Update, the client MUST update the global
// palette on all drawing surfaces
screen.colorMap = new IndexColorModel(8, numberColors, paletteEntries.data, paletteEntries.offset, false);
/* DEBUG */
buf.assertThatBufferIsFullyRead();
buf.unref();
}
Aggregations