From cb4a46e7fbe62d788e66ed6121c717a2d22a4d7c Mon Sep 17 00:00:00 2001 From: watcherhd Date: Thu, 21 Apr 2011 14:14:52 +0000 Subject: svn.miranda.im is moving to a new home! git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@7 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb --- skinengine/src/bitmap_funcs.h | 101 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 skinengine/src/bitmap_funcs.h (limited to 'skinengine/src/bitmap_funcs.h') diff --git a/skinengine/src/bitmap_funcs.h b/skinengine/src/bitmap_funcs.h new file mode 100644 index 0000000..054baef --- /dev/null +++ b/skinengine/src/bitmap_funcs.h @@ -0,0 +1,101 @@ +#ifndef bitmap_funcs_h__ +#define bitmap_funcs_h__ + +// This should make bitmap manipulations much easier... +class CMyBitmap +{ +public: + typedef unsigned long COLOR32; + static inline COLOR32 RGBA(unsigned char r, unsigned char g, unsigned char b, unsigned char a = 0xff) + { + return (a << 24) | (r << 16) | (g << 8) | b; + }; + +private: + HBITMAP hBmpSave, hBmp; + HDC dcBmp; + COLOR32 *bits; + COLOR32 *bitsSave; + int width, height; + + void free(); + + bool loadFromFile_pixel(const TCHAR *fn, const TCHAR *fnAlpha = 0); + bool loadFromFile_gradient(const TCHAR *fn, const TCHAR *fnAlpha = 0); + bool loadFromFile_png(const TCHAR *fn, const TCHAR *fnAlpha = 0); + bool loadFromFile_default(const TCHAR *fn, const TCHAR *fnAlpha = 0); + void premultipleChannels(); + +public: + CMyBitmap(); + CMyBitmap(int w, int h); + CMyBitmap(const TCHAR *fn, const TCHAR *fnAlpha = 0); + ~CMyBitmap(); + void allocate(int w, int h); + + bool loadFromFile(const TCHAR *fn, const TCHAR *fnAlpha = 0); + + int getWidth() { return width; } + int getHeight() { return height; } + + HDC getDC() { return dcBmp; } + HBITMAP getBitmap() { return hBmp; } + + void setAlpha(BYTE level); + void setAlphaRect(int x1, int y1, int x2, int y2, BYTE level); + void setAlphaRect(RECT rc, BYTE level) { setAlphaRect(rc.left, rc.top, rc.right, rc.bottom, level); } + + void makeOpaque(); + void makeOpaqueRect(int x1, int y1, int x2, int y2); + void makeOpaqueRect(RECT rc) { makeOpaqueRect(rc.left, rc.top, rc.right, rc.bottom); } + + void saveAlpha(int x = 0, int y = 0, int w = 0, int h = 0); + void restoreAlpha(int x = 0, int y = 0, int w = 0, int h = 0); + + void Blend(CMyBitmap *bmp, int x, int y, int w, int h); + void BlendPart(CMyBitmap *bmp, int xin, int yin, int win, int hin, int x, int y, int w, int h); + void BlendBits(COLOR32 *inbits, int inw, int inh, int x, int y, int w, int h); + + void Draw(CMyBitmap *bmp, int x, int y, int w, int h); + void DrawPart(CMyBitmap *bmp, int xin, int yin, int win, int hin, int x, int y, int w, int h); + + // slow, very slow... + void BlendColorized(CMyBitmap *bmp, int x, int y, int w, int h, COLOR32 color); + void DrawColorized(CMyBitmap *bmp, int x, int y, int w, int h, COLOR32 color); + void BlendPartColorized(CMyBitmap *bmp, int xin, int yin, int win, int hin, int x, int y, int w, int h, COLOR32 color); + + void Blur(int w, int h); + void IncreaseAlpha(float q); + + void DrawIcon(HICON hic, int x, int y, int w = 0, int h = 0); + void DrawText(TCHAR *str, int x, int y, int blur=0, int strength=0); + + __forceinline COLOR32 *getBits() { return bits; } + __forceinline COLOR32 *getRow(int row) { return bits + row * width; } + __forceinline COLOR32 *operator[] (int row) { return bits + row * width; } + + static __forceinline COLOR32 rgba(COLOR32 r, COLOR32 g, COLOR32 b, COLOR32 a) + { + return ((a & 0xff) << 24) | ((r & 0xff) << 16) | ((g & 0xff) << 8) | (b & 0xff); + } + static __forceinline COLOR32 getr(COLOR32 c) + { + return (c >> 16) & 0xff; + } + static __forceinline COLOR32 getg(COLOR32 c) + { + return (c >> 8) & 0xff; + } + static __forceinline COLOR32 getb(COLOR32 c) + { + return c & 0xff; + } + static __forceinline COLOR32 geta(COLOR32 c) + { + return (c >> 24) & 0xff; + } + + HRGN buildOpaqueRgn(int level = 64, bool opaque = true); +}; + +#endif // __bitmap_funcs_h__ -- cgit v1.2.3