public final int decode ( final InputStream stream , final ByteBuffer buffer ) throws IOException { // TODO: Allow decoding < row.length at a time and get rid of this assertion... if ( buffer . capacity ( ) < row . length ) { throw new AssertionError ( "This decoder needs a buffer.capacity() of at least one row" ) ; } while ( buffer . remaining ( ) >= row . length && srcY >= 0 ) { // NOTE: Decode only full rows, don't decode if y delta if ( dstX == 0 && srcY == dstY ) { decodeRow ( stream ) ; } int length = Math . min ( row . length - ( dstX * bitsPerSample ) / 8 , buffer . remaining ( ) ) ; buffer . put ( row , 0 , length ) ; dstX += ( length * 8 ) / bitsPerSample ; if ( dstX == ( row . length * 8 ) / bitsPerSample ) { dstX = 0 ; dstY ++ ; // NOTE: If src Y is > dst Y, we have a delta, and have to fill the // gap with zero-bytes if ( srcX > dstX ) { Arrays . fill ( row , 0 , ( srcX * bitsPerSample ) / 8 , ( byte ) 0 ) ; } if ( srcY > dstY ) { Arrays . fill ( row , ( byte ) 0 ) ; } } } return buffer . position ( ) ; }
Decodes as much data as possible from the stream into the buffer .