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