DIRECTORY
AIS, ViewerIO, IO, FS, Commander, ImagerViewer, ImagerBackdoor, Imager, ImagerPixelMap, ViewerClasses, ViewerOps
;
ReadHeader:
PROC [s:
IO.
STREAM]
RETURNS [width:
NAT ← 0, height:
NAT ← 0] = {
width ← ORD[s.GetChar[]];
THROUGH [0..3)
DO
width ← width * 256 + ORD[s.GetChar[]];
ENDLOOP;
height ← ORD[s.GetChar[]];
mesgOut.PutF["height is %g.\n", IO.int[height]];
THROUGH [0..3)
DO
height ← height * 256 + ORD[s.GetChar[]];
mesgOut.PutF["height is %g.\n", IO.int[height]];
ENDLOOP;
};
Init: Commander.CommandProc = {
ConvertToAIS: PROC[width: NAT, height: INT, s: IO.STREAM] = {
raster: AIS.Raster ← NEW[AIS.RasterPart ← [width, height, rd, 8, -1, 65535]];
fRed: AIS.FRef ← AIS.CreateFile["Red.ais", raster];
wRed: AIS.WRef ← AIS.OpenWindow[fRed, 0, width, 0, height];
fGreen: AIS.FRef ← AIS.CreateFile["Green.ais", raster];
wGreen: AIS.WRef ← AIS.OpenWindow[fGreen, 0, width, 0, height];
fBlue: AIS.FRef ← AIS.CreateFile["Blue.ais", raster];
wBlue: AIS.WRef ← AIS.OpenWindow[fBlue, 0, width, 0, height];
FOR line: INT IN [0..height) DO
FOR pixel: INT IN [0..width) DO
AIS.WriteSample [wRed, ORD[s.GetChar[]], line, pixel];
AIS.WriteSample [wGreen, ORD[s.GetChar[]], line, pixel];
AIS.WriteSample [wBlue, ORD[s.GetChar[]], line, pixel];
ENDLOOP;
ENDLOOP;
AIS.CloseFile[fRed];
AIS.CloseFile[fGreen];
AIS.CloseFile[fBlue];
};
s: IO.STREAM;
[mesgIn, mesgOut] ← ViewerIO.CreateViewerStreams["RGBToAIS"]; -- message viewer
mesgOut.PutF["Starting to execute procedure RGBToAIS.\n"];
s ← FS.StreamOpen["plane.img"];
[width, height] ← ReadHeader[s];
mesgOut.PutF["Width: %g. Height: %g.\n", IO.int[width], IO.int[height]];
ConvertToAIS[width, height, s]; -- Create the AIS Files
};