ImagerAISImpl.mesa
Michael Plass, July 12, 1983 1:45 pm
DIRECTORY
AIS,
Imager,
ImagerBasic,
Rope,
Scaled
;
ImagerAISImpl: CEDAR PROGRAM
IMPORTS AIS, Rope, Scaled
EXPORTS Imager
~ BEGIN
This is more or less just a stub implementation; slow and dirty, but it should work for testing.
TriColor: TYPE ~ REF TriColorRep;
TriColorRep: TYPE ~ RECORD [
red, green, blue: Array
];
Array: TYPE ~ REF ArrayRep;
ArrayRep: TYPE ~ RECORD [
SEQUENCE yPixels: NAT OF Row
];
Row: TYPE ~ REF RowRep;
RowRep: TYPE ~ RECORD [
PACKED SEQUENCE xPixels: NAT OF [0..256)
];
LoadAISData: PROC [aisName: Rope.ROPE] RETURNS [array: Array] ~ TRUSTED {
text: Rope.Text ← aisName.Flatten;
ais: AIS.FRef ← AIS.OpenFile[LOOPHOLE[text], FALSE];
window: AIS.WRef ← AIS.OpenWindow[ais];
xPixels: NAT;
yPixels: NAT;
pixelArray: ImagerBasic.PixelArray ← NEW[ImagerBasic.PixelArrayRep];
color: ImagerBasic.SampledColor ← NEW[ImagerBasic.SampledColorRep];
curLine, curPixel, xNextLine, xNextPixel, yNextLine, yNextPixel: INTEGER;
SELECT ais.raster.scanMode FROM
ru, lu, rd, ld => {xPixels ← ais.raster.scanLength; yPixels ← ais.raster.scanCount};
ur, ul, dr, dl => {xPixels ← ais.raster.scanCount; yPixels ← ais.raster.scanLength};
ENDCASE => ERROR;
SELECT ais.raster.scanMode FROM
ru => {curLine𡤀 curPixel𡤀 xNextLine𡤀 xNextPixel𡤁 yNextLine𡤁 yNextPixel𡤀};
ul => {curLine←xPixels-1; curPixel𡤀 xNextLine←-1; xNextPixel𡤀 yNextLine𡤀 yNextPixel𡤁};
ld => {curLine←yPixels-1; curPixel←xPixels-1; xNextLine𡤀 xNextPixel←-1; yNextLine←-1; yNextPixel𡤀};
dr => {curLine𡤀 curPixel←yPixels-1; xNextLine𡤁 xNextPixel𡤀 yNextLine𡤀 yNextPixel←-1};
rd => {curLine←yPixels-1; curPixel𡤀 xNextLine𡤀 xNextPixel𡤁 yNextLine←-1; yNextPixel𡤀};
ur => {curLine𡤀 curPixel𡤀 xNextLine𡤁 xNextPixel𡤀 yNextLine𡤀 yNextPixel𡤁};
lu => {curLine𡤀 curPixel←xPixels-1; xNextLine𡤀 xNextPixel←-1; yNextLine𡤁 yNextPixel𡤀};
dl => {curLine𡤌urLine←xPixels-1; curPixel←yPixels-1; xNextLine←-1; xNextPixel𡤀 yNextLine𡤀 yNextPixel←-1};
ENDCASE => ERROR;
array ← NEW[ArrayRep[yPixels]];
FOR y: NAT IN [0..yPixels) DO
row: Row ← array[y] ← NEW[RowRep[xPixels]];
savedLine: NAT ← curLine;
savedPixel: NAT ← curPixel;
FOR x: NAT IN [0..xPixels) DO
row[x] ← window.ReadSample[curLine, curPixel];
curLine ← curLine + xNextLine;
curPixel ← curPixel + xNextPixel;
ENDLOOP;
curLine ← savedLine + yNextLine;
curPixel ← savedPixel + yNextPixel;
ENDLOOP;
ais.CloseFile;
};
AISToColor: PUBLIC PROC [aisName: Rope.ROPE] RETURNS [ImagerBasic.Color] ~ {
pixelArray: ImagerBasic.PixelArray ← NEW[ImagerBasic.PixelArrayRep];
color: ImagerBasic.SampledColor ← NEW[ImagerBasic.SampledColorRep];
array: Array ← LoadAISData[aisName];
pixelArray.xPixels ← array[0].xPixels;
pixelArray.yPixels ← array.yPixels;
pixelArray.maxSampleValue ← 255;
pixelArray.samplesPerPixel ← 1;
pixelArray.get ← GetOne;
pixelArray.data ← array;
color.transparent ← FALSE;
color.pa ← pixelArray;
color.m ← [1, 0, 0, 0, 1, 0, identity];
color.colorMap ← $Intensity8bpp;
RETURN [color];
};
GetOne: PROC [self: ImagerBasic.PixelArray, buffer: ImagerBasic.PixelBuffer, nSamples: NAT, layer: INT, xStart, yStart: Scaled.Value, xDelta, yDelta: Scaled.Value] ~ {
array: Array ← NARROW[self.data];
yMax: INTEGER ← self.yPixels - 1;
xMax: INTEGER ← self.xPixels - 1;
FOR i: NAT IN [0..nSamples) DO
y: INTEGER ← yStart.Floor;
x: INTEGER ← xStart.Floor;
buffer[i] ← IF x IN [0..xMax] AND y IN [0..yMax] THEN array[y][x] ELSE 0;
xStart ← xStart.PLUS[xDelta];
yStart ← yStart.PLUS[yDelta];
ENDLOOP;
};
END.