Class ConverterFactory


  • public class ConverterFactory
    extends java.lang.Object
    This factory class creates IConverter objects for translation between a number of IVideoPicture and BufferedImage types. Not all image and picture types are supported. When an unsupported converter is requested, a descriptive UnsupportedOperationException is thrown.

    Each converter can translate between any supported IPixelFormat.Type and a single BufferedImage type. Converters can optionally resize during the conversion process.

    Each converter will re-sample the IVideoPicture it is converting to get the data in the same native byte layout as a BufferedImage if needed (using IVideoResampler). This step takes time and creates a new temporary copy of the image data. To avoid this step you can make sure the IVideoPicture.getPixelType() is of the same binary type as a BufferedImage.

    Put another way, if you're converting to BufferedImage.TYPE_3BYTE_BGR, we will not resample if the IVideoPicture.getPixelType() is IPixelFormat.Type.BGR24.

    • Field Detail

      • XUGGLER_ARGB_32

        public static final java.lang.String XUGGLER_ARGB_32
        Converts between IVideoPictures and BufferedImage of type BufferedImage.TYPE_INT_ARGB. CATION: The ARGB converter is not currently registered as a converter because the underlying FFMPEG support for ARGB is unstable. If you really need ARGB type, manually register the converter, but be aware that the ARGB images produces may be wrong or broken.
        See Also:
        Constant Field Values
      • XUGGLER_BGR_24

        public static final java.lang.String XUGGLER_BGR_24
        Converts between IVideoPictures and BufferedImage of type BufferedImage.TYPE_3BYTE_BGR
        See Also:
        Constant Field Values
    • Method Detail

      • registerConverter

        public static ConverterFactory.Type registerConverter​(ConverterFactory.Type converterType)
        Register a converter with this factory. The factory oragnizes the converters by descriptor, and thus each should be unique unless one whishes to replace an existing converter.
        Parameters:
        converterType - the type for the converter to be registered
        Returns:
        the converter type which this converter displaced, or NULL of this is a novel converter
      • unregisterConverter

        public static ConverterFactory.Type unregisterConverter​(ConverterFactory.Type converterType)
        Unregister a converter with this factory.
        Parameters:
        converterType - the type for the converter to be unregistered
        Returns:
        the converter type which removed, or NULL of this converter was not recognized
      • getRegisteredConverters

        public static java.util.Collection<ConverterFactory.TypegetRegisteredConverters()
        Get a collection of the registered converters. The collection is unmodifiable.
        Returns:
        an unmodifiable collection of converter types.
      • findRegisteredConverter

        public static ConverterFactory.Type findRegisteredConverter​(java.lang.String descriptor)
        Find a converter given a type descriptor.
        Parameters:
        descriptor - a unique string which describes this converter
        Returns:
        the converter found or NULL if it was not found.
      • findDescriptor

        public static java.lang.String findDescriptor​(java.awt.image.BufferedImage image)
        Find a descriptor given a BufferedImage.
        Parameters:
        image - a buffered image for which to find a descriptor
        Returns:
        the descriptor which matches the image or NULL if it was not found
      • createConverter

        public static IConverter createConverter​(java.lang.String converterDescriptor,
                                                 IVideoPicture picture)
        Create a converter which translates betewen BufferedImage and IVideoPicture types. The IPixelFormat.Type and size are extracted from the passed in picture. This factory will attempt to create a converter which can perform the translation. If no converter can be created, a descriptive UnsupportedOperationException is thrown.
        Parameters:
        converterDescriptor - the unique string descriptor of the converter which is to be created
        picture - the picture from which size and type are extracted
        Throws:
        java.lang.UnsupportedOperationException - if the converter can not be found
        java.lang.UnsupportedOperationException - if the found converter can not be properly initialized
        java.lang.IllegalArgumentException - if the passed IVideoPicture is NULL;
      • createConverter

        public static IConverter createConverter​(java.awt.image.BufferedImage image,
                                                 IPixelFormat.Type pictureType)
        Create a converter which translates betewen BufferedImage and IVideoPicture types. The BufferedImage type and size are extracted from the passed in image. This factory will attempt to create a converter which can perform the translation. If no converter can be created, a descriptive UnsupportedOperationException is thrown.
        Parameters:
        image - the image from which size and type are extracted
        pictureType - the picture type of the converter
        Throws:
        java.lang.UnsupportedOperationException - if no converter for the specifed BufferedImage type exists
        java.lang.UnsupportedOperationException - if the found converter can not be properly initialized
        java.lang.IllegalArgumentException - if the passed BufferedImage is NULL;
      • createConverter

        public static IConverter createConverter​(java.lang.String converterDescriptor,
                                                 IPixelFormat.Type pictureType,
                                                 int width,
                                                 int height)
        Create a converter which translates betewen BufferedImage and IVideoPicture types. This factory will attempt to create a converter which can perform the translation. If no converter can be created, a descriptive UnsupportedOperationException is thrown.
        Parameters:
        converterDescriptor - the unique string descriptor of the converter which is to be created
        pictureType - the picture type of the converter
        width - the width of pictures and images
        height - the height of pictures and images
        Throws:
        java.lang.UnsupportedOperationException - if the converter can not be found
        java.lang.UnsupportedOperationException - if the found converter can not be properly initialized
      • createConverter

        public static IConverter createConverter​(java.lang.String converterDescriptor,
                                                 IPixelFormat.Type pictureType,
                                                 int pictureWidth,
                                                 int pictureHeight,
                                                 int imageWidth,
                                                 int imageHeight)
        Create a converter which translates betewen BufferedImage and IVideoPicture types. This factory will attempt to create a converter which can perform the translation. If different image and pictures sizes are passed the converter will resize during translation. If no converter can be created, a descriptive UnsupportedOperationException is thrown.
        Parameters:
        converterDescriptor - the unique string descriptor of the converter which is to be created
        pictureType - the picture type of the converter
        pictureWidth - the width of pictures
        pictureHeight - the height of pictures
        imageWidth - the width of images
        imageHeight - the height of images
        Throws:
        java.lang.UnsupportedOperationException - if the converter can not be found
        java.lang.UnsupportedOperationException - if the converter can not be properly created or initialized
      • convertToType

        public static java.awt.image.BufferedImage convertToType​(java.awt.image.BufferedImage sourceImage,
                                                                 int targetType)
        Convert a BufferedImage of any type, to BufferedImage of a specified type. If the source image is the same type as the target type, then original image is returned, otherwise new image of the correct type is created and the content of the source image is copied into the new image.
        Parameters:
        sourceImage - the image to be converted
        targetType - the desired BufferedImage type
        Returns:
        a BufferedImage of the specifed target type.
        See Also:
        BufferedImage