summaryrefslogtreecommitdiff
path: root/splashscreen/src/bitmap_funcs.cpp
diff options
context:
space:
mode:
authormataes2007 <mataes2007@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-04-24 15:08:20 +0000
committermataes2007 <mataes2007@e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb>2011-04-24 15:08:20 +0000
commit04209d6e6d0e33082d82c5ff33bfdb0b3bc40c36 (patch)
treee204437f04c80bbd5afea46ec914fffcfc42e95b /splashscreen/src/bitmap_funcs.cpp
parent0a6b3eb280b298dc485d60155e6958185501225f (diff)
splashscreen:
rewritten to Unicode not used mirandaboot.ini, save settings in db support mp3 code optimization version bump added open file dialog filter translation git-svn-id: http://miranda-plugins.googlecode.com/svn/trunk@19 e753b5eb-9565-29b2-b5c5-2cc6f99dfbcb
Diffstat (limited to 'splashscreen/src/bitmap_funcs.cpp')
-rw-r--r--splashscreen/src/bitmap_funcs.cpp498
1 files changed, 11 insertions, 487 deletions
diff --git a/splashscreen/src/bitmap_funcs.cpp b/splashscreen/src/bitmap_funcs.cpp
index 162d832..20a1427 100644
--- a/splashscreen/src/bitmap_funcs.cpp
+++ b/splashscreen/src/bitmap_funcs.cpp
@@ -1,10 +1,6 @@
#include "headers.h"
-
#include "bitmap_funcs.h"
-//#include <ole2.h>
-//#include <olectl.h>
-
BOOL (WINAPI *_mempng2dib) (BYTE*, DWORD, BITMAPINFOHEADER**);
MyBitmap::MyBitmap()
@@ -26,7 +22,7 @@ MyBitmap::MyBitmap(int w, int h)
allocate(w,h);
}
-MyBitmap::MyBitmap(const char *fn, const char *fnAlpha)
+MyBitmap::MyBitmap(TCHAR *fn, TCHAR *fnAlpha)
{
dcBmp = 0;
hBmp = 0;
@@ -51,20 +47,6 @@ void MyBitmap::makeOpaque()
bits[i] |= 0xff000000;
}
-/*
-void MyBitmap::makeOpaqueRect(int x1, int y1, int x2, int y2)
-{
- if (!bits) return;
-
- for (int i = y1; i < y2; i++)
- 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)
@@ -125,67 +107,6 @@ void MyBitmap::restoreAlpha(int x, int y, int w, int h)
bitsSave = 0;
}
-/*
-void MyBitmap::DrawBits(COLOR32 *inbits, int inw, int inh, int x, int y, int w, int h)
-{
- if (!(bits && inbits)) return;
-
- float kx = (float)inw / w;
- float ky = (float)inh / h;
-
- if (x+w >= this->getWidth())
- w = this->getWidth() - x;
- 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)];
- }
- }
-}
-*/
-
-/*
-void MyBitmap::BlendBits(COLOR32 *inbits, int inw, int inh, int x, int y, int w, int h)
-{
- if (!(bits && inbits)) return;
-
- float kx = (float)inw / w;
- float ky = (float)inh / h;
-
- if (x+w >= this->getWidth())
- w = this->getWidth() - x;
- 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 = inbits[int(i*ky)*inw + int(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
- );
- }
- }
-}
-*/
void MyBitmap::Blend(MyBitmap *bmp, int x, int y, int w, int h)
{
if (!(bits && bmp && bmp->bits)) return;
@@ -221,412 +142,16 @@ void MyBitmap::Blend(MyBitmap *bmp, int x, int y, int w, int h)
}
}
-/*
-void MyBitmap::Draw(MyBitmap *bmp, int x, int y, int w, int h)
-{
- if (!(bits && bmp && bmp->bits)) return;
-
- if (!w) w = bmp->width;
- if (!h) h = bmp->height;
- float kx = (float)bmp->width / w;
- float ky = (float)bmp->height / h;
-
- if (x+w >= this->getWidth())
- w = this->getWidth() - x;
- 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)];
- }
- }
-}
-*/
-
-/*
-void MyBitmap::BlendColorized(MyBitmap *bmp, int x, int y, int w, int h, COLOR32 color)
-{
- if (!(bits && bmp && bmp->bits)) return;
-
- if (!w) w = bmp->width;
- if (!h) h = bmp->height;
- float kx = (float)bmp->width / w;
- float ky = (float)bmp->height / h;
-
- // we should swap B and R channels when working with win32 COLORREF
- float koef1r = (255 - getb(color)) / 128.0;
- 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);
-
- 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)]));
-
- 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 src = (cl > 128) ?
- rgba(
- (koef1r * cl + br)*alpha/255,
- (koef1g * cl + bg)*alpha/255,
- (koef1b * cl + bb)*alpha/255,
- alpha):
- rgba(
- koef2r * cl * alpha/255,
- koef2g * cl * alpha/255,
- koef2b * cl * alpha/255,
- alpha);
-// 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)+(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
- );
-
- }
- }
-}
-*/
-
-/*
-void MyBitmap::DrawColorized(MyBitmap *bmp, int x, int y, int w, int h, COLOR32 color)
-{
- if (!(bits && bmp && bmp->bits)) return;
-
- if (!w) w = bmp->width;
- if (!h) h = bmp->height;
- float kx = (float)bmp->width / w;
- float ky = (float)bmp->height / h;
-
- // we should swap B and R channels when working with win32 COLORREF
- float koef1r = (255 - getb(color)) / 128.0;
- 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);
-
- 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(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;
- bits[(i+y)*width + (j+x)] = (cl > 128) ?
- rgba(
- (koef1r * cl + br)*alpha/255,
- (koef1g * cl + bg)*alpha/255,
- (koef1b * cl + bb)*alpha/255,
- alpha):
- rgba(
- koef2r * cl * alpha/255,
- koef2g * cl * alpha/255,
- koef2b * cl * alpha/255,
- alpha);
-// 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)]));
- }
- }
-}
-*/
-
-/*
-void MyBitmap::BlendPart(MyBitmap *bmp, int xin, int yin, int win, int hin, int x, int y, int w, int h)
-{
- if (!(bits && bmp && bmp->bits)) return;
-
- if (!w) w = win;
- if (!h) h = hin;
- float kx = (float)win / w;
- float ky = (float)hin / h;
-
- if (x+w >= this->getWidth())
- w = this->getWidth() - x;
- 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)];
- 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)];
- }
- }
-}
-*/
-
-/*
-void MyBitmap::BlendPartColorized(MyBitmap *bmp, int xin, int yin, int win, int hin, int x, int y, int w, int h, COLOR32 color)
-{
- if (!(bits && bmp && bmp->bits)) return;
-
- if (!w) w = win;
- if (!h) h = hin;
- float kx = (float)win / w;
- float ky = (float)hin / h;
-
- if (x+w >= this->getWidth())
- w = this->getWidth() - x;
- if (y+h >= this->getHeight())
- h = this->getHeight() - y;
-
- // we should swap B and R channels when working with win32 COLORREF
- float koef1r = (255 - getb(color)) / 128.0;
- 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);
-
- 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;
- COLOR32 src = (cl > 128) ?
- rgba(
- (koef1r * cl + br)*alpha/255,
- (koef1g * cl + bg)*alpha/255,
- (koef1b * cl + bb)*alpha/255,
- alpha):
- rgba(
- koef2r * cl * alpha/255,
- koef2g * cl * alpha/255,
- koef2b * cl * alpha/255,
- alpha);
-// 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)+(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
- );
-
- 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)];
- }
- }
-}
-*/
-
-/*
-void MyBitmap::DrawPart(MyBitmap *bmp, int xin, int yin, int win, int hin, int x, int y, int w, int h)
-{
- if (!(bits && bmp && bmp->bits)) return;
-
- if (!w) w = win;
- if (!h) h = hin;
- float kx = (float)win / w;
- float ky = (float)hin / h;
-
- if (x+w >= this->getWidth())
- w = this->getWidth() - x;
- 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)];
- }
- }
-}
-*/
-
-/*
-void MyBitmap::DrawNoAlpha(MyBitmap *bmp, int x, int y, int w, int h)
-{
- if (!(bits && bmp && bmp->bits)) return;
-
- 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];
- }
- }
-}
-*/
-
-/*
-void MyBitmap::DrawIcon(HICON hic, int x, int y, int w, int h)
-{
- ICONINFO info;
- GetIconInfo(hic, &info);
-
- BITMAP bmpColor, bmpMask;
- GetObject(info.hbmMask, sizeof(bmpMask), &bmpMask);
- GetObject(info.hbmColor, sizeof(bmpColor), &bmpColor);
-
- 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)))
- {
- DeleteObject(info.hbmColor);
- DeleteObject(info.hbmMask);
- hic = (HICON)CopyImage(hic,IMAGE_ICON,w,h,LR_COPYFROMRESOURCE);
- GetIconInfo(hic, &info);
- GetObject(info.hbmMask, sizeof(bmpMask), &bmpMask);
- GetObject(info.hbmColor, sizeof(bmpColor), &bmpColor);
- }
-
- BYTE *cbit = new BYTE[bmpColor.bmWidthBytes*bmpColor.bmHeight];
- BYTE *mbit = new BYTE[bmpMask.bmWidthBytes*bmpMask.bmHeight];
- 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;
- if (!pixel[3])
- {
- pixel[3] = (*(mbit + i*bmpMask.bmWidthBytes + j*bmpMask.bmBitsPixel/8) & (1<<(7-j%8))) ? 0 : 255;
- }
-
- if (pixel[3] != 255)
- {
- pixel[0] = pixel[0] * pixel[3] / 255;
- pixel[1] = pixel[1] * pixel[3] / 255;
- pixel[2] = pixel[2] * pixel[3] / 255;
- }
- }
- }
-
- this->BlendBits((COLOR32 *)cbit, bmpColor.bmWidth, bmpColor.bmHeight, 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);
- }
-
- DeleteObject(info.hbmColor);
- DeleteObject(info.hbmMask);
-}
-*/
-
-void MyBitmap::DrawText(char *str, int x, int y)
+void MyBitmap::DrawText(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-2,y-2,sz.cx+2,sz.cy+2);
- ::DrawText(this->getDC(), str, strlen(str), &rc, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_NOPREFIX);
+ ::DrawText(this->getDC(), str, (int)_tcslen(str), &rc, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_NOPREFIX);
this->restoreAlpha(x-2,y-2,sz.cx+2,sz.cy+2);
//(x,y,sz.cx,sz.cy);
}
-/*
-void MyBitmap::DrawTextW(WCHAR *str, int x, int y)
-{
- if (MyGetTextExtentPoint32W && MyDrawTextW)
- {
- SIZE sz; MyGetTextExtentPoint32W(this->getDC(), str, MylstrlenW(str), &sz);
- RECT rc; SetRect(&rc, x, y, x+10000, y+10000);
- this->saveAlpha(x,y,sz.cx,sz.cy);
- MyDrawTextW(this->getDC(), str, MylstrlenW(str), &rc, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_NOPREFIX);
- this->restoreAlpha(x,y,sz.cx,sz.cy);
- }
-}
-*/
-
HRGN MyBitmap::buildOpaqueRgn()
{
return CreateRectRgn(0, 0, width, height);
@@ -658,16 +183,16 @@ HRGN MyBitmap::buildOpaqueRgn()
return rgn;
}
-bool MyBitmap::loadFromFile(const char *fn, const char *fnAlpha)
+bool MyBitmap::loadFromFile(TCHAR *fn, TCHAR *fnAlpha)
{
if (bits) free();
SIZE sz;
- char ext[5];
- memcpy(ext,fn+(strlen(fn)-4),5);
+ TCHAR *ext;
+ ext = &fn[lstrlen(fn)-4];
- if (!lstrcmpi(ext,".png"))
+ if (!lstrcmpi(ext, _T(".png")))
{
HANDLE hFile, hMap = NULL;
BYTE* ppMap = NULL;
@@ -679,7 +204,7 @@ bool MyBitmap::loadFromFile(const char *fn, const char *fnAlpha)
return false;
}
- if ((hFile = CreateFileA(fn, GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL)) != INVALID_HANDLE_VALUE)
+ 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);
@@ -695,9 +220,8 @@ bool MyBitmap::loadFromFile(const char *fn, const char *fnAlpha)
else
cbFileSize = 0;
#ifdef _DEBUG
- logMessage("Loading splash file","done");
+ logMessage(_T("Loading splash file"), _T("done"));
#endif
-
}
if (ppMap) UnmapViewOfFile(ppMap);
@@ -759,7 +283,7 @@ bool MyBitmap::loadFromFile(const char *fn, const char *fnAlpha)
if (!hBmpLoaded)
{
#ifdef _DEBUG
- logMessage("MyBitmap::loadFromFile", "Bitmap load failed");
+ logMessage(_T("MyBitmap::loadFromFile"), _T("Bitmap load failed"));
#endif
return false;
}
@@ -835,4 +359,4 @@ void MyBitmap::premultipleChannels()
{
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]));
-}
+} \ No newline at end of file