Copyright 2011-01-06 Werner Randelshofer

ch.randelshofer.media.quicktime
Class AppleRLEEncoder

java.lang.Object
  extended by ch.randelshofer.media.quicktime.AppleRLEEncoder

public class AppleRLEEncoder
extends java.lang.Object

Implements the run length encoding of the Apple QuickTime Animation (RLE) format.

An RLE-encoded frame has the following format:

 Header:
 uint32 chunkSize

 uint16 header 0x0000 => decode entire image
               0x0008 => starting line and number of lines follows
 if header==0x0008 {
   uint16 startingLine at which to begin updating frame
   uint16 reserved 0x0000
   uint16 numberOfLines to update
   uint16 reserved 0x0000
 }
 n-bytes compressed lines
 
The first 4 bytes defines the chunk length. This field also carries some other unknown flags, since at least one of the high bits is sometimes set.
If the overall length of the chunk is less than 8, treat the frame as a NOP, which means that the frame is the same as the one before it.
Next, there is a header of either 0x0000 or 0x0008. A header value with bit 3 set (header & 0x0008) indicates that information follows revealing at which line the decode process is to begin:
 2 bytes    starting line at which to begin updating frame
 2 bytes    unknown
 2 bytes    the number of lines to update
 2 bytes    unknown
 
If the header is 0x0000, then the decode begins from the first line and continues through the entire height of the image.
After the header comes the individual RLE-compressed lines. An individual compressed line is comprised of a skip code, followed by a series of RLE codes and pixel data:
  1 byte     skip code
  1 byte     RLE code
  n bytes    pixel data
  1 byte     RLE code
  n bytes    pixel data
 
After the skip byte is the first RLE code, which is a single signed byte. The RLE code can have the following meanings:

The pixel data has the following format:

References:
http://multimedia.cx/qtrle.txt

Version:
1.0 2011-01-05 Created.
Author:
Werner Randelshofer

Constructor Summary
AppleRLEEncoder()
           
 
Method Summary
 void writeDelta16(javax.imageio.stream.ImageOutputStream out, short[] data, short[] prev, int offset, int length, int step)
          Encodes a 16-bit delta frame.
 void writeDelta24(javax.imageio.stream.ImageOutputStream out, int[] data, int[] prev, int offset, int length, int step)
          Encodes a 24-bit delta frame.
 void writeDelta32(javax.imageio.stream.ImageOutputStream out, int[] data, int[] prev, int offset, int length, int step)
          Encodes a 32-bit delta frame.
 void writeKey16(javax.imageio.stream.ImageOutputStream out, short[] data, int offset, int length, int step)
          Encodes a 16-bit key frame.
 void writeKey24(javax.imageio.stream.ImageOutputStream out, int[] data, int offset, int length, int step)
          Encodes a 24-bit key frame.
 void writeKey32(javax.imageio.stream.ImageOutputStream out, int[] data, int offset, int length, int step)
          Encodes a 32-bit key frame.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AppleRLEEncoder

public AppleRLEEncoder()
Method Detail

writeKey16

public void writeKey16(javax.imageio.stream.ImageOutputStream out,
                       short[] data,
                       int offset,
                       int length,
                       int step)
                throws java.io.IOException
Encodes a 16-bit key frame.

Parameters:
out - The output stream. Must be set to Big-Endian.
data - The image data.
offset - The offset to the first pixel in the data array.
length - The width of the image in data elements.
step - The number to add to offset to get to the next scanline.
Throws:
java.io.IOException

writeDelta16

public void writeDelta16(javax.imageio.stream.ImageOutputStream out,
                         short[] data,
                         short[] prev,
                         int offset,
                         int length,
                         int step)
                  throws java.io.IOException
Encodes a 16-bit delta frame.

Parameters:
out - The output stream. Must be set to Big-Endian.
data - The image data.
prev - The image data of the previous frame.
offset - The offset to the first pixel in the data array.
length - The width of the image in data elements.
step - The number to add to offset to get to the next scanline.
Throws:
java.io.IOException

writeKey24

public void writeKey24(javax.imageio.stream.ImageOutputStream out,
                       int[] data,
                       int offset,
                       int length,
                       int step)
                throws java.io.IOException
Encodes a 24-bit key frame.

Parameters:
out - The output stream. Must be set to Big-Endian.
data - The image data.
offset - The offset to the first pixel in the data array.
length - The width of the image in data elements.
step - The number to add to offset to get to the next scanline.
Throws:
java.io.IOException

writeDelta24

public void writeDelta24(javax.imageio.stream.ImageOutputStream out,
                         int[] data,
                         int[] prev,
                         int offset,
                         int length,
                         int step)
                  throws java.io.IOException
Encodes a 24-bit delta frame.

Parameters:
out - The output stream. Must be set to Big-Endian.
data - The image data.
prev - The image data of the previous frame.
offset - The offset to the first pixel in the data array.
length - The width of the image in data elements.
step - The number to add to offset to get to the next scanline.
Throws:
java.io.IOException

writeKey32

public void writeKey32(javax.imageio.stream.ImageOutputStream out,
                       int[] data,
                       int offset,
                       int length,
                       int step)
                throws java.io.IOException
Encodes a 32-bit key frame.

Parameters:
out - The output stream. Must be set to Big-Endian.
data - The image data.
offset - The offset to the first pixel in the data array.
length - The width of the image in data elements.
step - The number to add to offset to get to the next scanline.
Throws:
java.io.IOException

writeDelta32

public void writeDelta32(javax.imageio.stream.ImageOutputStream out,
                         int[] data,
                         int[] prev,
                         int offset,
                         int length,
                         int step)
                  throws java.io.IOException
Encodes a 32-bit delta frame.

Parameters:
out - The output stream. Must be set to Big-Endian.
data - The image data.
prev - The image data of the previous frame.
offset - The offset to the first pixel in the data array.
length - The width of the image in data elements.
step - The number to add to offset to get to the next scanline.
Throws:
java.io.IOException

Copyright 2011-01-06 Werner Randelshofer