I have a buffer containing the data for an RLE-compressed 8-bit RGB TGA image. I want to load this into a Magick++ Image but I keep getting
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. 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.
If I remember correctly, later extended version of TGA introduced the string TRUEVISION-XFILE
as a magick identifier, but at the files footer table.
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...
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);
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.