diff options
author | Thomas Groman <tgroman@nuegia.net> | 2020-04-20 20:56:28 -0700 |
---|---|---|
committer | Thomas Groman <tgroman@nuegia.net> | 2020-04-20 20:56:28 -0700 |
commit | 508d270a4d78d491bbe1c67c309c404f547da58a (patch) | |
tree | d16e2a906501dcda7b4d268579896f03e125f553 /build/pypng/pipcat | |
parent | f9cab004186edb425a9b88ad649726605080a17c (diff) | |
download | webbrowser-508d270a4d78d491bbe1c67c309c404f547da58a.tar webbrowser-508d270a4d78d491bbe1c67c309c404f547da58a.tar.gz webbrowser-508d270a4d78d491bbe1c67c309c404f547da58a.tar.lz webbrowser-508d270a4d78d491bbe1c67c309c404f547da58a.tar.xz webbrowser-508d270a4d78d491bbe1c67c309c404f547da58a.zip |
added Comm Build System
Diffstat (limited to 'build/pypng/pipcat')
-rw-r--r-- | build/pypng/pipcat | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/build/pypng/pipcat b/build/pypng/pipcat new file mode 100644 index 0000000..e0d0805 --- /dev/null +++ b/build/pypng/pipcat @@ -0,0 +1,44 @@ +#!/usr/bin/env python +# $URL: http://pypng.googlecode.com/svn/trunk/code/pipcat $ +# $Rev: 77 $ + +# http://www.python.org/doc/2.4.4/lib/module-itertools.html +import itertools +import sys + +import png + +def cat(out, l): + """Concatenate the list of images. All input images must be same + height and have the same number of channels. They are concatenated + left-to-right. `out` is the (open file) destination for the + output image. `l` should be a list of open files (the input + image files). + """ + + l = map(lambda f: png.Reader(file=f), l) + # Ewgh, side effects. + map(lambda r: r.preamble(), l) + # The reference height; from the first image. + height = l[0].height + # The total target width + width = 0 + for i,r in enumerate(l): + if r.height != height: + raise Error('Image %d, height %d, does not match %d.' % + (i, r.height, height)) + width += r.width + pixel,info = zip(*map(lambda r: r.asDirect()[2:4], l)) + tinfo = dict(info[0]) + del tinfo['size'] + w = png.Writer(width, height, **tinfo) + def itercat(): + for row in itertools.izip(*pixel): + yield itertools.chain(*row) + w.write(out, itercat()) + +def main(argv): + return cat(sys.stdout, map(lambda n: open(n, 'rb'), argv[1:])) + +if __name__ == '__main__': + main(sys.argv) |