]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/imageutils.py
1 #----------------------------------------------------------------------
2 # Name: wxPython.lib.imageutils
3 # Purpose: A collection of functions for simple image manipulations
9 # Copyright: (c) 2002 by
10 # Licence: wxWindows license
11 #----------------------------------------------------------------------
17 Convert the given image (in place) to a grayed-out
18 version, appropriate for a 'disabled' appearance.
20 factor
= 0.7 # 0 < f < 1. Higher is grayer.
22 maskColor
= (anImage
.GetMaskRed(), anImage
.GetMaskGreen(), anImage
.GetMaskBlue())
25 data
= map(ord, list(anImage
.GetData()))
27 for i
in range(0, len(data
), 3):
28 pixel
= (data
[i
], data
[i
+1], data
[i
+2])
29 pixel
= makeGray(pixel
, factor
, maskColor
)
32 anImage
.SetData(''.join(map(chr, data
)))
35 def makeGray((r
,g
,b
), factor
, maskColor
):
37 Make a pixel grayed-out. If the pixel
38 matches the maskColor, it won't be
41 if (r
,g
,b
) != maskColor
:
42 return map(lambda x
: int((230 - x
) * factor
) + x
, (r
,g
,b
))
48 def stepColour(c
, step
):
50 stepColour is a utility function that simply darkens or lightens a
51 color, based on the specified step value. A step of 0 is
52 completely black and a step of 200 is totally white, and 100
53 results in the same color as was passed in.
55 def _blendColour(fg
, bg
, dstep
):
56 result
= bg
+ (dstep
* (fg
- bg
))
70 # step is 0..200 where 0 is completely black
71 # and 200 is completely white and 100 is the same
72 # convert that to a range of -1.0 .. 1.0
75 dstep
= (step
- 100.0)/100.0
80 dstep
= 1.0 - dstep
# 0 = transparent fg; 1 = opaque fg
84 dstep
= 1.0 + dstep
; # 0 = transparent fg; 1 = opaque fg
86 r
= _blendColour(r
, bg
, dstep
)
87 g
= _blendColour(g
, bg
, dstep
)
88 b
= _blendColour(b
, bg
, dstep
)
90 return wx
.Colour(int(r
), int(g
), int(b
))