public void decodeRAW ( ByteBuffer [ ] buffer , int [ ] strides , int numMCURows ) throws IOException { if ( ! insideSOS ) { throw new IllegalStateException ( "decode not started" ) ; } if ( numMCURows <= 0 || currentMCURow + numMCURows > mcuCountY ) { throw new IllegalArgumentException ( "numMCURows" ) ; } int scanN = order . length ; if ( scanN != components . length ) { throw new UnsupportedOperationException ( "for RAW decode all components need to be decoded at once" ) ; } if ( scanN > buffer . length || scanN > strides . length ) { throw new IllegalArgumentException ( "not enough buffers" ) ; } for ( int compIdx = 0 ; compIdx < scanN ; compIdx ++ ) { order [ compIdx ] . outPos = buffer [ compIdx ] . position ( ) ; } outer : for ( int j = 0 ; j < numMCURows ; j ++ ) { ++ currentMCURow ; for ( int i = 0 ; i < mcuCountX ; i ++ ) { for ( int compIdx = 0 ; compIdx < scanN ; compIdx ++ ) { Component c = order [ compIdx ] ; int outStride = strides [ compIdx ] ; int outPosY = c . outPos + 8 * ( i * c . blocksPerMCUHorz + j * c . blocksPerMCUVert * outStride ) ; for ( int y = 0 ; y < c . blocksPerMCUVert ; y ++ , outPosY += 8 * outStride ) { for ( int x = 0 , outPos = outPosY ; x < c . blocksPerMCUHorz ; x ++ , outPos += 8 ) { try { decodeBlock ( data , c ) ; } catch ( ArrayIndexOutOfBoundsException ex ) { throwBadHuffmanCode ( ) ; } idct2D . compute ( buffer [ compIdx ] , outPos , outStride , data ) ; } } } if ( -- todo <= 0 ) { if ( ! checkRestart ( ) ) { break outer ; } } } } checkDecodeEnd ( ) ; for ( int compIdx = 0 ; compIdx < scanN ; compIdx ++ ) { Component c = order [ compIdx ] ; buffer [ compIdx ] . position ( c . outPos + numMCURows * c . blocksPerMCUVert * 8 * strides [ compIdx ] ) ; } }
Decodes each color component of the JPEG file separately into a separate ByteBuffer . The number of buffers must match the number of color channels . Each color channel can have a different sub sampling factor .