]> git.saurik.com Git - wxWidgets.git/blame - wxPython/wx/lib/imageutils.py
Change multipleChoiceDialog to use wx.MultiChoiceDialog instead of
[wxWidgets.git] / wxPython / wx / lib / imageutils.py
CommitLineData
d14a1e28
RD
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#----------------------------------------------------------------------
1fded56b 12
d14a1e28 13from __future__ import nested_scopes
1fded56b 14
d14a1e28
RD
15
16def 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
36def 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)