diff options
Diffstat (limited to 'imageloader.c')
-rw-r--r-- | imageloader.c | 114 |
1 files changed, 54 insertions, 60 deletions
diff --git a/imageloader.c b/imageloader.c index fd8e6a35..e989b84d 100644 --- a/imageloader.c +++ b/imageloader.c @@ -6,6 +6,7 @@ using namespace Magick; + cImageLoader::cImageLoader() { InitializeMagick(NULL); logoExtension = "png"; @@ -14,39 +15,64 @@ cImageLoader::cImageLoader() { cImageLoader::~cImageLoader() { } -bool cImageLoader::LoadLogo(const char *logo, int width = -1, int height = -1) { - if( width == -1 ) - width = logoWidth; - if( height == -1 ) - height = logoHeight; - +cImage* cImageLoader::LoadLogo(const char *logo, int width, int height) { if( (width == 0) || (height==0) ) - return false; + return NULL; + dsyslog("imageloader LoadLogo: %s", logo); std::string logoLower = logo; toLowerCase(logoLower); cString File = cString::sprintf("%s/%s.%s", *Config.logoPath, logoLower.c_str(), *logoExtension); + + cImage *img; + img = imgCache.GetImage( *File, width, height ); + if( img != NULL ) + return img; + bool success = LoadImage(File); if( !success ) { dsyslog("imageloader LoadLogo: %s could not be loaded", *File); - return false; + return NULL; } - if( height != 0 || width != 0 ) { - buffer.sample( Geometry(width, height) ); - } - return true; + img = CreateImage(width, height); + if( img == NULL ) + return NULL; + imgCache.InsertImage(img, logoLower, width, height); + return img; } -int cImageLoader::Height(void) { - Geometry geo = buffer.size(); - return geo.height(); -} +cImage* cImageLoader::LoadIcon(const char *cIcon, int width, int height, bool preserveAspect) { + if ((width == 0)||(height==0)) + return NULL; + + cString File = cString::sprintf("%s%s/%s.%s", *Config.iconPath, Setup.OSDTheme, cIcon, *logoExtension); + + cImage *img; + img = imgCache.GetImage( *File, width, height ); + if( img != NULL ) + return img; + + bool success = LoadImage(File); + if( !success ) { + File = cString::sprintf("%s%s/%s.%s", *Config.iconPath, "default", cIcon, *logoExtension); + img = imgCache.GetImage( *File, width, height ); + if( img != NULL ) + return img; -int cImageLoader::Width(void) { - Geometry geo = buffer.size(); - return geo.width(); + success = LoadImage(File); + if( !success ) { + dsyslog("imageloader LoadIcon: %s could not be loaded", *File); + return NULL; + } + } + img = CreateImage(width, height); + if( img == NULL ) + return NULL; + imgCache.InsertImage(img, cIcon, width, height); + return img; } +/* bool cImageLoader::LoadIcon(const char *cIcon, int size) { if (size==0) return false; @@ -64,11 +90,11 @@ bool cImageLoader::LoadIcon(const char *cIcon, int size) { buffer.sample(Geometry(size, size)); return true; } +*/ -bool cImageLoader::LoadIcon(const char *cIcon, int width, int height, bool preserveAspect) { +/* +bool cImageLoader::LoadIcon2(const char *cIcon) { try { - if ((width == 0)||(height==0)) - return false; cString File = cString::sprintf("%s%s/%s.%s", *Config.iconPath, Setup.OSDTheme, cIcon, *logoExtension); bool success = LoadImage(File); @@ -80,12 +106,6 @@ bool cImageLoader::LoadIcon(const char *cIcon, int width, int height, bool prese return false; } } - if (preserveAspect) { - buffer.sample(Geometry(width, height)); - } else { - cString geometry = cString::sprintf("%dx%d!", width, height); - buffer.scale(Geometry(*geometry)); - } return true; } catch (...) { @@ -94,32 +114,15 @@ bool cImageLoader::LoadIcon(const char *cIcon, int width, int height, bool prese } cImage cImageLoader::GetImage() { - int w, h; - w = buffer.columns(); - h = buffer.rows(); - cImage image (cSize(w, h)); - const PixelPacket *pixels = buffer.getConstPixels(0, 0, w, h); - for (int iy = 0; iy < h; ++iy) { - for (int ix = 0; ix < w; ++ix) { - tColor col = (~int(pixels->opacity * 255 / MaxRGB) << 24) - | (int(pixels->green * 255 / MaxRGB) << 8) - | (int(pixels->red * 255 / MaxRGB) << 16) - | (int(pixels->blue * 255 / MaxRGB) ); - image.SetPixel(cPoint(ix, iy), col); - ++pixels; - } - } - return image; + return CreateImageCopy(); } -Color cImageLoader::Argb2Color(tColor col) { - tIndex alpha = (col & 0xFF000000) >> 24; - tIndex red = (col & 0x00FF0000) >> 16; - tIndex green = (col & 0x0000FF00) >> 8; - tIndex blue = (col & 0x000000FF); - Color color(MaxRGB*red/255, MaxRGB*green/255, MaxRGB*blue/255, MaxRGB*(0xFF-alpha)/255); - return color; +cImage cImageLoader::GetImage(int width, int height, bool preserveAspect) { + cImage *img; + img = CreateImage(width, height, preserveAspect); + return *img; } +*/ void cImageLoader::toLowerCase(std::string &str) { const int length = str.length(); @@ -127,12 +130,3 @@ void cImageLoader::toLowerCase(std::string &str) { str[i] = std::tolower(str[i]); } } - -bool cImageLoader::LoadImage(cString File) { - try { - buffer.read(*File); - } catch (...) { - return false; - } - return true; -} |