dataLen -= ID_SIZE;
// get the chunk number
int chunkNum = buffer.buf[buffer.bufPtr] & 0xff;
if (chunkNum > numChunks) {
throw new IIOException
("Image format Error; chunk num > num chunks");
}
// get the number of chunks, which should match
int newNumChunks = buffer.buf[buffer.bufPtr+1] & 0xff;
if (numChunks != newNumChunks) {
throw new IIOException
("Image format Error; icc num chunks mismatch");
}
dataLen -= 2;
if (debug) {
System.out.println("chunkNum: " + chunkNum
+ ", numChunks: " + numChunks
+ ", dataLen: " + dataLen);
}
boolean retval = false;
byte [] profileData = new byte[dataLen];
buffer.readData(profileData);
chunks.add(profileData);
length += dataLen;
chunksRead++;
if (chunksRead < numChunks) {
inICC = true;
} else {
if (debug) {
System.out.println("Completing profile; total length is "
+ length);
}
// create an array for the whole thing
profile = new byte[length];
// copy the existing chunks, releasing them
// Note that they may be out of order
int index = 0;
for (int i = 1; i <= numChunks; i++) {
boolean foundIt = false;
for (int chunk = 0; chunk < chunks.size(); chunk++) {
byte [] chunkData = (byte []) chunks.get(chunk);
if (chunkData[0] == i) { // Right one
System.arraycopy(chunkData, 2,
profile, index,
chunkData.length-2);
index += chunkData.length-2;
foundIt = true;
}
}
if (foundIt == false) {
throw new IIOException
("Image Format Error: Missing ICC chunk num " + i);
}
}
chunks = null;