mirror of
https://github.com/lovell/sharp.git
synced 2025-07-10 11:00:14 +02:00
Avoid calling g_type_from_name #2535
This commit is contained in:
parent
ceff628add
commit
573ed5f4b5
@ -195,31 +195,38 @@ namespace sharp {
|
|||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Regenerate this table with something like:
|
||||||
|
*
|
||||||
|
* $ vips -l foreign | grep -i load | awk '{ print $2, $1; }'
|
||||||
|
*
|
||||||
|
* Plus a bit of editing.
|
||||||
|
*/
|
||||||
std::map<std::string, ImageType> loaderToType = {
|
std::map<std::string, ImageType> loaderToType = {
|
||||||
{ "jpegload", ImageType::JPEG },
|
{ "VipsForeignLoadJpegFile", ImageType::JPEG },
|
||||||
{ "jpegload_buffer", ImageType::JPEG },
|
{ "VipsForeignLoadJpegBuffer", ImageType::JPEG },
|
||||||
{ "pngload", ImageType::PNG },
|
{ "VipsForeignLoadPngFile", ImageType::PNG },
|
||||||
{ "pngload_buffer", ImageType::PNG },
|
{ "VipsForeignLoadPngBuffer", ImageType::PNG },
|
||||||
{ "webpload", ImageType::WEBP },
|
{ "VipsForeignLoadWebpFile", ImageType::WEBP },
|
||||||
{ "webpload_buffer", ImageType::WEBP },
|
{ "VipsForeignLoadWebpBuffer", ImageType::WEBP },
|
||||||
{ "tiffload", ImageType::TIFF },
|
{ "VipsForeignLoadTiffFile", ImageType::TIFF },
|
||||||
{ "tiffload_buffer", ImageType::TIFF },
|
{ "VipsForeignLoadTiffBuffer", ImageType::TIFF },
|
||||||
{ "gifload", ImageType::GIF },
|
{ "VipsForeignLoadGifFile", ImageType::GIF },
|
||||||
{ "gifload_buffer", ImageType::GIF },
|
{ "VipsForeignLoadGifBuffer", ImageType::GIF },
|
||||||
{ "svgload", ImageType::SVG },
|
{ "VipsForeignLoadSvgFile", ImageType::SVG },
|
||||||
{ "svgload_buffer", ImageType::SVG },
|
{ "VipsForeignLoadSvgBuffer", ImageType::SVG },
|
||||||
{ "heifload", ImageType::HEIF },
|
{ "VipsForeignLoadHeifFile", ImageType::HEIF },
|
||||||
{ "heifload_buffer", ImageType::HEIF },
|
{ "VipsForeignLoadHeifBuffer", ImageType::HEIF },
|
||||||
{ "pdfload", ImageType::PDF },
|
{ "VipsForeignLoadPdfFile", ImageType::PDF },
|
||||||
{ "pdfload_buffer", ImageType::PDF },
|
{ "VipsForeignLoadPdfBuffer", ImageType::PDF },
|
||||||
{ "magickload", ImageType::MAGICK },
|
{ "VipsForeignLoadMagickFile", ImageType::MAGICK },
|
||||||
{ "magickload_buffer", ImageType::MAGICK },
|
{ "VipsForeignLoadMagickBuffer", ImageType::MAGICK },
|
||||||
{ "openslideload", ImageType::OPENSLIDE },
|
{ "VipsForeignLoadOpenslide", ImageType::OPENSLIDE },
|
||||||
{ "ppmload", ImageType::PPM },
|
{ "VipsForeignLoadPpmFile", ImageType::PPM },
|
||||||
{ "fitsload", ImageType::FITS },
|
{ "VipsForeignLoadFits", ImageType::FITS },
|
||||||
{ "openexrload", ImageType::EXR },
|
{ "VipsForeignLoadOpenexr", ImageType::EXR },
|
||||||
{ "vipsload", ImageType::VIPS },
|
{ "VipsForeignLoadVips", ImageType::VIPS },
|
||||||
{ "rawload", ImageType::RAW }
|
{ "VipsForeignLoadRaw", ImageType::RAW }
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -229,7 +236,7 @@ namespace sharp {
|
|||||||
ImageType imageType = ImageType::UNKNOWN;
|
ImageType imageType = ImageType::UNKNOWN;
|
||||||
char const *load = vips_foreign_find_load_buffer(buffer, length);
|
char const *load = vips_foreign_find_load_buffer(buffer, length);
|
||||||
if (load != nullptr) {
|
if (load != nullptr) {
|
||||||
auto it = loaderToType.find(vips_nickname_find(g_type_from_name(load)));
|
auto it = loaderToType.find(load);
|
||||||
if (it != loaderToType.end()) {
|
if (it != loaderToType.end()) {
|
||||||
imageType = it->second;
|
imageType = it->second;
|
||||||
}
|
}
|
||||||
@ -244,7 +251,7 @@ namespace sharp {
|
|||||||
ImageType imageType = ImageType::UNKNOWN;
|
ImageType imageType = ImageType::UNKNOWN;
|
||||||
char const *load = vips_foreign_find_load(file);
|
char const *load = vips_foreign_find_load(file);
|
||||||
if (load != nullptr) {
|
if (load != nullptr) {
|
||||||
auto it = loaderToType.find(vips_nickname_find(g_type_from_name(load)));
|
auto it = loaderToType.find(load);
|
||||||
if (it != loaderToType.end()) {
|
if (it != loaderToType.end()) {
|
||||||
imageType = it->second;
|
imageType = it->second;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user