Copyright 2012-04-26 Werner Randelshofer

org.monte.media.avi
Class RunLengthCodec

java.lang.Object
  extended by org.monte.media.AbstractCodec
      extended by org.monte.media.AbstractVideoCodec
          extended by org.monte.media.avi.RunLengthCodec
All Implemented Interfaces:
Codec

public class RunLengthCodec
extends AbstractVideoCodec

RunLengthCodec encodes a BufferedImage as a byte[] array.

This codec only works with the AVI file format. Other formats, such as QuickTime, use a different encoding for run-length compressed video.

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

Supported input formats:

Supported output formats: The codec supports lossless delta- and key-frame encoding of images with 8 bits per pixel.

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

A frame is compressed line by line from bottom to top.

Each line of a frame is compressed individually. A line consists of two-byte op-codes optionally followed by data. The end of the line is marked with the EOL op-code.

The following op-codes are supported:

Example:
 Compressed data         Expanded data

 03 04                   04 04 04
 05 06                   06 06 06 06 06
 00 03 45 56 67 00       45 56 67
 02 78                   78 78
 00 02 05 01             Move 5 right and 1 down
 02 78                   78 78
 00 00                   End of line
 09 1E                   1E 1E 1E 1E 1E 1E 1E 1E 1E
 00 01                   End of RLE bitmap
 
References:
http://wiki.multimedia.cx/index.php?title=Microsoft_RLE

Version:
$Id: RunLengthCodec.java 186 2012-03-28 11:18:42Z werner $
Author:
Werner Randelshofer

Field Summary
 
Fields inherited from class org.monte.media.AbstractCodec
inputFormat, inputFormats, name, outputFormat, outputFormats
 
Fields inherited from interface org.monte.media.Codec
CODEC_FAILED, CODEC_INPUT_NOT_CONSUMED, CODEC_OK, CODEC_OUTPUT_NOT_FILLED
 
Constructor Summary
RunLengthCodec()
           
 
Method Summary
 int process(Buffer in, Buffer out)
          Performs the media processing defined by this codec.
 void reset()
          Empty implementation of the reset method.
 void writeDelta8(javax.imageio.stream.ImageOutputStream out, byte[] data, byte[] prev, int width, int height, int offset, int scanlineStride)
          Encodes an 8-bit delta frame.
 void writeDelta8(java.io.OutputStream out, byte[] data, byte[] prev, int width, int height, int offset, int scanlineStride)
          Encodes an 8-bit key frame.
 void writeKey8(javax.imageio.stream.ImageOutputStream out, byte[] data, int width, int height, int offset, int scanlineStride)
          Encodes an 8-bit key frame.
 void writeKey8(java.io.OutputStream out, byte[] data, int width, int height, int offset, int scanlineStride)
          Encodes an 8-bit key frame.
 
Methods inherited from class org.monte.media.AbstractVideoCodec
copyImage, getARGB32, getBufferedImage, getIndexed8, getRGB15, getRGB16, getRGB24, writeInt24, writeInt24LE, writeInts24, writeInts24LE
 
Methods inherited from class org.monte.media.AbstractCodec
getInputFormat, getInputFormats, getName, getOutputFormat, getOutputFormats, setInputFormat, setOutputFormat, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

RunLengthCodec

public RunLengthCodec()
Method Detail

reset

public void reset()
Description copied from class: AbstractCodec
Empty implementation of the reset method. Don't call super.

Specified by:
reset in interface Codec
Overrides:
reset 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.

writeKey8

public void writeKey8(java.io.OutputStream out,
                      byte[] data,
                      int width,
                      int height,
                      int offset,
                      int scanlineStride)
               throws java.io.IOException
Encodes an 8-bit key frame.

Parameters:
out - The output stream.
data - The image data.
offset - The offset to the first pixel in the data array.
width - The width of the image in data elements.
scanlineStride - The number to append to offset to get to the next scanline.
Throws:
java.io.IOException

writeKey8

public void writeKey8(javax.imageio.stream.ImageOutputStream out,
                      byte[] data,
                      int width,
                      int height,
                      int offset,
                      int scanlineStride)
               throws java.io.IOException
Encodes an 8-bit key frame.

Parameters:
out - The output stream.
data - The image data.
offset - The offset to the first pixel in the data array.
width - The width of the image in data elements.
scanlineStride - The number to append to offset to get to the next scanline.
Throws:
java.io.IOException

writeDelta8

public void writeDelta8(java.io.OutputStream out,
                        byte[] data,
                        byte[] prev,
                        int width,
                        int height,
                        int offset,
                        int scanlineStride)
                 throws java.io.IOException
Encodes an 8-bit key frame.

Parameters:
out - The output stream.
data - The image data.
offset - The offset to the first pixel in the data array.
width - The width of the image in data elements.
scanlineStride - The number to append to offset to get to the next scanline.
Throws:
java.io.IOException

writeDelta8

public void writeDelta8(javax.imageio.stream.ImageOutputStream out,
                        byte[] data,
                        byte[] prev,
                        int width,
                        int height,
                        int offset,
                        int scanlineStride)
                 throws java.io.IOException
Encodes an 8-bit delta frame.

Parameters:
out - The output stream.
data - The image data.
prev - The image data of the previous frame.
offset - The offset to the first pixel in the data array.
width - The width of the image in data elements.
scanlineStride - The number to append to offset to get to the next scanline.
Throws:
java.io.IOException

Copyright 2012-04-26 Werner Randelshofer