summaryrefslogtreecommitdiff
path: root/libcore
diff options
context:
space:
mode:
authorlouis <louis.braun@gmx.de>2015-04-02 07:50:14 +0200
committerlouis <louis.braun@gmx.de>2015-04-02 07:50:14 +0200
commit4ae8e01ed91d123f1ad5ab34d45cc9dc3f7852ad (patch)
tree1cda8ff1a262dadbb0bfe3a8a9ca28a7e64900d7 /libcore
parent60a41eb99672297d3dc79baa5c0a319dc0500337 (diff)
downloadvdr-plugin-skindesigner-4ae8e01ed91d123f1ad5ab34d45cc9dc3f7852ad.tar.gz
vdr-plugin-skindesigner-4ae8e01ed91d123f1ad5ab34d45cc9dc3f7852ad.tar.bz2
automatically detect type of image if no file extension is available
Diffstat (limited to 'libcore')
-rw-r--r--libcore/imageloader.c37
-rw-r--r--libcore/imageloader.h1
2 files changed, 36 insertions, 2 deletions
diff --git a/libcore/imageloader.c b/libcore/imageloader.c
index 9b2a5b7..96c2915 100644
--- a/libcore/imageloader.c
+++ b/libcore/imageloader.c
@@ -4,6 +4,7 @@
#include <string>
#include <dirent.h>
#include <iostream>
+#include <fstream>
cImageLoader::cImageLoader() {
importer = NULL;
@@ -77,8 +78,11 @@ bool cImageLoader::LoadImage(const char *fullpath) {
importer = new cImageImporterSVG;
else if (endswith(fullpath, ".jpg"))
importer = new cImageImporterJPG;
- else
- return false;
+ else {
+ importer = cImageImporter::CreateImageImporter(fullpath);
+ if (!importer)
+ return false;
+ }
return importer->LoadImage(fullpath);
}
@@ -91,6 +95,35 @@ bool cImageLoader::LoadImage(std::string Path, std::string FileName, std::string
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
//
diff --git a/libcore/imageloader.h b/libcore/imageloader.h
index 6a83dec..93a81ab 100644
--- a/libcore/imageloader.h
+++ b/libcore/imageloader.h
@@ -22,6 +22,7 @@ public:
virtual bool LoadImage(const char *path) { return false; };
virtual void DrawToCairo(cairo_t *cr) {};
virtual void GetImageSize(int &width, int &height) {};
+ static cImageImporter* CreateImageImporter(const char* path);
};
// Image importer for PNG