File: imageutils.py

package info (click to toggle)
wxwidgets2.6 2.6.3.2.1.5%2Betch1
  • links: PTS
  • area: main
  • in suites: etch
  • size: 83,228 kB
  • ctags: 130,941
  • sloc: cpp: 820,043; ansic: 113,030; python: 107,485; makefile: 42,996; sh: 10,305; lex: 194; yacc: 128; xml: 95; pascal: 74
file content (45 lines) | stat: -rw-r--r-- 1,406 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#----------------------------------------------------------------------
# Name:        wxPython.lib.imageutils
# Purpose:     A collection of functions for simple image manipulations
#
# Author:      Robb Shecter
#
# Created:     7-Nov-2002
# RCS-ID:      $Id: imageutils.py,v 1.4 2003/11/12 21:29:08 RD Exp $
# Copyright:   (c) 2002 by
# Licence:     wxWindows license
#----------------------------------------------------------------------

from __future__ import nested_scopes


def grayOut(anImage):
    """
    Convert the given image (in place) to a grayed-out
    version, appropriate for a 'disabled' appearance.
    """
    factor = 0.7        # 0 < f < 1.  Higher is grayer.
    if anImage.HasMask():
        maskColor = (anImage.GetMaskRed(), anImage.GetMaskGreen(), anImage.GetMaskBlue())
    else:
        maskColor = None
    data = map(ord, list(anImage.GetData()))

    for i in range(0, len(data), 3):
        pixel = (data[i], data[i+1], data[i+2])
        pixel = makeGray(pixel, factor, maskColor)
        for x in range(3):
            data[i+x] = pixel[x]
    anImage.SetData(''.join(map(chr, data)))


def makeGray((r,g,b), factor, maskColor):
    """
    Make a pixel grayed-out. If the pixel
    matches the maskColor, it won't be
    changed.
    """
    if (r,g,b) != maskColor:
        return map(lambda x: int((230 - x) * factor) + x, (r,g,b))
    else:
        return (r,g,b)