boolean wantHTables = true;
float quality = JPEG.DEFAULT_QUALITY;
byte[] componentIDs = { 1, 2, 3, 4};
int numComponents = 0;
ImageTypeSpecifier destType = null;
if (param != null) {
destType = param.getDestinationType();
if (destType != null) {
if (imageType != null) {
// Ignore the destination type.
writer.warningOccurred
(JPEGImageWriter.WARNING_DEST_IGNORED);
destType = null;
}
}
// The only progressive mode that makes sense here is MODE_DEFAULT
if (param.canWriteProgressive()) {
// the param may not be one of ours, so it may return false.
// If so, the following would throw an exception
if (param.getProgressiveMode() == ImageWriteParam.MODE_DEFAULT) {
wantProg = true;
wantOptimized = true;
wantHTables = false;
}
}
if (param instanceof JPEGImageWriteParam) {
JPEGImageWriteParam jparam = (JPEGImageWriteParam) param;
if (jparam.areTablesSet()) {
wantQTables = false; // If the param has them, metadata shouldn't
wantHTables = false;
if ((jparam.getDCHuffmanTables().length > 2)
|| (jparam.getACHuffmanTables().length > 2)) {
wantExtended = true;
}
}
// Progressive forces optimized, regardless of param setting
// so consult the param re optimized only if not progressive
if (!wantProg) {
wantOptimized = jparam.getOptimizeHuffmanTables();
if (wantOptimized) {
wantHTables = false;
}
}
}
// compression quality should determine the q tables. Note that this
// will be ignored if we already decided not to create any.
// Again, the param may not be one of ours, so we must check that it
// supports compression settings
if (param.canWriteCompressed()) {
if (param.getCompressionMode() == ImageWriteParam.MODE_EXPLICIT) {
quality = param.getCompressionQuality();
}
}
}
// We are done with the param, now for the image types
ColorSpace cs = null;
if (destType != null) {
ColorModel cm = destType.getColorModel();
numComponents = cm.getNumComponents();
boolean hasExtraComponents = (cm.getNumColorComponents() != numComponents);
boolean hasAlpha = cm.hasAlpha();
cs = cm.getColorSpace();
int type = cs.getType();