Process:
PROC [cmd: Commander.Handle, op: {render, matte}]
RETURNS [err:
ROPE ¬
NIL] ~ {
ENABLE {
format, Convert.Error => {err ¬ "bad command argument"; GOTO Bad};
PFS.Error => {err ¬ "can't open rib file"; GOTO Bad};
IO.Error, IO.EndOfStream => {err ¬ "can't find Format statement in rib file"; GOTO Bad};
};
GetSize:
PROC [file:
ROPE]
RETURNS [wh: IntegerPair] ~ {
contents: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[file]];
DO
IF Rope.Equal[
IO.GetCedarTokenRope[contents].token, "Format",
FALSE]
THEN {wh.x ¬ IO.GetInt[contents]; wh.y ¬ IO.GetInt[contents]; EXIT};
ENDLOOP;
};
ModifyFile:
PROC [file:
ROPE, wh: IntegerPair, light: Triple] ~ {
in: IO.STREAM ¬ PFS.StreamOpen[PFS.PathFromRope[file]];
out: IO.STREAM ¬ FS.StreamOpen[file, $create];
DO
line: ROPE ¬ IO.GetLineRope[in ! IO.EndOfStream => EXIT];
SELECT
TRUE
FROM
Rope.Find[line, "Format", 0,
FALSE] # -1 =>
IF wh # [] THEN line ¬ IO.PutFR["Format %g %g 1", IO.int[wh.x], IO.int[wh.y]];
Rope.Find[line, "distantlight\" 2", 0,
FALSE] # -1 =>
IF light # []
THEN line ¬
IO.PutFR["LightSource \"distantlight\" 2 \"lightcolor\" [1.0 1.0 1.0] \"intensity\" [1.0] \"from\" [%g %g %g] \"to\" [0.0 0.0 0.0]",
IO.real[light.x], IO.real[light.y], IO.real[light.z]];
ENDCASE;
IO.PutF1[out, "%g\n", IO.rope[line]];
ENDLOOP;
IO.Close[out];
};
DoCommand:
PROC [command:
ROPE] ~ {
IO.PutF1[cmd.out, "%g\n", IO.rope[command]];
[] ¬ CommanderOps.DoCommand[command, cmd];
};
BaseRIB:
PROC [name:
ROPE]
RETURNS [base:
ROPE] ~ {
i: INT ¬ Rope.FindBackward[name, ".rib",, FALSE];
base ¬ Rope.Substr[name, 0, IF i = -1 THEN Rope.Length[name] ELSE i];
};
i: INTEGER ¬ 1;
base, name: ROPE ¬ NIL;
light: Triple ¬ [];
wh: IntegerPair ¬ [];
args: CommanderOps.ArgumentVector ¬ CommanderOps.Parse[cmd];
WHILE i < args.argc
DO
GetInt:
PROC
RETURNS [n:
INTEGER] ~ {
IF (i ¬ i+1) = args.argc THEN ERROR format;
n ¬ Convert.IntFromRope[args[i]];
};
GetReal:
PROC
RETURNS [r:
REAL] ~ {
IF (i ¬ i+1) = args.argc THEN ERROR format;
r ¬ Convert.RealFromRope[args[i]];
};
SELECT
TRUE
FROM
Rope.Equal[args[i], "-light"] => {light.x¬GetReal[]; light.y¬GetReal[]; light.z¬GetReal[]};
Rope.Equal[args[i], "-size"] => {wh.x ¬ GetInt[]; wh.y ¬ GetInt[]};
ENDCASE =>
IF name =
NIL
THEN name ¬ args[i]
ELSE RETURN[IO.PutFR1["redundant name: %g", IO.rope[args[i]]]];
i ¬ i+1;
ENDLOOP;
IF name = NIL THEN RETURN["missing file name"];
base ¬ BaseRIB[name];
IF wh # [] OR light # [] THEN ModifyFile[name, wh, light];
IF wh = [] THEN wh ¬ GetSize[name];
SELECT op
FROM
render => {
DoCommand[Rope.Concat["WritePlain ", name]];
DoCommand[Rope.Concat["! render ", name]];
DoCommand[
IO.PutFR["! tiffcopy -none -noalpha %g.tiff %g.dump",
IO.rope[base], IO.rope[base]]];
DoCommand[
IO.PutFLR["Ct RawDumpToAIS %g.dump %g -w %g -h %g",
LIST[IO.rope[base], IO.rope[base], IO.int[wh.x], IO.int[wh.y]]]];
DoCommand[Rope.Cat["Ct View ", base, "-red.ais"]];
};
matte => {
matteName: ROPE ¬ Rope.Concat[base, ".Matte"];
DoCommand[IO.PutFR["! tiffsize -src White.tiff -sw 0 0 100 100 -dst Temp.tiff -db 0 0 %g %g", IO.int[wh.x], IO.int[wh.y]]];
DoCommand[
IO.PutFR["! tiffcomp \"%g.tiff = %g.tiff over Temp.tiff\"",
IO.rope[matteName], IO.rope[base]]];
DoCommand[
IO.PutFR["! tiffcopy -none -noalpha %g.tiff %g.dump",
IO.rope[matteName], IO.rope[matteName]]];
DoCommand[
IO.PutFLR["ct RawDumpToAIS %g.dump %g -w %g -h %g",
LIST[IO.rope[matteName], IO.rope[matteName], IO.int[wh.x], IO.int[wh.y]]]];
DoCommand[Rope.Cat["Ct View ", matteName, "-red.ais"]];
DoCommand["Delete Temp.tiff"];
};
ENDCASE;
EXITS Bad => NULL;
};