/* */
/* */ public class CodecRIFUtil
/* */ {
/* */ public static RenderedImage create(String type, ParameterBlock paramBlock, RenderingHints renderHints)
/* */ {
/* 46 */ ImagingListener listener = ImageUtil.getImagingListener(renderHints);
/* */
/* 48 */ SeekableStream source = (SeekableStream)paramBlock.getObjectParameter(0);
/* */
/* 51 */ ImageDecodeParam param = null;
/* 52 */ if (paramBlock.getNumParameters() > 1) {
/* 53 */ param = (ImageDecodeParam)paramBlock.getObjectParameter(1);
/* */ }
/* 55 */ int page = 0;
/* 56 */ if (paramBlock.getNumParameters() > 2) {
/* 57 */ page = paramBlock.getIntParameter(2);
/* */ }
/* */
/* 60 */ ImageDecoder dec = ImageCodec.createImageDecoder(type, source, param);
/* */ try {
/* 62 */ int bound = 2;
/* 63 */ ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);
/* */
/* 65 */ if (renderHints != null)
/* */ {
/* 68 */ RenderingHints.Key key = JAI.KEY_OPERATION_BOUND;
/* 69 */ if (renderHints.containsKey(key)) {
/* 70 */ bound = ((Integer)renderHints.get(key)).intValue();
/* */ }
/* */
/* */ }
/* */
/* 77 */ boolean canAttemptRecovery = source.canSeekBackwards();
/* */
/* 80 */ long streamPosition = -9223372036854775808L;
/* 81 */ if (canAttemptRecovery) {
/* */ try {
/* 83 */ streamPosition = source.getFilePointer();
/* */ } catch (IOException ioe) {
/* 85 */ listener.errorOccurred(JaiI18N.getString("StreamRIF1"), ioe, CodecRIFUtil.class, false);
/* */
/* 89 */ canAttemptRecovery = false;
/* */ }
/* */ }
/* */
/* 93 */ OpImage image = null;
/* */ try
/* */ {
/* 96 */ image = new NullOpImage(dec.decodeAsRenderedImage(page), layout, renderHints, bound);
/* */ }
/* */ catch (OutOfMemoryError memoryError)
/* */ {
/* 104 */ if (canAttemptRecovery)
/* */ {
/* 106 */ TileCache cache = image != null ? image.getTileCache() : RIFUtil.getTileCacheHint(renderHints);
/* */
/* 109 */ if (cache != null) {
/* 110 */ cache.flush();
/* */ }
/* */
/* 114 */ System.gc();
/* */
/* 117 */ source.seek(streamPosition);
/* */
/* 120 */ image = new NullOpImage(dec.decodeAsRenderedImage(page), layout, renderHints, bound);
/* */ }
/* */ else
/* */ {
/* 126 */ String message = JaiI18N.getString("CodecRIFUtil0");
/* 127 */ listener.errorOccurred(message, new ImagingException(message, memoryError), CodecRIFUtil.class, false);
/* */ }
/* */
/* */ }
/* */
/* 135 */ return image;
/* */ } catch (Exception e) {
/* 137 */ listener.errorOccurred(JaiI18N.getString("CodecRIFUtil1"), e, CodecRIFUtil.class, false);
/* */ }
/* */
/* 140 */ return null;
/* */ }