/**
  * @param binaryName Name of one of the kdu_* binaries
  * @return
  */
 private static String getPath(String binaryName) {
   String path = Configuration.getInstance().getString(PATH_TO_BINARIES_CONFIG_KEY);
   if (path != null && path.length() > 0) {
     path = StringUtils.stripEnd(path, File.separator) + File.separator + binaryName;
   } else {
     path = binaryName;
   }
   return path;
 }
 Scale.Filter getUpscaleFilter() {
   final String upscaleFilterStr =
       Configuration.getInstance().getString(UPSCALE_FILTER_CONFIG_KEY);
   try {
     return Scale.Filter.valueOf(upscaleFilterStr.toUpperCase());
   } catch (Exception e) {
     logger.warn("Invalid value for {}", UPSCALE_FILTER_CONFIG_KEY);
   }
   return null;
 }
  @Test
  public void testGetImageInfoWithOrientation() throws Exception {
    Configuration.getInstance().setProperty(RESPECT_ORIENTATION_CONFIG_KEY, true);

    final File fixture = TestUtil.getImage("jpg-rotated.jpg");

    final FileProcessor fproc = (FileProcessor) newInstance();
    fproc.setSourceFile(fixture);
    fproc.setSourceFormat(Format.JPG);

    final ImageInfo info = fproc.getImageInfo();
    assertEquals(Orientation.ROTATE_90, info.getOrientation());
  }
  private void postProcessUsingJava2d(
      final ImageReader reader,
      final OperationList opList,
      final ImageInfo imageInfo,
      final ReductionFactor reductionFactor,
      final OutputStream outputStream)
      throws IOException, ProcessorException {
    BufferedImage image = Java2dUtil.reduceTo8Bits(reader.read());

    // The crop has already been applied, but we need to retain a
    // reference to it for any redactions.
    Crop crop = null;
    for (Operation op : opList) {
      if (op instanceof Crop) {
        crop = (Crop) op;
        break;
      }
    }

    // Redactions happen immediately after cropping.
    List<Redaction> redactions = new ArrayList<>();
    for (Operation op : opList) {
      if (op instanceof Redaction) {
        redactions.add((Redaction) op);
      }
    }
    image = Java2dUtil.applyRedactions(image, crop, reductionFactor, redactions);

    // Apply most remaining operations.
    for (Operation op : opList) {
      if (op instanceof Scale) {
        final Scale scale = (Scale) op;
        final Float upOrDown = scale.getResultingScale(imageInfo.getSize());
        if (upOrDown != null) {
          final Scale.Filter filter = (upOrDown > 1) ? getUpscaleFilter() : getDownscaleFilter();
          scale.setFilter(filter);
        }

        image = Java2dUtil.scaleImage(image, scale, reductionFactor);
      } else if (op instanceof Transpose) {
        image = Java2dUtil.transposeImage(image, (Transpose) op);
      } else if (op instanceof Rotate) {
        image = Java2dUtil.rotateImage(image, (Rotate) op);
      } else if (op instanceof Color) {
        image = Java2dUtil.transformColor(image, (Color) op);
      }
    }

    // Apply the sharpen operation, if present.
    final Configuration config = Configuration.getInstance();
    final float sharpenValue = config.getFloat(SHARPEN_CONFIG_KEY, 0);
    final Sharpen sharpen = new Sharpen(sharpenValue);
    image = Java2dUtil.sharpenImage(image, sharpen);

    // Apply all remaining operations.
    for (Operation op : opList) {
      if (op instanceof Watermark) {
        try {
          image = Java2dUtil.applyWatermark(image, (Watermark) op);
        } catch (ConfigurationException e) {
          logger.error(e.getMessage());
        }
      }
    }

    new ImageWriter(opList).write(image, opList.getOutputFormat(), outputStream);
    image.flush();
  }