private static void computeRegions(Rectangle sourceBounds,Dimension destSize,ImageWriteParam p){
  ImageWriteParam param;
  int periodX=1;
  int periodY=1;
  if (p != null) {
    int[] sourceBands=p.getSourceBands();
    if (sourceBands != null && (sourceBands.length != 1 || sourceBands[0] != 0)) {
      throw new IllegalArgumentException("Cannot sub-band image!");
    }
    Rectangle sourceRegion=p.getSourceRegion();
    if (sourceRegion != null) {
      sourceRegion=sourceRegion.intersection(sourceBounds);
      sourceBounds.setBounds(sourceRegion);
    }
    int gridX=p.getSubsamplingXOffset();
    int gridY=p.getSubsamplingYOffset();
    sourceBounds.x+=gridX;
    sourceBounds.y+=gridY;
    sourceBounds.width-=gridX;
    sourceBounds.height-=gridY;
    periodX=p.getSourceXSubsampling();
    periodY=p.getSourceYSubsampling();
  }
  destSize.setSize((sourceBounds.width + periodX - 1) / periodX,(sourceBounds.height + periodY - 1) / periodY);
  if (destSize.width <= 0 || destSize.height <= 0) {
    throw new IllegalArgumentException("Empty source region!");
  }
}

private static void computeRegions ( Rectangle sourceBounds , Dimension destSize , ImageWriteParam p ) { ImageWriteParam param ; int periodX = 1 ; int periodY = 1 ; if ( p != null ) { int [ ] sourceBands = p . getSourceBands ( ) ; if ( sourceBands != null && ( sourceBands . length != 1 || sourceBands [ 0 ] != 0 ) ) { throw new IllegalArgumentException ( "Cannot sub-band image!" ) ; } Rectangle sourceRegion = p . getSourceRegion ( ) ; if ( sourceRegion != null ) { sourceRegion = sourceRegion . intersection ( sourceBounds ) ; sourceBounds . setBounds ( sourceRegion ) ; } int gridX = p . getSubsamplingXOffset ( ) ; int gridY = p . getSubsamplingYOffset ( ) ; sourceBounds . x += gridX ; sourceBounds . y += gridY ; sourceBounds . width -= gridX ; sourceBounds . height -= gridY ; periodX = p . getSourceXSubsampling ( ) ; periodY = p . getSourceYSubsampling ( ) ; } destSize . setSize ( ( sourceBounds . width + periodX - 1 ) / periodX , ( sourceBounds . height + periodY - 1 ) / periodY ) ; if ( destSize . width <= 0 || destSize . height <= 0 ) { throw new IllegalArgumentException ( "Empty source region!" ) ; } }
compute the source region and destination dimensions taking any parameter settings into account .
