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/pipscalez | |
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/pipscalez')
-rw-r--r-- | build/pypng/pipscalez | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/build/pypng/pipscalez b/build/pypng/pipscalez new file mode 100644 index 0000000..c60762d --- /dev/null +++ b/build/pypng/pipscalez @@ -0,0 +1,53 @@ +#!/usr/bin/env python +# $URL: http://pypng.googlecode.com/svn/trunk/code/pipscalez $ +# $Rev: 131 $ + +# pipscalez +# Enlarge an image by an integer factor horizontally and vertically. + +def rescale(inp, out, xf, yf): + from array import array + import png + + r = png.Reader(file=inp) + _,_,pixels,meta = r.asDirect() + typecode = 'BH'[meta['bitdepth'] > 8] + planes = meta['planes'] + # We are going to use meta in the call to Writer, so expand the + # size. + x,y = meta['size'] + x *= xf + y *= yf + meta['size'] = (x,y) + del x + del y + # Values per row, target row. + vpr = meta['size'][0] * planes + def iterscale(): + for row in pixels: + bigrow = array(typecode, [0]*vpr) + row = array(typecode, row) + for c in range(planes): + channel = row[c::planes] + for i in range(xf): + bigrow[i*planes+c::xf*planes] = channel + for _ in range(yf): + yield bigrow + w = png.Writer(**meta) + w.write(out, iterscale()) + + +def main(argv=None): + import sys + + if argv is None: + argv = sys.argv + xf = int(argv[1]) + if len(argv) > 2: + yf = int(argv[2]) + else: + yf = xf + return rescale(sys.stdin, sys.stdout, xf, yf) + +if __name__ == '__main__': + main() |