@Override
  protected TilesetInfo convert(File image, TilesetInfo info) throws TilingException {
    long startTime = System.currentTimeMillis();
    log.info("Generating PTIF for file " + image.getName() + ": " + info.getImageWidth() + "x" + info.getImageHeight()
        + ", " + info.getZoomLevels() + " zoom levels");

    try {
      // Step 1 - compute pyramid
      log.debug("Computing pyramid");
      List<String> levels = computePyramid(info);

      // Step 2 - merge
      log.debug("Merging");
      File tempFile = new File(image.getParent(), "tmp.tif");
      levels.add(tempFile.getAbsolutePath());
      processor.merge(levels, "tiff:tile-geometry=" + TILE_SIZE + "x" + TILE_SIZE, "jpeg");

      // Step 3 - rename
      File emptyDir = null;
      if (!tilesetRootDir.getName().endsWith(".tif") && !tilesetRootDir.getName().endsWith(".ptif")) {
    	  emptyDir = new File(tilesetRootDir.getAbsolutePath());
    	  tilesetRootDir = new File(tilesetRootDir.getAbsolutePath() + ".tif");
      }
      
      if (emptyDir != null)
    	  emptyDir.delete();
    	  
      if (tilesetRootDir.exists()) {
        if (!tilesetRootDir.delete())
          throw new TilingException("Failed to delete directory:" + tilesetRootDir);
      }
      if (!tempFile.renameTo(tilesetRootDir))
        throw new TilingException("Failed to rename directory:" + tempFile);

      // Step 4 - remove temporary files
      for (int i = 1; i < levels.size() - 1; i++) {
        tempFile = new File(levels.get(i));
        if (!tempFile.delete())
          log.error("Failed to delete temp file:" + tempFile);
      }
    } catch (Exception e) {
      throw new TilingException(e.getMessage());
    }

    log.info("Took " + (System.currentTimeMillis() - startTime) + " ms.");
    return info;
  }