summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile3
-rw-r--r--libcore/imageloader.c12
-rw-r--r--libcore/imageloader.h4
-rw-r--r--libcore/imagemagickwrapper.c177
-rw-r--r--libcore/imagemagickwrapper.h10
-rw-r--r--views/view.c6
6 files changed, 65 insertions, 147 deletions
diff --git a/Makefile b/Makefile
index 2160ae6..7b2b7d8 100644
--- a/Makefile
+++ b/Makefile
@@ -55,6 +55,9 @@ else ifeq ($(IMAGELIB), graphicsmagick)
LIBS += $(shell pkg-config --libs GraphicsMagick++)
endif
+INCLUDES += $(shell pkg-config --cflags cairo-png)
+LIBS += $(shell pkg-config --libs cairo-png)
+
LIBS += $(shell xml2-config --libs)
### The object files:
diff --git a/libcore/imageloader.c b/libcore/imageloader.c
index 61e8076..07b324e 100644
--- a/libcore/imageloader.c
+++ b/libcore/imageloader.c
@@ -14,16 +14,12 @@ cImageLoader::cImageLoader() : cImageMagickWrapper() {
cImageLoader::~cImageLoader() {
}
-cImage cImageLoader::GetImage() {
- return CreateImageCopy();
+cImage *cImageLoader::GetImage(int width, int height) {
+ return CreateImage(width, height, false);
}
-bool cImageLoader::LoadImage(const char *path, int width, int height) {
- if (cImageMagickWrapper::LoadImage(path)) {
- buffer.sample(Geometry(width, height));
- return true;
- }
- return false;
+bool cImageLoader::LoadImage(const char *path) {
+ return cImageMagickWrapper::LoadImage(path);
}
void cImageLoader::DeterminateChannelLogoSize(int &width, int &height) {
diff --git a/libcore/imageloader.h b/libcore/imageloader.h
index 2a148be..b2966c9 100644
--- a/libcore/imageloader.h
+++ b/libcore/imageloader.h
@@ -14,8 +14,8 @@ class cImageLoader : public cImageMagickWrapper {
public:
cImageLoader();
~cImageLoader();
- cImage GetImage();
- bool LoadImage(const char *path, int width, int height);
+ cImage *GetImage(int width, int height);
+ bool LoadImage(const char *path);
void DeterminateChannelLogoSize(int &width, int &height);
private:
};
diff --git a/libcore/imagemagickwrapper.c b/libcore/imagemagickwrapper.c
index ab1bcba..79e48e7 100644
--- a/libcore/imagemagickwrapper.c
+++ b/libcore/imagemagickwrapper.c
@@ -12,151 +12,74 @@ cImageMagickWrapper::~cImageMagickWrapper() {
}
cImage *cImageMagickWrapper::CreateImage(int width, int height, bool preserveAspect) {
+ if (image == NULL) return NULL;
+
int w, h;
- w = buffer.columns();
- h = buffer.rows();
+ w = cairo_image_surface_get_width(image);
+ h = cairo_image_surface_get_height(image);
if (width == 0)
width = w;
if (height == 0)
height = h;
+
+ cairo_surface_t *surface;
+ surface = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, width, height);
+
+ cairo_t *cr;
+ cr = cairo_create(surface);
+
+ double sx = width / (double)w;
+ double sy = height / (double)h;
if (preserveAspect) {
- unsigned scale_w = 1000 * width / w;
- unsigned scale_h = 1000 * height / h;
- if (scale_w > scale_h)
- width = w * height / h;
- else
- height = h * width / w;
- }
- const PixelPacket *pixels = buffer.getConstPixels(0, 0, w, h);
- cImage *image = new cImage(cSize(width, height));
- tColor *imgData = (tColor *)image->Data();
- if (w != width || h != height) {
- ImageScaler scaler;
- scaler.SetImageParameters(imgData, width, width, height, w, h);
- for (const void *pixels_end = &pixels[w*h]; pixels < pixels_end; ++pixels)
- scaler.PutSourcePixel(pixels->blue / ((MaxRGB + 1) / 256),
- pixels->green / ((MaxRGB + 1) / 256),
- pixels->red / ((MaxRGB + 1) / 256),
- ~((unsigned char)(pixels->opacity / ((MaxRGB + 1) / 256))));
- return image;
+ if (sx < sy)
+ sy = sx;
+ if (sy < sx)
+ sx = sy;
}
- for (const void *pixels_end = &pixels[width*height]; pixels < pixels_end; ++pixels)
- *imgData++ = ((~int(pixels->opacity / ((MaxRGB + 1) / 256)) << 24) |
- (int(pixels->green / ((MaxRGB + 1) / 256)) << 8) |
- (int(pixels->red / ((MaxRGB + 1) / 256)) << 16) |
- (int(pixels->blue / ((MaxRGB + 1) / 256)) ));
- return image;
-}
+ cairo_scale(cr, sx, sy);
-cImage cImageMagickWrapper::CreateImageCopy() {
- 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;
-}
+ cairo_set_source_surface(cr, image, 0, 0);
+ cairo_paint(cr);
-bool cImageMagickWrapper::LoadImage(std::string FileName, std::string Path, std::string Extension) {
- try {
- std::stringstream sstrImgFile;
- sstrImgFile << Path << FileName << "." << Extension;
- std::string imgFile = sstrImgFile.str();
- if (config.debugImageLoading)
- dsyslog("skindesigner: trying to load: %s", imgFile.c_str());
- buffer.read(imgFile.c_str());
- if (config.debugImageLoading)
- dsyslog("skindesigner: %s sucessfully loaded", imgFile.c_str());
- } catch( Magick::Warning &warning ) {
- if (config.debugImageLoading)
- dsyslog("skindesigner: Magick Warning: %s", warning.what());
- return true;
- } catch( Magick::Error &error ) {
- if (config.debugImageLoading)
- dsyslog("skindesigner: Magick Error: %s", error.what());
- return false;
- } catch(...) {
- if (config.debugImageLoading)
- dsyslog("skindesigner: an unknown Magick error occured during image loading");
- return false;
- }
- return true;
+ cairo_status_t status = cairo_status (cr);
+ if (status)
+ dsyslog("skindesigner: Cairo CreateImage Error %s", cairo_status_to_string(status));
+
+ unsigned char *data = cairo_image_surface_get_data(surface);
+ cImage *cimage = new cImage(cSize(width, height), (tColor*)data);
+
+ cairo_destroy(cr);
+ cairo_surface_destroy(image);
+ image = NULL;
+
+ return cimage;
}
bool cImageMagickWrapper::LoadImage(const char *fullpath) {
if ((fullpath == NULL) || (strlen(fullpath) < 5))
return false;
- try {
- if (config.debugImageLoading)
- dsyslog("skindesigner: trying to load: %s", fullpath);
- buffer.read(fullpath);
- if (config.debugImageLoading)
- dsyslog("skindesigner: %s sucessfully loaded", fullpath);
- } catch( Magick::Warning &warning ) {
- if (config.debugImageLoading)
- dsyslog("skindesigner: Magick Warning: %s", warning.what());
- return true;
- } catch( Magick::Error &error ) {
- if (config.debugImageLoading)
- dsyslog("skindesigner: Magick Error: %s", error.what());
- return false;
- } catch(...) {
- if (config.debugImageLoading)
- dsyslog("skindesigner: an unknown Magick error occured during image loading");
- return false;
- }
- return true;
-}
-Color cImageMagickWrapper::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;
-}
+ if (image != NULL) cairo_surface_destroy(image);
-void cImageMagickWrapper::CreateGradient(tColor back, tColor blend, int width, int height, double wfactor, double hfactor) {
- Color Back = Argb2Color(back);
- Color Blend = Argb2Color(blend);
- int maxw = MaxRGB * wfactor;
- int maxh = MaxRGB * hfactor;
-
- Image imgblend(Geometry(width, height), Blend);
- imgblend.modifyImage();
- imgblend.type(TrueColorMatteType);
- PixelPacket *pixels = imgblend.getPixels(0, 0, width, height);
- for (int x = 0; x < width; x++) {
- for (int y = 0; y < height; y++) {
- PixelPacket *pixel = pixels + y * width + x;
- int opacity = (maxw / width * x + maxh - maxh / height * y) / 2;
- pixel->opacity = (opacity <= MaxRGB) ? opacity : MaxRGB;
- }
- }
- imgblend.syncPixels();
+ if (config.debugImageLoading)
+ dsyslog("skindesigner: trying to load: %s", fullpath);
- Image imgback(Geometry(width, height), Back);
- imgback.composite(imgblend, 0, 0, OverCompositeOp);
+ image = cairo_image_surface_create_from_png(fullpath);
- buffer = imgback;
-}
+ if (cairo_surface_status(image)) {
+ if (config.debugImageLoading)
+ dsyslog("skindesigner: Cairo LoadImage Error: %s", cairo_status_to_string(cairo_surface_status(image)));
+ image = NULL;
+ return false;
+ }
-void cImageMagickWrapper::CreateBackground(tColor back, tColor blend, int width, int height, bool mirror) {
- CreateGradient(back, blend, width, height, 0.8, 0.8);
- if (mirror)
- buffer.flop();
+ return true;
}
-void cImageMagickWrapper::CreateBackgroundReverse(tColor back, tColor blend, int width, int height) {
- CreateGradient(back, blend, width, height, 1.3, 0.7);
+
+// Just a different way to call LoadImage. Calls the above one.
+bool cImageMagickWrapper::LoadImage(std::string FileName, std::string Path, std::string Extension) {
+ std::stringstream sstrImgFile;
+ sstrImgFile << Path << FileName << "." << Extension;
+ std::string imgFile = sstrImgFile.str();
+ return LoadImage(imgFile.c_str());
}
diff --git a/libcore/imagemagickwrapper.h b/libcore/imagemagickwrapper.h
index 5f9901e..b0c19e8 100644
--- a/libcore/imagemagickwrapper.h
+++ b/libcore/imagemagickwrapper.h
@@ -3,26 +3,20 @@
#define X_DISPLAY_MISSING
-#include <Magick++.h>
+#include <cairo.h>
#include <vdr/osd.h>
-using namespace Magick;
class cImageMagickWrapper {
private:
- void CreateGradient(tColor back, tColor blend, int width, int height, double wfactor, double hfactor);
public:
cImageMagickWrapper();
~cImageMagickWrapper();
protected:
- Image buffer;
- Color Argb2Color(tColor col);
+ cairo_surface_t *image = NULL;
cImage *CreateImage(int width, int height, bool preserveAspect = true);
- cImage CreateImageCopy(void);
bool LoadImage(std::string FileName, std::string Path, std::string Extension);
bool LoadImage(const char *fullpath);
- void CreateBackground(tColor back, tColor blend, int width, int height, bool mirror = false);
- void CreateBackgroundReverse(tColor back, tColor blend, int width, int height);
};
#endif //__NOPACITY_IMAGEMAGICKWRAPPER_H
diff --git a/views/view.c b/views/view.c
index 75a24e0..8711136 100644
--- a/views/view.c
+++ b/views/view.c
@@ -711,8 +711,10 @@ void cView::DoDrawImage(int num, cTemplateFunction *func, int x0, int y0) {
break; }
case itImage: {
cImageLoader imgLoader;
- if (imgLoader.LoadImage(path.c_str(), width, height)) {
- DrawImage(num, pos, imgLoader.GetImage());
+ if (imgLoader.LoadImage(path.c_str())) {
+ cImage *image = imgLoader.GetImage(width, height);
+ DrawImage(num, pos, *image);
+ delete(image);
}
break; }
default: