ProduceTapesImpl.mesa
Copyright Ó 1987 by Xerox Corporation. All rights reserved.
Maureen Stone, July 24, 1989 12:43:16 pm PDT
Production code around calls to InterpressToTape
Sizes, converts to Interpress and writes tapes for images
DIRECTORY
InterpressToTape, AIS, Imager, Rope, PrintColor, ImagerInterpress, ImagerPixelArray, ImagerColor, ImagerBox, ImagerFont, Real, FS, OptronicsTape;
ProduceTapesImpl: CEDAR PROGRAM
IMPORTS AIS, Imager, ImagerInterpress, Rope, ImagerPixelArray, ImagerColor, ImagerFont, Real, FS, InterpressToTape
EXPORTS
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
ColorCorrection: TYPE ~ PrintColor.ColorCorrection;
IPSpec: TYPE ~ InterpressToTape.IPSpec;
IPSpecRep: TYPE ~ InterpressToTape.IPSpecRep;
RGB: TYPE ~ ImagerColor.RGB;
Makes sized Interpress masters from AIS
AISEndings: TYPE = ARRAY [0..2] OF ROPE;
redGreenBlue: AISEndings ← ["-red", "-green", "-blue"];
redGrnBlu: AISEndings ← ["-red", "-grn", "-blu"];
ImageAndLabel: PROC [context: Imager.Context, pa: ImagerPixelArray.PixelArray, note: ROPE, fontSize: REAL, onSide: BOOLEANFALSE] RETURNS[widthInPixels, heightInPixels: NAT] ~ {
Assume the context background is black, so label in white
nLines: NAT ← pa.sSize;
nPixels: NAT ← pa.fSize;
widthInPixels ← nPixels;
heightInPixels ← nLines;
IF note#NIL THEN {
width: PROC[extent: ImagerFont.Extents] RETURNS[REAL] = {
RETURN[extent.leftExtent+extent.rightExtent]};
height: PROC[extent: ImagerFont.Extents] RETURNS[REAL] = {
RETURN[extent.ascent+extent.descent]};
font: ImagerFont.Font ← ImagerFont.Scale[ImagerFont.Find["Xerox/PressFonts/Helvetica-mrr"],fontSize];
noteBox: ImagerFont.Extents ← ImagerFont.RopeBoundingBox[font, note];
gap: REAL ← 2.0; --standard small space
noteSize: REAL ← 2*gap+height[noteBox];
writeNote: PROC = {
Imager.SetColor[context, Imager.white];
IF onSide THEN {
Imager.TranslateT[context, [nPixels+gap, nLines-(nLines-width[noteBox])/2.0]];
Imager.RotateT[context, -90];
Imager.SetXY[context,[0,0]];
widthInPixels ← Real.Round[nPixels+noteSize];
heightInPixels ← nLines;
}
ELSE {
Imager.SetXY[context, [x: (nPixels-width[noteBox])/2.0, y: nLines+gap]];
widthInPixels ← nPixels;
heightInPixels ← Real.Round[nLines+noteSize];
};
Imager.SetFont[context, font];
Imager.ShowRope[context, note];
};
Imager.DoSave[context, writeNote];
};
Imager.SetSampledColor[context, pa, NIL, ImagerColor.NewColorOperatorRGB[255]];
Imager.MaskRectangle[context, [0,0, nPixels, nLines]];
};
AISSpec: TYPE = RECORD[aisRoot, note: ROPE];
IPFromFourAIS: PUBLIC PROC [ipName: ROPE, aisSpecs: ARRAY[0..3] OF AISSpec, xPitch,yPitch, aisWidth: REAL, aisEndings: AISEndings ← redGrnBlu, onSide: BOOLEANFALSE] ~ {
ip: ImagerInterpress.Ref ← ImagerInterpress.Create[ipName];
xPitchInMeters: REAL ← xPitch*Imager.metersPerInch;
yPitchInMeters: REAL ← yPitch*Imager.metersPerInch;
current: NAT ← 0;
action: PROC[context: Imager.Context] = {
writeAIS: PROC = {
aisRoot: ROPE ← aisSpecs[current].aisRoot;
note: ROPE ← aisSpecs[current].note;
pa: ImagerPixelArray.PixelArray ← ImagerPixelArray.Join3AIS[Rope.Cat[aisRoot, aisEndings[0], ".ais"], Rope.Cat[aisRoot, aisEndings[1], ".ais"], Rope.Cat[aisRoot, aisEndings[2], ".ais"] ];
nLines: NAT ← pa.sSize;
nPixels: NAT ← pa.fSize;
ppi: REAL ← nPixels/aisWidth;
fontSize: REAL ← 8*ppi/Imager.pointsPerInch;
Imager.ScaleT[context,Imager.metersPerPoint*Imager.pointsPerInch/ppi];
[,] ← ImageAndLabel[context, pa, note, fontSize, onSide];
};
Imager.SetColor[context, Imager.black];
We're in meters
Imager.MaskRectangle[context,[0,0,2*xPitchInMeters,2*yPitchInMeters]];
current ← 0;
Imager.DoSave[context, writeAIS];
Imager.TranslateT[context,[xPitchInMeters, 0]];
current ← 1;
Imager.DoSave[context, writeAIS];
Imager.TranslateT[context,[-xPitchInMeters, yPitchInMeters]];
current ← 2;
Imager.DoSave[context, writeAIS];
Imager.TranslateT[context,[xPitchInMeters, 0]];
current ← 3;
Imager.DoSave[context, writeAIS];
};
ImagerInterpress.DoPage[ip, action, 1];
ImagerInterpress.Close[ip];
};
IPFromColorAIS: PUBLIC PROC [aisRoot, ipName, note: ROPE, ppi: REAL ← 0, width: REAL ← 0, aisEndings: AISEndings ← redGrnBlu, onSide: BOOLEANFALSE] RETURNS[fDim, sDim: REAL] ~ {
ip: ImagerInterpress.Ref ← ImagerInterpress.Create[ipName];
action: PROC[context: Imager.Context] = {
pa: ImagerPixelArray.PixelArray ← ImagerPixelArray.Join3AIS[Rope.Cat[aisRoot, aisEndings[0], ".ais"], Rope.Cat[aisRoot, aisEndings[1], ".ais"], Rope.Cat[aisRoot, aisEndings[2], ".ais"] ];
fontSize: REAL ← 8*ppi/Imager.pointsPerInch;
Imager.SetColor[context, Imager.black];
Imager.MaskRectangle[context,[0,0,nPixels+2*fontSize,nLines+2*fontSize]];
[widthInPixels, heightInPixels] ← ImageAndLabel[context, pa, note, fontSize, onSide];
};
scale: REAL ← 1;
nLines,nPixels, widthInPixels, heightInPixels: NAT;
[nLines,nPixels] ← SizeFromAISFile[Rope.Cat[aisRoot, aisEndings[0], ".ais"]];
use either ppi or longestSize, whichever is not 0
IF ppi <= 0 AND width <= 0 THEN ERROR;
IF ppi=0 THEN ppi ← nPixels/width;
scale ← Imager.metersPerPoint*Imager.pointsPerInch/ppi;
ImagerInterpress.DoPage[ip, action, scale];
ImagerInterpress.Close[ip];
RETURN[fDim: widthInPixels/ppi, sDim: heightInPixels/ppi];
};
IPFromAISSquared: PUBLIC PROC [aisRoot, ipName: ROPE, ppi: REAL ← 0, width: REAL ← 0, aisEndings: AISEndings ← redGrnBlu, background: RGB ] RETURNS[fDim, sDim: REAL] ~ {
ip: ImagerInterpress.Ref ← ImagerInterpress.Create[ipName];
action: PROC[context: Imager.Context] = {
pa: ImagerPixelArray.PixelArray ← ImagerPixelArray.Join3AIS[Rope.Cat[aisRoot, aisEndings[0], ".ais"], Rope.Cat[aisRoot, aisEndings[1], ".ais"], Rope.Cat[aisRoot, aisEndings[2], ".ais"] ];
Imager.SetColor[context, ImagerColor.ColorFromRGB[background]];
Imager.MaskRectangle[context,[0,0,nPixels, nPixels]];
Imager.TranslateT[context, [0,(nPixels-nLines)/2]];
[widthInPixels, heightInPixels] ← ImageAndLabel[context, pa, NIL, 1, FALSE];
};
scale: REAL ← 1;
nLines,nPixels, widthInPixels, heightInPixels: NAT;
[nLines,nPixels] ← SizeFromAISFile[Rope.Cat[aisRoot, aisEndings[0], ".ais"]];
use either ppi or width, whichever is not 0
IF ppi <= 0 AND width <= 0 THEN ERROR;
IF ppi=0 THEN ppi ← nPixels/width;
scale ← Imager.metersPerPoint*Imager.pointsPerInch/ppi;
ImagerInterpress.DoPage[ip, action, scale];
ImagerInterpress.Close[ip];
RETURN[fDim: widthInPixels/ppi, sDim: heightInPixels/ppi];
};
SizeFromAISFile: PROC[name: ROPE] RETURNS[nLines, nPixels: NAT] = {
fRef: AIS.FRef ← AIS.OpenFile[name];
raster: AIS.Raster ← AIS.ReadRaster[fRef];
nLines ← raster.scanCount;
nPixels ← raster.scanLength;
};
Making IPSpecs
MakeIPList: PROC [ip0,ip1,ip2,ip3,ip4,ip5: IPSpec ← NIL] RETURNS [list: LIST OF IPSpec] ~ {
RETURN[LIST[ip0,ip1,ip2,ip3,ip4,ip5]];
};
IPFromRoot: PROC[aisRoot, ipDir: ROPE] RETURNS[ipName: ROPE] = {
cp: FS.ComponentPositions;
full: ROPE;
[full, cp] ← FS.ExpandName[aisRoot];
ipName ← Rope.Cat[ipDir, Rope.Substr[base: full, start: cp.base.start, len: cp.base.length], ".ip"];
};
MakeIPSpecFromAIS: PROC [aisRoot, ipDir, note: ROPE, aisPPI, outPPI: NAT, width: REAL, colorCorrection: ColorCorrection ← NIL] RETURNS [IPSpec] ~ {
fDim,sDim: REAL;
ipName: ROPE ← IPFromRoot[ipDir, aisRoot];
[fDim, sDim] ← IPFromColorAIS[aisRoot: aisRoot, ipName: ipName, note: note, ppi: aisPPI, width: width];
RETURN[NEW[InterpressToTape.IPSpecRep ← [name: ipName, page: 1, pixelsPerInch: outPPI, fOrg: 0, sOrg: 0, fDim: fDim, sDim: sDim, surfaceUnitsPerPixel: 1, colorCorrection: colorCorrection, achromatic: FALSE]]];
};
MakeIPSpec: PROC [name: ROPE, fOrg, sOrg: REAL, fDim, sDim: REAL, surfaceUnitsPerPixel: NAT ← 5, colorCorrection: ColorCorrection ← NIL, ppi: NAT, achromatic: BOOLEAN] RETURNS [IPSpec] ~ {
IF fDim = 0 OR sDim = 0 THEN [fOrg, sOrg, fDim, sDim] ← InterpressToTape.DefaultIPSize[name, 1];
RETURN[NEW[InterpressToTape.IPSpecRep ← [name: name, page: 1, pixelsPerInch: ppi, fDim: fDim, sDim: sDim, fOrg: fOrg, sOrg: sOrg, surfaceUnitsPerPixel: surfaceUnitsPerPixel, colorCorrection: colorCorrection, achromatic: achromatic]]];
};
END.