Version 1.0
Download source here and compile with:
cc -o ptrans ptrans.c -lm
Frustrated with trying to make photostats using my scanner and printer, I came up with this utility: PTRANS.
PTRANS does scaling and Floyd-Steinberg dithering with one unique feature: it only loads two scan lines at a time into memory.
Hence if you scan an A4/Letter-sized image at high resolution --- which can easily consume 100 to 1000 MB --- and want to re-size or dither the image for printing, with PTRANS, you only need 2 MB of RAM to do this.
PTRANS scales with proper interpolation and smoothing. Try for example:
tifftopnm lena_std.tif | ptrans -scale 256,256 -s 6.0 > lena_std0.pbm
tifftopnm lena_std.tif | ptrans -scale 256,256 -s 2.0 > lena_std1.pbm
tifftopnm lena_std.tif | ptrans -scale 256,256 -s 0.5 > lena_std2.pbm
tifftopnm lena_std.tif | ptrans -scale 32,32 -grayscale | ptrans -scale 256,256 -s 1.5 > lena_std.pbm
tifftopnm lena_std.tif | ptrans -scale 256,85 -multiply 1,3 -s 1.5 > lena_std.pbm
tifftopnm lena_std.tif | ptrans -scale 85,256 -multiply 3,1 -s 1.5 > lena_std.pbm
PTRANS reads PGM and PPM files (P5 and P6), so you need utilities like ???topnm ???toppm if you need to process PNG, GIF, or TIFF formats.
The output of PTRANS can be sent to anything --- see the package netpbm with its suite of pbmto??? tools.
PTRANS is nice for doing photostats. Here is ptrans -h:
PTRANS Copyright (C) 2008 Paul Sheer All rights reserved.
- www.protonet.co.za -
usage: ptrans [-multiply W,H] [-scale W,H] [-input FILENAME] [-gamma F] [-s F]
[-threshold N] [-grayscale] [-float] [-output FILENAME]
Scales and dithers an image while holding only 2 scanlines in memory at a time.
This allows extremely large images to be processed using very little RAM.
Produces PBM (i.e. P4) dithered output, or PGM (i.e. P5) gray-level output
from PPM or PGM (P5 or P6) input.
Reads/writes from/to stdin/out if -input/-output not specified
-multiply makes bigger dots (try -multiply 3,3),
-scale sets output width and height in pixels using linear interpolation.
-gamma adjusts brightness F range 0.2 to 5.0
-s use S curve color adjustment F is gamma value of 0.2 to 5.0.
Good for contrast adjustment. -s 1000.0 is equivalent to -threshold 32768
-threshold clips N range 0-65535
-float floating point interpolation
-grayscale output P5 gray-level file, 1 byte per pixel
Example: some HP printers can be used as an A4 photostat machine
in combination with a scanner:
scanimage -x 210 -y 297 --resolution 300 | \
ptrans -scale 3307,7014 -multiply 3,1 -s 1.2 | \
foo2xqx -g 9921x7014 -u 50x0 -r1200x600 -p9 -m1 -n1 -d1 -s7 -J -U -D0 \
> /dev/usblp0
|