#! /usr/bin/gawk -f # Last edited on 2004-08-04 13:44:58 by stolfi BEGIN { usage = ( ARGV[0] " < IMAGELIST > IMAGELIST" ); # Reads the concatenation of one or more 00-IMAGES files, in one of the # formats # # {ONAME} size {SX}x{SY} segment {CX}x{CY}{DX}{DY} -> {NNAME} # 1 2 3 4 5 6 7 # # {ONAME} size {SX}x{SY} scaled to {RX}x{RY} segment {CX}x{CY}{DX}{DY} -> {NNAME} # 1 2 3 4 5 6 7 8 9 10 # # where ONAME is an absolute pathname followed by an optional # scene number in brackets, SX SY RX RY CX CY are unsigned ints, # DX DY are signed ints, NNAME is a name of the form AAA/BBB/CCC/DDD.png # # Writes those records to the list in the format # # {NNAME} {PL} {PR} {PT} {PB} {PM} {KX} {KY} {KD} {ONAME} # 1 2 3 4 5 6 7 8 9 10 # # where PL PR PT PB are the signed displacement of the segment's # left, right, top, and bottom edges from the corresponding edges of # the reduced picture; PM is the signed minimum of those numbers; # KX, KY are the signed half-integer displacements between the # center of the picture and the center of the reduced image; and KD # is the fractional Euclidean norm of those two numbers. A positive # displacement means inwards, a negative one means outward (hence # implies padding). } /^ *([\#]|$)/ { next; } /./ { oname = $1; if ($2 != "size") { data_error(("missing \"size\"")); } size = $3; if ($4 == "scaled") { if ($5 != "to") { data_error(("missing \"to\"")); } scaled = $6; k = 7; } else { scaled = size; k = 4; } if ($(k) != "segment") { data_error(("missing \"segment\"")); } segment = $(k+1); if ($(k+2) != "->") { data_error(("missing \"->\"")); } nname = $(k+3); if (NF != k+3) { data_error(("bad NF")); } split(scaled, fld, /[x]/); RX = fld[1]+0; RY = fld[2]+0; gsub(/[+]/, "x+", segment); gsub(/[-]/, "x-", segment); split(segment, fld, /[x]/); CX = fld[1]+0; CY = fld[2]+0; DX = fld[3]+0; DY = fld[4]+0; PL = DX; PR = RX - (DX + CX); PT = DY; PB = RY - (DY + CY); PM = min(min(PL,PR), min(PT,PB)); KX = DX + (CX - RX)/2; KY = DY + (CY - RY)/2; KD = sqrt(KX*KX + KY*KY); printf "%s %+4d %+4d %+4d %+4d %+4d %+6.1f %+6.1f %7.1f %s\n", \ nname, PL, PR, PT, PB, PM, KX, KY, KD, oname; next; } function min(x,y) { return (x < y ? x : y); } function data_error(msg) { printf "** line %d: %s\n", FNR, msg > "/dev/stderr"; nerr++; next; }