diff options
author | George Hazan <george.hazan@gmail.com> | 2015-04-14 16:03:35 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2015-04-14 16:03:35 +0000 |
commit | ac093517c8a975f51d8a696c34a6f75ce3a7fd10 (patch) | |
tree | 5296e27606b9079ec077dde85167e9331f47bb56 /plugins/SplashScreen | |
parent | 2ea12fed0b4177a4caff56ab5486e789e0bb9143 (diff) |
- fix for mixing delete & delete[];
- code cleaning
git-svn-id: http://svn.miranda-ng.org/main/trunk@12816 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'plugins/SplashScreen')
-rw-r--r-- | plugins/SplashScreen/src/bitmap_funcs.cpp | 179 |
1 files changed, 81 insertions, 98 deletions
diff --git a/plugins/SplashScreen/src/bitmap_funcs.cpp b/plugins/SplashScreen/src/bitmap_funcs.cpp index e7498e3cc6..7951adb88c 100644 --- a/plugins/SplashScreen/src/bitmap_funcs.cpp +++ b/plugins/SplashScreen/src/bitmap_funcs.cpp @@ -37,7 +37,7 @@ MyBitmap::MyBitmap(int w, int h) bits = 0;
width = height = 0;
bitsSave = 0;
- allocate(w,h);
+ allocate(w, h);
}
MyBitmap::MyBitmap(TCHAR *fn, TCHAR *fnAlpha)
@@ -53,7 +53,7 @@ MyBitmap::MyBitmap(TCHAR *fn, TCHAR *fnAlpha) MyBitmap::~MyBitmap()
{
if (bitsSave)
- delete [] bitsSave;
+ delete[] bitsSave;
free();
}
@@ -68,7 +68,7 @@ void MyBitmap::makeOpaque() void MyBitmap::saveAlpha(int x, int y, int w, int h)
{
if (bitsSave)
- delete [] bitsSave;
+ delete[] bitsSave;
if (!w) w = width;
if (!h) h = height;
@@ -76,15 +76,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++;
}
}
@@ -100,28 +98,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;
}
@@ -134,27 +129,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)+(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)] = 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
);
}
}
@@ -163,10 +156,10 @@ void MyBitmap::Blend(MyBitmap *bmp, int x, int y, int w, int h) void MyBitmap::DrawText(TCHAR *str, int x, int y)
{
SIZE sz; GetTextExtentPoint32(this->getDC(), str, (int)mir_tstrlen(str), &sz);
- RECT rc; SetRect(&rc, x, y, x+10000, y+10000);
- this->saveAlpha(x-2,y-2,sz.cx+2,sz.cy+2);
+ 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, -1, &rc, DT_LEFT | DT_TOP | DT_SINGLELINE | DT_NOPREFIX);
- this->restoreAlpha(x-2,y-2,sz.cx+2,sz.cy+2);
+ this->restoreAlpha(x - 2, y - 2, sz.cx + 2, sz.cy + 2);
//(x,y,sz.cx,sz.cy);
}
@@ -177,7 +170,7 @@ HRGN MyBitmap::buildOpaqueRgn() //
int i, rectCount = 0;
for (i = 0; i < width*height; i++)
- if (((bits[i] >> 24)&0xff) >= 128)
+ if (((bits[i] >> 24) & 0xff) >= 128)
rectCount++;
RGNDATA *rgnData = (RGNDATA *)malloc(sizeof(RGNDATAHEADER) + rectCount * sizeof(RECT));
@@ -189,9 +182,8 @@ HRGN MyBitmap::buildOpaqueRgn() char *p = (char *)&(rgnData->Buffer);
for (i = 0; i < width*height; i++)
- if (((bits[i] >> 24)&0xff) >= 128)
- {
- SetRect((LPRECT)p, i%width,i/width,i%width+1,i/width+1);
+ if (((bits[i] >> 24) & 0xff) >= 128) {
+ SetRect((LPRECT)p, i%width, i / width, i%width + 1, i / width + 1);
p += sizeof(RECT);
}
@@ -208,38 +200,36 @@ bool MyBitmap::loadFromFile(TCHAR *fn, TCHAR *fnAlpha) SIZE sz;
TCHAR *ext;
- ext = &fn[mir_tstrlen(fn)-4];
+ ext = &fn[mir_tstrlen(fn) - 4];
- if (!mir_tstrcmpi(ext, _T(".png")))
- {
+ if (!mir_tstrcmpi(ext, _T(".png"))) {
HANDLE hFile, hMap = NULL;
BYTE* ppMap = NULL;
long cbFileSize = 0;
BITMAPINFOHEADER* pDib;
BYTE* pDibBits = 0;
-
+
if (!png2dibConvertor) {
return false;
}
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 != 0 )
- {
+ if ((ppMap = (BYTE*)MapViewOfFile(hMap, FILE_MAP_READ, 0, 0, 0)) != NULL)
+ cbFileSize = GetFileSize(hFile, NULL);
+ if (cbFileSize != 0) {
PNG2DIB param;
param.pSource = ppMap;
param.cbSourceSize = cbFileSize;
param.pResult = &pDib;
if (png2dibConvertor((char*)param.pSource, param.cbSourceSize, param.pResult))
- pDibBits = (BYTE*)(pDib+1);
+ pDibBits = (BYTE*)(pDib + 1);
else
cbFileSize = 0;
- #ifdef _DEBUG
- logMessage(_T("Loading splash file"), _T("done"));
- #endif
+#ifdef _DEBUG
+ logMessage(_T("Loading splash file"), _T("done"));
+#endif
}
if (ppMap) UnmapViewOfFile(ppMap);
@@ -248,13 +238,12 @@ bool MyBitmap::loadFromFile(TCHAR *fn, TCHAR *fnAlpha) if (!cbFileSize) return false;
- BITMAPINFO *bi=(BITMAPINFO*)pDib;
- BYTE *pt=(BYTE*)bi;
- pt+=bi->bmiHeader.biSize;
+ BITMAPINFO *bi = (BITMAPINFO*)pDib;
+ BYTE *pt = (BYTE*)bi;
+ pt += bi->bmiHeader.biSize;
HBITMAP hBitmap = NULL;
- if (bi->bmiHeader.biBitCount!=32)
- {
+ 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);
@@ -265,25 +254,22 @@ bool MyBitmap::loadFromFile(TCHAR *fn, TCHAR *fnAlpha) DeleteObject(hBitmap);
}
- else
- {
- BYTE *ptPixels = pt;
- hBitmap = CreateDIBSection(NULL, bi, DIB_RGB_COLORS, (void **)&ptPixels, NULL, 0);
- memcpy(ptPixels,pt,bi->bmiHeader.biSizeImage);
+ else {
+ BYTE *ptPixels = pt;
+ hBitmap = CreateDIBSection(NULL, bi, DIB_RGB_COLORS, (void **)&ptPixels, NULL, 0);
+ memcpy(ptPixels, pt, bi->bmiHeader.biSizeImage);
allocate(abs(bi->bmiHeader.biWidth), abs(bi->bmiHeader.biHeight));
//memcpy(bits, pt, bi->bmiHeader.biSizeImage);
- 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];
+ 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;
}
@@ -295,14 +281,13 @@ bool MyBitmap::loadFromFile(TCHAR *fn, TCHAR *fnAlpha) GlobalFree(pDib);
DeleteObject(hBitmap);
return true;
- } else
- {
+ }
+ else {
HBITMAP hBmpLoaded = (HBITMAP)LoadImage(NULL, fn, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
- if (!hBmpLoaded)
- {
- #ifdef _DEBUG
- logMessage(_T("MyBitmap::loadFromFile"), _T("Bitmap load failed"));
- #endif
+ if (!hBmpLoaded) {
+#ifdef _DEBUG
+ logMessage(_T("MyBitmap::loadFromFile"), _T("Bitmap load failed"));
+#endif
return false;
}
@@ -311,7 +296,7 @@ bool MyBitmap::loadFromFile(TCHAR *fn, 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);
@@ -322,13 +307,12 @@ bool MyBitmap::loadFromFile(TCHAR *fn, TCHAR *fnAlpha) MyBitmap alpha;
if (fnAlpha && alpha.loadFromFile(fnAlpha) &&
(alpha.getWidth() == width) &&
- (alpha.getHeight() == height))
- {
+ (alpha.getHeight() == height)) {
for (int i = 0; i < width*height; i++)
- bits[i] = (bits[i] & 0x00ffffff) | ( (alpha.bits[i] & 0x000000ff) << 24 );
+ bits[i] = (bits[i] & 0x00ffffff) | ((alpha.bits[i] & 0x000000ff) << 24);
premultipleChannels();
- } else
- {
+ }
+ else {
makeOpaque();
}
return true;
@@ -351,8 +335,7 @@ void MyBitmap::allocate(int w, int h) bi.bmiHeader.biBitCount = 32;
bi.bmiHeader.biCompression = BI_RGB;
- if (dcBmp)
- {
+ if (dcBmp) {
DeleteObject(SelectObject(dcBmp, hBmpSave));
DeleteDC(dcBmp);
}
@@ -376,5 +359,5 @@ void MyBitmap::free() 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]));
+ 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 |