Some cleanup and minor bugfixes

This commit is contained in:
Manuel Reimer 2014-11-04 16:55:45 +01:00
parent e519aa7d75
commit 2bd5a4057b
2 changed files with 21 additions and 16 deletions

View File

@ -14,7 +14,8 @@ cImageLoader::~cImageLoader() {
} }
cImage *cImageLoader::CreateImage(int width, int height, bool preserveAspect) { cImage *cImageLoader::CreateImage(int width, int height, bool preserveAspect) {
if (!importer) return NULL; if (!importer)
return NULL;
int w, h; int w, h;
importer->GetImageSize(w, h); importer->GetImageSize(w, h);
@ -87,18 +88,19 @@ bool cImageLoader::LoadImage(std::string Path, std::string FileName, std::string
void cImageLoader::DeterminateChannelLogoSize(int &width, int &height) { void cImageLoader::DeterminateChannelLogoSize(int &width, int &height) {
cString logoPath; cString logoPath;
cString logoPathSkin = cString::sprintf("%s%s/themes/%s/logos/", *config.skinPath, Setup.OSDSkin, Setup.OSDTheme); cString logoPathSkin = cString::sprintf("%s%s/themes/%s/logos/", *config.skinPath, Setup.OSDSkin, Setup.OSDTheme);
if (FolderExists(*logoPathSkin)) {
if (FolderExists(*logoPathSkin))
logoPath = logoPathSkin; logoPath = logoPathSkin;
} else { else
logoPath = config.logoPath; logoPath = config.logoPath;
}
cString logoExt = config.logoExtension; cString logoExt = config.logoExtension;
DIR *folder = NULL; DIR *folder = NULL;
struct dirent *file; struct dirent *file;
folder = opendir(logoPath); folder = opendir(logoPath);
if (!folder) { if (!folder)
return; return;
}
while (file = readdir(folder)) { while (file = readdir(folder)) {
if (endswith(file->d_name, *logoExt)) { if (endswith(file->d_name, *logoExt)) {
std::stringstream filePath; std::stringstream filePath;
@ -192,6 +194,7 @@ bool cImageImporterSVG::LoadImage(const char *path) {
return false; return false;
} }
// 90 dpi is the hardcoded default setting of the Inkscape SVG editor
rsvg_handle_set_dpi(handle, 90); rsvg_handle_set_dpi(handle, 90);
return true; return true;
@ -242,9 +245,11 @@ bool cImageImporterJPG::LoadImage(const char *path) {
return false; return false;
} }
// Allocate space for our decompress struct
cinfo = (j_decompress_ptr)malloc(sizeof(struct jpeg_decompress_struct));
// We set up the normal JPEG error routines, then override error_exit. // We set up the normal JPEG error routines, then override error_exit.
struct my_error_mgr jerr; struct my_error_mgr jerr;
cinfo = (j_decompress_ptr)malloc(sizeof(struct jpeg_decompress_struct));
cinfo->err = jpeg_std_error(&jerr.pub); cinfo->err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit; jerr.pub.error_exit = my_error_exit;
jerr.pub.output_message = my_output_message; jerr.pub.output_message = my_output_message;
@ -275,7 +280,8 @@ void cImageImporterJPG::DrawToCairo(cairo_t *cr) {
unsigned char *bmp_buffer = NULL; unsigned char *bmp_buffer = NULL;
// Re-establish error handling // Re-establish error handling. We have to do this again as the saved
// calling environment of "LoadImage" is invalid if we reach here!
struct my_error_mgr jerr; struct my_error_mgr jerr;
cinfo->err = jpeg_std_error(&jerr.pub); cinfo->err = jpeg_std_error(&jerr.pub);
jerr.pub.error_exit = my_error_exit; jerr.pub.error_exit = my_error_exit;
@ -308,7 +314,7 @@ void cImageImporterJPG::DrawToCairo(cairo_t *cr) {
jpeg_read_scanlines(cinfo, buffer_array, 1); jpeg_read_scanlines(cinfo, buffer_array, 1);
} }
// Step 7: Finish decompression. Free all libjpeg stuff and close file. // Step 7: Finish decompression.
(void)jpeg_finish_decompress(cinfo); (void)jpeg_finish_decompress(cinfo);
// Cleanup. In this "ImageImporter" we clean up everything in "DrawToCairo" // Cleanup. In this "ImageImporter" we clean up everything in "DrawToCairo"
@ -323,8 +329,8 @@ void cImageImporterJPG::DrawToCairo(cairo_t *cr) {
// Do some ugly byte shifting. // Do some ugly byte shifting.
// Byte order in libjpeg: RGB // Byte order in libjpeg: RGB
// Byte order in cairo and VDR: BGRA // Byte order in cairo and VDR: BGRA
for (int index = (width * height) - 1; index >= 0; index--) {
unsigned char temp[3]; unsigned char temp[3];
for (int index = (width * height) - 1; index >= 0; index--) {
unsigned char *target = bmp_buffer + (index * 4); unsigned char *target = bmp_buffer + (index * 4);
unsigned char *source = bmp_buffer + (index * 3); unsigned char *source = bmp_buffer + (index * 3);
memcpy(&temp[0], source + 2, 1); memcpy(&temp[0], source + 2, 1);

View File

@ -15,7 +15,7 @@ class cImageImporter {
public: public:
cImageImporter() {}; cImageImporter() {};
virtual ~cImageImporter() {}; virtual ~cImageImporter() {};
virtual bool LoadImage(const char *path) {}; 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) {};
}; };
@ -47,7 +47,7 @@ private:
// Image importer for JPG // Image importer for JPG
#if BITS_IN_JSAMPLE != 8 #if BITS_IN_JSAMPLE != 8
#error libjpeg-turbo has to be compiled with 8-bit samples! #error libjpeg has to be compiled with 8-bit samples!
#endif #endif
struct my_error_mgr { struct my_error_mgr {
@ -61,7 +61,6 @@ my_error_exit(j_common_ptr cinfo) {
my_error_mgr *myerr = (my_error_mgr*) cinfo->err; my_error_mgr *myerr = (my_error_mgr*) cinfo->err;
// Always display the message. // Always display the message.
// We could postpone this until after returning, if we chose.
(*cinfo->err->output_message) (cinfo); (*cinfo->err->output_message) (cinfo);
// Return control to the setjmp point // Return control to the setjmp point
@ -91,7 +90,7 @@ private:
class cImageLoader { class cImageLoader {
private: private:
cImageImporter *importer = NULL; cImageImporter *importer;
public: public:
cImageLoader(); cImageLoader();
virtual ~cImageLoader(); virtual ~cImageLoader();