Package com.lightcrafts.mediax.jai.util

Examples of com.lightcrafts.mediax.jai.util.ImagingListener


        if(!SerializableStateImpl.class.isAssignableFrom(ssi)) {
            throw new IllegalArgumentException(JaiI18N.getString("SerializerImpl0"));
        }

        ImagingListener listener =
            ImageUtil.getImagingListener((RenderingHints)null);
        Class[] classes = null;
        try {
            Method m1 = ssi.getMethod("getSupportedClasses", null);
            classes = (Class[])m1.invoke(null, null);
        } catch(java.lang.NoSuchMethodException e) {
            String message = JaiI18N.getString("SerializerImpl1");
            listener.errorOccurred(message,
                                   new RemoteImagingException(message, e),
                                   SerializerImpl.class, false);
        } catch (java.lang.IllegalAccessException e) {
            String message = JaiI18N.getString("SerializerImpl1");
            listener.errorOccurred(message,
                                   new RemoteImagingException(message, e),
                                   SerializerImpl.class, false);
        } catch (java.lang.reflect.InvocationTargetException e) {
            String message = JaiI18N.getString("SerializerImpl1");
            listener.errorOccurred(message,
                                   new RemoteImagingException(message, e),
                                   SerializerImpl.class, false);
        }

        boolean supportsSubclasses = false;
        try {
            Method m2 = ssi.getMethod("permitsSubclasses", null);
            Boolean b = (Boolean)m2.invoke(null, null);
            supportsSubclasses = b.booleanValue();
        } catch(java.lang.NoSuchMethodException e) {
            String message = JaiI18N.getString("SerializerImpl4");
            listener.errorOccurred(message,
                                   new RemoteImagingException(message, e),
                                   SerializerImpl.class, false);
        } catch (java.lang.IllegalAccessException e) {
            String message = JaiI18N.getString("SerializerImpl4");
            listener.errorOccurred(message,
                                   new RemoteImagingException(message, e),
                                   SerializerImpl.class, false);
        } catch (java.lang.reflect.InvocationTargetException e) {
            String message = JaiI18N.getString("SerializerImpl4");
            listener.errorOccurred(message,
                                   new RemoteImagingException(message, e),
                                   SerializerImpl.class, false);
        }

        int numClasses = classes.length;
View Full Code Here


    public boolean permitsSubclasses() {
        return areSubclassesPermitted;
    }

    private void sendExceptionToListener(String message, Exception e) {
        ImagingListener listener =
            ImageUtil.getImagingListener((RenderingHints)null);
        listener.errorOccurred(message,
                               new ImagingException(message, e),
                               this, false);
    }
View Full Code Here

              getDescriptor(registryMode, formatName);
  return (TileCodecDescriptor)registry.getDescriptor(registryMode, formatName);
    }

    void sendExceptionToListener(String message, Exception e) {
        ImagingListener listener= JAI.getDefaultInstance().getImagingListener();
        listener.errorOccurred(message, e, this, false);
    }
View Full Code Here

         java.awt.image.renderable.ParameterBlock.class};

      factoryMethod = factoryClass.getMethod("create", paramTypes);

  } catch (NoSuchMethodException e) {
            ImagingListener listener =
                JAI.getDefaultInstance().getImagingListener();
            String message = JaiI18N.getString("RegistryMode0") + " " +
                             factoryClass.getName() + ".";
            listener.errorOccurred(message, e,
                                   RenderableRegistryMode.class, false);
//      e.printStackTrace();
  }

  return factoryMethod;
View Full Code Here

         java.awt.image.renderable.ParameterBlock.class};

      factoryMethod = factoryClass.getMethod("create", paramTypes);

  } catch (NoSuchMethodException e) {
            ImagingListener listener =
                JAI.getDefaultInstance().getImagingListener();
            String message = JaiI18N.getString("RegistryMode0") + " " +
                             factoryClass.getName() + ".";
            listener.errorOccurred(message, e,
                                   RemoteRenderableRegistryMode.class, false);
//      e.printStackTrace();
  }

  return factoryMethod;
View Full Code Here

         java.awt.RenderingHints.class};

      factoryMethod = factoryClass.getMethod("create", paramTypes);

  } catch (NoSuchMethodException e) {
            ImagingListener listener =
                JAI.getDefaultInstance().getImagingListener();
            String message = JaiI18N.getString("RegistryMode0") + " " +
                             factoryClass.getName() + ".";
            listener.errorOccurred(message, e,
                                   RenderedRegistryMode.class, false);
//      e.printStackTrace();
  }

  return factoryMethod;
View Full Code Here

    /**
     * Creates an image from a SeekableStream.
     */
    public RenderedImage create(ParameterBlock paramBlock,
                                RenderingHints renderHints) {
        ImagingListener listener = ImageUtil.getImagingListener(renderHints);
        SeekableStream src = (SeekableStream)paramBlock.getObjectParameter(0);
        try {
            src.seek(0L);
        } catch (IOException e) {
            listener.errorOccurred(JaiI18N.getString("StreamRIF0"),
                                   e, this, false);
//            e.printStackTrace();
            return null;
        }

        ImageDecodeParam param = null;
        if (paramBlock.getNumParameters() > 1) {
            param = (ImageDecodeParam)paramBlock.getObjectParameter(1);
        }

        String[] names = ImageCodec.getDecoderNames(src);

        OperationRegistry registry =
            JAI.getDefaultInstance().getOperationRegistry();
        int bound = OpImage.OP_IO_BOUND;
        ImageLayout layout = RIFUtil.getImageLayoutHint(renderHints);

        if (renderHints != null) {
            RenderingHints.Key key;

            key = JAI.KEY_OPERATION_REGISTRY;
            if (renderHints.containsKey(key)) {
                registry = (OperationRegistry)renderHints.get(key);
            }

            key = JAI.KEY_OPERATION_BOUND;
            if (renderHints.containsKey(key)) {
                bound = ((Integer)renderHints.get(key)).intValue();
            }
        }

        // Try to create a JAI operation with the given name
        for (int i = 0; i < names.length; i++) {
            RenderedImageFactory rif = null;
            try {
                rif = RIFRegistry.get(registry, names[i]);
            } catch(IllegalArgumentException iae) {
                // ignore IAE.
            }
            if(rif != null) {
                RenderedImage im = RIFRegistry.create(registry, names[i],
                                                      paramBlock, renderHints);
                if (im != null) {
                    return im;
                }
            }
        }

        // Set flag indicating that a recovery may be attempted if
        // an OutOfMemoryError occurs during the decodeAsRenderedImage()
        // call - which is only possible if the stream can seek backwards.
        boolean canAttemptRecovery = src.canSeekBackwards();

        // Save the stream position prior to decodeAsRenderedImage().
        long streamPosition = Long.MIN_VALUE;
        if(canAttemptRecovery) {
            try {
                streamPosition = src.getFilePointer();
            } catch(IOException ioe) {
                listener.errorOccurred(JaiI18N.getString("StreamRIF1"),
                                       ioe, this, false);
                // Unset the recovery attempt flag but otherwise
                // ignore the exception.
                canAttemptRecovery = false;
            }
        }

        // Try to create an ImageDecoder directly
        for (int i = 0; i < names.length; i++) {
            ImageDecoder dec =
                ImageCodec.createImageDecoder(names[i], src, param);
            RenderedImage im = null;
            try {
                im = dec.decodeAsRenderedImage();
            } catch(OutOfMemoryError memoryError) {
                // Ran out of memory - may be due to the decoder being
                // obliged to read the entire image when it creates the
                // RenderedImage it returns.
                if(canAttemptRecovery) {
                    // First flush the cache if one is defined.
                    TileCache cache = RIFUtil.getTileCacheHint(renderHints);
                    if(cache != null) {
                        cache.flush();
                    }

                    // Force garbage collection.
                    System.gc(); //slow

                    try {
                        // Reposition the stream before the previous decoding.
                        src.seek(streamPosition);

                        // Retry image decoding.
                        im = dec.decodeAsRenderedImage();
                    } catch (IOException ioe) {
                        listener.errorOccurred(JaiI18N.getString("StreamRIF2"),
                                               ioe, this, false);
                        im = null;
                    }
                } else {
                    String message = JaiI18N.getString("CodecRIFUtil0");
                    listener.errorOccurred(message,
                                           new ImagingException(message,
                                                                memoryError),
                                           this, false);
                    // Re-throw the error.
//                    throw memoryError;
                }
            } catch (IOException e) {
                listener.errorOccurred(JaiI18N.getString("StreamRIF2"),
                                       e, this, false);
                im = null;
            }

            // If decoding succeeded, wrap the result in an OpImage.
View Full Code Here

                java.awt.image.SampleModel.class};

      factoryMethod = factoryClass.getMethod("createEncoder", paramTypes);

  } catch (NoSuchMethodException e) {
            ImagingListener listener =
                JAI.getDefaultInstance().getImagingListener();
            String message = JaiI18N.getString("RegistryMode0") + " " +
                             factoryClass.getName() + ".";
            listener.errorOccurred(message, e,
                                   TileEncoderRegistryMode.class, false);
//      e.printStackTrace();
  }

  return factoryMethod;
View Full Code Here

         java.awt.RenderingHints.class};

      factoryMethod = factoryClass.getMethod("create", paramTypes);

  } catch (NoSuchMethodException e) {
            ImagingListener listener =
                JAI.getDefaultInstance().getImagingListener();
            String message = JaiI18N.getString("RegistryMode0") + " " +
                             factoryClass.getName() + ".";
            listener.errorOccurred(message, e,
                                   CollectionRegistryMode.class, false);
//      e.printStackTrace();
  }

  return factoryMethod;
View Full Code Here

     * Stores an image to a stream.
     */
    public RenderedImage create(ParameterBlock paramBlock,
                                RenderingHints renderHints) {

        ImagingListener listener = ImageUtil.getImagingListener(renderHints);

        // Retrieve the OutputStream.
        OutputStream stream = (OutputStream)paramBlock.getObjectParameter(0);

        // Retrieve the format.
        String format = (String)paramBlock.getObjectParameter(1);

        // Retrieve the ImageEncodeParam (which may be null).
        ImageEncodeParam param = null;
        if(paramBlock.getNumParameters() > 2) {
            param = (ImageEncodeParam)paramBlock.getObjectParameter(2);
        }

        // Create an ImageEncoder.
        ImageEncoder encoder =
            ImageCodec.createImageEncoder(format, stream, param);

        // Check the ImageEncoder.
        if(encoder == null) {
            throw new RuntimeException(JaiI18N.getString("EncodeRIF0"));
        }

        // Store the data.
        RenderedImage im = (RenderedImage)paramBlock.getSource(0);
        try {
            encoder.encode(im);
            stream.flush();
      // Fix 4665208: EncodeRIF closed the stream after flush
      // User may put more into the stream
            //stream.close();
        } catch (IOException e) {
            String message = JaiI18N.getString("EncodeRIF1") + " " + format;
            listener.errorOccurred(message, e, this, false);
//            e.printStackTrace();
            return null;
        }

        return im;
View Full Code Here

TOP

Related Classes of com.lightcrafts.mediax.jai.util.ImagingListener

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.