Class SwScale

  • All Implemented Interfaces:
    javax.media.Codec, javax.media.Controls, javax.media.PlugIn

    public class SwScale
    extends net.sf.fmj.media.AbstractCodec
    Implements an FMJ Codec which uses libswscale to scale images and convert between color spaces (typically, RGB and YUV).
    Author:
    Sebastien Vincent, Lyubomir Marinov
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int MIN_SWS_SCALE_HEIGHT_OR_WIDTH
      The minimum height and/or width of the input and/or output to be passed to sws_scale in order to prevent its crashing.
      • Fields inherited from class net.sf.fmj.media.AbstractCodec

        inputFormat, inputFormats, opened, outputFormat
      • Fields inherited from interface javax.media.PlugIn

        BUFFER_PROCESSED_FAILED, BUFFER_PROCESSED_OK, INPUT_BUFFER_NOT_CONSUMED, OUTPUT_BUFFER_NOT_FILLED, PLUGIN_TERMINATED
    • Constructor Summary

      Constructors 
      Constructor Description
      SwScale()
      Initializes a new SwScale instance which doesn't have an output size and will use a default one when it becomes necessary unless an explicit one is specified in the meantime.
      SwScale​(boolean fixOddYuv420Size)
      Initializes a new SwScale instance which can optionally attempt to keep the width and height of YUV 420 output even.
      SwScale​(boolean fixOddYuv420Size, boolean preserveAspectRatio)
      Initializes a new SwScale instance which can optionally attempt to keep the width and height of YUV 420 output even and to preserve the aspect ratio of the video frames provided to the instance as input to be processed.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()
      Close codec.
      javax.media.Format getInputFormat()
      Gets the Format in which this Codec is currently configured to accept input media data.
      Dimension getOutputSize()
      Gets the output size.
      javax.media.Format[] getSupportedOutputFormats​(javax.media.Format input)
      Gets the supported output formats for an input one.
      int process​(javax.media.Buffer in, javax.media.Buffer out)
      Processes (converts color space and/or scales) an input Buffer into an output Buffer.
      javax.media.Format setInputFormat​(javax.media.Format format)
      Sets the input format.
      javax.media.Format setOutputFormat​(javax.media.Format format)
      Sets the Format in which this Codec is to output media data.
      void setOutputSize​(Dimension size)
      Sets the output size.
      • Methods inherited from class net.sf.fmj.media.AbstractCodec

        checkInputBuffer, dump, getOutputFormat, getSupportedInputFormats, isEOM, propagateEOM
      • Methods inherited from class net.sf.fmj.media.AbstractPlugIn

        getName, open, reset
      • Methods inherited from class net.sf.fmj.media.AbstractControls

        addControl, getControl, getControls, removeControl
      • Methods inherited from interface javax.media.Controls

        getControl, getControls
      • Methods inherited from interface javax.media.PlugIn

        getName, open, reset
    • Field Detail

      • MIN_SWS_SCALE_HEIGHT_OR_WIDTH

        public static final int MIN_SWS_SCALE_HEIGHT_OR_WIDTH
        The minimum height and/or width of the input and/or output to be passed to sws_scale in order to prevent its crashing.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SwScale

        public SwScale()
        Initializes a new SwScale instance which doesn't have an output size and will use a default one when it becomes necessary unless an explicit one is specified in the meantime.
      • SwScale

        public SwScale​(boolean fixOddYuv420Size)
        Initializes a new SwScale instance which can optionally attempt to keep the width and height of YUV 420 output even.
        Parameters:
        fixOddYuv420Size - true to have the new instance keep the width and height of YUV 420 output even; otherwise, false
      • SwScale

        public SwScale​(boolean fixOddYuv420Size,
                       boolean preserveAspectRatio)
        Initializes a new SwScale instance which can optionally attempt to keep the width and height of YUV 420 output even and to preserve the aspect ratio of the video frames provided to the instance as input to be processed.
        Parameters:
        fixOddYuv420Size - true to have the new instance keep the width and height of YUV 420 output even; otherwise, false
        preserveAspectRatio - true to have the new instance preserve the aspect ratio of the video frames provided to it as input to be processed; otherwise, false
    • Method Detail

      • close

        public void close()
        Close codec.
        Specified by:
        close in interface javax.media.PlugIn
        Overrides:
        close in class net.sf.fmj.media.AbstractPlugIn
      • getInputFormat

        public javax.media.Format getInputFormat()
        Gets the Format in which this Codec is currently configured to accept input media data.

        Makes the protected super implementation public.

        Overrides:
        getInputFormat in class net.sf.fmj.media.AbstractCodec
        Returns:
        the Format in which this Codec is currently configured to accept input media data
        See Also:
        AbstractCodec.getInputFormat()
      • getOutputSize

        public Dimension getOutputSize()
        Gets the output size.
        Returns:
        the output size
      • getSupportedOutputFormats

        public javax.media.Format[] getSupportedOutputFormats​(javax.media.Format input)
        Gets the supported output formats for an input one.
        Specified by:
        getSupportedOutputFormats in interface javax.media.Codec
        Specified by:
        getSupportedOutputFormats in class net.sf.fmj.media.AbstractCodec
        Parameters:
        input - input format to get supported output ones for
        Returns:
        array of supported output formats
      • process

        public int process​(javax.media.Buffer in,
                           javax.media.Buffer out)
        Processes (converts color space and/or scales) an input Buffer into an output Buffer.
        Specified by:
        process in interface javax.media.Codec
        Specified by:
        process in class net.sf.fmj.media.AbstractCodec
        Parameters:
        in - the input Buffer to process (from)
        out - the output Buffer to process into
        Returns:
        BUFFER_PROCESSED_OK if in has been successfully processed into out
      • setInputFormat

        public javax.media.Format setInputFormat​(javax.media.Format format)
        Sets the input format.
        Specified by:
        setInputFormat in interface javax.media.Codec
        Overrides:
        setInputFormat in class net.sf.fmj.media.AbstractCodec
        Parameters:
        format - format to set
        Returns:
        format
      • setOutputFormat

        public javax.media.Format setOutputFormat​(javax.media.Format format)
        Sets the Format in which this Codec is to output media data.
        Specified by:
        setOutputFormat in interface javax.media.Codec
        Overrides:
        setOutputFormat in class net.sf.fmj.media.AbstractCodec
        Parameters:
        format - the Format in which this Codec is to output media data
        Returns:
        the Format in which this Codec is currently configured to output media data or null if format was found to be incompatible with this Codec
      • setOutputSize

        public void setOutputSize​(Dimension size)
        Sets the output size.
        Parameters:
        size - the size to set as the output size