mirror of
https://projects.vdr-developer.org/git/vdr-plugin-skindesigner.git
synced 2023-10-19 17:58:31 +02:00
Use cairo to read PNG files
This commit is contained in:
parent
943c899288
commit
8bf7b33c1d
3
Makefile
3
Makefile
@ -55,6 +55,9 @@ else ifeq ($(IMAGELIB), graphicsmagick)
|
|||||||
LIBS += $(shell pkg-config --libs GraphicsMagick++)
|
LIBS += $(shell pkg-config --libs GraphicsMagick++)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
INCLUDES += $(shell pkg-config --cflags cairo-png)
|
||||||
|
LIBS += $(shell pkg-config --libs cairo-png)
|
||||||
|
|
||||||
LIBS += $(shell xml2-config --libs)
|
LIBS += $(shell xml2-config --libs)
|
||||||
|
|
||||||
### The object files:
|
### The object files:
|
||||||
|
@ -12,64 +12,59 @@ cImageMagickWrapper::~cImageMagickWrapper() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
cImage *cImageMagickWrapper::CreateImage(int width, int height, bool preserveAspect) {
|
cImage *cImageMagickWrapper::CreateImage(int width, int height, bool preserveAspect) {
|
||||||
|
if (image == NULL) return NULL;
|
||||||
|
|
||||||
int w, h;
|
int w, h;
|
||||||
w = buffer.columns();
|
w = cairo_image_surface_get_width(image);
|
||||||
h = buffer.rows();
|
h = cairo_image_surface_get_height(image);
|
||||||
if (width == 0)
|
if (width == 0)
|
||||||
width = w;
|
width = w;
|
||||||
if (height == 0)
|
if (height == 0)
|
||||||
height = h;
|
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 / w;
|
||||||
|
double sy = height / h;
|
||||||
if (preserveAspect) {
|
if (preserveAspect) {
|
||||||
unsigned scale_w = 1000 * width / w;
|
if (sx < sy)
|
||||||
unsigned scale_h = 1000 * height / h;
|
sy = sx;
|
||||||
if (scale_w > scale_h)
|
if (sy < sx)
|
||||||
width = w * height / h;
|
sx = sy;
|
||||||
else
|
|
||||||
height = h * width / w;
|
|
||||||
}
|
}
|
||||||
const PixelPacket *pixels = buffer.getConstPixels(0, 0, w, h);
|
cairo_scale(cr, sx, sy);
|
||||||
cImage *image = new cImage(cSize(width, height));
|
|
||||||
tColor *imgData = (tColor *)image->Data();
|
cairo_set_source_surface(cr, image, 0, 0);
|
||||||
if (w != width || h != height) {
|
cairo_paint(cr);
|
||||||
ImageScaler scaler;
|
|
||||||
scaler.SetImageParameters(imgData, width, width, height, w, h);
|
unsigned char *data = cairo_image_surface_get_data(surface);
|
||||||
for (const void *pixels_end = &pixels[w*h]; pixels < pixels_end; ++pixels)
|
cImage *cimage = new cImage(cSize(width, height), (tColor*)data);
|
||||||
scaler.PutSourcePixel(pixels->blue / ((MaxRGB + 1) / 256),
|
|
||||||
pixels->green / ((MaxRGB + 1) / 256),
|
cairo_destroy(cr);
|
||||||
pixels->red / ((MaxRGB + 1) / 256),
|
cairo_surface_destroy(image);
|
||||||
~((unsigned char)(pixels->opacity / ((MaxRGB + 1) / 256))));
|
image = NULL;
|
||||||
return image;
|
|
||||||
}
|
return cimage;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool cImageMagickWrapper::LoadImage(const char *fullpath) {
|
bool cImageMagickWrapper::LoadImage(const char *fullpath) {
|
||||||
if ((fullpath == NULL) || (strlen(fullpath) < 5))
|
if ((fullpath == NULL) || (strlen(fullpath) < 5))
|
||||||
return false;
|
return false;
|
||||||
try {
|
|
||||||
|
if (image != NULL) cairo_surface_destroy(image);
|
||||||
|
|
||||||
|
image = cairo_image_surface_create_from_png(fullpath);
|
||||||
|
|
||||||
|
if (cairo_surface_status(image)) {
|
||||||
if (config.debugImageLoading)
|
if (config.debugImageLoading)
|
||||||
dsyslog("skindesigner: trying to load: %s", fullpath);
|
dsyslog("skindesigner: Cairo Error: %s", cairo_status_to_string(cairo_surface_status(image)));
|
||||||
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 false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,10 +3,9 @@
|
|||||||
|
|
||||||
#define X_DISPLAY_MISSING
|
#define X_DISPLAY_MISSING
|
||||||
|
|
||||||
#include <Magick++.h>
|
#include <cairo.h>
|
||||||
#include <vdr/osd.h>
|
#include <vdr/osd.h>
|
||||||
|
|
||||||
using namespace Magick;
|
|
||||||
|
|
||||||
class cImageMagickWrapper {
|
class cImageMagickWrapper {
|
||||||
private:
|
private:
|
||||||
@ -14,7 +13,7 @@ public:
|
|||||||
cImageMagickWrapper();
|
cImageMagickWrapper();
|
||||||
~cImageMagickWrapper();
|
~cImageMagickWrapper();
|
||||||
protected:
|
protected:
|
||||||
Image buffer;
|
cairo_surface_t *image = NULL;
|
||||||
cImage *CreateImage(int width, int height, bool preserveAspect = true);
|
cImage *CreateImage(int width, int height, bool preserveAspect = true);
|
||||||
bool LoadImage(std::string FileName, std::string Path, std::string Extension);
|
bool LoadImage(std::string FileName, std::string Path, std::string Extension);
|
||||||
bool LoadImage(const char *fullpath);
|
bool LoadImage(const char *fullpath);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user