AISConvertersImpl.mesa
Copyright Ó 1991, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 2, 1991 7:26 pm PDT
Michael Plass, February 3, 1992 12:29 pm PST
DIRECTORY AISFileFormat, AISIO, Basics, Commander, CommanderOps, FileNames, FS, Imager, ImagerColor, ImagerFont, ImagerInterpress, ImagerPixelArray, ImagerPixelArrayAIS, ImagerTransformation, IO, PFS, Rope;
AISConvertersImpl: CEDAR PROGRAM
IMPORTS AISIO, Basics, Commander, CommanderOps, FileNames, FS, Imager, ImagerColor, ImagerFont, ImagerInterpress, ImagerPixelArray, ImagerPixelArrayAIS, ImagerTransformation, IO, PFS, Rope
~ BEGIN
Conversion Procedures
AISToInterpress and ColorAISToInterpress: convert AIS file(s) to IP master (at least version 3.1).
width, height in meters, per IP convention. The IP master is not closed on completion.
See /CedarChest7.0/InterpressConverters/AisPressConvertersCommand.mesa
ROPE:     TYPE ~ Rope.ROPE;
PixelArray:   TYPE ~ ImagerPixelArray.PixelArray;
inch:     REAL ~ 0.0254;  -- inches to meters conversion factor
defaultPageWidth: REAL ~ 8.5*inch; -- for normal sized paper
defaultPageHeight: REAL ~ 11*inch; -- for normal sized paper
aisMargin:   REAL ¬ 0.25*inch; -- offset of AIS images on regular-sized paper
ipHeader:    ROPE ~ "Interpress/Xerox/3.0 ";
aisCaptionFont:  ROPE ~ "xerox/pressfonts/helvetica-mir";
aisCaptionLoc:  Imager.VEC ~ [72, 9];
PixelArrayToInterpress: PROC [
pa: PixelArray,
colorOp: ImagerColor.ColorOperator,
ipRef: ImagerInterpress.Ref,
width, height: REAL,
caption: ROPE]
~ {
Paint: PROC [context: Imager.Context] ~ {
Caption: PROC ~ {
Imager.ScaleT[context, inch/72.0];
Imager.SetFont[context, ImagerFont.Scale[ImagerFont.Find[aisCaptionFont], 9]];
Imager.SetXY[context, aisCaptionLoc];
Imager.ShowRope[context, caption];
};
Imager.SetPriorityImportant[context, TRUE];
IF NOT Rope.IsEmpty[caption] THEN Imager.DoSave[context, Caption];
Imager.TranslateT[context, [width*0.5, height*0.5]];
Imager.ScaleT[context, scale];
Imager.TranslateT[context, [-(r.x+r.w*0.5), -(r.y+r.h*0.5)]];
Imager.SetSampledColor[context, pa,, colorOp];
Imager.MaskRectangle[context, r];
};
r: Imager.Rectangle ¬ ImagerTransformation.TransformRectangle[pa.m, [0,0,pa.sSize,pa.fSize]];
scale: REAL ¬ MIN[(width-2*aisMargin)/r.w, (height-2*aisMargin)/r.h];
ImagerInterpress.DeclarePixelArray[ipRef, pa];
ImagerInterpress.DoPage[ipRef, Paint, 1.0];
};
AISToInterpress: PROC [
aisName: ROPE,
ipRef: ImagerInterpress.Ref,
width: REAL ¬ defaultPageWidth,
height: REAL ¬ defaultPageHeight,
caption: ROPE ¬ NIL]
~ {
info: AISIO.Info ¬ AISIO.ReadInfo[aisName];
pa: PixelArray ¬ ImagerPixelArrayAIS.FromAIS[aisName];
maxSample: CARDINAL ~ ImagerPixelArray.MaxSampleValue[pa, 0];
colorOp: ImagerColor.ColorOperator ¬ IF Basics.Card16FromH[info.uca.bitsPerSample] = 0
THEN ImagerColor.NewColorOperatorGrayLinear[0, maxSample, maxSample+1]
ELSE ImagerColor.NewColorOperatorGrayLinear[maxSample, 0, maxSample+1];
PixelArrayToInterpress[pa, colorOp, ipRef, width, height, caption];
};
ColorAISToInterpress: PROC [
red, grn, blu: ROPE,
ipRef: ImagerInterpress.Ref,
width: REAL ¬ defaultPageWidth,
height: REAL ¬ defaultPageHeight,
caption: ROPE ¬ NIL]
~ {
pa: PixelArray ¬ ImagerPixelArrayAIS.Join3AIS[red, grn, blu];
maxSample: CARDINAL ~ ImagerPixelArray.MaxSampleValue[pa, 0];
colorOp: ImagerColor.ColorOperator ¬ ImagerColor.NewColorOperatorRGB[maxSample];
PixelArrayToInterpress[pa, colorOp, ipRef, width, height, caption];
};
Command
aisToIPUsage: ROPE ~ "Usage: AISToIP <ip name> ← <ais name> [-q]
  <ip name> is the name of the created Interpress master
  <ais name> is either:
   the name of a black/white AIS file (ending with \".ais\"), or
   the base name of an AIS color triplet
  [-q] suppresses an Interpress caption";
AISToIPCmd: Commander.CommandProc ~ {
a: CommanderOps.ArgumentVector ¬ CommanderOps.Parse[cmd];
IF a.argc IN [4..5] AND Rope.Equal[a[2], "←"] AND (a.argc # 5 OR Rope.Equal[a[4], "-q"])
THEN {
ENABLE PFS.Error, AISIO.Error => GOTO Bad;
comment: ROPE ¬ IF a.argc = 5 THEN NIL ELSE Rope.Substr[cmd.commandLine, 0, Rope.SkipTo[cmd.commandLine, 0, "\l\r"]];
ipRef: ImagerInterpress.Ref ¬ ImagerInterpress.Create[a[1], ipHeader];
i: FileInfo ¬ Parse[a[3]];
IF i.color
THEN ColorAISToInterpress[i.names[0], i.names[1], i.names[2], ipRef,,, comment]
ELSE AISToInterpress[i.names[0], ipRef,,, comment];
ImagerInterpress.Close[ipRef];
EXITS Bad => RETURN[$Failure, "bad file"];
}
ELSE RETURN[$Failure, aisToIPUsage];
};
FileInfo: TYPE ~ RECORD [color: BOOL ¬ FALSE, names: ARRAY [0..3) OF ROPE ¬ ALL[NIL]];
Parse: PROC [fileName: ROPE] RETURNS [i: FileInfo] ~ {
FileChoice: PROC [r: ROPE, a, b, c: ROPE ¬ NIL] RETURNS [ret: ROPE] ~ {
AISSuffix: PROC [base, suffix: ROPE] RETURNS [ROPE] ~ {
RETURN[IO.PutFR["%g-%g.ais", IO.rope[base], IO.rope[suffix]]];
};
IF FileExists[ret ¬ AISSuffix[r, a]] THEN RETURN;
IF b = NIL THEN RETURN[NIL];
IF FileExists[ret ¬ AISSuffix[r, b]] THEN RETURN;
IF c = NIL THEN RETURN[NIL];
IF NOT FileExists[ret ¬ AISSuffix[r, c]] THEN RETURN[NIL];
};
FileExists: PROC [name: ROPE] RETURNS [ok: BOOL ¬ TRUE] ~ {
[] ¬ FS.FileInfo[name ! FS.Error => {ok ¬ FALSE; CONTINUE}];
};
name: ROPE ¬ FileNames.ResolveRelativePath[fileName];
suffix: ROPE ¬ FileNames.Tail[FileNames.StripVersionNumber[name], '.];
IF Rope.Equal[suffix, "ais", FALSE] AND FileExists[name] THEN {i.names[0] ¬ name; RETURN};
i.names[0] ¬ FileChoice[name, "red", "r"];
i.names[1] ¬ FileChoice[name, "grn", "green", "g"];
i.names[2] ¬ FileChoice[name, "blu", "blue", "b"];
IF i.names[0] # NIL AND i.names[1] # NIL AND i.names[2] # NIL
THEN {i.color ¬ TRUE; RETURN};
IF FileExists[Rope.Concat[name, ".ais"]] THEN {i.names[0] ¬ Rope.Concat[name, ".ais"]; RETURN};
IF FileExists[name] THEN i.names[0] ¬ name;
};
Start Code
Commander.Register["AISToIP", AISToIPCmd, aisToIPUsage];
END.