This action will force synchronization from xiaozhuai/imageinfo, which will overwrite any changes that you have made since you forked the repository, and can not be recovered!!!
Synchronous operation will process in the background and will refresh the page when finishing processing. Please be patient.
Cross platform super fast single header c++ library to get image size and format without loading/decoding.
The imageinfo don't get image format by file ext name, but infer by file header bytes and character.
As few I/O times as possible! Read as few bytes as possible!
Some test image files are from image-size. Many thanks to @netroy.
Rust version: imageinfo-rs
cmake -B build .
cmake --build build -- all
cmake --build build -- check
call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\VC\Auxiliary\Build\vcvars32.bat"
cmake -G "NMake Makefiles" -B build .
cmake --build build -- all
cmake --build build -- check
auto imageInfo = getImageInfo<IIFilePathReader>("images/valid/jpg/sample.jpg");
std::cout << "File: " << file << "\n";
std::cout << " - Error : " << imageInfo.getErrorMsg() << "\n";
std::cout << " - Width : " << imageInfo.getWidth() << "\n";
std::cout << " - Height : " << imageInfo.getHeight() << "\n";
std::cout << " - Format : " << imageInfo.getFormat() << "\n";
std::cout << " - Ext : " << imageInfo.getExt() << "\n";
std::cout << " - Full Ext : " << imageInfo.getFullExt() << "\n";
std::cout << " - Mimetype : " << imageInfo.getMimetype() << "\n\n";
You can pass a file path and use IIFilePathReader
,
and there are some builtin reader IIFileReader
, IIFileStreamReader
, IIRawDataReader
FILE *file = fopen("images/valid/jpg/sample.jpg", "rb");
auto imageInfo = getImageInfo<IIFileReader>(file);
fclose(file);
std::ifstream file("images/valid/jpg/sample.jpg", std::ios::in);
auto imageInfo = getImageInfo<IIFileStreamReader>(file);
file.close();
// Suppose we already got data and size
// void *data;
// size_t size;
auto imageInfo = getImageInfo<IIRawDataReader>(IIRawData(data, size));
If you known the file is likely a JPEG, you can provide likely format
parameter to improve performance;
auto imageInfo = getImageInfo<IIFilePathReader>("images/valid/jpg/sample.jpg", II_FORMAT_JPEG);
First, take a look at IIFileReader
, all your need to do is define a class and implement size
and read
method. (not override)
class IIFileReader {
public:
explicit IIFileReader(FILE *file) : m_file(file) {}
inline size_t size() {
if (m_file != nullptr) {
fseek(m_file, 0, SEEK_END);
return ftell(m_file);
} else {
return 0;
}
}
inline void read(void *buf, off_t offset, size_t size) {
fseek(m_file, offset, SEEK_SET);
fread(buf, 1, size, m_file);
}
private:
FILE *m_file = nullptr;
};
Then, let's try to make a reader for Android assets file
class IIAndroidAssetFileReader {
public:
explicit IIAndroidAssetFileReader(AAsset *file) : m_file(file) {}
inline size_t size() {
if (m_file != nullptr) {
return AAsset_getLength(m_file);
} else {
return 0;
}
}
inline void read(void *buf, off_t offset, size_t size) {
AAsset_seek(m_file, offset, SEEK_SET);
AAsset_read(m_file, buf, size);
}
private:
AAsset *m_file = nullptr;
};
// Suppose we have a AAssetManager
// AAssetManager *manager;
// Open with AASSET_MODE_RANDOM mode to seek forward and backward
AAsset *file = AAssetManager_open(manager, "test.png", AASSET_MODE_RANDOM);
auto imageInfo = getImageInfo<IIAndroidAssetFileReader>(file);
AAsset_close(file);
Pretty easy?
Don't be stingy with your star : )
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。