1 // TortoiseSVN - a Windows shell extension for easy version control
\r
3 // Copyright (C) 2003-2006 - Stefan Kueng
\r
5 // This program is free software; you can redistribute it and/or
\r
6 // modify it under the terms of the GNU General Public License
\r
7 // as published by the Free Software Foundation; either version 2
\r
8 // of the License, or (at your option) any later version.
\r
10 // This program is distributed in the hope that it will be useful,
\r
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
\r
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
\r
13 // GNU General Public License for more details.
\r
15 // You should have received a copy of the GNU General Public License
\r
16 // along with this program; if not, write to the Free Software Foundation,
\r
17 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
\r
20 #include "stdex_vector.h"
\r
34 int CDib::BytesPerLine(int nWidth, int nBitsPerPixel)
\r
36 int nBytesPerLine = nWidth * nBitsPerPixel;
\r
37 nBytesPerLine = ( (nBytesPerLine + 31) & (~31) ) / 8;
\r
38 return nBytesPerLine;
\r
41 void CDib::DeleteObject()
\r
45 ::DeleteObject(m_hBitmap);
\r
48 memset(&m_BMinfo, 0, sizeof(m_BMinfo));
\r
51 void CDib::Create32BitFromPicture (CPictureHolder* pPicture, int iWidth, int iHeight)
\r
58 tempDC.CreateCompatibleDC(&dc);
\r
60 newBMP.CreateDiscardableBitmap(&dc,iWidth,iHeight);
\r
62 CBitmap* pOldBitmap = tempDC.SelectObject(&newBMP);
\r
64 r.SetRect(0,0,iWidth,iHeight);
\r
65 pPicture->Render(&tempDC,r,r);
\r
67 // Create a 32 bit bitmap
\r
68 stdex::vector<DWORD> pBits(iWidth * iHeight);
\r
71 bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
\r
72 bi.bmiHeader.biWidth = iWidth;
\r
73 bi.bmiHeader.biHeight = iHeight;
\r
74 bi.bmiHeader.biPlanes = 1;
\r
75 bi.bmiHeader.biBitCount = 32;
\r
76 bi.bmiHeader.biCompression = BI_RGB;
\r
77 bi.bmiHeader.biSizeImage = 0;
\r
78 bi.bmiHeader.biXPelsPerMeter = 0;
\r
79 bi.bmiHeader.biYPelsPerMeter = 0;
\r
80 bi.bmiHeader.biClrUsed = 0;
\r
81 bi.bmiHeader.biClrImportant = 0;
\r
84 SetBitmap(&bi, pBits);
\r
86 DWORD* pAr = (DWORD*)GetDIBits();
\r
88 // Copy data into the 32 bit dib..
\r
89 for(int i=0;i<iHeight;i++)
\r
91 for(int j=0;j<iWidth;j++)
\r
93 pAr[(i*iWidth)+j] = FixColorRef(tempDC.GetPixel(j,i));
\r
97 tempDC.SelectObject(pOldBitmap);
\r
100 BOOL CDib::SetBitmap(const LPBITMAPINFO lpBitmapInfo, const LPVOID lpBits)
\r
104 if (!lpBitmapInfo || !lpBits)
\r
109 DWORD dwBitmapInfoSize = sizeof(BITMAPINFO);
\r
111 memcpy(&m_BMinfo, lpBitmapInfo, dwBitmapInfoSize);
\r
113 hDC = ::GetDC(NULL);
\r
120 m_hBitmap = CreateDIBSection(hDC, &m_BMinfo,
\r
121 DIB_RGB_COLORS, &m_pBits, NULL, 0);
\r
122 ::ReleaseDC(NULL, hDC);
\r
129 DWORD dwImageSize = m_BMinfo.bmiHeader.biSizeImage;
\r
130 if (dwImageSize == 0)
\r
132 int nBytesPerLine = BytesPerLine(lpBitmapInfo->bmiHeader.biWidth,
\r
133 lpBitmapInfo->bmiHeader.biBitCount);
\r
134 dwImageSize = nBytesPerLine * lpBitmapInfo->bmiHeader.biHeight;
\r
139 memcpy(m_pBits, lpBits, dwImageSize);
\r
144 BOOL CDib::Draw(CDC* pDC, CPoint ptDest)
\r
149 CSize size = GetSize();
\r
150 CPoint SrcOrigin = CPoint(0,0);
\r
152 BOOL resVal = FALSE;
\r
154 resVal = SetDIBitsToDevice(pDC->GetSafeHdc(),
\r
155 ptDest.x, ptDest.y,
\r
157 SrcOrigin.x, SrcOrigin.y,
\r
158 SrcOrigin.y, size.cy - SrcOrigin.y,
\r
159 GetDIBits(), &m_BMinfo,
\r
165 COLORREF CDib::FixColorRef(COLORREF clr)
\r
167 int r = GetRValue(clr);
\r
168 int g = GetGValue(clr);
\r
169 int b = GetBValue(clr);
\r