]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wx/lib/imageutils.py
Added $Id keyword, a bit of cleanup and also some backwards
[wxWidgets.git] / wxPython / wx / lib / imageutils.py
1 #----------------------------------------------------------------------
2 # Name: wxPython.lib.imageutils
3 # Purpose: A collection of functions for simple image manipulations
4 #
5 # Author: Robb Shecter
6 #
7 # Created: 7-Nov-2002
8 # RCS-ID: $Id$
9 # Copyright: (c) 2002 by
10 # Licence: wxWindows license
11 #----------------------------------------------------------------------
12
13 from __future__ import nested_scopes
14
15
16 def grayOut(anImage):
17 """
18 Convert the given image (in place) to a grayed-out
19 version, appropriate for a 'disabled' appearance.
20 """
21 factor = 0.7 # 0 < f < 1. Higher is grayer.
22 if anImage.HasMask():
23 maskColor = (anImage.GetMaskRed(), anImage.GetMaskGreen(), anImage.GetMaskBlue())
24 else:
25 maskColor = None
26 data = map(ord, list(anImage.GetData()))
27
28 for i in range(0, len(data), 3):
29 pixel = (data[i], data[i+1], data[i+2])
30 pixel = makeGray(pixel, factor, maskColor)
31 for x in range(3):
32 data[i+x] = pixel[x]
33 anImage.SetData(''.join(map(chr, data)))
34
35
36 def makeGray((r,g,b), factor, maskColor):
37 """
38 Make a pixel grayed-out. If the pixel
39 matches the maskColor, it won't be
40 changed.
41 """
42 if (r,g,b) != maskColor:
43 return map(lambda x: int((230 - x) * factor) + x, (r,g,b))
44 else:
45 return (r,g,b)