Class AbstractRLEDecoder

  • All Implemented Interfaces:
    Decoder
    Direct Known Subclasses:
    RLE4Decoder, RLE8Decoder

    abstract class AbstractRLEDecoder
    extends java.lang.Object
    implements Decoder
    Abstract base class for RLE decoding as specified by in the Windows BMP (aka DIB) file format.
    Version:
    $Id: AbstractRLEDecoder.java#1 $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int bitsPerSample  
      protected int dstX  
      protected int dstY  
      protected byte[] row  
      protected int srcX  
      protected int srcY  
      protected int width  
    • Constructor Summary

      Constructors 
      Constructor Description
      AbstractRLEDecoder​(int width, int bitsPerSample)
      Creates an RLEDecoder.
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected static int checkEOF​(int val)
      Checks a read byte for EOF marker.
      int decode​(java.io.InputStream stream, java.nio.ByteBuffer buffer)
      Decodes as much data as possible, from the stream into the buffer.
      protected abstract void decodeRow​(java.io.InputStream stream)
      Decodes one full row of image data.
      • Methods inherited from class java.lang.Object

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

      • width

        protected final int width
      • bitsPerSample

        protected final int bitsPerSample
      • row

        protected final byte[] row
      • srcX

        protected int srcX
      • srcY

        protected int srcY
      • dstX

        protected int dstX
      • dstY

        protected int dstY
    • Constructor Detail

      • AbstractRLEDecoder

        AbstractRLEDecoder​(int width,
                           int bitsPerSample)
        Creates an RLEDecoder. As RLE encoded BMPs may contain x and y deltas, etc, we need to know height and width of the image.
        Parameters:
        width - width of the image
        bitsPerSample - pits per sample
    • Method Detail

      • decodeRow

        protected abstract void decodeRow​(java.io.InputStream stream)
                                   throws java.io.IOException
        Decodes one full row of image data.
        Parameters:
        stream - the input stream containing RLE data
        Throws:
        java.io.IOException - if an I/O related exception occurs while reading
      • decode

        public final int decode​(java.io.InputStream stream,
                                java.nio.ByteBuffer buffer)
                         throws java.io.IOException
        Decodes as much data as possible, from the stream into the buffer.
        Specified by:
        decode in interface Decoder
        Parameters:
        stream - the input stream containing RLE data
        buffer - the buffer to decode the data to
        Returns:
        the number of bytes decoded from the stream, to the buffer
        Throws:
        java.io.IOException - if an I/O related exception occurs while reading
      • checkEOF

        protected static int checkEOF​(int val)
                               throws java.io.EOFException
        Checks a read byte for EOF marker.
        Parameters:
        val - the byte to check
        Returns:
        the value of val if positive.
        Throws:
        java.io.EOFException - if val is negative