summaryrefslogtreecommitdiff
path: root/plugins/Popup
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/Popup')
-rw-r--r--plugins/Popup/src/bitmap_funcs.cpp688
-rw-r--r--plugins/Popup/src/popup_wnd2.cpp13
2 files changed, 307 insertions, 394 deletions
diff --git a/plugins/Popup/src/bitmap_funcs.cpp b/plugins/Popup/src/bitmap_funcs.cpp
index 4c9f42514c..91cb7093d2 100644
--- a/plugins/Popup/src/bitmap_funcs.cpp
+++ b/plugins/Popup/src/bitmap_funcs.cpp
@@ -27,13 +27,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#define PU_BMP_ACCURATE_ARITHMETICS
#ifdef PU_BMP_ACCURATE_ARITHMETICS
- #define PU_DIV255(x) ((x)/255)
- #define PU_DIV128(x) ((x)/128)
- typedef float pu_koef;
+#define PU_DIV255(x) ((x)/255)
+#define PU_DIV128(x) ((x)/128)
+typedef float pu_koef;
#else
- #define PU_DIV255(x) ((x)>>8)
- #define PU_DIV128(x) ((x)>>7)
- typedef long pu_koef;
+#define PU_DIV255(x) ((x)>>8)
+#define PU_DIV128(x) ((x)>>7)
+typedef long pu_koef;
#endif
MyBitmap::MyBitmap()
@@ -52,7 +52,7 @@ MyBitmap::MyBitmap(int w, int h)
bits = 0;
width = height = 0;
bitsSave = 0;
- allocate(w,h);
+ allocate(w, h);
}
MyBitmap::MyBitmap(const TCHAR *fn, const TCHAR *fnAlpha)
@@ -68,7 +68,7 @@ MyBitmap::MyBitmap(const TCHAR *fn, const TCHAR *fnAlpha)
MyBitmap::~MyBitmap()
{
if (bitsSave)
- delete [] bitsSave;
+ delete[] bitsSave;
freemem();
}
@@ -77,7 +77,7 @@ void MyBitmap::makeOpaque()
if (!bits) return;
GdiFlush();
- for (int i=0; i < width*height; i++)
+ for (int i = 0; i < width*height; i++)
bits[i] |= 0xff000000;
}
@@ -87,17 +87,16 @@ void MyBitmap::makeOpaqueRect(int x1, int y1, int x2, int y2)
GdiFlush();
for (int i = y1; i < y2; i++)
- for (int j = x1; j < x2; j++)
- {
- int idx = i * width + j;
- bits[idx] |= 0xff000000;
+ for (int j = x1; j < x2; j++) {
+ int idx = i * width + j;
+ bits[idx] |= 0xff000000;
}
}
void MyBitmap::saveAlpha(int x, int y, int w, int h)
{
if (bitsSave)
- delete [] bitsSave;
+ delete[] bitsSave;
GdiFlush();
@@ -111,15 +110,13 @@ void MyBitmap::saveAlpha(int x, int y, int w, int h)
bitsSave = new COLOR32[w*h];
COLOR32 *p1 = bitsSave;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- COLOR32 *p2 = bits + (y+i)*width + x;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ COLOR32 *p2 = bits + (y + i)*width + x;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
*p1++ = *p2++;
}
}
@@ -137,28 +134,25 @@ void MyBitmap::restoreAlpha(int x, int y, int w, int h)
COLOR32 *p1 = bitsSave;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- COLOR32 *p2 = bits + (y+i)*width + x;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
- if ((*p1&0x00ffffff) != (*p2&0x00ffffff))
- {
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ COLOR32 *p2 = bits + (y + i)*width + x;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
+ if ((*p1 & 0x00ffffff) != (*p2 & 0x00ffffff)) {
*p2 |= 0xff000000;
- } else
- {
- *p2 = (*p2&0x00ffffff) | (*p1&0xff000000);
+ }
+ else {
+ *p2 = (*p2 & 0x00ffffff) | (*p1 & 0xff000000);
}
++p1;
++p2;
}
}
- delete [] bitsSave;
+ delete[] bitsSave;
bitsSave = 0;
}
@@ -171,20 +165,18 @@ void MyBitmap::DrawBits(COLOR32 *inbits, int inw, int inh, int x, int y, int w,
float kx = (float)inw / w;
float ky = (float)inh / h;
- if (x+w >= this->getWidth())
+ if (x + w >= this->getWidth())
w = this->getWidth() - x;
- if (y+h >= this->getHeight())
+ if (y + h >= this->getHeight())
h = this->getHeight() - y;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
- bits[(i+y)*width + (j+x)] = inbits[int(i*ky)*inw + int(j*kx)];
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
+ bits[(i + y)*width + (j + x)] = inbits[int(i*ky)*inw + int(j*kx)];
}
}
}
@@ -198,27 +190,25 @@ void MyBitmap::BlendBits(COLOR32 *inbits, int inw, int inh, int x, int y, int w,
float kx = (float)inw / w;
float ky = (float)inh / h;
- if (x+w >= this->getWidth())
+ if (x + w >= this->getWidth())
w = this->getWidth() - x;
- if (y+h >= this->getHeight())
+ if (y + h >= this->getHeight())
h = this->getHeight() - y;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
COLOR32 src = inbits[int(i*ky)*inw + int(j*kx)];
- COLOR32 dst = bits[(i+y)*width + (j+x)];
+ COLOR32 dst = bits[(i + y)*width + (j + x)];
long alpha = geta(src);
- bits[(i+y)*width + (j+x)] = rgba(
- getr(src)+PU_DIV255((255-alpha)*getr(dst)),
- getg(src)+PU_DIV255((255-alpha)*getg(dst)),
- getb(src)+PU_DIV255((255-alpha)*getb(dst)),
- geta(src)+PU_DIV255((255-alpha)*geta(dst))
+ bits[(i + y)*width + (j + x)] = rgba(
+ getr(src) + PU_DIV255((255 - alpha)*getr(dst)),
+ getg(src) + PU_DIV255((255 - alpha)*getg(dst)),
+ getb(src) + PU_DIV255((255 - alpha)*getb(dst)),
+ geta(src) + PU_DIV255((255 - alpha)*geta(dst))
);
}
}
@@ -235,27 +225,25 @@ void MyBitmap::Blend(MyBitmap *bmp, int x, int y, int w, int h)
float kx = (float)bmp->width / w;
float ky = (float)bmp->height / h;
- if (x+w >= this->getWidth())
+ if (x + w >= this->getWidth())
w = this->getWidth() - x;
- if (y+h >= this->getHeight())
+ if (y + h >= this->getHeight())
h = this->getHeight() - y;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
COLOR32 src = bmp->bits[int(i*ky)*bmp->width + int(j*kx)];
- COLOR32 dst = bits[(i+y)*width + (j+x)];
+ COLOR32 dst = bits[(i + y)*width + (j + x)];
long alpha = geta(src);
- bits[(i+y)*width + (j+x)] = rgba(
- getr(src)+PU_DIV255((255-alpha)*getr(dst)),
- getg(src)+PU_DIV255((255-alpha)*getg(dst)),
- getb(src)+PU_DIV255((255-alpha)*getb(dst)),
- geta(src)+PU_DIV255((255-alpha)*geta(dst))
+ bits[(i + y)*width + (j + x)] = rgba(
+ getr(src) + PU_DIV255((255 - alpha)*getr(dst)),
+ getg(src) + PU_DIV255((255 - alpha)*getg(dst)),
+ getb(src) + PU_DIV255((255 - alpha)*getb(dst)),
+ geta(src) + PU_DIV255((255 - alpha)*geta(dst))
);
}
}
@@ -270,8 +258,7 @@ void MyBitmap::Draw(MyBitmap *bmp, int x, int y, int w, int h)
if (!w) w = bmp->width;
if (!h) h = bmp->height;
- if (!x && !y && (w == width) && (h == height) && (w == bmp->width) && (h == bmp->height))
- {
+ if (!x && !y && (w == width) && (h == height) && (w == bmp->width) && (h == bmp->height)) {
// fast bitmap copy is possible good for animated avatars
CopyMemory(bits, bmp->bits, width*height*sizeof(COLOR32));
return;
@@ -280,20 +267,18 @@ void MyBitmap::Draw(MyBitmap *bmp, int x, int y, int w, int h)
float kx = (float)bmp->width / w;
float ky = (float)bmp->height / h;
- if (x+w >= this->getWidth())
+ if (x + w >= this->getWidth())
w = this->getWidth() - x;
- if (y+h >= this->getHeight())
+ if (y + h >= this->getHeight())
h = this->getHeight() - y;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
- bits[(i+y)*width + (j+x)] = bmp->bits[int(i*ky)*bmp->width + int(j*kx)];
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
+ bits[(i + y)*width + (j + x)] = bmp->bits[int(i*ky)*bmp->width + int(j*kx)];
}
}
}
@@ -314,58 +299,43 @@ void MyBitmap::BlendColorized(MyBitmap *bmp, int x, int y, int w, int h, COLOR32
float koef1g = (255 - getg(color)) / 128.0;
float koef1b = (255 - getr(color)) / 128.0;
- int br = - 255 + 2 * getb(color);
- int bg = - 255 + 2 * getg(color);
- int bb = - 255 + 2 * getr(color);
+ int br = -255 + 2 * getb(color);
+ int bg = -255 + 2 * getg(color);
+ int bb = -255 + 2 * getr(color);
float koef2r = (getb(color)) / 128.0;
float koef2g = (getg(color)) / 128.0;
float koef2b = (getr(color)) / 128.0;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
-
-// COLOR32 cl = getr(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]);
-// bits[(i+y)*width + (j+x)] = (cl > 128) ?
-// rgba(koef1r * cl + br, koef1g * cl + bg, koef1b * cl + bb, geta(bmp->bits[int(i*ky)*bmp->width + int(j*kx)])):
-// rgba(koef2r * cl, koef2g * cl, koef2b * cl, geta(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]));
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
long alpha = geta(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]);
-// COLOR32 cl = getr(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]);
- COLOR32 cl = alpha ? getr(bmp->bits[int(i*ky)*bmp->width + int(j*kx)])*255/alpha : 0;
+ COLOR32 cl = alpha ? getr(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]) * 255 / alpha : 0;
#pragma warning(push)
#pragma warning(disable: 4244)
COLOR32 src = (cl > 128) ?
rgba(
- PU_DIV255((koef1r * cl + br)*alpha),
- PU_DIV255((koef1g * cl + bg)*alpha),
- PU_DIV255((koef1b * cl + bb)*alpha),
- alpha):
+ PU_DIV255((koef1r * cl + br)*alpha),
+ PU_DIV255((koef1g * cl + bg)*alpha),
+ PU_DIV255((koef1b * cl + bb)*alpha),
+ alpha) :
rgba(
- PU_DIV255(koef2r * cl * alpha),
- PU_DIV255(koef2g * cl * alpha),
- PU_DIV255(koef2b * cl * alpha),
- alpha);
+ PU_DIV255(koef2r * cl * alpha),
+ PU_DIV255(koef2g * cl * alpha),
+ PU_DIV255(koef2b * cl * alpha),
+ alpha);
#pragma warning(pop)
-// COLOR32 cl = getr(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]);
-// COLOR32 src = (cl > 128) ?
-// rgba(koef1r * cl + br, koef1g * cl + bg, koef1b * cl + bb, alpha):
-// rgba(koef2r * cl, koef2g * cl, koef2b * cl, alpha);
- COLOR32 dst = bits[(i+y)*width + (j+x)];
-// long alpha = geta(src);
- bits[(i+y)*width + (j+x)] = rgba(
- getr(src)+PU_DIV255((255-alpha)*getr(dst)),
- getg(src)+PU_DIV255((255-alpha)*getg(dst)),
- getb(src)+PU_DIV255((255-alpha)*getb(dst)),
- geta(src)+PU_DIV255((255-alpha)*geta(dst))
- );
-
+ COLOR32 dst = bits[(i + y)*width + (j + x)];
+ bits[(i + y)*width + (j + x)] = rgba(
+ getr(src) + PU_DIV255((255 - alpha)*getr(dst)),
+ getg(src) + PU_DIV255((255 - alpha)*getg(dst)),
+ getb(src) + PU_DIV255((255 - alpha)*getb(dst)),
+ geta(src) + PU_DIV255((255 - alpha)*geta(dst)));
}
}
}
@@ -386,39 +356,36 @@ void MyBitmap::DrawColorized(MyBitmap *bmp, int x, int y, int w, int h, COLOR32
float koef1g = (255 - getg(color)) / 128.0;
float koef1b = (255 - getr(color)) / 128.0;
- int br = - 255 + 2 * getb(color);
- int bg = - 255 + 2 * getg(color);
- int bb = - 255 + 2 * getr(color);
+ int br = -255 + 2 * getb(color);
+ int bg = -255 + 2 * getg(color);
+ int bb = -255 + 2 * getr(color);
float koef2r = (getb(color)) / 128.0;
float koef2g = (getg(color)) / 128.0;
float koef2b = (getr(color)) / 128.0;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
long alpha = geta(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]);
-// COLOR32 cl = getr(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]);
- COLOR32 cl = alpha ? getr(bmp->bits[int(i*ky)*bmp->width + int(j*kx)])*255/alpha : 0;
+ COLOR32 cl = alpha ? getr(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]) * 255 / alpha : 0;
#pragma warning(push)
#pragma warning(disable: 4244)
- bits[(i+y)*width + (j+x)] = (cl > 128) ?
+ bits[(i + y)*width + (j + x)] = (cl > 128) ?
rgba(
- PU_DIV255((koef1r * cl + br)*alpha),
- PU_DIV255((koef1g * cl + bg)*alpha),
- PU_DIV255((koef1b * cl + bb)*alpha),
- alpha):
+ PU_DIV255((koef1r * cl + br)*alpha),
+ PU_DIV255((koef1g * cl + bg)*alpha),
+ PU_DIV255((koef1b * cl + bb)*alpha),
+ alpha) :
rgba(
- PU_DIV255(koef2r * cl * alpha),
- PU_DIV255(koef2g * cl * alpha),
- PU_DIV255(koef2b * cl * alpha),
- alpha);
+ PU_DIV255(koef2r * cl * alpha),
+ PU_DIV255(koef2g * cl * alpha),
+ PU_DIV255(koef2b * cl * alpha),
+ alpha);
#pragma warning(pop)
}
}
@@ -436,27 +403,25 @@ void MyBitmap::BlendPart(MyBitmap *bmp, int xin, int yin, int win, int hin, int
float kx = (float)win / w;
float ky = (float)hin / h;
- if (x+w >= this->getWidth())
+ if (x + w >= this->getWidth())
w = this->getWidth() - x;
- if (y+h >= this->getHeight())
+ if (y + h >= this->getHeight())
h = this->getHeight() - y;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
- COLOR32 src = bmp->bits[int(yin+i*ky)*bmp->width + int(xin+j*kx)];
- COLOR32 dst = bits[(i+y)*width + (j+x)];
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
+ COLOR32 src = bmp->bits[int(yin + i*ky)*bmp->width + int(xin + j*kx)];
+ COLOR32 dst = bits[(i + y)*width + (j + x)];
long alpha = geta(src);
- bits[(i+y)*width + (j+x)] = rgba(
- getr(src)+PU_DIV255((255-alpha)*getr(dst)),
- getg(src)+PU_DIV255((255-alpha)*getg(dst)),
- getb(src)+PU_DIV255((255-alpha)*getb(dst)),
- geta(src)+PU_DIV255((255-alpha)*geta(dst))
+ bits[(i + y)*width + (j + x)] = rgba(
+ getr(src) + PU_DIV255((255 - alpha)*getr(dst)),
+ getg(src) + PU_DIV255((255 - alpha)*getg(dst)),
+ getb(src) + PU_DIV255((255 - alpha)*getb(dst)),
+ geta(src) + PU_DIV255((255 - alpha)*geta(dst))
);
}
}
@@ -474,9 +439,9 @@ void MyBitmap::BlendPartColorized(MyBitmap *bmp, int xin, int yin, int win, int
float kx = (float)win / w;
float ky = (float)hin / h;
- if (x+w >= this->getWidth())
+ if (x + w >= this->getWidth())
w = this->getWidth() - x;
- if (y+h >= this->getHeight())
+ if (y + h >= this->getHeight())
h = this->getHeight() - y;
// we should swap B and R channels when working with win32 COLORREF
@@ -484,63 +449,43 @@ void MyBitmap::BlendPartColorized(MyBitmap *bmp, int xin, int yin, int win, int
float koef1g = (255 - getg(color)) / 128.0;
float koef1b = (255 - getr(color)) / 128.0;
- int br = - 255 + 2 * getb(color);
- int bg = - 255 + 2 * getg(color);
- int bb = - 255 + 2 * getr(color);
+ int br = -255 + 2 * getb(color);
+ int bg = -255 + 2 * getg(color);
+ int bb = -255 + 2 * getr(color);
float koef2r = (getb(color)) / 128.0;
float koef2g = (getg(color)) / 128.0;
float koef2b = (getr(color)) / 128.0;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
-
- long alpha = geta(bmp->bits[int(yin+i*ky)*bmp->width + int(xin+j*kx)]);
-// COLOR32 cl = getr(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]);
- COLOR32 cl = alpha ? getr(bmp->bits[int(yin+i*ky)*bmp->width + int(xin+j*kx)])*255/alpha : 0;
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
+
+ long alpha = geta(bmp->bits[int(yin + i*ky)*bmp->width + int(xin + j*kx)]);
+ COLOR32 cl = alpha ? getr(bmp->bits[int(yin + i*ky)*bmp->width + int(xin + j*kx)]) * 255 / alpha : 0;
#pragma warning(push)
#pragma warning(disable: 4244)
COLOR32 src = (cl > 128) ?
rgba(
- PU_DIV255((koef1r * cl + br)*alpha),
- PU_DIV255((koef1g * cl + bg)*alpha),
- PU_DIV255((koef1b * cl + bb)*alpha),
- alpha):
+ PU_DIV255((koef1r * cl + br)*alpha),
+ PU_DIV255((koef1g * cl + bg)*alpha),
+ PU_DIV255((koef1b * cl + bb)*alpha),
+ alpha) :
rgba(
- PU_DIV255(koef2r * cl * alpha),
- PU_DIV255(koef2g * cl * alpha),
- PU_DIV255(koef2b * cl * alpha),
- alpha);
+ PU_DIV255(koef2r * cl * alpha),
+ PU_DIV255(koef2g * cl * alpha),
+ PU_DIV255(koef2b * cl * alpha),
+ alpha);
#pragma warning(pop)
-// COLOR32 cl = getr(bmp->bits[int(i*ky)*bmp->width + int(j*kx)]);
-// COLOR32 src = (cl > 128) ?
-// rgba(koef1r * cl + br, koef1g * cl + bg, koef1b * cl + bb, alpha):
-// rgba(koef2r * cl, koef2g * cl, koef2b * cl, alpha);
- COLOR32 dst = bits[(i+y)*width + (j+x)];
-// long alpha = geta(src);
- bits[(i+y)*width + (j+x)] = rgba(
- getr(src)+PU_DIV255((255-alpha)*getr(dst)),
- getg(src)+PU_DIV255((255-alpha)*getg(dst)),
- getb(src)+PU_DIV255((255-alpha)*getb(dst)),
- geta(src)+PU_DIV255((255-alpha)*geta(dst))
- );
-
-/* COLOR32 src = bmp->bits[int(yin+i*ky)*bmp->width + int(xin+j*kx)];
- COLOR32 dst = bits[(i+y)*width + (j+x)];
- long alpha = geta(src);
- bits[(i+y)*width + (j+x)] = rgba(
- getr(src)+(255-alpha)*getr(dst)/255,
- getg(src)+(255-alpha)*getg(dst)/255,
- getb(src)+(255-alpha)*getb(dst)/255,
- geta(src)+(255-alpha)*geta(dst)/255
- );*/
-// bits[(i+y)*width + (j+x)] = bmp->bits[int(yin+i*ky)*bmp->width + int(xin+j*kx)];
+ COLOR32 dst = bits[(i + y)*width + (j + x)];
+ bits[(i + y)*width + (j + x)] = rgba(
+ getr(src) + PU_DIV255((255 - alpha)*getr(dst)),
+ getg(src) + PU_DIV255((255 - alpha)*getg(dst)),
+ getb(src) + PU_DIV255((255 - alpha)*getb(dst)),
+ geta(src) + PU_DIV255((255 - alpha)*geta(dst)));
}
}
}
@@ -557,20 +502,18 @@ void MyBitmap::DrawPart(MyBitmap *bmp, int xin, int yin, int win, int hin, int x
float kx = (float)win / w;
float ky = (float)hin / h;
- if (x+w >= this->getWidth())
+ if (x + w >= this->getWidth())
w = this->getWidth() - x;
- if (y+h >= this->getHeight())
+ if (y + h >= this->getHeight())
h = this->getHeight() - y;
- for (int i=0; i < h; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- for (int j = 0; j < w; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
- bits[(i+y)*width + (j+x)] = bmp->bits[int(yin+i*ky)*bmp->width + int(xin+j*kx)];
+ for (int i = 0; i < h; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ for (int j = 0; j < w; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
+ bits[(i + y)*width + (j + x)] = bmp->bits[int(yin + i*ky)*bmp->width + int(xin + j*kx)];
}
}
}
@@ -581,15 +524,13 @@ void MyBitmap::DrawNoAlpha(MyBitmap *bmp, int x, int y, int w, int h)
GdiFlush();
- for (int i=0; i < bmp->height; i++)
- {
- if (i+y < 0) continue;
- if (i+y >= height) break;
- for (int j = 0; j < bmp->width; j++)
- {
- if (j+x < 0) continue;
- if (j+x >= width) break;
- bits[(i+y)*width + (j+x)] = bmp->bits[i*bmp->width + j];
+ for (int i = 0; i < bmp->height; i++) {
+ if (i + y < 0) continue;
+ if (i + y >= height) break;
+ for (int j = 0; j < bmp->width; j++) {
+ if (j + x < 0) continue;
+ if (j + x >= width) break;
+ bits[(i + y)*width + (j + x)] = bmp->bits[i*bmp->width + j];
}
}
}
@@ -608,13 +549,11 @@ void MyBitmap::DrawIcon(HICON hic, int x, int y, int w, int h)
if (!w) w = abs(bmpMask.bmWidth);
if (!h) h = abs(bmpMask.bmHeight);
- if (bmpColor.bmBitsPixel == 32)
- {
- if ((w != abs(bmpMask.bmWidth)) || (h != abs(bmpMask.bmHeight)))
- {
+ if (bmpColor.bmBitsPixel == 32) {
+ if ((w != abs(bmpMask.bmWidth)) || (h != abs(bmpMask.bmHeight))) {
DeleteObject(info.hbmColor);
DeleteObject(info.hbmMask);
- HICON hicTmp = (HICON)CopyImage(hic,IMAGE_ICON,w,h,LR_COPYFROMRESOURCE);
+ HICON hicTmp = (HICON)CopyImage(hic, IMAGE_ICON, w, h, LR_COPYFROMRESOURCE);
GetIconInfo(hicTmp, &info);
GetObject(info.hbmMask, sizeof(bmpMask), &bmpMask);
GetObject(info.hbmColor, sizeof(bmpColor), &bmpColor);
@@ -626,18 +565,13 @@ void MyBitmap::DrawIcon(HICON hic, int x, int y, int w, int h)
GetBitmapBits(info.hbmColor, bmpColor.bmWidthBytes*bmpColor.bmHeight, cbit);
GetBitmapBits(info.hbmMask, bmpMask.bmWidthBytes*bmpMask.bmHeight, mbit);
- for (int i=0; i < bmpColor.bmHeight; i++)
- {
- for (int j = 0; j < bmpColor.bmWidth; j++)
- {
- BYTE *pixel = cbit + i*bmpColor.bmWidthBytes + j*4;
+ for (int i = 0; i < bmpColor.bmHeight; i++) {
+ for (int j = 0; j < bmpColor.bmWidth; j++) {
+ BYTE *pixel = cbit + i*bmpColor.bmWidthBytes + j * 4;
if (!pixel[3])
- {
- pixel[3] = (*(mbit + i*bmpMask.bmWidthBytes + j*bmpMask.bmBitsPixel/8) & (1<<(7-j%8))) ? 0 : 255;
- }
+ pixel[3] = (*(mbit + i*bmpMask.bmWidthBytes + j*bmpMask.bmBitsPixel / 8) & (1 << (7 - j % 8))) ? 0 : 255;
- if (pixel[3] != 255)
- {
+ if (pixel[3] != 255) {
pixel[0] = PU_DIV255(pixel[0] * pixel[3]);
pixel[1] = PU_DIV255(pixel[1] * pixel[3]);
pixel[2] = PU_DIV255(pixel[2] * pixel[3]);
@@ -647,13 +581,13 @@ void MyBitmap::DrawIcon(HICON hic, int x, int y, int w, int h)
this->BlendBits((COLOR32 *)cbit, bmpColor.bmWidth, bmpColor.bmHeight, x, y, w, h);
- delete [] mbit;
- delete [] cbit;
- } else
- {
- this->saveAlpha(x,y,w,h);
+ delete[] mbit;
+ delete[] cbit;
+ }
+ else {
+ this->saveAlpha(x, y, w, h);
DrawIconEx(this->getDC(), x, y, hic, w, h, 0, NULL, DI_NORMAL);
- this->restoreAlpha(x,y,w,h);
+ this->restoreAlpha(x, y, w, h);
}
DeleteObject(info.hbmColor);
@@ -663,10 +597,10 @@ void MyBitmap::DrawIcon(HICON hic, int x, int y, int w, int h)
void MyBitmap::Draw_Text(TCHAR *str, int x, int y)
{
SIZE sz; GetTextExtentPoint32(this->getDC(), str, lstrlen(str), &sz);
- RECT rc; SetRect(&rc, x, y, x+10000, y+10000);
- this->saveAlpha(x,y,sz.cx,sz.cy);
+ RECT rc; SetRect(&rc, x, y, x + 10000, y + 10000);
+ this->saveAlpha(x, y, sz.cx, sz.cy);
DrawText(this->getDC(), str, lstrlen(str), &rc, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_NOPREFIX);
- this->restoreAlpha(x,y,sz.cx,sz.cy);
+ this->restoreAlpha(x, y, sz.cx, sz.cy);
}
// based on code by Yuriy Zaporozhets from:
@@ -688,19 +622,14 @@ HRGN MyBitmap::buildOpaqueRgn(int level, bool opaque)
int first = 0;
bool wasfirst = false;
bool ismask = false;
- for (int i=0; i < height; i++)
- {
+ for (int i = 0; i < height; i++) {
int j; // we will need j after the loop!
- for (j = 0; j < width; j++)
- {
+ for (j = 0; j < width; j++) {
ismask = opaque ? geta(this->getRow(i)[j]) > (DWORD)level : geta(this->getRow(i)[j]) < (DWORD)level;
- if (wasfirst)
- {
- if (!ismask)
- {
- SetRect(&pRects[pRgnData->rdh.nCount++], first, i, j, i+1);
- if (pRgnData->rdh.nCount >= (DWORD) rectsCount)
- {
+ if (wasfirst) {
+ if (!ismask) {
+ SetRect(&pRects[pRgnData->rdh.nCount++], first, i, j, i + 1);
+ if (pRgnData->rdh.nCount >= (DWORD)rectsCount) {
rectsCount += addRectsCount;
LPRGNDATA pRgnDataNew = (LPRGNDATA)(new BYTE[sizeof(RGNDATAHEADER) + (rectsCount)*sizeof(RECT)]);
memcpy(pRgnDataNew, pRgnData, sizeof(RGNDATAHEADER) + pRgnData->rdh.nCount * sizeof(RECT));
@@ -710,19 +639,16 @@ HRGN MyBitmap::buildOpaqueRgn(int level, bool opaque)
}
wasfirst = false;
}
- } else
- if (ismask) // set wasfirst when mask is found
- {
+ }
+ else if (ismask) { // set wasfirst when mask is found
first = j;
wasfirst = true;
}
}
- if (wasfirst && ismask)
- {
- SetRect(&pRects[pRgnData->rdh.nCount++], first, i, j, i+1);
- if (pRgnData->rdh.nCount >= (DWORD) rectsCount)
- {
+ if (wasfirst && ismask) {
+ SetRect(&pRects[pRgnData->rdh.nCount++], first, i, j, i + 1);
+ if (pRgnData->rdh.nCount >= (DWORD)rectsCount) {
rectsCount += addRectsCount;
LPRGNDATA pRgnDataNew = (LPRGNDATA)(new BYTE[sizeof(RGNDATAHEADER) + (rectsCount)*sizeof(RECT)]);
memcpy(pRgnDataNew, pRgnData, sizeof(RGNDATAHEADER) + pRgnData->rdh.nCount * sizeof(RECT));
@@ -732,7 +658,6 @@ HRGN MyBitmap::buildOpaqueRgn(int level, bool opaque)
}
wasfirst = false;
}
-
}
HRGN hRgn = ExtCreateRegion(NULL, sizeof(RGNDATAHEADER) + pRgnData->rdh.nCount*sizeof(RECT), (LPRGNDATA)pRgnData);
@@ -753,13 +678,13 @@ static int hex2dec(char hex)
bool MyBitmap::loadFromFile_pixel(const TCHAR *fn, const TCHAR *fnAlpha)
{
- allocate(1,1);
- int r, g, b, a=255;
+ allocate(1, 1);
+ int r, g, b, a = 255;
const TCHAR *p = fn + lstrlen(_T("pixel:"));
r = (hex2dec(p[0]) << 4) + hex2dec(p[1]);
g = (hex2dec(p[2]) << 4) + hex2dec(p[3]);
b = (hex2dec(p[4]) << 4) + hex2dec(p[5]);
- *bits = rgba(r,g,b,a);
+ *bits = rgba(r, g, b, a);
return true;
}
@@ -767,31 +692,29 @@ bool MyBitmap::loadFromFile_gradient(const TCHAR *fn, const TCHAR *fnAlpha)
{
const TCHAR *p = fn + lstrlen(_T("gradient:"));
- if (*p == 'h') allocate(256,1);
- else allocate(1,256);
+ if (*p == 'h') allocate(256, 1);
+ else allocate(1, 256);
- int r, g, b, a=255;
+ int r, g, b, a = 255;
p += 2;
r = (hex2dec(p[0]) << 4) + hex2dec(p[1]);
g = (hex2dec(p[2]) << 4) + hex2dec(p[3]);
b = (hex2dec(p[4]) << 4) + hex2dec(p[5]);
- COLOR32 from = rgba(r,g,b,a);
+ COLOR32 from = rgba(r, g, b, a);
p += 7;
r = (hex2dec(p[0]) << 4) + hex2dec(p[1]);
g = (hex2dec(p[2]) << 4) + hex2dec(p[3]);
b = (hex2dec(p[4]) << 4) + hex2dec(p[5]);
- COLOR32 to = rgba(r,g,b,a);
+ COLOR32 to = rgba(r, g, b, a);
- for (int i=0; i < 256; ++i)
- {
+ for (int i = 0; i < 256; ++i) {
bits[i] = rgba(
- ((255-i) * getr(from) + i * getr(to)) / 255,
- ((255-i) * getg(from) + i * getg(to)) / 255,
- ((255-i) * getb(from) + i * getb(to)) / 255,
- 255
- );
+ ((255 - i) * getr(from) + i * getr(to)) / 255,
+ ((255 - i) * getg(from) + i * getg(to)) / 255,
+ ((255 - i) * getb(from) + i * getb(to)) / 255,
+ 255);
}
return true;
@@ -799,77 +722,70 @@ bool MyBitmap::loadFromFile_gradient(const TCHAR *fn, const TCHAR *fnAlpha)
bool MyBitmap::loadFromFile_png(const TCHAR *fn, const TCHAR *fnAlpha)
{
- if (ServiceExists(MS_PNG2DIB))
- {
- HANDLE hFile, hMap = 0;
- BYTE *ppMap = 0;
- long cbFileSize = 0;
- BITMAPINFOHEADER *pDib;
- BYTE *pDibBits;
- if ((hFile = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE)
- if ((hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
- if ((ppMap = (BYTE*)MapViewOfFile( hMap, FILE_MAP_READ, 0, 0, 0 )) != NULL)
- cbFileSize = GetFileSize(hFile, NULL);
- if (cbFileSize)
- {
- PNG2DIB param;
- param.pSource = ppMap;
- param.cbSourceSize = cbFileSize;
- param.pResult = &pDib;
- if (CallService(MS_PNG2DIB, 0, (LPARAM)&param))
- pDibBits = (BYTE*)(pDib+1);
- else
- cbFileSize = 0;
- }
+ if (!ServiceExists(MS_PNG2DIB))
+ return false;
- if (ppMap) UnmapViewOfFile(ppMap);
- if (hMap) CloseHandle(hMap);
- if (hFile) CloseHandle(hFile);
-
- if (!cbFileSize) return false;
-
- BITMAPINFO *bi=(BITMAPINFO*)pDib;
- BYTE *pt=(BYTE*)bi;
- pt+=bi->bmiHeader.biSize;
-
- if (bi->bmiHeader.biBitCount != 32)
- {
- allocate(abs(bi->bmiHeader.biWidth), abs(bi->bmiHeader.biHeight));
- HDC hdcTmp = CreateCompatibleDC(getDC());
- HBITMAP hBitmap = CreateDIBitmap(getDC(), pDib, CBM_INIT, pDibBits, bi, DIB_PAL_COLORS);
- SelectObject(hdcTmp, hBitmap);
- BitBlt(this->getDC(), 0, 0, abs(bi->bmiHeader.biWidth), abs(bi->bmiHeader.biHeight), hdcTmp, 0, 0, SRCCOPY);
- this->makeOpaque();
- DeleteDC(hdcTmp);
- DeleteObject(hBitmap);
- } else
- {
- allocate(abs(bi->bmiHeader.biWidth), abs(bi->bmiHeader.biHeight));
- BYTE *p2=(BYTE *)pt;
- for (int y=0; y<bi->bmiHeader.biHeight; ++y)
- {
- BYTE *p1=(BYTE *)bits + (bi->bmiHeader.biHeight-y-1)*bi->bmiHeader.biWidth*4;
- for (int x=0; x<bi->bmiHeader.biWidth; ++x)
- {
- p1[0]= p2[0];
- p1[1]= p2[1];
- p1[2]= p2[2];
- p1[3]= p2[3];
- p1 += 4;
- p2 += 4;
- }
+ HANDLE hFile, hMap = 0;
+ BYTE *ppMap = 0;
+ long cbFileSize = 0;
+ BITMAPINFOHEADER *pDib;
+ BYTE *pDibBits;
+ if ((hFile = CreateFile(fn, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE)
+ if ((hMap = CreateFileMapping(hFile, NULL, PAGE_READONLY, 0, 0, NULL)) != NULL)
+ if ((ppMap = (BYTE*)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
+ cbFileSize = GetFileSize(hFile, NULL);
+ if (cbFileSize) {
+ PNG2DIB param;
+ param.pSource = ppMap;
+ param.cbSourceSize = cbFileSize;
+ param.pResult = &pDib;
+ if (CallService(MS_PNG2DIB, 0, (LPARAM)&param))
+ pDibBits = (BYTE*)(pDib + 1);
+ else
+ cbFileSize = 0;
+ }
+
+ if (ppMap) UnmapViewOfFile(ppMap);
+ if (hMap) CloseHandle(hMap);
+ if (hFile) CloseHandle(hFile);
+
+ if (!cbFileSize) return false;
+
+ BITMAPINFO *bi = (BITMAPINFO*)pDib;
+ BYTE *pt = (BYTE*)bi;
+ pt += bi->bmiHeader.biSize;
+
+ if (bi->bmiHeader.biBitCount != 32) {
+ allocate(abs(bi->bmiHeader.biWidth), abs(bi->bmiHeader.biHeight));
+ HDC hdcTmp = CreateCompatibleDC(getDC());
+ HBITMAP hBitmap = CreateDIBitmap(getDC(), pDib, CBM_INIT, pDibBits, bi, DIB_PAL_COLORS);
+ HBITMAP hOldBmp = (HBITMAP)SelectObject(hdcTmp, hBitmap);
+ BitBlt(this->getDC(), 0, 0, abs(bi->bmiHeader.biWidth), abs(bi->bmiHeader.biHeight), hdcTmp, 0, 0, SRCCOPY);
+ this->makeOpaque();
+ SelectObject(hdcTmp, hOldBmp);
+ DeleteDC(hdcTmp);
+ DeleteObject(hBitmap);
+ }
+ else {
+ allocate(abs(bi->bmiHeader.biWidth), abs(bi->bmiHeader.biHeight));
+ BYTE *p2 = (BYTE *)pt;
+ for (int y = 0; y < bi->bmiHeader.biHeight; ++y) {
+ BYTE *p1 = (BYTE *)bits + (bi->bmiHeader.biHeight - y - 1)*bi->bmiHeader.biWidth * 4;
+ for (int x = 0; x < bi->bmiHeader.biWidth; ++x) {
+ p1[0] = p2[0];
+ p1[1] = p2[1];
+ p1[2] = p2[2];
+ p1[3] = p2[3];
+ p1 += 4;
+ p2 += 4;
}
-// memcpy(bits, pt, bi->bmiHeader.biSizeImage);
- premultipleChannels();
}
- GlobalFree(pDib);
- return true;
- } else
- {
-// MSGERROR(TranslateT("You need the png2dib plugin v. 0.1.3.x or later to process PNG images");
- return false;
+ premultipleChannels();
}
+
+ GlobalFree(pDib);
+ return true;
}
bool MyBitmap::loadFromFile_default(const TCHAR *fn, const TCHAR *fnAlpha)
@@ -884,7 +800,7 @@ bool MyBitmap::loadFromFile_default(const TCHAR *fn, const TCHAR *fnAlpha)
HDC dcTmp = CreateCompatibleDC(0);
GetBitmapDimensionEx(hBmpLoaded, &sz);
- HBITMAP hBmpDcSave = (HBITMAP)SelectObject(dcTmp, hBmpLoaded);
+ HBITMAP hBmpDcSave = (HBITMAP)SelectObject(dcTmp, hBmpLoaded);
allocate(sz.cx, sz.cy);
BitBlt(dcBmp, 0, 0, width, height, dcTmp, 0, 0, SRCCOPY);
@@ -895,15 +811,13 @@ bool MyBitmap::loadFromFile_default(const TCHAR *fn, const TCHAR *fnAlpha)
MyBitmap alpha;
if (fnAlpha && alpha.loadFromFile(fnAlpha) &&
(alpha.getWidth() == width) &&
- (alpha.getHeight() == height))
- {
- for (int i=0; i < width*height; i++)
- bits[i] = (bits[i] & 0x00ffffff) | ( (alpha.bits[i] & 0x000000ff) << 24 );
+ (alpha.getHeight() == height)) {
+ for (int i = 0; i < width*height; i++)
+ bits[i] = (bits[i] & 0x00ffffff) | ((alpha.bits[i] & 0x000000ff) << 24);
premultipleChannels();
- } else
- {
- makeOpaque();
}
+ else makeOpaque();
+
return true;
}
@@ -931,23 +845,21 @@ void MyBitmap::allocate(int w, int h)
height = h;
BITMAPINFO bi;
-
- bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
- bi.bmiHeader.biWidth = w;
- bi.bmiHeader.biHeight = -h;
- bi.bmiHeader.biPlanes = 1;
- bi.bmiHeader.biBitCount = 32;
- bi.bmiHeader.biCompression = BI_RGB;
-
- if (dcBmp)
- {
+ bi.bmiHeader.biSize = sizeof(bi.bmiHeader);
+ bi.bmiHeader.biWidth = w;
+ bi.bmiHeader.biHeight = -h;
+ bi.bmiHeader.biPlanes = 1;
+ bi.bmiHeader.biBitCount = 32;
+ bi.bmiHeader.biCompression = BI_RGB;
+
+ if (dcBmp) {
DeleteObject(SelectObject(dcBmp, hBmpSave));
DeleteDC(dcBmp);
}
- hBmp = (HBITMAP)CreateDIBSection(0, &bi, DIB_RGB_COLORS, (void **)&bits, 0, 0);
- dcBmp = CreateCompatibleDC(0);
- hBmpSave = (HBITMAP)SelectObject(dcBmp, hBmp);
+ hBmp = (HBITMAP)CreateDIBSection(0, &bi, DIB_RGB_COLORS, (void **)&bits, 0, 0);
+ dcBmp = CreateCompatibleDC(0);
+ hBmpSave = (HBITMAP)SelectObject(dcBmp, hBmp);
GdiFlush();
}
@@ -969,6 +881,6 @@ void MyBitmap::premultipleChannels()
{
GdiFlush();
- for (int i=0; i < width*height; i++)
- bits[i] = rgba(getr(bits[i])*geta(bits[i])/255, getg(bits[i])*geta(bits[i])/255, getb(bits[i])*geta(bits[i])/255, geta(bits[i]));
+ for (int i = 0; i < width*height; i++)
+ bits[i] = rgba(getr(bits[i])*geta(bits[i]) / 255, getg(bits[i])*geta(bits[i]) / 255, getb(bits[i])*geta(bits[i]) / 255, geta(bits[i]));
}
diff --git a/plugins/Popup/src/popup_wnd2.cpp b/plugins/Popup/src/popup_wnd2.cpp
index cbfc012529..cb2b350861 100644
--- a/plugins/Popup/src/popup_wnd2.cpp
+++ b/plugins/Popup/src/popup_wnd2.cpp
@@ -166,13 +166,14 @@ PopupWnd2::~PopupWnd2()
if (m_hwnd)
SetWindowLongPtr(m_hwnd, GWLP_USERDATA, 0);
- if (m_bmp) delete m_bmp;
- if (m_bmpBase) delete m_bmpBase;
- if (m_bmpAnimate) delete m_bmpAnimate;
- if (m_mtText) MText.Destroy(m_mtText);
+ delete m_bmp;
+ delete m_bmpBase;
+ delete m_bmpAnimate;
+ delete m_avatar;
+ delete []m_actions;
+
+ if (m_mtText) MText.Destroy(m_mtText);
if (m_mtTitle) MText.Destroy(m_mtTitle);
- if (m_avatar) delete m_avatar;
- if (m_actions) delete [] m_actions;
}
void PopupWnd2::startThread()