]>
git.saurik.com Git - wxWidgets.git/blob - src/common/rgncmn.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Methods of wxRegion that have a generic implementation
6 // Created: 27-Mar-2003
8 // Copyright: (c) Robin Dunn
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
13 #pragma implementation "rgncmn.h"
17 // For compilers that support precompilation, includes "wx.h".
18 #include "wx/wxprec.h"
24 #include "wx/region.h"
25 #include "wx/bitmap.h"
29 #include "wx/dcmemory.h"
32 //---------------------------------------------------------------------------
36 wxBitmap
wxRegion::ConvertToBitmap() const
38 wxRect box
= GetBox();
39 wxBitmap
bmp(box
.GetRight(), box
.GetBottom());
42 dc
.SetBackground(*wxBLACK_BRUSH
);
44 dc
.SetClippingRegion(*this);
45 dc
.SetBackground(*wxWHITE_BRUSH
);
47 dc
.SelectObject(wxNullBitmap
);
51 //---------------------------------------------------------------------------
53 bool wxRegion::Union(const wxBitmap
& bmp
,
54 const wxColour
& transColour
,
58 unsigned char loR
, loG
, loB
;
59 unsigned char hiR
, hiG
, hiB
;
61 wxCHECK_MSG((bmp
.GetMask() != NULL
) || transColour
.Ok(),
63 wxT("Either the bitmap should have a mask or a colour should be given."));
65 wxImage image
= bmp
.ConvertToImage();
69 loR
= image
.GetMaskRed();
70 loG
= image
.GetMaskGreen();
71 loB
= image
.GetMaskBlue();
75 loR
= transColour
.Red();
76 loG
= transColour
.Green();
77 loB
= transColour
.Blue();
80 hiR
= wxMin(0xFF, loR
+ tolerance
);
81 hiG
= wxMin(0xFF, loG
+ tolerance
);
82 hiB
= wxMin(0xFF, loB
+ tolerance
);
84 // Loop through the image row by row, pixel by pixel, building up
85 // rectangles to add to the region.
86 int width
= image
.GetWidth();
87 int height
= image
.GetHeight();
88 for (int y
=0; y
< height
; y
++)
94 for (int x
=0; x
< width
; x
++)
96 // search for a continuous range of non-transparent pixels
100 unsigned char R
= image
.GetRed(x
,y
);
101 unsigned char G
= image
.GetGreen(x
,y
);
102 unsigned char B
= image
.GetBlue(x
,y
);
103 if (( R
>= loR
&& R
<= hiR
) &&
104 ( G
>= loG
&& G
<= hiG
) &&
105 ( B
>= loB
&& B
<= hiB
)) // It's transparent
110 // Add the run of non-transparent pixels (if any) to the region
121 // No wxImage support
126 //---------------------------------------------------------------------------