diff options
Diffstat (limited to 'bitmap.c')
-rw-r--r-- | bitmap.c | 93 |
1 files changed, 72 insertions, 21 deletions
@@ -1,5 +1,5 @@ /* - * $Id: bitmap.c,v 1.11 2004/06/05 16:52:44 lordjaxom Exp $ + * $Id: bitmap.c,v 1.13 2004/06/11 15:01:58 lordjaxom Exp $ */ #include "bitmap.h" @@ -10,6 +10,9 @@ #endif #ifdef HAVE_IMAGEMAGICK #include <Magick++.h> +using Magick::Image; +using Magick::PixelPacket; +using Magick::Exception; #endif template<> @@ -19,10 +22,37 @@ void cImageCache::Delete(string &key, cText2SkinBitmap *&value) { cImageCache cText2SkinBitmap::mCache(10); -cText2SkinBitmap::cText2SkinBitmap(void): cBitmap(1, 1, 1) { +cText2SkinBitmap::cText2SkinBitmap(void)/*: cBitmap(1, 1, 1)*/ { + mCurrent = 0; + mLastGet = 0; } cText2SkinBitmap::~cText2SkinBitmap() { + for (int i = 0; i < (int)mBitmaps.size(); ++i) + delete mBitmaps[i]; +} + +cBitmap &cText2SkinBitmap::Get(int &UpdateIn) { + if (mBitmaps.size() == 1) + return *mBitmaps[0]; + + time_t upd, cur = time_ms(); + int diff; + if (mLastGet == 0) { + mLastGet = cur; + upd = mDelay; + } else if ((diff = cur - mLastGet) >= mDelay) { + mCurrent = (mCurrent + 1) % mBitmaps.size(); + mLastGet = cur; + upd = mDelay; + } else { + upd = mDelay - diff; + } + + if (UpdateIn == 0 || UpdateIn > upd) + UpdateIn = upd; + + return *mBitmaps[mCurrent]; } cText2SkinBitmap *cText2SkinBitmap::Load(const char *Filename) { @@ -55,57 +85,78 @@ cText2SkinBitmap *cText2SkinBitmap::Load(const char *Filename) { return false; } +bool cText2SkinBitmap::LoadXpm(const char *Filename) { + cBitmap *bmp = new cBitmap(1,1,1); + if (bmp->LoadXpm(Filename)) { + mBitmaps.push_back(bmp); + return true; + } + delete bmp; + return false; +} + #ifdef HAVE_IMLIB2 bool cText2SkinBitmap::LoadImlib(const char *Filename) { Imlib_Image image; + cBitmap *bmp = NULL; image = imlib_load_image(Filename); if (!image) return false; Imlib_Context ctx = imlib_context_new(); imlib_context_push(ctx); imlib_context_set_image(image); - SetSize(imlib_image_get_width(), imlib_image_get_height()); - SetBpp(8); + bmp = new cBitmap(imlib_image_get_width(), imlib_image_get_height(), 8); uint8_t *data = (uint8_t*)imlib_image_get_data_for_reading_only(); int pal = 0, pos = 0; - for (int y = 0; y < Height(); ++y) { - for (int x = 0; x < Width(); ++x) { + for (int y = 0; y < bmp->Height(); ++y) { + for (int x = 0; x < bmp->Width(); ++x) { tColor col = (data[pos + 3] << 24) | (data[pos + 2] << 16) | (data[pos + 1] << 8) | data[pos + 0]; - int res = Index(col); + int res = bmp->Index(col); if (pal > 0 && res == 0) ;//esyslog("ERROR: text2skin: Too many colors used in palette"); else - SetIndex(x, y, res); + bmp->SetIndex(x, y, res); pos += 4; } } imlib_free_image(); imlib_context_free(ctx); + mBitmaps.push_back(bmp); return true; } #endif #ifdef HAVE_IMAGEMAGICK bool cText2SkinBitmap::LoadMagick(const char *Filename) { - Magick::Image image; + vector<Image> images; + cBitmap *bmp = NULL; try { int w, h; - image.read(Filename); - w = image.columns(); - h = image.rows(); - SetSize(w, h); - SetBpp(8); + vector<Image>::iterator it; + readImages(&images, Filename); + if (images.size() == 0) { + esyslog("ERROR: text2skin: Couldn't load %s", Filename); + return false; + } + mDelay = images[0].animationDelay(); + for (it = images.begin(); it != images.end(); ++it) { + w = (*it).columns(); + h = (*it).rows(); + bmp = new cBitmap(w, h, 8); - const Magick::PixelPacket *ptr = image.getConstPixels(0, 0, w, h); - for (int iy = 0; iy < h; ++iy) { - for (int ix = 0; ix < w; ++ix) { - tColor col = (((~ptr->opacity & 0xFF00) << 16) | ((ptr->red & 0xFF00) << 8) | (ptr->green & 0xFF00) | ((ptr->blue & 0xFF00) >> 8)); - DrawPixel(ix, iy, col); - ++ptr; + const PixelPacket *ptr = (*it).getConstPixels(0, 0, w, h); + for (int iy = 0; iy < h; ++iy) { + for (int ix = 0; ix < w; ++ix) { + tColor col = (((~ptr->opacity & 0xFF00) << 16) | ((ptr->red & 0xFF00) << 8) | (ptr->green & 0xFF00) | ((ptr->blue & 0xFF00) >> 8)); + bmp->DrawPixel(ix, iy, col); + ++ptr; + } } + mBitmaps.push_back(bmp); } - } catch (Magick::Exception &e) { + } catch (Exception &e) { esyslog("ERROR: text2skin: Couldn't load %s: %s", Filename, e.what()); + delete bmp; return false; } return true; |