summaryrefslogtreecommitdiffstats
path: root/build/pypng/piprgb
blob: fbe1082af9758503a02420799c74f1ce8ddef285 (plain)
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
#!/usr/bin/env python
# $URL: http://pypng.googlecode.com/svn/trunk/code/piprgb $
# $Rev: 131 $
# piprgb
#
# Convert input image to RGB or RGBA format.  Output will be colour type
# 2 or 6, and will not have a tRNS chunk.

import png

def rgb(out, inp):
    """Convert to RGB/RGBA."""

    r = png.Reader(file=inp)
    r.preamble()
    if r.alpha or r.trns:
        get = r.asRGBA
    else:
        get = r.asRGB
    pixels,info = get()[2:4]
    w = png.Writer(**info)
    w.write(out, pixels)

def main(argv=None):
    import sys

    if argv is None:
        argv = sys.argv
    if len(argv) > 1:
        f = open(argv[1], 'rb')
    else:
        f = sys.stdin
    return rgb(sys.stdout, f)

if __name__ == '__main__':
    main()