mirror of
https://projects.vdr-developer.org/git/vdr-plugin-skindesigner.git
synced 2023-10-19 17:58:31 +02:00
automatically detect type of image if no file extension is available
This commit is contained in:
parent
60a41eb996
commit
4ae8e01ed9
1
HISTORY
1
HISTORY
@ -263,3 +263,4 @@ Version 0.3.3
|
|||||||
|
|
||||||
- fixed backward compatibility to VDR version < 2.1.1 where
|
- fixed backward compatibility to VDR version < 2.1.1 where
|
||||||
cRecording::IsInUse() was introduced
|
cRecording::IsInUse() was introduced
|
||||||
|
- automatically detect type of image if no file extension is available
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <dirent.h>
|
#include <dirent.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
cImageLoader::cImageLoader() {
|
cImageLoader::cImageLoader() {
|
||||||
importer = NULL;
|
importer = NULL;
|
||||||
@ -77,8 +78,11 @@ bool cImageLoader::LoadImage(const char *fullpath) {
|
|||||||
importer = new cImageImporterSVG;
|
importer = new cImageImporterSVG;
|
||||||
else if (endswith(fullpath, ".jpg"))
|
else if (endswith(fullpath, ".jpg"))
|
||||||
importer = new cImageImporterJPG;
|
importer = new cImageImporterJPG;
|
||||||
else
|
else {
|
||||||
|
importer = cImageImporter::CreateImageImporter(fullpath);
|
||||||
|
if (!importer)
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
return importer->LoadImage(fullpath);
|
return importer->LoadImage(fullpath);
|
||||||
}
|
}
|
||||||
@ -91,6 +95,35 @@ bool cImageLoader::LoadImage(std::string Path, std::string FileName, std::string
|
|||||||
return LoadImage(imgFile.c_str());
|
return LoadImage(imgFile.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
cImageImporter* cImageImporter::CreateImageImporter(const char* path) {
|
||||||
|
char pngSig[] = { 0x89, 0x50, 0x4E, 0x47, 0x0D, 0x0A, 0x1A, 0x0A };
|
||||||
|
char jpgSig[] = { 0xFF, 0xD8, 0xFF, 0xD9 };
|
||||||
|
char buffer[8] = { 0 };
|
||||||
|
ifstream f(path, ios::in | ios::binary);
|
||||||
|
f.read(buffer, 8);
|
||||||
|
if (!f)
|
||||||
|
return NULL;
|
||||||
|
if(buffer[0] == jpgSig[0] && buffer[1] == jpgSig[1]) {
|
||||||
|
f.seekg(-2, f.end);
|
||||||
|
f.read(buffer, 2);
|
||||||
|
if(buffer[0] == jpgSig[2] && buffer[1] == jpgSig[3]) {
|
||||||
|
f.close();
|
||||||
|
return new cImageImporterJPG;
|
||||||
|
}
|
||||||
|
} else if(buffer[0] == pngSig[0]
|
||||||
|
&& buffer[1] == pngSig[1]
|
||||||
|
&& buffer[2] == pngSig[2]
|
||||||
|
&& buffer[3] == pngSig[3]
|
||||||
|
&& buffer[4] == pngSig[4]
|
||||||
|
&& buffer[5] == pngSig[5]
|
||||||
|
&& buffer[6] == pngSig[6]
|
||||||
|
&& buffer[7] == pngSig[7]) {
|
||||||
|
f.close();
|
||||||
|
return new cImageImporterPNG;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Image importer for PNG
|
// Image importer for PNG
|
||||||
//
|
//
|
||||||
|
@ -22,6 +22,7 @@ public:
|
|||||||
virtual bool LoadImage(const char *path) { return false; };
|
virtual bool LoadImage(const char *path) { return false; };
|
||||||
virtual void DrawToCairo(cairo_t *cr) {};
|
virtual void DrawToCairo(cairo_t *cr) {};
|
||||||
virtual void GetImageSize(int &width, int &height) {};
|
virtual void GetImageSize(int &width, int &height) {};
|
||||||
|
static cImageImporter* CreateImageImporter(const char* path);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Image importer for PNG
|
// Image importer for PNG
|
||||||
|
Loading…
Reference in New Issue
Block a user