#! /usr/bin/gawk -f # Last edited on 2012-09-07 18:11:50 by stolfilocal BEGIN{ # Calling: ( cd ${dir} && mkcut.gawk -v NX={WIDTH} -v NY={HEIGHT} -v SZ={SIZE} {PARMS}.txt ) # Input: a list of lines {IMAGE} {CUTNUM} {SCALE} {RAWX} {RAWY} # Output: cutset files "{IMAGE}-c{CUTNUM}.cut", in current diretory abort = -1; # Image dimensions: if (NX == "") { arg_error(("must define input image width {NX}")); } if (NY == "") { arg_error(("must define input image height {NY}")); } if (SZ == "") { arg_error(("must define cutout size {SZ}")); } } (abort >= 0) { exit abort; } # Remove comments //{ gsub(/[ ]*([\#].*|$)/, "", $0); } # Ignore blank lines /^$/{ next; } # Process data: (NF == 5){ im = $1; cn = $2; sc = $3; rx = $4; ry = $5; sx = int(sc*rx/8)*8; sy = int(sc*ry/8)*8; if (sx+SZ > NX) { data_error(("cutout exceeds width")); } if (sy+SZ > NY) { data_error(("cutout exceeds height")); } cutfile = (im "-c" sprintf("%02d",cn) ".cut"); printf "%s %5d %5d %+6d %+6d\n", cutfile, SZ, SZ, sx, sy > "/dev/stderr"; printf "-crop %dx%d+%d+%d\n", SZ, SZ, sx, sy > cutfile; close(cutfile); next; } // { data_error(("invalid format")); next; } function arg_error(msg) { printf "** argument error: %s\n", msg > "/dev/stderr"; exit 1; } function data_error(msg) { printf "%s:%d: %s\n", FILENAME, FNR, msg > "/dev/stderr"; printf " [%s]\n", $0 > "/dev/stderr"; abort = 1; exit abort; }