COSDocument doc = this.documentHandler.getDocument().getDocument();
COSBase csInlinedBase = dict.getItem(COSName
.getPDFName(STREAM_DICTIONARY_KEY_COLOR_SPACE));
ColorSpaceHelper csHelper = null;
if (csInlinedBase != null) {
if (COSUtils.isString(csInlinedBase, doc)) {
// ---- In InlinedImage only DeviceGray/RGB/CMYK and restricted Indexed
// color spaces
// are allowed.
String colorSpace = COSUtils.getAsString(csInlinedBase, doc);
ColorSpaces cs = null;
try {
cs = ColorSpaces.valueOf(colorSpace);
} catch (IllegalArgumentException e) {
// ---- The color space is unknown.
// ---- Try to access the resources dictionary, the color space can be
// a reference.
PDColorSpace pdCS = (PDColorSpace) this.getColorSpaces().get(
colorSpace);
if (pdCS != null) {
cs = ColorSpaces.valueOf(pdCS.getName());
csHelper = ColorSpaceHelperFactory.getColorSpaceHelper(pdCS,
documentHandler, ColorSpaceRestriction.ONLY_DEVICE);
}
}
if (cs == null) {
throwContentStreamException("The ColorSpace is unknown",
ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY);
}
}
if (csHelper == null) {
csHelper = ColorSpaceHelperFactory.getColorSpaceHelper(csInlinedBase,
documentHandler, ColorSpaceRestriction.ONLY_DEVICE);
}
List<ValidationError> errors = new ArrayList<ValidationError>();
try {
if (!csHelper.validate(errors)) {
ValidationError ve = errors.get(0);
throwContentStreamException(ve.getDetails(), ve.getErrorCode());
}
} catch (ValidationException e) {
throw new IOException(e.getMessage());