}
// If only one profile left we skip the transform -
// it can be only CIEXYZ
if (profiles.size() > 1) {
sequence.add(new ICC_Transform(profiles.toArray(new ICC_Profile[0])));
// Add non-ICC color space to the sequence
sequence.add(conversionSequence[i]);
}
profiles.clear();
profiles.add(xyzProfile);
iccSequenceStarted = false; // Sequence of ICC profiles is processed
} else { // Add non-ICC color space to the sequence
sequence.add(conversionSequence[i]);
}
}
if (dst != conversionLast && dst != null) { // Add last profile if needed
if (dst instanceof ICC_Profile) {
profiles.add(dst);
iccSequenceStarted = true;
} else if (iccSequenceStarted) {
profiles.add(xyzProfile);
} else {
sequence.add(dst); // Add last non-ICC color space to the sequence
}
}
if (iccSequenceStarted) { // Make last transform if needed
sequence.add(new ICC_Transform(profiles.toArray(new ICC_Profile[0])));
if (dst != null && !(dst instanceof ICC_Profile)) {
sequence.add(dst); // Add last non-ICC color space to the
// sequence
}
}
// Calculate max number of components
// This number will be used for memory allocation
maxComponents = 0;
Object o;
for (int i=0, size = sequence.size(); i<size; i++) {
o = sequence.get(i);
if (o instanceof ICC_Transform) {
ICC_Transform t = (ICC_Transform) o;
maxComponents =
(maxComponents > t.getNumInputChannels() + 1) ?
maxComponents :
t.getNumInputChannels() + 1;
maxComponents =
(maxComponents > t.getNumOutputChannels() + 1) ?
maxComponents :
t.getNumOutputChannels() + 1;
} else {
ColorSpace cs = (ColorSpace) o;
maxComponents =
(maxComponents > cs.getNumComponents() + 1) ?
maxComponents :