Program: 30263
Project: 30263
Buggy source:
/** 
 * Extract an image from a texture atlas.
 * @param page The image file related to the page the region is in
 * @param region The region to extract
 * @param outputDirFile The output directory
 * @param padding padding (in pixels) to apply to the image
 * @return The extracted image
 */
private BufferedImage extractImage(BufferedImage page,Region region,File outputDirFile,int padding){
  BufferedImage splitImage=null;
  if (region.rotate) {
    BufferedImage srcImage=page.getSubimage(region.left,region.top,region.height,region.width);
    splitImage=new BufferedImage(region.width,region.height,page.getType());
    AffineTransform transform=new AffineTransform();
    transform.rotate(Math.toRadians(90.0));
    transform.translate(0,-region.width);
    AffineTransformOp op=new AffineTransformOp(transform,AffineTransformOp.TYPE_BILINEAR);
    op.filter(srcImage,splitImage);
  }
 else {
    splitImage=page.getSubimage(region.left,region.top,region.width,region.height);
  }
  if (padding > 0) {
    BufferedImage paddedImage=new BufferedImage(splitImage.getWidth() + padding * 2,splitImage.getHeight() + padding * 2,page.getType());
    Graphics2D g2=paddedImage.createGraphics();
    g2.drawImage(splitImage,padding,padding,null);
    g2.dispose();
    return paddedImage;
  }
 else   if (region.originalWidth != region.width || region.originalHeight != region.height) {
    BufferedImage paddedImage=new BufferedImage(region.originalWidth,region.originalHeight,page.getType());
    Graphics2D g2=paddedImage.createGraphics();
    g2.drawImage(splitImage,(int)region.offsetX,region.originalHeight - region.height,null);
    g2.dispose();
    return paddedImage;
  }
 else {
    return splitImage;
  }
}

Fixed version (ground truth):
/** 
 * Extract an image from a texture atlas.
 * @param page The image file related to the page the region is in
 * @param region The region to extract
 * @param outputDirFile The output directory
 * @param padding padding (in pixels) to apply to the image
 * @return The extracted image
 */
private BufferedImage extractImage(BufferedImage page,Region region,File outputDirFile,int padding){
  BufferedImage splitImage=null;
  if (region.rotate) {
    BufferedImage srcImage=page.getSubimage(region.left,region.top,region.height,region.width);
    splitImage=new BufferedImage(region.width,region.height,page.getType());
    AffineTransform transform=new AffineTransform();
    transform.rotate(Math.toRadians(90.0));
    transform.translate(0,-region.width);
    AffineTransformOp op=new AffineTransformOp(transform,AffineTransformOp.TYPE_BILINEAR);
    op.filter(srcImage,splitImage);
  }
 else {
    splitImage=page.getSubimage(region.left,region.top,region.width,region.height);
  }
  if (padding > 0) {
    BufferedImage paddedImage=new BufferedImage(splitImage.getWidth() + padding * 2,splitImage.getHeight() + padding * 2,page.getType());
    Graphics2D g2=paddedImage.createGraphics();
    g2.drawImage(splitImage,padding,padding,null);
    g2.dispose();
    return paddedImage;
  }
 else   if (region.originalWidth != region.width || region.originalHeight != region.height) {
    BufferedImage paddedImage=new BufferedImage(region.originalWidth,region.originalHeight,page.getType());
    Graphics2D g2=paddedImage.createGraphics();
    g2.drawImage(splitImage,(int)region.offsetX,region.originalHeight - region.height - (int)region.offsetY,null);
    g2.dispose();
    return paddedImage;
  }
 else {
    return splitImage;
  }
}