summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVille Skyttä <ville.skytta@iki.fi>2009-07-14 00:28:51 +0300
committerVille Skyttä <ville.skytta@iki.fi>2009-07-14 00:28:51 +0300
commite671882a3b64a83dce98d84cdd58e2f48ed83fc0 (patch)
tree0af339926947df92fdd758c4a97eb7f8050d9196
parent2a448802b7a8683cbfed601f2d6f7e4aaafca845 (diff)
downloadvdr-plugin-text2skin-e671882a3b64a83dce98d84cdd58e2f48ed83fc0.tar.gz
vdr-plugin-text2skin-e671882a3b64a83dce98d84cdd58e2f48ed83fc0.tar.bz2
Ensure only one image library is used.
-rw-r--r--Makefile26
-rw-r--r--README7
-rw-r--r--bitmap.c108
3 files changed, 64 insertions, 77 deletions
diff --git a/Makefile b/Makefile
index 3d2d7e7..564625a 100644
--- a/Makefile
+++ b/Makefile
@@ -6,10 +6,8 @@ STRIP=strip
# Text2Skin if you use Imlib2! (That's why I actually implemented ImageMagick)
# TBD: is this still true?
-# Define only one of these, leave others commented out.
-HAVE_IMAGEMAGICK=1
-#HAVE_GRAPHICSMAGICK=1
-#HAVE_IMLIB2=1 # not recommended
+# External image lib to use: imagemagick, graphicsmagick, imlib2 or none
+IMAGELIB = imagemagick
# DO NOT EDIT BELOW THIS LINE UNLESS YOU KNOW WHAT YOU'RE DOING
@@ -70,23 +68,19 @@ ifdef DEVELOPMENT_FEATURES
DEFINES += -DDEVELOPMENT_FEATURES
endif
-ifdef HAVE_IMLIB2
- DEFINES += -DHAVE_IMLIB2
- INCLUDES += $(shell pkg-config --cflags imlib2)
- LIBS += $(shell pkg-config --libs imlib2)
- OBJS += quantize.o
-endif
-
-ifdef HAVE_IMAGEMAGICK
+ifeq ($(IMAGELIB), imagemagick)
DEFINES += -DHAVE_IMAGEMAGICK
INCLUDES += $(shell pkg-config --cflags ImageMagick++)
LIBS += $(shell pkg-config --libs ImageMagick++)
-endif
-
-ifdef HAVE_GRAPHICSMAGICK
- DEFINES += -DHAVE_IMAGEMAGICK # yep, really HAVE_IMAGEMAGICK
+else ifeq ($(IMAGELIB), graphicsmagick)
+ DEFINES += -DHAVE_IMAGEMAGICK # yep, really HAVE_IMAGEMAGICK here
INCLUDES += $(shell pkg-config --cflags GraphicsMagick++)
LIBS += $(shell pkg-config --libs GraphicsMagick++)
+else ifeq ($(IMAGELIB), imlib2)
+ DEFINES += -DHAVE_IMLIB2
+ INCLUDES += $(shell pkg-config --cflags imlib2)
+ LIBS += $(shell pkg-config --libs imlib2)
+ OBJS += quantize.o
endif
ifdef DEBUG
diff --git a/README b/README
index 7562090..ac9b9ec 100644
--- a/README
+++ b/README
@@ -26,8 +26,8 @@ Prerequisites:
For loading images in format other than simple XPM, you will need an image
library. You can choose between three supported libraries, ImageMagick,
GraphicsMagick or Imlib2, of which the first one is the default. You can
-specify which library to use (if any) in the first few lines of the Makefile.
-Here is an overview of the advantages and drawbacks of each solution:
+specify which library to use (if any) using the IMAGELIB variable in Makefile.
+Here is an overview of the advantages and drawbacks of each alternative:
No library
- you can only load XPM files
@@ -40,9 +40,6 @@ Imlib2
+ you can load many different image types
- CRASHES WHEN USED TOGETHER WITH THE GRAPHTFT-PLUGIN!
-Using more than one of the above at the same time doesn't make sense, just
-choose one or none.
-
HINT: Although the manuals of ImageMagick and GraphicsMagick claim that the
used library Magick++ is part of the source distribution, some binary
distributions may have to install Magick++ separately.
diff --git a/bitmap.c b/bitmap.c
index e58b251..87252ea 100644
--- a/bitmap.c
+++ b/bitmap.c
@@ -6,13 +6,12 @@
#include "setup.h"
#include <vdr/tools.h>
#define X_DISPLAY_MISSING
-#ifdef HAVE_IMLIB2
-#include "quantize.h"
-#include <Imlib2.h>
-#endif
#ifdef HAVE_IMAGEMAGICK
#include <Magick++.h>
using namespace Magick;
+#elif defined(HAVE_IMLIB2)
+#include "quantize.h"
+#include <Imlib2.h>
#endif
#include <glob.h>
@@ -150,60 +149,9 @@ bool cText2SkinBitmap::LoadXpm(const char *Filename) {
return false;
}
-#if !(defined(HAVE_IMLIB2) || defined(HAVE_IMAGEMAGICK))
bool cText2SkinBitmap::LoadNonXpm(const char *Filename, int height, int width, int colors, bool Quiet) {
- if (!Quiet)
- esyslog("ERROR: text2skin: unknown file format for %s", Filename);
-}
-#endif
-
-#ifdef HAVE_IMLIB2
-bool cText2SkinBitmap::LoadNonXpm(const char *Filename, int height, int width, int colors, bool Quiet) {
- Imlib_Image image;
- unsigned char * outputImage = NULL;
- unsigned int * outputPalette = NULL;
- cQuantizeWu* quantizer = new cQuantizeWu();
- cBitmap *bmp = NULL;
- image = imlib_load_image(Filename);
- if (!image)
- return false;
- Imlib_Context ctx = imlib_context_new();
- imlib_context_push(ctx);
- if (height != 0 || width != 0){
- imlib_context_set_image(image);
- image = imlib_create_cropped_scaled_image(0,0,imlib_image_get_width(), imlib_image_get_height() ,width , height);
- }
- imlib_context_set_image(image);
- bmp = new cBitmap(imlib_image_get_width(), imlib_image_get_height(), 8);
- uint8_t *data = (uint8_t*)imlib_image_get_data_for_reading_only();
- if ( colors != 0 ){
- quantizer->Quantize(data, imlib_image_get_width()* imlib_image_get_height(), colors);
- outputImage = quantizer->OutputImage();
- outputPalette = quantizer->OutputPalette();
- }
- int pos = 0;
- for (int y = 0; y < bmp->Height(); ++y) {
- for (int x = 0; x < bmp->Width(); ++x) {
- if ( colors != 0 ){
- bmp->DrawPixel(x, y , outputPalette[outputImage[y * bmp->Width() + x]] | 0xFF000000 );
- }else{
- tColor col = (data[pos + 3] << 24) | (data[pos + 2] << 16) | (data[pos + 1] << 8) | data[pos + 0];
- bmp->DrawPixel(x, y, col);
- pos += 4;
- }
- }
- }
-
- imlib_free_image();
- imlib_context_free(ctx);
- mBitmaps.push_back(bmp);
- delete(quantizer);
- return true;
-}
-#endif
#ifdef HAVE_IMAGEMAGICK
-bool cText2SkinBitmap::LoadNonXpm(const char *Filename, int height, int width, int colors, bool Quiet) {
std::vector<Image> images;
cBitmap *bmp = NULL;
try {
@@ -258,5 +206,53 @@ bool cText2SkinBitmap::LoadNonXpm(const char *Filename, int height, int width, i
return false;
}
return true;
-}
+
+#elif defined(HAVE_IMLIB2)
+ Imlib_Image image;
+ unsigned char * outputImage = NULL;
+ unsigned int * outputPalette = NULL;
+ cQuantizeWu* quantizer = new cQuantizeWu();
+ cBitmap *bmp = NULL;
+ image = imlib_load_image(Filename);
+ if (!image)
+ return false;
+ Imlib_Context ctx = imlib_context_new();
+ imlib_context_push(ctx);
+ if (height != 0 || width != 0){
+ imlib_context_set_image(image);
+ image = imlib_create_cropped_scaled_image(0,0,imlib_image_get_width(), imlib_image_get_height() ,width , height);
+ }
+ imlib_context_set_image(image);
+ bmp = new cBitmap(imlib_image_get_width(), imlib_image_get_height(), 8);
+ uint8_t *data = (uint8_t*)imlib_image_get_data_for_reading_only();
+ if ( colors != 0 ){
+ quantizer->Quantize(data, imlib_image_get_width()* imlib_image_get_height(), colors);
+ outputImage = quantizer->OutputImage();
+ outputPalette = quantizer->OutputPalette();
+ }
+ int pos = 0;
+ for (int y = 0; y < bmp->Height(); ++y) {
+ for (int x = 0; x < bmp->Width(); ++x) {
+ if ( colors != 0 ){
+ bmp->DrawPixel(x, y , outputPalette[outputImage[y * bmp->Width() + x]] | 0xFF000000 );
+ }else{
+ tColor col = (data[pos + 3] << 24) | (data[pos + 2] << 16) | (data[pos + 1] << 8) | data[pos + 0];
+ bmp->DrawPixel(x, y, col);
+ pos += 4;
+ }
+ }
+ }
+
+ imlib_free_image();
+ imlib_context_free(ctx);
+ mBitmaps.push_back(bmp);
+ delete(quantizer);
+ return true;
+
+#else /* Not built with external image library */
+ if (!Quiet)
+ esyslog("ERROR: text2skin: unknown file format for %s", Filename);
+ return false;
+
#endif
+}