如何以无损方式从JPEG图像创建金字塔平铺的TIFF

时间:2021-01-22 21:23:54

I need to create tiled pyramid TIFF file with JPEG-compressed tiles from large JPEG image using lossless jpeg operations i.e. crop in jpegtran. Is there any tool or java code around to perform such operation?

我需要使用无损jpeg操作(即jpegtran中的裁剪)从大JPEG图像创建具有JPEG压缩切片的平铺金字塔TIFF文件。是否有任何工具或Java代码来执行此类操作?

Currently I'm using my Java code to create tiled pyramid TIFF, but it doing it in lossy way:

目前我正在使用我的Java代码创建平铺金字塔TIFF,但它以有损方式执行:

public static void writeTiff(RenderedOp src, File dstFile, float jpegQuality, int tileSize, int pyramid, String interpolation) throws IOException {
    dstFile.getParentFile().mkdirs();
    TIFFImageWriterSpi imageWriterSpi = new TIFFImageWriterSpi();
    TIFFImageWriter imageWriter = (TIFFImageWriter)imageWriterSpi.createWriterInstance();
    ImageOutputStream out = new FileImageOutputStream(dstFile);
    try {
        imageWriter.setOutput(out);
        imageWriter.prepareWriteSequence(null);
        BufferedImage img = null;
        for(int i=0; i<pyramid; i++) {
            img = img==null ? src.getAsBufferedImage() : JAIUtils.scale(img, 0.5F, interpolation).getAsBufferedImage();
            TIFFImageWriteParam imageWriteParam = (TIFFImageWriteParam)imageWriter.getDefaultWriteParam();
            if (tileSize>0 && (img.getWidth()>tileSize || img.getHeight()>tileSize)) {
                imageWriteParam.setTilingMode(ImageWriteParam.MODE_EXPLICIT);
                imageWriteParam.setTiling(tileSize, tileSize, 0, 0);
            }
            if (jpegQuality > 0) {
                imageWriteParam.setCompressionMode(ImageWriteParam.MODE_EXPLICIT );
                imageWriteParam.setCompressionType("JPEG");
                imageWriteParam.setCompressionQuality(jpegQuality);
            }
            imageWriter.writeToSequence(new IIOImage(img, null, null), imageWriteParam );
        }
        imageWriter.endWriteSequence();
    } finally {
        out.close();
    }
}

1 个解决方案

#1


0  

Ossim works well from the command line, but I see it has a JNI binding, too.

Ossim在命令行中工作得很好,但我发现它也有JNI绑定。

#1


0  

Ossim works well from the command line, but I see it has a JNI binding, too.

Ossim在命令行中工作得很好,但我发现它也有JNI绑定。