[英]Magick++ not loading TGA blob
I have a buffer containing the data for an RLE-compressed 8-bit RGB TGA image. 我有一个缓冲区,其中包含RLE压缩的8位RGB TGA图像的数据。 I want to load this into a Magick++ Image but I keep getting
我想将其加载到Magick ++图像中,但我不断
Magick: no decode delegate for this image format `' @ error/blob.c/BlobToImage/353
Here is my code 这是我的代码
#include <Magick++.h>
#include <fstream>
int main(int argc, char** argv)
{
std::ifstream file("window_borders.tga", std::ios::binary | std::ios::ate);
std::streamsize size = file.tellg();
file.seekg(0, std::ios::beg);
char* buffer = new char[size];
if (!file.read(buffer, size)) return 1;
Magick::Blob data_blob(buffer, size);
Magick::Image m_image(data_blob);
return 0;
}
If I identify it I get 如果我识别出
window_borders.tga TGA 330x390 330x390+0+0 8-bit sRGB 33106B 0.000u 0:00.000
Annoyingly, if I specify this info, then it works just fine. 烦人的是,如果我指定此信息,那么它就可以正常工作。 I can even convert it:
我什至可以转换它:
Magick::Image m_image(data_blob, Magick::Geometry("330x390"), "TGA");
m_image.magick("JPEG");
m_image.write("test.jpg");
And indeed test.jpg
and window_borders.tga
look identical. 事实上
test.jpg
和window_borders.tga
看起来相同。 Why can't it detect the format automatically? 为什么无法自动检测格式?
Why can't it detect the format automatically?
为什么无法自动检测格式?
The TGA format never really had a unique "magick-number" header, or some other quick+reliable way to identify if a TGA exist within a blob. TGA格式从没有真正具有唯一的“ magick-number”标头,或其他任何快速可靠的方式来识别Blob中是否存在TGA。
If I remember correctly, later extended version of TGA introduced the string TRUEVISION-XFILE
as a magick identifier, but at the files footer table. 如果我没记错的话,后来TGA的扩展版本在文件页脚表中引入了字符串
TRUEVISION-XFILE
作为magick标识符。
I'm not an expert, but I imagine some software designers would be shaking their heads. 我不是专家,但我想有些软件设计师会摇头。
Now, not only are you responsible for knowing the file format ahead of time (by given filename) , but have to fully & correctly read the image-header to determine where the image-data stops, and the image-footer starts. 现在,您不仅要负责(通过给定的文件名)提前知道文件格式,而且还必须完全正确地读取图像标题,以确定图像数据在哪里停止,然后图像页脚开始。
I would guess that this would be a large contributing factor into why there's no IsTGA
method like we have IsPNG
, IsTIFF
, and so on... 我猜想这将是为什么没有像
IsPNG
, IsTIFF
类的IsTGA
方法的一个重要因素...
As you've previously discovered one solution. 正如您之前发现的一种解决方案。
Magick::Image m_image(data_blob, Magick::Geometry("330x390"), "TGA");
// This should work too.
Magick::Image m_image(data_blob, Magick::Geometry("0x0"), "TGA");
But you can also do the following. 但是您也可以执行以下操作。
Magick::image m_image;
m_image.magick("TGA");
m_image.read(data_blob);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.