Package com.avpkit.core.video
Class ConverterFactory
- java.lang.Object
-
- com.avpkit.core.video.ConverterFactory
-
public class ConverterFactory extends java.lang.Object
This factory class createsIConverterobjects for translation between a number ofIVideoPictureandBufferedImagetypes. Not all image and picture types are supported. When an unsupported converter is requested, a descriptiveUnsupportedOperationExceptionis thrown.Each converter can translate between any supported
IPixelFormat.Typeand a singleBufferedImagetype. Converters can optionally resize during the conversion process.Each converter will re-sample the
IVideoPictureit is converting to get the data in the same native byte layout as aBufferedImageif needed (usingIVideoResampler). This step takes time and creates a new temporary copy of the image data. To avoid this step you can make sure theIVideoPicture.getPixelType()is of the same binary type as aBufferedImage.Put another way, if you're converting to
BufferedImage.TYPE_3BYTE_BGR, we will not resample if theIVideoPicture.getPixelType()isIPixelFormat.Type.BGR24.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classConverterFactory.TypeThis class describes a converter type and is used to register and unregister types withConverterFactory.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringXUGGLER_ARGB_32Converts between IVideoPictures andBufferedImageof typeBufferedImage.TYPE_INT_ARGB.static java.lang.StringXUGGLER_BGR_24Converts between IVideoPictures andBufferedImageof typeBufferedImage.TYPE_3BYTE_BGR
-
Constructor Summary
Constructors Modifier Constructor Description protectedConverterFactory()Default constructor
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static java.awt.image.BufferedImageconvertToType(java.awt.image.BufferedImage sourceImage, int targetType)Convert aBufferedImageof any type, toBufferedImageof a specified type.static IConvertercreateConverter(java.awt.image.BufferedImage image, IPixelFormat.Type pictureType)Create a converter which translates betewenBufferedImageandIVideoPicturetypes.static IConvertercreateConverter(java.lang.String converterDescriptor, IPixelFormat.Type pictureType, int width, int height)Create a converter which translates betewenBufferedImageandIVideoPicturetypes.static IConvertercreateConverter(java.lang.String converterDescriptor, IPixelFormat.Type pictureType, int pictureWidth, int pictureHeight, int imageWidth, int imageHeight)Create a converter which translates betewenBufferedImageandIVideoPicturetypes.static IConvertercreateConverter(java.lang.String converterDescriptor, IVideoPicture picture)Create a converter which translates betewenBufferedImageandIVideoPicturetypes.static java.lang.StringfindDescriptor(java.awt.image.BufferedImage image)Find a descriptor given aBufferedImage.static ConverterFactory.TypefindRegisteredConverter(java.lang.String descriptor)Find a converter given a type descriptor.static java.util.Collection<ConverterFactory.Type>getRegisteredConverters()Get a collection of the registered converters.static ConverterFactory.TyperegisterConverter(ConverterFactory.Type converterType)Register a converter with this factory.static ConverterFactory.TypeunregisterConverter(ConverterFactory.Type converterType)Unregister a converter with this factory.
-
-
-
Field Detail
-
XUGGLER_ARGB_32
public static final java.lang.String XUGGLER_ARGB_32
Converts between IVideoPictures andBufferedImageof typeBufferedImage.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 andBufferedImageof typeBufferedImage.TYPE_3BYTE_BGR- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ConverterFactory
protected ConverterFactory()
Default constructor
-
-
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.Type> getRegisteredConverters()
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 aBufferedImage.- 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 betewenBufferedImageandIVideoPicturetypes. TheIPixelFormat.Typeand 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 descriptiveUnsupportedOperationExceptionis thrown.- Parameters:
converterDescriptor- the unique string descriptor of the converter which is to be createdpicture- the picture from which size and type are extracted- Throws:
java.lang.UnsupportedOperationException- if the converter can not be foundjava.lang.UnsupportedOperationException- if the found converter can not be properly initializedjava.lang.IllegalArgumentException- if the passedIVideoPictureis NULL;
-
createConverter
public static IConverter createConverter(java.awt.image.BufferedImage image, IPixelFormat.Type pictureType)
Create a converter which translates betewenBufferedImageandIVideoPicturetypes. TheBufferedImagetype 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 descriptiveUnsupportedOperationExceptionis thrown.- Parameters:
image- the image from which size and type are extractedpictureType- the picture type of the converter- Throws:
java.lang.UnsupportedOperationException- if no converter for the specifed BufferedImage type existsjava.lang.UnsupportedOperationException- if the found converter can not be properly initializedjava.lang.IllegalArgumentException- if the passedBufferedImageis NULL;
-
createConverter
public static IConverter createConverter(java.lang.String converterDescriptor, IPixelFormat.Type pictureType, int width, int height)
Create a converter which translates betewenBufferedImageandIVideoPicturetypes. This factory will attempt to create a converter which can perform the translation. If no converter can be created, a descriptiveUnsupportedOperationExceptionis thrown.- Parameters:
converterDescriptor- the unique string descriptor of the converter which is to be createdpictureType- the picture type of the converterwidth- the width of pictures and imagesheight- the height of pictures and images- Throws:
java.lang.UnsupportedOperationException- if the converter can not be foundjava.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 betewenBufferedImageandIVideoPicturetypes. 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 descriptiveUnsupportedOperationExceptionis thrown.- Parameters:
converterDescriptor- the unique string descriptor of the converter which is to be createdpictureType- the picture type of the converterpictureWidth- the width of picturespictureHeight- the height of picturesimageWidth- the width of imagesimageHeight- the height of images- Throws:
java.lang.UnsupportedOperationException- if the converter can not be foundjava.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 aBufferedImageof any type, toBufferedImageof 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 convertedtargetType- the desired BufferedImage type- Returns:
- a BufferedImage of the specifed target type.
- See Also:
BufferedImage
-
-