Class PackBitsEncoder

  • All Implemented Interfaces:
    Encoder

    public final class PackBitsEncoder
    extends java.lang.Object
    implements Encoder
    Encoder implementation for Apple PackBits run-length encoding.

    From Wikipedia, the free encyclopedia
    PackBits is a fast, simple compression scheme for run-length encoding of data.

    Apple introduced the PackBits format with the release of MacPaint on the Macintosh computer. This compression scheme is one of the types of compression that can be used in TIFF-files.

    A PackBits data stream consists of packets of one byte of header followed by data. The header is a signed byte; the data can be signed, unsigned, or packed (such as MacPaint pixels).

    PackBits
    Header byteData
    0 to 127 1 + n literal bytes of data
    0 to -127 One byte of data, repeated 1 - n times in the decompressed output
    -128 No operation

    Note that interpreting 0 as positive or negative makes no difference in the output. Runs of two bytes adjacent to non-runs are typically written as literal data.

    Version:
    $Id: //depot/branches/personal/haraldk/twelvemonkeys/release-2/twelvemonkeys-core/src/main/java/com/twelvemonkeys/io/enc/PackBitsEncoder.java#1 $
    See Also:
    Understanding PackBits
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private byte[] buffer  
    • Constructor Summary

      Constructors 
      Constructor Description
      PackBitsEncoder()
      Creates a PackBitsEncoder.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void encode​(java.io.OutputStream pStream, byte[] pBuffer, int pOffset, int pLength)  
      void encode​(java.io.OutputStream stream, java.nio.ByteBuffer buffer)
      Encodes up to buffer.remaining() bytes into the given input stream, from the given buffer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • buffer

        private final byte[] buffer
    • Constructor Detail

      • PackBitsEncoder

        public PackBitsEncoder()
        Creates a PackBitsEncoder.
    • Method Detail

      • encode

        public void encode​(java.io.OutputStream stream,
                           java.nio.ByteBuffer buffer)
                    throws java.io.IOException
        Description copied from interface: Encoder
        Encodes up to buffer.remaining() bytes into the given input stream, from the given buffer.
        Specified by:
        encode in interface Encoder
        Parameters:
        stream - the output stream to encode data to
        buffer - buffer to read data from
        Throws:
        java.io.IOException - if an I/O error occurs
      • encode

        private void encode​(java.io.OutputStream pStream,
                            byte[] pBuffer,
                            int pOffset,
                            int pLength)
                     throws java.io.IOException
        Throws:
        java.io.IOException