Buggy code:
} else { fis = new FileInputStream ( getMetadata ( ) . idsId ) ; toSkip += getMetadata ( ) . offset ; } try { gzipStream = new GZIPInputStream ( fis ) ; } catch ( final IOException e ) { gzip = false ; getStream ( ) . seek ( ( ( getMetadata ( ) . offset ) + ( planeIndex * len ) ) ) ; gzipStream = null ; } } if ( ( gzipStream ) != null ) { while ( toSkip > 0 ) { toSkip -= gzipStream . skip ( toSkip ) ; } data = new byte [ ( ( int ) ( len * ( meta . storedRGB ( ) ? meta . get ( imageIndex ) . getAxisLength ( CHANNEL ) : 1 ) ) ) ] ; int toRead = data . length ; while ( toRead > 0 ) { toRead -= gzipStream . read ( data , ( ( data . length ) - toRead ) , toRead ) ; } } } final int sizeC = ( ( int ) ( ( meta . getLifetime ( ) ) ? 1 : meta . get ( imageIndex ) . getAxisLength ( CHANNEL ) ) ) ; if ( ( ! ( getMetadata ( ) . get ( imageIndex ) . isMultichannel ( ) ) ) && ( getMetadata ( ) . storedRGB ( ) ) ) { getStream ( ) . seek ( ( ( getMetadata ( ) . offset ) + ( len * ( FormatTools . positionToRaster ( 0 , this , new long [ ] { coordinates [ 0 ] , 0 , coordinates [ 2 ] } ) ) ) ) ) ; if ( ( ! ( gzip ) ) && ( ( data ) == null ) ) { data = new byte [ ( ( int ) ( len * ( getMetadata ( ) . get ( imageIndex ) . getAxisLength ( CHANNEL ) ) ) ) ] ; getStream ( ) . read ( data ) ; } else if ( ( ! ( gzip ) ) && ( ( ( coordinates [ 0 ] ) != ( prevCoordinates [ 0 ] ) ) || ( ( coordinates [ 2 ] ) != ( prevCoordinates [ 2 ] ) ) ) ) { getStream ( ) . read ( data ) ; } for ( int row = y ; row < ( h + y ) ; row ++ ) { for ( int col = x ; col < ( w + x ) ; col ++ ) { final int src = ( ( int ) ( bpp * ( ( planeIndex % ( meta . get ( imageIndex ) . getAxisLength ( CHANNEL ) ) ) + ( sizeC * ( row * ( ( row * ( meta . get ( imageIndex ) . getAxisLength ( X ) ) ) + col ) ) ) ) ) ) ; final int dest = bpp * ( ( ( row - y ) * w ) + ( col - x ) ) ; System . arraycopy ( data , src , plane . getBytes ( ) , dest , bpp ) ; } } } else if ( gzip ) { final RandomAccessInputStream s = new RandomAccessInputStream ( getContext ( ) , data ) ; readPlane ( s , imageIndex , planeMin , planeMax , plane ) ; s . close ( ) ; } else { readPlane ( getStream ( ) , imageIndex , planeMin , planeMax , plane ) ; } if ( invertY ) { final byte [ ] row = new byte [ rowLen ] ; for ( int r = 0 ; r < ( h // 2 ) ; r ++ ) { final int topOffset = r * rowLen ; final int bottomOffset = ( ( h - r ) - 1 ) * rowLen ; System . arraycopy ( plane . getBytes ( ) , topOffset , row , 0 , rowLen ) ; <START_BUG> System . arraycopy ( plane . getBytes ( ) , bottomOffset , plane , topOffset , rowLen ) ; <END_BUG> System . arraycopy ( row , 0 , plane . getBytes ( ) , bottomOffset , rowLen ) ; } } prevPlane = planeIndex ; return plane ; } @ Override public void close ( final boolean fileOnly ) throws IOException { } @ Override public void setMetadata ( final ICSFormat . Metadata meta ) throws IOException { } @ Override public void setSource ( final RandomAccessInputStream stream , final SCIFIOConfig config ) throws IOException { } @ Override public String [ ] getDomains ( ) { } } public static class Writer extends AbstractWriter < ICSFormat . Metadata > { private long dimensionOffset ; private int dimensionLength ; private long pixelOffset ; private long lastPlane = - 1 ; private RandomAccessOutputStream pixels ; @ Override protected String [ ] makeCompressionTypes ( ) { } @ Override protected void initialize ( final int imageIndex , final long planeIndex , final long [ ] planeMin , final long [ ] planeMax ) throws FormatException , IOException { } @ Override public void writePlane ( final int imageIndex , final long planeIndex , final Plane plane , final long [ ] planeMin , final long [ ] planeMax ) throws FormatException , IOException { } @ Override public boolean canDoStacks ( ) { } @ Override public int [ ] getPixelTypes ( final String codec ) { } public void close ( final int imageIndex ) throws IOException { } @ Override public void setDest ( final String id ) throws FormatException , IOException { } @ Override public void setDest ( final String id , final int imageIndex ) throws FormatException , IOException { }

Fix:
System . arraycopy ( plane . getBytes ( ) , bottomOffset , plane . getBytes ( ) , topOffset , rowLen ) ;