diff --git a/HISTORY b/HISTORY index 8d49d34..5852e24 100644 --- a/HISTORY +++ b/HISTORY @@ -262,4 +262,5 @@ Version 0.3.3 Version 0.3.4 - fixed backward compatibility to VDR version < 2.1.1 where - cRecording::IsInUse() was introduced \ No newline at end of file + cRecording::IsInUse() was introduced +- automatically detect type of image if no file extension is available 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 #include #include +#include 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