File: SVImageImpl.mesa
Last edited by Bier on December 18, 1982 1:38 am
Author: Eric Bier before June 30, 1983 11:27 am
Contents: Routines for manipulating 24 bit per pixel color images
DIRECTORY
AIS,
ConvertUnsafe,
Directory,
Graphics,
GraphicsColor,
GraphicsOps,
MessageWindow,
ReadAIS,
Real,
Rope,
SV2d,
SVBoundBox,
SVFiles,
SVImage,
SVVector2d;
SVImageImpl: PROGRAM
IMPORTS AIS, ConvertUnsafe, Directory, Graphics, GraphicsColor, GraphicsOps, MessageWindow, ReadAIS, Real, Rope, SVFiles, SVVector2d
EXPORTS SVImage =
BEGIN
Image: TYPE = REF ImageObj;
ImageObj: TYPE = SVImage.ImageObj;
BoundBox: TYPE = REF BoundBoxObj;
BoundBoxObj: TYPE = SVBoundBox.BoundBoxObj;
Color: TYPE = GraphicsColor.Color;
ImageRef: TYPE = GraphicsOps.ImageRef;
Mark: TYPE = Graphics.Mark;
Point2d: TYPE = SV2d.Point2d;
WRef: TYPE = AIS.WRef;
FRef: TYPE = AIS.FRef;
IsEven: PRIVATE PROC [n: NAT] RETURNS [BOOL] = {
RETURN [(n/2)*2 = n];
};
RoundDown: PRIVATE PROC [r: REAL] RETURNS [rDown: INTEGER] = {
find the largest integer less than r (or equal to if r is positive).
IF r = 0 THEN RETURN[0];
IF r > 0 THEN {
rDown ← Real.FixI[r];
RETURN}
ELSE {
r ← -r;-- make it positive
rDown ← Real.FixI[r];
rDown ← rDown + 1;
rDown ← - rDown;
};
};
RoundUp: PRIVATE PROC [r: REAL] RETURNS [rUp: INTEGER] = {
find the smallest integer greater than r (or equal to if r is negative).
IF r = 0 THEN RETURN[0];
IF r > 0 THEN {
rUp ← Real.FixI[r];
rUp ← rUp + 1;
RETURN}
ELSE {
r ← -r;-- make it positive
rUp ← Real.FixI[r];
rUp ← - rUp;
};
};
CountSamples: PRIVATE PROC [realMinX, realMinY, realMaxX, realMaxY, resolution: REAL] RETURNS [numberOfSamplesX, numberOfSamplesY: NAT] = {
We are given a minimum bounding box to be filled. Calculate the number of samples in the x direction as follows: Find the number of samples which will just fit in the alloted x extent. Now add one (Since <number of inter-sample distances> + 1 = number of samples, we actually add two). If the resulting number is odd, add 1 again. Do the same for the y direction.
(Because of unimplemented features in some of the printing software, it is useful to round all ais file sizes to even numbers of pixels.)
xExtent/72 = x extent in inches. (xExtent/72)*resolution = samples which will fit. Round this down to the nearest integer.
xExtent, yExtent, realSamplesX, realSamplesY: REAL;
xExtent ← realMaxX - realMinX; -- x extent in screen dots
yExtent ← realMaxY - realMinY; -- y extent in screen dots
realSamplesX ← (xExtent*resolution)/72.0;
realSamplesY ← (yExtent*resolution)/72.0;
numberOfSamplesX ← Real.FixI[realSamplesX] + 2;
numberOfSamplesY ← Real.FixI[realSamplesY] + 2;
IF NOT IsEven[numberOfSamplesX] THEN numberOfSamplesX ← numberOfSamplesX + 1;
IF NOT IsEven[numberOfSamplesY] THEN numberOfSamplesY ← numberOfSamplesY + 1;
}; -- end of CountSamples
OpenImage: PUBLIC PROC [aisRope: Rope.ROPE, bAndWOnly: BOOL, realMinX, realMinY, realMaxX, realMaxY, resolution: REAL, raster: AIS.Raster, commentString: LONG STRING] RETURNS [I: Image, numberOfSamplesX, numberOfSamplesY: NAT] = {
Bound box is in camera coordinates
f: AIS.FRef;
INEW[ImageObj];
[numberOfSamplesX, numberOfSamplesY] ← CountSamples[realMinX, realMinY, realMaxX, realMaxY, resolution];
raster^ ← [numberOfSamplesY, numberOfSamplesX, rd, 8, -1, 65535];
IF bAndWOnly THEN {
bwString: LONG STRING ← [30];
I.bAndWOnly ← TRUE;
ConvertUnsafe.AppendRope[bwString, aisRope];
f ← ReadAIS.CreateFile[bwString, raster, commentString, TRUE, 0, resolution];
I.bwWindow ← AIS.OpenWindow[f];
}
ELSE {
redRope: Rope.ROPE ← Rope.Concat[SVFiles.FilenameMinusExtension[aisRope], "-red.ais"];
greenRope: Rope.ROPE ← Rope.Concat[SVFiles.FilenameMinusExtension[aisRope], "-green.ais"];
blueRope: Rope.ROPE ← Rope.Concat[SVFiles.FilenameMinusExtension[aisRope], "-blue.ais"];
bwRope: Rope.ROPE ← aisRope;
redString: LONG STRING ← [30];
greenString: LONG STRING ← [30];
blueString: LONG STRING ← [30];
bwString: LONG STRING ← [30];
I.bAndWOnly ← FALSE;
ConvertUnsafe.AppendRope[bwString, bwRope];
ConvertUnsafe.AppendRope[redString, redRope];
ConvertUnsafe.AppendRope[greenString, greenRope];
ConvertUnsafe.AppendRope[blueString, blueRope];
f ← ReadAIS.CreateFile[redString, raster, commentString, TRUE, 0, resolution];
I.redWindow ← AIS.OpenWindow[f];
f ← ReadAIS.CreateFile[greenString, raster, commentString, TRUE, 0, resolution];
I.greenWindow ← AIS.OpenWindow[f];
f ← ReadAIS.CreateFile[blueString, raster, commentString, TRUE, 0, resolution];
I.blueWindow ← AIS.OpenWindow[f];
f ← ReadAIS.CreateFile[bwString, raster, commentString, TRUE, 0, resolution];
I.bwWindow ← AIS.OpenWindow[f];
};
MessageWindow.Append[" New "];
MessageWindow.Append[aisRope];
MessageWindow.Append["'s created."];
};-- end of OpenImage
DeleteFile: PRIVATE PROC [name: Rope.ROPE] = {
success: BOOL;
nameString: LONG STRING ← [20];
ConvertUnsafe.AppendRope[nameString, name];
success ← AIS.DeleteFile[nameString];
IF NOT success THEN {MessageWindow.Append["No "];
MessageWindow.Append[name];
MessageWindow.Append[". "];}
ELSE {
MessageWindow.Append[name];
MessageWindow.Append["... "];
};
};-- end of DeleteFile
Truncate: PROC [value: REAL] RETURNS [m: CARDINAL] = {
Truncate the REAL value to 0-255
SELECT value FROM
<0 => ERROR;
>255.0 => m ← 255;
ENDCASE => m ← Real.FixC[value];
};
PutImage2: PROC [I: Image, i, j: INTEGER, color: Color, minX, maxX, minY, maxY: INTEGER] = {
i is row. j is column. i = maxY maps to 0. i = minY maps to maxY-minY.
j = maxX maps to maxX-minX. j = minX maps to 0.
intRed, intGreen, intBlue, intIntensity: CARDINAL;
red, green, blue: REAL;
[red, green, blue] ← GraphicsColor.ColorToRGB [color];
intRed ← Truncate[red*255.0];
intGreen ← Truncate[green*255.0];
intBlue ← Truncate[blue*255.0];
intIntensity ← Truncate[GraphicsColor.ColorToIntensity[color]*255.0];
AIS.WriteSample[I.redWindow, intRed, maxY - i, j - minX];
AIS.WriteSample[I.greenWindow, intGreen, maxY - i, j - minX];
AIS.WriteSample[I.blueWindow, intBlue, maxY - i, j - minX];
AIS.WriteSample[I.bwWindow, intIntensity, maxY - i, j - minX];
};
PutImage: PUBLIC PROC [I: Image, i, j: INTEGER, color: Color, xSamples, ySamples: NAT] = {
i is row. j is column. i = ySamples maps to 0. i = 1 maps to ySamples-1.
j = xSamples-1 maps to xSamples-1. j = 0 maps to 0.
IF I.bAndWOnly THEN {
intIntensity: CARDINAL;
intIntensity ← Truncate[GraphicsColor.ColorToIntensity[color]*255.0];
AIS.WriteSample[I.bwWindow, intIntensity, ySamples-i, j];
}
ELSE {
intRed, intGreen, intBlue, intIntensity: CARDINAL;
red, green, blue: REAL;
[red, green, blue] ← GraphicsColor.ColorToRGB [color];
intRed ← Truncate[red*255.0];
intGreen ← Truncate[green*255.0];
intBlue ← Truncate[blue*255.0];
intIntensity ← Truncate[GraphicsColor.ColorToIntensity[color]*255.0];
AIS.WriteSample[I.redWindow, intRed, ySamples-i, j];
AIS.WriteSample[I.greenWindow, intGreen, ySamples-i, j];
AIS.WriteSample[I.blueWindow, intBlue, ySamples-i, j];
AIS.WriteSample[I.bwWindow, intIntensity, ySamples-i, j];
};
};
CloseImage: PUBLIC PROC [I: Image, aisRope: Rope.ROPE] = {
f: AIS.FRef;
IF I.bAndWOnly THEN {
f ← I.bwWindow.fref;
AIS.CloseWindow[I.bwWindow];
AIS.CloseFile[f];
MessageWindow.Append[aisRope];
MessageWindow.Append[" now closed"];
MessageWindow.Blink[];
}
ELSE {
f ← I.blueWindow.fref;
AIS.CloseWindow[I.blueWindow];
AIS.CloseFile[f];
f ← I.bwWindow.fref;
AIS.CloseWindow[I.bwWindow];
AIS.CloseFile[f];
f ← I.redWindow.fref;
AIS.CloseWindow[I.redWindow];
AIS.CloseFile[f];
f ← I.greenWindow.fref;
AIS.CloseWindow[I.greenWindow];
AIS.CloseFile[f];
MessageWindow.Append[" (red green blue BandW) "];
MessageWindow.Append[aisRope];
MessageWindow.Append[" now closed"];
MessageWindow.Blink[];
};
}; -- end of CloseImage
BoundBoxOfImage: PRIVATE PROC [image: ImageRef, resolution: REAL ← 72.0] RETURNS [boundBox: BoundBox] = {
xmin,ymin,xmax,ymax, xExtent, yExtent: REAL;
[xmin,ymin,xmax,ymax] ← GraphicsOps.ImageBox[image];
xmin,ymin,xmax,ymax are now in units of samples. Resolution is in samples per inch.
There are 72 screen dots per inch. We wish to normalize as if xmin = ymin = 0;
xExtent ← xmax - xmin;
yExtent ← ymax - ymin;
xExtent ← (xExtent/resolution)*72.0;
yExtent ← (yExtent/resolution)*72.0;
boundBox ← NEW[BoundBoxObj];
boundBox.minVert ← [0,0,0];
boundBox.maxVert ← [xExtent,yExtent, 0];
};
NewBlackAndWhiteImage: PUBLIC PROC [imageName: Rope.ROPE] RETURNS [image: ImageRef, success: BOOL] = {
bwName: Rope.ROPE ← Rope.Concat[SVFiles.FilenameMinusExtension[imageName],".ais"];
success ← TRUE;
image ← GraphicsOps.NewAisImage[imageName
!Directory.Error => {success ← FALSE; CONTINUE}];
IF NOT success THEN {
MessageWindow.Append["Open AIS file failed", TRUE];
MessageWindow.Blink[];
RETURN};
};
NewColorImage: PUBLIC PROC [imageName: Rope.ROPE] RETURNS [redimage, greenimage, blueimage: ImageRef, success: BOOL] = {
redName: Rope.ROPE ← Rope.Concat[SVFiles.FilenameMinusExtension[imageName],"-red.ais"];
greenName: Rope.ROPE ← Rope.Concat[SVFiles.FilenameMinusExtension[imageName],"-green.ais"];
blueName: Rope.ROPE ← Rope.Concat[SVFiles.FilenameMinusExtension[imageName],"-blue.ais"];
success ← TRUE;
redimage ← GraphicsOps.NewAisImage[redName
!Directory.Error => {success ← FALSE; CONTINUE}];
greenimage ← GraphicsOps.NewAisImage[greenName
!Directory.Error => {success ← FALSE; CONTINUE}];
blueimage ← GraphicsOps.NewAisImage[blueName
!Directory.Error => {success ← FALSE; CONTINUE}];
IF NOT success THEN {
MessageWindow.Append["Open AIS file failed", TRUE];
MessageWindow.Blink[];
RETURN};
};
DrawAlignedBlackAndWhiteImage: PUBLIC PROC [dc: Graphics.Context, imageName: Rope.ROPE, resolution: REAL, screenWRTCamera: Point2d, boundBox: BoundBox, raw: BOOL] = {
Count how many samples there are in the x and y directions of the image. Look at the resolution (default is 72.0). This gives the actual size of the image. Frame it evenly around the clipBox.
info: ReadAIS.MyAISInfo;
stepSize, xStart, yStart: REAL;
lowerLeft, upperRight: Point2d;
samplesX, samplesY: NAT;
mark: Mark;
success: BOOL;
extentX, extentY, projectionX, projectionY, trueExtentX, trueExtentY: REAL;
[info, success] ← ReadAIS.Read[imageName];
IF NOT success THEN RETURN;
resolution ← ReadAIS.ResolutionFromInfo[info];
[samplesX, samplesY] ← ReadAIS.SamplesFromInfo[info];
stepSize ← 72.0/resolution; -- in screen dots per sample
lowerLeft ← SVVector2d.Difference[[boundBox.minVert[1], boundBox.minVert[2]], screenWRTCamera];
upperRight ← SVVector2d.Difference[[boundBox.maxVert[1], boundBox.maxVert[2]], screenWRTCamera];
extentX ← boundBox.maxVert[1] - boundBox.minVert[1];
extentY ← boundBox.maxVert[2] - boundBox.minVert[2];
trueExtentX ← Real.Float[samplesX-1]*stepSize;
trueExtentY ← Real.Float[samplesY-1]*stepSize;
projectionX ← (trueExtentX - extentX)/2.0;
projectionY ← (trueExtentY - extentY)/2.0;
xStart ← lowerLeft[1] - projectionX;
yStart ← lowerLeft[2] - projectionY;
xStart ← xStart - stepSize/2.0;
yStart ← yStart - stepSize/2.0;
mark ← Graphics.Save[dc];
Graphics.Translate[dc, xStart, yStart];
DrawBlackAndWhiteImage[dc, imageName, boundBox, resolution, raw];
Graphics.Restore[dc, mark];
};
DrawBlackAndWhiteImage: PUBLIC PROC [dc: Graphics.Context, imageName: Rope.ROPE, clipBox: BoundBox ← NIL, resolution: REAL ← 72.0, raw: BOOL] = {
clipBox in units of screen dots, in coordinates whose origin is the lower left hand corner of the ais image.
resolution is in dots per inch (72 is screen resolution).
Draws the ais file of given resolution such that its lower left hand corner is at the current origin of dc.
This involves several steps.
1) Find the total size of the clipBox. If no clipBox is given, use the whole image size.
2) Find the scaling factors needed to interpret the image as having the stated resolution
3) Translate appropriately
4) Draw.
minX, maxX, minY, maxY: REAL;
clipPath: Graphics.Path ← Graphics.NewPath[4];
lowerLeft, upperRight: Point2d;
image: ImageRef;
success: BOOL;
scale: REAL;
mark: Mark;
OPEN THE IMAGE
[image, success] ← NewBlackAndWhiteImage[imageName];
IF NOT success THEN RETURN;
Substitute for NIL parameters.
IF clipBox = NIL THEN clipBox ← BoundBoxOfImage[image, resolution];
BoundBoxOfImage in screen dots relative to lower left corner of image.
Find clipBox in screen coordinates (ie its lowerLeft and upperRight points)
lowerLeft ← [0,0];-- screen coords
upperRight ← SVVector2d.Sum[[clipBox.maxVert[1], clipBox.maxVert[2]],
lowerLeft];-- screen coords
box bounds in screen coordinates
minX ← lowerLeft[1];
maxX ← upperRight[1] +1;
minY ← lowerLeft[2];
maxY ← upperRight[2] +1;
Now find the scaling factors for the given resolution.
scale ← 72.0/resolution;
mark ← Graphics.Save[dc];
create the bounding box we have just calculated
Graphics.MoveTo[clipPath, minX, minY];
Graphics.LineTo[clipPath, minX, maxY];
Graphics.LineTo[clipPath, maxX, maxY];
Graphics.LineTo[clipPath, maxX, minY];
Graphics.SetColor[dc, GraphicsColor.black];
Graphics.DrawStroke[dc, clipPath, 2, TRUE];
Graphics.ClipArea[dc, clipPath];
Graphics.Translate[dc, minX, minY];
If lowerLeft were not [0,0], we would perform this translate
Graphics.SetCP[dc, 0, 0];-- put lower left corner of image at this new origin
Graphics.SetColor[dc, GraphicsColor.black];
SVDraw.Cross[dc, 0, 0, 20];
Graphics.Scale[dc, scale, scale];
Graphics.DrawImage[dc, image];
Graphics.Restore[dc, mark];
};
DrawAndScaleBlackAndWhiteImage: PUBLIC PROC [dc: Graphics.Context, imageName: Rope.ROPE, screenWRTCamera: Point2d, realMinX, realMinY, realMaxX, realMaxY: REAL] = {
minX, maxX, minY, maxY: INTEGER;
clipPath: Graphics.Path ← Graphics.NewPath[4];
lowerLeft, upperRight: Point2d;
Take file in AIS coordinates (right and down) and display in SCREEN coords.
AIS origin is displaced from CAMERA origin by minX, minY.
The clipping region has its origin at the ais origin and proceeds scanwidth and scanheight.
screenOrigin: Point2d;
success: BOOLTRUE;
image: ImageRef;
imageXmin, imageYmin, imageXmax, imageYmax, xScale, yScale: REAL;
mark: Mark ← Graphics.Save[dc];
[image, success] ← NewBlackAndWhiteImage[imageName];
IF NOT success THEN RETURN;
Substitute for NIL parameters
lowerLeft ← SVVector2d.Difference[[realMinX, realMinY], screenWRTCamera];
upperRight ← SVVector2d.Difference[[realMaxX, realMaxY], screenWRTCamera];
Box bounds in screen coordinates
minX ← RoundDown[lowerLeft[1]];
maxX ← RoundUp[upperRight[1]];
minY ← RoundDown[lowerLeft[2]];
maxY ← RoundUp[upperRight[2]];
IF NOT IsEven[maxX - minX + 1] THEN maxX ← maxX + 1;
IF NOT IsEven[maxY - minY + 1] THEN maxY ← maxY + 1;
screenOrigin ← [minX, minY];-- ais file origin with respect to screen origin
Now find the bounding box of the ais file and scale the ais file to fit in the viewport.
[imageXmin, imageYmin, imageXmax, imageYmax] ← GraphicsOps.ImageBox[image];
xScale ← (maxX-minX)/(imageXmax-imageXmin);
yScale ← (maxY-minY)/(imageYmax-imageYmin);
Graphics.MoveTo[clipPath, screenOrigin[1], screenOrigin[2]];
Graphics.LineTo[clipPath, screenOrigin[1], screenOrigin[2]+maxY-minY];
Graphics.LineTo[clipPath, screenOrigin[1] + maxX-minX, screenOrigin[2]+maxY-minY];
Graphics.LineTo[clipPath, screenOrigin[1] + maxX-minX, screenOrigin[2]];
Graphics.ClipArea[dc, clipPath];
Graphics.Translate[dc, screenOrigin[1], screenOrigin[2]];
Graphics.SetCP[dc, 0, 0];
Graphics.Scale[dc, xScale, yScale];
Graphics.SetColor[dc, GraphicsColor.white];
Graphics.DrawImage[dc, image, TRUE];
Graphics.Restore[dc, mark];
};
DrawAlignedColorImage: PUBLIC PROC [dc: Graphics.Context, imageName: Rope.ROPE, resolution: REAL, screenWRTCamera: Point2d, boundBox: BoundBox] = {
Count how many samples there are in the x and y directions of the image. Look at the resolution (default is 72.0). This gives the actual size of the image. Frame it evenly around the clipBox.
info: ReadAIS.MyAISInfo;
stepSize, xStart, yStart: REAL;
lowerLeft, upperRight: Point2d;
redName: Rope.ROPE ← Rope.Concat[SVFiles.FilenameMinusExtension[imageName],"-red.ais"];
samplesX, samplesY: NAT;
mark: Mark;
success: BOOL;
extentX, extentY, projectionX, projectionY, trueExtentX, trueExtentY: REAL;
[info, success] ← ReadAIS.Read[redName];
IF NOT success THEN RETURN;
resolution ← ReadAIS.ResolutionFromInfo[info];
[samplesX, samplesY] ← ReadAIS.SamplesFromInfo[info];
stepSize ← 72.0/resolution; -- in screen dots per sample
lowerLeft ← SVVector2d.Difference[[boundBox.minVert[1], boundBox.minVert[2]], screenWRTCamera];
upperRight ← SVVector2d.Difference[[boundBox.maxVert[1], boundBox.maxVert[2]], screenWRTCamera];
extentX ← boundBox.maxVert[1] - boundBox.minVert[1];
extentY ← boundBox.maxVert[2] - boundBox.minVert[2];
trueExtentX ← Real.Float[samplesX-1]*stepSize;
trueExtentY ← Real.Float[samplesY-1]*stepSize;
projectionX ← (trueExtentX - extentX)/2.0;
projectionY ← (trueExtentY - extentY)/2.0;
xStart ← lowerLeft[1] - projectionX;
yStart ← lowerLeft[2] - projectionY;
xStart ← xStart - stepSize/2.0;
yStart ← yStart - stepSize/2.0;
mark ← Graphics.Save[dc];
Graphics.Translate[dc, xStart, yStart];
DrawColorImage[dc, imageName, boundBox, resolution];
Graphics.Restore[dc, mark];
};
DrawColorImage: PUBLIC PROC [dc: Graphics.Context, imageName: Rope.ROPE, clipBox: BoundBox ← NIL, resolution: REAL ← 72.0] = {
See comment for DrawBlackAndWhiteImage
minX, maxX, minY, maxY: REAL;
lowerLeft, upperRight: Point2d;
success: BOOL;
redimage, greenimage, blueimage: ImageRef;
scale: REAL;
clipPath: Graphics.Path ← Graphics.NewPath[4];
mark: Mark ← Graphics.Save[dc];
[redimage, greenimage, blueimage, success] ← NewColorImage[imageName];
IF NOT success THEN RETURN;
IF clipBox = NIL THEN clipBox ← BoundBoxOfImage[redimage, resolution];
lowerLeft ← [0,0];-- screen coords
upperRight ← SVVector2d.Sum[[clipBox.maxVert[1], clipBox.maxVert[2]],
lowerLeft];-- screen coords
box bounds in screen coordinates
minX ← lowerLeft[1];
maxX ← upperRight[1] +1;
minY ← lowerLeft[2];
maxY ← upperRight[2] +1;
now find the scaling factors for the given resolution
scale ← 72.0/resolution;
Graphics.MoveTo[clipPath, minX, minY];
Graphics.LineTo[clipPath, minX, maxY];
Graphics.LineTo[clipPath, maxX, maxY];
Graphics.LineTo[clipPath, maxX, minY];
Graphics.SetColor[dc, GraphicsColor.black];
Graphics.DrawStroke[dc, clipPath, 2, TRUE];
Graphics.ClipArea[dc, clipPath];
Graphics.Translate[dc, minX, minY];
If lowerLeft were not [0,0], we would perform this translate.
Graphics.SetCP[dc, 0, 0]; -- put lower left corner of image at this new origin
Graphics.Scale[dc, scale, scale];
[] ← Graphics.SetPaintMode[dc, opaque];
Graphics.SetColor[dc, GraphicsColor.red];
Graphics.DrawImage[dc, redimage];
[] ← Graphics.SetPaintMode[dc, transparent];
Graphics.SetColor[dc, GraphicsColor.green];
Graphics.DrawImage[dc, greenimage];
Graphics.SetColor[dc, GraphicsColor.blue];
Graphics.DrawImage[dc, blueimage];
Graphics.Restore[dc, mark];
};
DrawAndScaleColorImage: PUBLIC PROC [dc: Graphics.Context, imageName: Rope.ROPE, screenWRTCamera: Point2d, realMinX, realMinY, realMaxX, realMaxY: REAL] = {
minX, maxX, minY, maxY: INTEGER;
lowerLeft, upperRight: Point2d;
Take file in ais coordinates (right and down) and display in SCREEN coords.
AIS origin is displaced from CAMERA origin by minX, minY.
The clipping region has its origin at the ais origin and proceeds scanwidth and scanheight.
screenOrigin: Point2d;
redimage, greenimage, blueimage: ImageRef;
success: BOOL;
imageXmin, imageYmin, imageXmax, imageYmax, xScale, yScale: REAL;
clipPath: Graphics.Path ← Graphics.NewPath[4];
mark: Mark ← Graphics.Save[dc];
[redimage, greenimage, blueimage, success] ← NewColorImage[imageName];
IF NOT success THEN RETURN;
lowerLeft ← SVVector2d.Difference[[realMinX, realMinY], screenWRTCamera];
upperRight ← SVVector2d.Difference[[realMaxX, realMaxY], screenWRTCamera];
Box bounds in screen coordinates
minX ← RoundDown[lowerLeft[1]];
maxX ← RoundUp[upperRight[1]];
minY ← RoundDown[lowerLeft[2]];
maxY ← RoundUp[upperRight[2]];
IF NOT IsEven[maxX - minX + 1] THEN maxX ← maxX + 1;
IF NOT IsEven[maxY - minY + 1] THEN maxY ← maxY + 1;
screenOrigin ← [minX, minY];-- ais file lower left with respect to screen origin
Now find the bounding box of the ais file and scale the ais file to fit in the viewport
[imageXmin, imageYmin, imageXmax, imageYmax] ← GraphicsOps.ImageBox[redimage];
xScale ← (maxX-minX)/(imageXmax-imageXmin);
yScale ← (maxY-minY)/(imageYmax-imageYmin);
Graphics.MoveTo[clipPath, screenOrigin[1], screenOrigin[2]];
Graphics.LineTo[clipPath, screenOrigin[1], screenOrigin[2]+maxY-minY];
Graphics.LineTo[clipPath, screenOrigin[1] + maxX-minX, screenOrigin[2]+maxY-minY];
Graphics.LineTo[clipPath, screenOrigin[1] + maxX-minX, screenOrigin[2]];
Graphics.ClipArea[dc, clipPath];
Graphics.Translate[dc, screenOrigin[1], screenOrigin[2]];
Graphics.SetCP[dc, 0, 0];
Graphics.Scale[dc, xScale, yScale];
[] ← Graphics.SetPaintMode[dc, opaque];
Graphics.SetColor[dc, GraphicsColor.red];
Graphics.DrawImage[dc, redimage];
[] ← Graphics.SetPaintMode[dc, transparent];
Graphics.SetColor[dc, GraphicsColor.green];
Graphics.DrawImage[dc, greenimage];
Graphics.SetColor[dc, GraphicsColor.blue];
Graphics.DrawImage[dc, blueimage];
Graphics.Restore[dc, mark];
}; -- end of DrawAndScaleColorImage
END.