Black pipscalez
@@ -4,23 +4,25 @@ import png
Description = """Enlarge an image by an integer factor horizontally and vertically."""
+
def rescale(inp, out, xf, yf):
from array import array
r = png.Reader(file=inp)
_, _, pixels, meta = r.asDirect()
- typecode = 'BH'[meta['bitdepth'] > 8]
- planes = meta['planes']
+ 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, y = meta["size"]
x *= xf
y *= yf
- meta['size'] = (x,y)
+ meta["size"] = (x, y)
del x
del y
# Values per row, target row.
- vpr = meta['size'][0] * planes
+ vpr = meta["size"][0] * planes
+
def iterscale():
for row in pixels:
bigrow = array(typecode, [0] * vpr)
@@ -31,6 +33,7 @@ def rescale(inp, out, xf, yf):
bigrow[i * planes + c :: xf * planes] = channel
for _ in range(yf):
yield bigrow
+
w = png.Writer(**meta)
w.write(out, iterscale())
@@ -49,5 +52,6 @@ def main(argv=None):
return rescale(png.binary_stdin(), png.binary_stdout(), args.xfactor, args.yfactor)
-if __name__ == '__main__':
+
+if __name__ == "__main__":
main()
