无法在 Mac 上使用 Libtiff 写入 TIFF 文件

发布于 2024-09-14 05:12:33 字数 1711 浏览 4 评论 0原文

TIFFWriteScanline 在 Windows 和 Linux 上工作,但在 Mac 上失败

更新的问题:

我使用 libtiff3.9.4 在 mac 上用 c++ 读取和写入 TIFF 文件 10.6.4。我的项目被编写为可移植的并且无需任何 Windows 32 位和 Ubuntu 64 位上的问题。但在 Mac 上 Libtiff 函数 TIFFWriteScanline 总是失败(它返回!= 1)。这 TIFF 文件已创建,但没有任何内容。我能够 读取 LZW 压缩图像,但我无法写入它。 此外,该程序还适用于 Windows 上的 CCITT Group4 图像 和 linux,但在 mac 上读取扫描线失败。

我尝试了 libtiff3.8.2 和 libtiff4.0.0beta6 但没有任何运气。

为什么 libtiff 在 Mac 上工作时不会写入扫描线的任何想法 在linux上可以吗?

代码:

// set baseline tags
TIFFSetField(tiffImage, TIFFTAG_IMAGEWIDTH, 7368);
TIFFSetField(tiffImage, TIFFTAG_IMAGELENGTH, 4757);
TIFFSetField(tiffImage, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tiffImage, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tiffImage, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tiffImage, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
TIFFSetField(tiffImage, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(tiffImage, TIFFTAG_THRESHHOLDING, 1);
TIFFSetField(tiffImage, TIFFTAG_XRESOLUTION, 400;
TIFFSetField(tiffImage, TIFFTAG_YRESOLUTION, 400);
TIFFSetField(tiffImage, TIFFTAG_RESOLUTIONUNIT, 2);

uint32  rowsPerStrip;
rowsPerStrip = tiffData->height;
rowsPerStrip = TIFFDefaultStripSize(tiffImage, rowsPerStrip);
TIFFSetField(tiffImage, TIFFTAG_ROWSPERSTRIP, rowsPerStrip);
TIFFSetupStrips(tiffImage);

// row buffer
scanlineSize = TIFFScanlineSize(tiffImage);
scanline = (unsigned char*) _TIFFmalloc(scanlineSize);

// write image
for (int i = 0; i < iplImage->height; i++)
{
   memcpy(scanline, iplImage->imageData + iplImage->widthStep*i, scanlineSize);
   if(TIFFWriteScanline(tiffImage, scanline, i, 0) != 1){
      //Error
   }
}

// clean up
_TIFFfree(scanline);

TIFFWriteScanline works on Windows and Linux but fails on Mac

Updated question:

I use libtiff3.9.4 for reading and writing TIFF files in c++ on mac
10.6.4. My project is written to be portable and runs without any
issues on both Windows 32-bit og Ubuntu 64-bit. But on the mac the
Libtiff function TIFFWriteScanline always fails (it returns != 1). The
TIFF file is created, but it does not have any contents. I'am able to
read the LZW compressed images but i'm not able to write it.
Furthermore the program also works for CCITT Group4 images on windows
and linux, but read scanline fails on the mac.

I have tried both libtiff3.8.2 and libtiff4.0.0beta6 without any luck.

Any ideas why libtiff won't write scanlines on the mac when it works
fine on linux?

Code:

// set baseline tags
TIFFSetField(tiffImage, TIFFTAG_IMAGEWIDTH, 7368);
TIFFSetField(tiffImage, TIFFTAG_IMAGELENGTH, 4757);
TIFFSetField(tiffImage, TIFFTAG_BITSPERSAMPLE, 8);
TIFFSetField(tiffImage, TIFFTAG_SAMPLESPERPIXEL, 1);
TIFFSetField(tiffImage, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT);
TIFFSetField(tiffImage, TIFFTAG_COMPRESSION, COMPRESSION_LZW);
TIFFSetField(tiffImage, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK);
TIFFSetField(tiffImage, TIFFTAG_THRESHHOLDING, 1);
TIFFSetField(tiffImage, TIFFTAG_XRESOLUTION, 400;
TIFFSetField(tiffImage, TIFFTAG_YRESOLUTION, 400);
TIFFSetField(tiffImage, TIFFTAG_RESOLUTIONUNIT, 2);

uint32  rowsPerStrip;
rowsPerStrip = tiffData->height;
rowsPerStrip = TIFFDefaultStripSize(tiffImage, rowsPerStrip);
TIFFSetField(tiffImage, TIFFTAG_ROWSPERSTRIP, rowsPerStrip);
TIFFSetupStrips(tiffImage);

// row buffer
scanlineSize = TIFFScanlineSize(tiffImage);
scanline = (unsigned char*) _TIFFmalloc(scanlineSize);

// write image
for (int i = 0; i < iplImage->height; i++)
{
   memcpy(scanline, iplImage->imageData + iplImage->widthStep*i, scanlineSize);
   if(TIFFWriteScanline(tiffImage, scanline, i, 0) != 1){
      //Error
   }
}

// clean up
_TIFFfree(scanline);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

掐死时间 2024-09-21 05:12:33

根据您提供的信息很难判断,但我最好的猜测是您编译的 libtiff 不支持您正在使用的特定输出格式。

另外,如果 TIFFWriteScanline 返回 -1,则应该有错误消息,除非您替换了自己的错误处理程序。这应该是了解正在发生的事情的有用线索。

It's hard to tell with the information you've given, but my best guess is that you compiled libtiff without support for the particular output format you are using.

Also, if TIFFWriteScanline returns -1, there should be an error message unless you have substituted your own error handler. This should be a useful clue as to what is going on.

淡莣 2024-09-21 05:12:33

我很久以前就把这个问题移到了 LibTiff 邮件列表,但我忘了在这里给出答案,所以这里是:

我插入了 printf 并修改了 Libtiff 中的一些 TiffError 消息
代码,结果发现这些更改在任何地方都没有显示
我的程序失败了。经过几个小时的搜索后我发现
OpenCV 中的内置 Libtiff 库(libhighgui.dylib)是导致
我头疼。我知道 OpenCV 使用 Libtiff 但我不使用内置的
版本,因为它不提供 Libtiff 的完整功能。我
重新安装了没有 Libtiff 的 OpenCV2.1.0 并解决了问题(它
可能只是包含的依赖项的顺序
造成麻烦)。

我现在可以编写 LWZ 压缩图像。有关更多详细信息,请参阅 LibTiff 邮件列表。

I moved this question to the LibTiff mailing list a long time ago, but i forgot to give the answer here, so here it is:

I inserted printf and modified some TiffError messages in the Libtiff
code, and it turned out that these changes did not show anywhere when
my program failed. After searching for at few hours i found that the
built-in Libtiff library in OpenCV (libhighgui.dylib) was the cause of
my headache. I know OpenCV uses Libtiff but I do not use the build-in
version since it does not provide the full functionality of Libtiff. I
reinstalled OpenCV2.1.0 without Libtiff and it solved the issue (it
might just have been the order of the included dependencies that was
causing trouble).

I'm now able to write LWZ compressed images. For more details see the LibTiff mailing list.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文