RenderViaFileSystem:
PROC [t: Tool] ~ {
command: ROPE ¬ IO.PutFR1["render %gTemp.rib", IO.rope[t.directory]];
Controls.TypescriptWrite[t.typescript, "writing RIB... "];
WriteRIBtoFile[t, IO.PutFR1["%gTemp.rib", IO.rope[t.directory]]];
t.unixSpawn ¬ UnixSpawnTCP.Spawn[command, t.cmd.out, t.cmd.out, Done, ReadOut, t];
Controls.TypescriptWrite[t.typescript, "rendering... "];
};
Update: CtViewer.ViewerProc ~ {
-- can not be nested
u: REF ViewerData ¬ NARROW[clientData];
ImagerSample.BasicTransfer[maps[0].map, u.bwMap, [u.y, u.x], [0, 0], [u.h, u.w]];
affectedRegion ¬ [[u.y, u.x], [u.y+u.h, u.x+u.w]];
};
ShowColor: CtViewer.ViewerProc ~ {
-- can not be nested
u: REF ViewerData ¬ NARROW[clientData];
context: Imager.Context ¬ CtBasic.ContextFromSampleMaps[maps];
pm: ImagerPixel.PixelMap ¬ ImagerPixel.MakePixelMap[u.t.rMap, u.t.gMap, u.t.bMap];
pa: ImagerPixelArray.PixelArray ¬
ImagerPixelArray.FromPixelMap[pm, [[0, 0], u.size], [down, right]];
op: ImagerColor.ColorOperator ¬ ImagerColor.NewColorOperatorRGB[255];
Imager.DrawSampledColor[context, pa, op];
affectedRegion.max ¬ u.size;
};
ReadOut: CedarProcess.ForkableProc ~ {
With thanks to Michael Plass.
Done: ERROR = CODE;
CheckMap:
PROC [map: SampleMap]
RETURNS [ret: SampleMap] ~ {
IF (ret ¬ map) =
NIL
OR ImagerSample.GetSize[ret] # u.size
THEN {
IF map # NIL THEN ImagerSample.ReleaseScratchMap[map];
ret ¬ ImagerSample.ObtainScratchMap[[[0, 0], u.size], 8];
};
};
windowS: IO.STREAM;
u: REF ViewerData ¬ NEW[ViewerData];
s: REF SpawnData ¬ NARROW[data];
t: Tool ¬ u.t ¬ NARROW[s.clientData];
x, y, w, h, nBytes, charsIndex: INTEGER ¬ 0;
v: ViewerClasses.Viewer ¬ CtViewer.currentViewer
¬ CtViewer.GetViewer[Rope.Concat[t.name, ": Image"], right, t.frameSize.y, TRUE];
window: REF TEXT ¬ RefText.ObtainScratch[100];
chars: CHARPtr ¬ UXStrings.ObtainScratch[1024];
rLine, gLine, bLine, bwLine: SampleBuffer;
u.size ¬ SF.Min[[v.ch, v.cw], [t.frameSize.y, t.frameSize.x]];
u.bwMap ¬ ImagerSample.ObtainScratchMap[[[0, 0], [100, 100]], 8];
bwLine ¬ ImagerSample.ObtainScratchSamples[100];
IF t.color
THEN {
rLine ¬ ImagerSample.ObtainScratchSamples[100];
gLine ¬ ImagerSample.ObtainScratchSamples[100];
bLine ¬ ImagerSample.ObtainScratchSamples[100];
t.rMap ¬ CheckMap[t.rMap];
t.gMap ¬ CheckMap[t.gMap];
t.bMap ¬ CheckMap[t.bMap];
};
CtMap.Gamma[];
DO
TRUSTED {
ENABLE Done => EXIT;
Next:
UNSAFE
PROC
RETURNS [char:
CHAR] ~
UNCHECKED {
IF charsIndex >= nBytes
THEN {
IF (nBytes ¬ UnixSysCalls.Read[s.fdOut, chars, 1023]) <= 0 THEN ERROR Done;
charsIndex ¬ 0;
};
char ¬ chars[charsIndex];
charsIndex ¬ charsIndex+1;
};
ch: CHAR ¬ 0c;
window.length ¬ 0;
WHILE (ch ¬ Next[]) # '\n
DO
window ¬ RefText.AppendChar[window, ch];
ENDLOOP;
windowS ¬ IO.TIS[window];
x ¬ u.x ¬ IO.GetInt[windowS];
y ¬ u.y ¬ IO.GetInt[windowS];
IF (w ¬ IO.GetInt[windowS])+x > v.cw THEN w ¬ v.cw-x;
IF (h ¬ IO.GetInt[windowS])+y > v.ch THEN h ¬ v.ch-y;
IF x >= v.cw THEN LOOP;
IF y >= v.ch THEN EXIT;
IF w+x > v.cw THEN w ¬ v.cw-x;
IF h+y > v.ch THEN h ¬ v.ch-y;
u.w ¬ w;
u.h ¬ h;
FOR j:
INT
IN [0..h)
DO
FOR i:
INT
IN [0..w)
DO
r: BYTE ~ ORD[Next[]];
g: BYTE ~ ORD[Next[]];
b: BYTE ~ ORD[Next[]];
IF t.color THEN {rLine[i] ¬ r; gLine[i] ¬ g; bLine[i] ¬ b};
bwLine[i] ¬ MIN[255, MAX[0, Real.Round[.3*REAL[r]+.59*REAL[g]+.11*REAL[b]]]];
ENDLOOP;
ImagerSample.PutSamples[u.bwMap, [j, 0],, bwLine, 0, w];
IF t.color
THEN {
ImagerSample.PutSamples[t.rMap, [y+j, x],, rLine, 0, w];
ImagerSample.PutSamples[t.gMap, [y+j, x],, gLine, 0, w];
ImagerSample.PutSamples[t.bMap, [y+j, x],, bLine, 0, w];
};
ENDLOOP;
CtViewer.DoWithViewer[v, Update, u];
CedarProcess.CheckAbort[];
};
ENDLOOP;
IF t.color THEN {CtMap.Dither[]; CtViewer.DoWithViewer[v, ShowColor, t]};
RefText.ReleaseScratch[window];
UXStrings.ReleaseScratch[chars];
FOR l:
LIST
OF SampleBuffer ¬
LIST[rLine, gLine, bLine, bwLine], l.rest
WHILE l #
NIL
DO
IF l.first # NIL THEN ImagerSample.ReleaseScratchSamples[l.first];
ENDLOOP;
ImagerSample.ReleaseScratchMap[u.bwMap];
IF t.ribMode = file
THEN {
DoCommand[t, IO.PutFR["! tiffcopy -none -noalpha %gTemp.tiff %gTemp.dump", IO.rope[t.directory], IO.rope[t.directory]], "tiffcopy... "];
DoCommand[t, IO.PutFLR["Ct DumpToAIS %gTemp.dump %gTemp -gbr -size %g %g", LIST[IO.rope[t.directory], IO.rope[t.directory], IO.int[t.frameSize.x], IO.int[t.frameSize.y]]], "to AIS... "];
DoCommand[t,
IO.PutFR["Ct View %gTemp%g -right",
IO.rope[t.directory], IO.rope[IF t.color THEN NIL ELSE "-red.ais"]], "display "];
Could try these Unix commands:
tiffcopy -noalpha Temp.tiff
source /import/sandpiper/top/enable; readtif Temp.tiff | writeais -dir AIS
mv AIS/r.ais Temp-red.ais; mv AIS/g.ais Temp-grn.ais; mv AIS/b.ais Temp-blu.ais
};
};