private BufferedImage readImage(ImageReader jpegReader, ImageReadParam param) throws IOException {
            if (ycckDecodeMode) {
                // The standard Oracle Java JPEG readers can't deal with CMYK YCCK encoded images
                // without a little help from us. We'll try and pick up such instances and work around it.
                final IIOMetadata imageMeta = jpegReader.getImageMetadata(0);
                if (imageMeta != null) {
                    final Node standardMeta = imageMeta.getAsTree(IIOMetadataFormatImpl.standardMetadataFormatName);
                    if (standardMeta != null) {
                        final Node chroma = getChild(standardMeta, "Chroma");
                        if (chroma != null) {
                            final Node csType = getChild(chroma, "ColorSpaceType");
                            if (csType != null) {
                                final Attr csTypeNameNode = (Attr)csType.getAttributes().getNamedItem("name");
                                if (csTypeNameNode != null && "YCCK".equals(csTypeNameNode.getValue())) {
                                    // So it's a YCCK image, and we can coax a workable image out of it
                                    // by grabbing the raw raster and installing a YCCK converting
                                    // color space wrapper around the existing (CMYK) color space; this will
                                    // do the YCCK conversion for us

                                    // first make sure we can get the unadjusted raster
                                    final Raster raster = jpegReader.readRaster(0, param);

                                    // and now use it with a YCCK converting color space.
                                    PDFImage.this.colorSpace = new PDFColorSpace(new YCCKColorSpace(colorSpace.getColorSpace()));
                                    // re-calculate the color model since the color space has changed
                                    cm = PDFImage.this.createColorModel();
                                    return new BufferedImage(
                                        cm,
                                        Raster.createWritableRaster(raster.getSampleModel(), raster.getDataBuffer(), null),
                                        true,
                                        null);

                                }
                            }
                        }
                    }
                }

                throw new IIOException("Not a YCCK image");

            } else {

                if (param != null && param.getDestination() != null) {
                    // if we've already set up a destination image then we'll use it
                    return jpegReader.read(0, param);
                } else {
                    // otherwise we'll create a new buffered image with the
                    // desired color model
                    return new BufferedImage(cm, jpegReader.read(0, param).getRaster(), true, null);
                }
            }

        }