protected void validImageColorSpace(PDFOperator operator) throws ContentStreamException, IOException
{
COSDictionary dict = operator.getImageParameters().getDictionary();
COSBase csInlinedBase = dict.getItem(COSName.CS);
ColorSpaceHelper csHelper = null;
if (csInlinedBase != null)
{
if (COSUtils.isString(csInlinedBase, cosDocument))
{
/*
* In InlinedImage only DeviceGray/RGB/CMYK and restricted Indexed color spaces are allowed.
*/
String colorSpace = COSUtils.getAsString(csInlinedBase, cosDocument);
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.
Map<String, PDColorSpace> colorSpaces = this.getResources().getColorSpaces();
if (colorSpaces != null)
{
PDColorSpace pdCS = colorSpaces.get(colorSpace);
if (pdCS != null)
{
cs = ColorSpaces.valueOf(pdCS.getName());
PreflightConfiguration cfg = context.getConfig();
ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.ONLY_DEVICE);
}
}
}
if (cs == null)
{
registerError("The ColorSpace is unknown", ERROR_GRAPHIC_UNEXPECTED_VALUE_FOR_KEY);
return;
}
}
if (csHelper == null)
{
PDColorSpace pdCS = PDColorSpaceFactory.createColorSpace(csInlinedBase);
PreflightConfiguration cfg = context.getConfig();
ColorSpaceHelperFactory csFact = cfg.getColorSpaceHelperFact();
csHelper = csFact.getColorSpaceHelper(context, pdCS, ColorSpaceRestriction.ONLY_DEVICE);
}
csHelper.validate();
}
}