diff options
author | Maniac <maniac> | 2011-05-14 19:41:46 +0200 |
---|---|---|
committer | Maniac <maniac> | 2011-05-14 19:41:46 +0200 |
commit | 5c50e932568d197c9b2579c6d5c6feeac5ef4b3a (patch) | |
tree | b539ed3a9975fc78416dd5dd8871fd4193b877a2 | |
parent | 13737cd6f7997480565ddda01cb940e01fae9ad1 (diff) | |
download | vdr-plugin-skinpearlhd-5c50e932568d197c9b2579c6d5c6feeac5ef4b3a.tar.gz vdr-plugin-skinpearlhd-5c50e932568d197c9b2579c6d5c6feeac5ef4b3a.tar.bz2 |
rewrite of the bitmap rendering
If compiled with DEBUG_SKINPEARLHD=1 the runtime of the bitmap render is displayed
-rw-r--r-- | Makefile | 4 | ||||
-rw-r--r-- | bitmap.c | 135 | ||||
-rw-r--r-- | bitmap.h | 17 | ||||
-rw-r--r-- | pearlhd.c | 11 |
4 files changed, 49 insertions, 118 deletions
@@ -50,6 +50,10 @@ INCLUDES += -I/usr/include/ImageMagick DEFINES += -D_GNU_SOURCE -DPLUGIN_NAME_I18N='"$(PLUGIN)"' +ifdef DEBUG_SKINPEARLHD +DEFINES += -DDEBUG_SKINPEARLHD +endif + ### The object files (add further files here): OBJS = $(PLUGIN).o pearlhd.o bitmap.o config.o setup.o @@ -1,9 +1,5 @@ -#ifdef HAVE_C295 -#include <stl.h> -#endif #include "bitmap.h" -using namespace std; //need ??? using namespace Magick; cOSDImageBitmap::cOSDImageBitmap() { @@ -11,102 +7,53 @@ cOSDImageBitmap::cOSDImageBitmap() { cOSDImageBitmap::~cOSDImageBitmap() { } - -bool cOSDImageBitmap::LoadZoomed(const char *file, int zoomWidth, int zoomHeight, int zoomLeft, int zoomTop) { - bool status; - status = LoadImageMagick(imgkZoom, file); - if (zoomWidth != 0) - imgkZoom.crop(Geometry(zoomWidth, zoomHeight, zoomLeft, zoomTop)); - height = imgkZoom.rows(); - width = imgkZoom.columns(); - return status; -} -bool cOSDImageBitmap::Load(const char *file) -{ - return LoadImageMagick(imgkImage, file); -} - -void cOSDImageBitmap::Render(cBitmap & bmp, int colors, int alpha) +bool cOSDImageBitmap::Load(cBitmap &bmp, const char *Filename, int width, int height, int bpp) { - dsyslog("start to rande image"); - if (!loadingFailed) { - // quantize the picture - QuantizeImageMagick(imgkImage, colors, false); - // generate cBitmap - ConvertImgk2Bmp(bmp, imgkImage, colors); - } else { - dsyslog("can't rander image, loading failed!!!!!!!!!!!!!!!!!"); - } -} + try + { + #ifdef DEBUG_SKINPEARLHD + int start = cTimeMs::Now(); + #endif + + int w, h; + Image osdImage; + osdImage.read(Filename); -void cOSDImageBitmap::Render(cBitmap &bmp, int wWindow, int hWindow, int colors, bool dither) { - int w = wWindow; - int h = hWindow; - int wNew, hNew; - wNew = wWindow; - hNew = hWindow; - if (!loadingFailed) { - Image imgkRender = imgkImage; - width = imgkRender.columns(); - height = imgkRender.rows(); - if (height != h || width != w) { - imgkRender.scale(Geometry(wNew, hNew, 0, 0) ); - width = imgkRender.columns(); - height = imgkRender.rows(); - } - QuantizeImageMagick(imgkRender, colors, dither); - ConvertImgk2Bmp(bmp, imgkRender, colors); - } -} - -bool cOSDImageBitmap::LoadImageMagick(Image &imgkLoad, const char *file) { - try { - imgkLoad.read(file); - if (imgkLoad.fileSize() == 0) { - loadingFailed = true; - return false; - } - else { - height = imgkLoad.baseRows(); - width = imgkLoad.baseColumns(); - origWidth = width; - origHeight = height; - loadingFailed = false; - return true; + if (bpp != 0) + { + osdImage.opacity(OpaqueOpacity); + osdImage.backgroundColor( Color(0, 0, 0, 0)); + osdImage.quantizeColorSpace(RGBColorspace); + osdImage.quantizeColors(bpp); + osdImage.quantize(); + } + + if (height != 0 || width != 0) + osdImage.sample( Geometry(width, height)); + w = osdImage.columns(); + h = osdImage.rows(); + bmp.SetSize(w, h); + + const PixelPacket *pixels = osdImage.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) ); + bmp.DrawPixel(ix, iy, col); + ++pixels; + } } + #ifdef DEBUG_SKINPEARLHD + printf ("skinpearlhd: bitmap render took %d ms\n", int(cTimeMs::Now()-start)); + #endif + return true; } - catch(exception &error) + catch (...) { - loadingFailed = true; return false; } } - -void cOSDImageBitmap::QuantizeImageMagick(Image &imgkQuant, int colors, bool dither) { - if (colors < 24) - { - imgkQuant.quantizeColors(colors); - imgkQuant.quantizeDither(dither); - } - imgkQuant.quantize(); -} - -void cOSDImageBitmap::ConvertImgk2Bmp(cBitmap &bmp, Image &imgkConv, int colors) { - int w = Width(); - int h = Height(); - tColor col; - bmp.SetSize(w, h); - bmp.SetBpp(colors); - const PixelPacket *pixels = imgkConv.getConstPixels(0, 0, w, h); - for (int iy = 0; iy < h; iy++) { - for (int ix = 0; ix < w; ix++) { - col = (0xFF << 24) - | ( (pixels->green * 255 / MaxRGB) << 8) - | ( (pixels->red * 255 / MaxRGB) << 16) - | ( (pixels->blue * 255 / MaxRGB) ); - bmp.DrawPixel(ix, iy, col); - pixels++; - } - } -} @@ -13,23 +13,8 @@ class cOSDImageBitmap { public: cOSDImageBitmap(); ~cOSDImageBitmap(); - bool LoadZoomed(const char *file, int zoomWidth, int zoomHeight, int zoomLeft, int zoomTop); - bool Load(const char *file); - void Save(const char *file); - void Render(cBitmap &bmp, int wWindow, int hWindow, int colors, bool dither); - void Render(cBitmap &bmp, int colors, int alpha=255); - inline int Width() { return width; } - inline int Height() { return height; } - + bool Load(cBitmap &bmp, const char *Filename, int width=0, int height=0, int bpp=0); private: - bool LoadImageMagick(Image &imgkLoad, const char *file); - void QuantizeImageMagick(Image &imgkQuant, int colors, bool dither); - void ConvertImgk2Bmp(cBitmap &bmp, Image &imgkConv, int colors); - Image imgkZoom, imgkImage; - int ZoomWidth, ZoomHeight, ZoomLeft, ZoomTop; - int origWidth, origHeight; - bool loadingFailed; - int width, height; }; #endif @@ -213,17 +213,13 @@ void cSkinPearlHDDisplayChannel::SetChannel(const cChannel *Channel, int Number) switch (PearlHDConfig.ChannelLogoPos) { case 1 : - if(osdbitmap.Load(displayLogoPath.c_str())){ - logo.SetSize(64, 48); - osdbitmap.Render(logo, 64, 48, bpp, false); + if(osdbitmap.Load(logo, displayLogoPath.c_str(), 64, 48)){ osd->DrawBitmap(x1ChannelInfo+120, y1ChannelInfo, logo); } break; case 2 : - if(osdbitmap.Load(displayLogoPath.c_str())){ - logo.SetSize(120, 100); - osdbitmap.Render(logo, 120, 100, bpp, false); + if(osdbitmap.Load(logo, displayLogoPath.c_str(), 120, 100)){ osd->DrawBitmap(x2ChannelInfo-125, y2ChannelInfo-110, logo); } break; @@ -964,8 +960,7 @@ void cSkinPearlHDDisplayMenu::SetEvent(const cEvent *Event) epgPath << cPlugin::ConfigDirectory() << "/tvm2vdr/epgimages"; } epgPath << "/" << Event->EventID() << "." << logoFormat; - if(osdbitmap.Load(epgPath.str().c_str())){ - osdbitmap.Render(epgImg, 300, 225, bpp, false); + if(osdbitmap.Load(epgImg, epgPath.str().c_str(), 300, 225, bpp)){ osd->DrawBitmap(x2Menu-330, y2Menu-285, epgImg); } } |