简体   繁体   中英

Using libtiff's TIFFReadRawTile to get a jpeg tile without decompression/compression

我有一个金字塔形的切片tiff文件,我想提取切片而不进行解码和重新编码jpeg,我已经看到,使用TIFFReadRawTile()函数可以提取原始切片而无需解码,我该如何编写提取的缓冲区到可读的jpeg文件?

The task you are up to is not a trivial one. You might want to take a closer look at tiff2pdf utility's source code. The utility does what you need and you might extract relevant parts from it.

The problem is, the utility does many other things you will have to discard. Also, not any JPEG-in-TIFF could be successfully processed by the utility. Basically, because there is enough semi-broken TIFFs out there.

I've found that actually there is no way to get the encoded tile without directly messing with the huffmann tables of the tiff, which is pretty tricky.

The only way I've found is to read the decoded tile and then do some magic with vips to output to jpeg directly.

tdata_t buf;
tsize_t len;

buf = _TIFFmalloc( TIFFTileSize( tif ) );
len = TIFFReadEncodedTile(tif, tile, buf, (tsize_t) -1);

VImage result ((void *) buf, 256, 256, 3, VImage::FMTUCHAR);

void *outBuffer;
unsigned long len;
vips_jpegsave_buffer(result, &outBuffer, &len, "Q", 90, NULL);

and the use cout to output the image after some headers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM