PROC [filename:Rope.
Buffer: TYPE = REF BufferRec;
BufferRec: TYPE = PACKED ARRAY [0..2048) OF [0..255];
fdIn: AIS.FRef;
wIn: AIS.WRef;
rIn:AIS.Raster;
buffer:Buffer ← NEW[BufferRec];
counts: ARRAY[0..255] OF LONG CARDINAL ← ALL[0];
nPixels:REAL ← 0;
histogram ← NEW[HistogramRec];
fdIn ← AIS.OpenFile[name:filename];
wIn ← AIS.OpenWindow[fdIn];
rIn ← AIS.ReadRaster[fdIn];
FOR line:
NAT
IN [0.. rIn.scanCount)
DO
TRUSTED {
AIS.UnsafeReadLine[w:wIn, buffer:[length:rIn.scanLength, addr:LOOPHOLE[buffer]], line:line]
};
FOR pixel:
NAT
IN [0..rIn.scanLength)
DO
IF buffer[pixel]
IN [low..high]
THEN {
nPixels ← nPixels + 1;
counts[buffer[pixel]] ← counts[buffer[pixel]] + 1;
}
ENDLOOP;
ENDLOOP;
FOR i:
NAT
IN [0..255]
DO
histogram[i] ← counts[i]/nPixels;
ENDLOOP;
AIS.CloseWindow[wIn];
AIS.CloseFile[fdIn];
};