Class DIBCodec

All Implemented Interfaces:
Codec

public class DIBCodec extends AbstractVideoCodec
DIBCodec encodes a BufferedImage as a Microsoft Device Independent Bitmap (DIB) into a byte array.

The DIB codec only works with the AVI file format. Other file formats, such as QuickTime, use a different encoding for uncompressed video.

This codec currently only supports encoding from a BufferedImage into the file format. Decoding support may be added in the future.

This codec does not encode the color palette of an image. This must be done separately.

The pixels of a frame are written row by row from bottom to top and from the left to the right. 24-bit pixels are encoded as BGR.

Supported input formats:

  • Format with BufferedImage.class, any width, any height, depth=4.
Supported output formats:
  • Format with byte[].class, same width and height as input format, depth=4.
Author:
Werner Randelshofer
  • Constructor Details

    • DIBCodec

      public DIBCodec()
  • Method Details

    • setOutputFormat

      public Format setOutputFormat(Format f)
      Description copied from interface: Codec
      Sets the output format. Returns the format that was actually set. This is the closest format that the Codec supports. Returns null if the specified format is not supported and no reasonable match could be found.
      Specified by:
      setOutputFormat in interface Codec
      Overrides:
      setOutputFormat in class AbstractCodec
    • process

      public int process(Buffer in, Buffer out)
      Description copied from interface: Codec
      Performs the media processing defined by this codec.

      Copies the data from the input buffer into the output buffer.

      Returns:
      A combination of processing flags.
    • decode

      public int decode(Buffer in, Buffer out)
    • encode

      public int encode(Buffer in, Buffer out)
    • readKey4

      public void readKey4(byte[] in, int offset, int length, BufferedImage img)
    • readKey8

      public void readKey8(byte[] in, int offset, int length, BufferedImage img)
    • readKey24

      public void readKey24(byte[] in, int offset, int length, BufferedImage img)
    • writeKey4

      public void writeKey4(OutputStream out, byte[] pixels, int width, int height, int offset, int scanlineStride) throws IOException
      Encodes a 4-bit key frame.
      Parameters:
      out - The output stream.
      pixels - The image data.
      width - The width of the image in data elements.
      offset - The offset to the first pixel in the data array.
      scanlineStride - The number to append to offset to get to the next scanline.
      Throws:
      IOException
    • writeKey8

      public void writeKey8(OutputStream out, byte[] pixels, int width, int height, int offset, int scanlineStride) throws IOException
      Encodes an 8-bit key frame.
      Parameters:
      out - The output stream.
      pixels - The image data.
      width - The width of the image in data elements.
      offset - The offset to the first pixel in the data array.
      scanlineStride - The number to append to offset to get to the next scanline.
      Throws:
      IOException
    • writeKey24

      public void writeKey24(OutputStream out, int[] pixels, int width, int height, int offset, int scanlineStride) throws IOException
      Encodes a 24-bit key frame.
      Parameters:
      out - The output stream.
      pixels - The image data.
      width - The width of the image in data elements.
      offset - The offset to the first pixel in the data array.
      scanlineStride - The number to append to offset to get to the next scanline.
      Throws:
      IOException