summaryrefslogtreecommitdiff
path: root/bitmap.c
diff options
context:
space:
mode:
Diffstat (limited to 'bitmap.c')
-rw-r--r--bitmap.c103
1 files changed, 38 insertions, 65 deletions
diff --git a/bitmap.c b/bitmap.c
index 3aa91a5..0137289 100644
--- a/bitmap.c
+++ b/bitmap.c
@@ -1,5 +1,5 @@
/*
- * $Id: bitmap.c,v 1.16 2004/06/16 18:46:50 lordjaxom Exp $
+ * $Id: bitmap.c,v 1.17 2004/06/18 16:08:11 lordjaxom Exp $
*/
#include "bitmap.h"
@@ -14,13 +14,40 @@
using namespace Magick;
#endif
-template<>
-void cImageCache::Delete(string &key, cText2SkinBitmap *&value) {
- delete value;
-}
+cText2SkinCache cText2SkinBitmap::mCache(Text2SkinSetup.MaxCacheFill);
-cImageCache cText2SkinBitmap::mCache(Text2SkinSetup.MaxCacheFill);
-bool cText2SkinBitmap::mFirstTime = true;
+cText2SkinBitmap *cText2SkinBitmap::Load(const char *Filename, int Alpha) {
+ if (mCache.Contains(Filename))
+ return mCache[Filename];
+ else {
+ cText2SkinBitmap *bmp = new cText2SkinBitmap;
+ int len = strlen(Filename);
+ bool result = false;
+ if (len > 4) {
+ if (strcmp(Filename + len - 4, ".xpm") == 0)
+ result = bmp->LoadXpm(Filename, Alpha);
+ else {
+#ifdef HAVE_IMLIB2
+ result = bmp->LoadImlib(Filename, Alpha);
+#else
+# ifdef HAVE_IMAGEMAGICK
+ result = bmp->LoadMagick(Filename, Alpha);
+# endif
+#endif
+ }
+ //else
+ //esyslog("ERROR: text2skin: unknown file format for %s", Filename);
+ } else
+ esyslog("ERROR: text2skin: filename %s too short to identify format", Filename);
+
+ if (result) {
+ bmp->SetAlpha(Alpha);
+ return (mCache[Filename] = bmp);
+ } else
+ delete bmp;
+ }
+ return false;
+}
cText2SkinBitmap::cText2SkinBitmap(void) {
mCurrent = 0;
@@ -40,7 +67,6 @@ cBitmap &cText2SkinBitmap::Get(int &UpdateIn) {
time_t upd, cur = time_ms();
int diff;
if (mLastGet == 0) {
- Dprintf("lastget was %d\n", mLastGet);
mLastGet = cur;
upd = mDelay;
} else if ((diff = cur - mLastGet) >= mDelay) {
@@ -51,12 +77,9 @@ cBitmap &cText2SkinBitmap::Get(int &UpdateIn) {
upd = mDelay - diff;
}
- Dprintf("delay: %d, diff %d\n", mDelay, diff);
-
if (UpdateIn == 0 || UpdateIn > upd)
UpdateIn = upd;
- Dprintf("Get: returning frame %d\n", mCurrent);
return *mBitmaps[mCurrent];
}
@@ -75,39 +98,6 @@ void cText2SkinBitmap::SetAlpha(int Alpha) {
}
}
-cText2SkinBitmap *cText2SkinBitmap::Load(const char *Filename, int Alpha) {
- if (mCache.Contains(Filename))
- return mCache[Filename];
- else {
- cText2SkinBitmap *bmp = new cText2SkinBitmap;
- int len = strlen(Filename);
- bool result = false;
- if (len > 4) {
- if (strcmp(Filename + len - 4, ".xpm") == 0)
- result = bmp->LoadXpm(Filename, Alpha);
- else {
-#ifdef HAVE_IMLIB2
- result = bmp->LoadImlib(Filename, Alpha);
-#else
-# ifdef HAVE_IMAGEMAGICK
- result = bmp->LoadMagick(Filename, Alpha);
-# endif
-#endif
- }
- //else
- //esyslog("ERROR: text2skin: unknown file format for %s", Filename);
- } else
- esyslog("ERROR: text2skin: filename %s too short to identify format", Filename);
-
- if (result) {
- bmp->SetAlpha(Alpha);
- return (mCache[Filename] = bmp);
- } else
- delete bmp;
- }
- return false;
-}
-
bool cText2SkinBitmap::LoadXpm(const char *Filename, int Alpha) {
cBitmap *bmp = new cBitmap(1,1,1);
if (bmp->LoadXpm(Filename)) {
@@ -147,9 +137,6 @@ bool cText2SkinBitmap::LoadImlib(const char *Filename, int Alpha) {
#ifdef HAVE_IMAGEMAGICK
bool cText2SkinBitmap::LoadMagick(const char *Filename, int Alpha) {
- if (mFirstTime)
- InitializeMagick("text2skin");
-
vector<Image> images;
cBitmap *bmp = NULL;
try {
@@ -169,28 +156,14 @@ bool cText2SkinBitmap::LoadMagick(const char *Filename, int Alpha) {
return false;
}
bmp = new cBitmap(w, h, (*it).depth());
+ Dprintf("this image has %d colors\n", (*it).totalColors());
- if ((*it).classType() == PseudoClass) {
- int total = (*it).totalColors();
- for (int ic = 0; ic < (int)total; ++ic) {
- Color c = (*it).colorMap(ic);
- tColor col = (~(c.alphaQuantum() * 255 / MaxRGB) << 24) | ((c.redQuantum() * 255 / MaxRGB) << 16) | ((c.greenQuantum() * 255 / MaxRGB) << 8) | (c.blueQuantum() * 255 / MaxRGB);
- bmp->SetColor(ic, col);
- }
- }
-
const PixelPacket *pix = (*it).getConstPixels(0, 0, w, h);
- const IndexPacket *idx = (*it).getConstIndexes();
for (int iy = 0; iy < h; ++iy) {
for (int ix = 0; ix < w; ++ix) {
- if ((*it).classType() == PseudoClass) {
- bmp->SetIndex(ix, iy, *idx);
- ++idx;
- } else {
- tColor col = (~(pix->opacity * 255 / MaxRGB) << 24) | ((pix->red * 255 / MaxRGB) << 16) | ((pix->green * 255 / MaxRGB) << 8) | (pix->blue * 255 / MaxRGB);
- bmp->DrawPixel(ix, iy, col);
- ++pix;
- }
+ tColor col = (~(pix->opacity * 255 / MaxRGB) << 24) | ((pix->red * 255 / MaxRGB) << 16) | ((pix->green * 255 / MaxRGB) << 8) | (pix->blue * 255 / MaxRGB);
+ bmp->DrawPixel(ix, iy, col);
+ ++pix;
}
}
mBitmaps.push_back(bmp);