CtFile.mesa
Copyright Ó 1985, 1992 by Xerox Corporation. All rights reserved.
Bloomenthal, July 3, 1992 3:19 pm PDT
Procedures for reading/writing files to/from the color display.
DIRECTORY CtBasic, Imager, ImagerColor, ImagerPixelArray, ImagerSample, InterpressInterpreter, IO, Rope;
CtFile: CEDAR DEFINITIONS
~ BEGIN
RealPair:    TYPE ~ CtBasic.RealPair;
SampleMap:   TYPE ~ CtBasic.SampleMap;
SampleMaps:   TYPE ~ CtBasic.SampleMaps;
PixelArray:   TYPE ~ CtBasic.PixelArray;
Box:     TYPE ~ Imager.Box;
Context:    TYPE ~ Imager.Context;
STREAM:    TYPE ~ IO.STREAM;
ROPE:     TYPE ~ Rope.ROPE;
FileType:    TYPE = {bad, ip, bw, color};
FileInfo:    TYPE ~ RECORD [type: FileType, names: ARRAY [0..3) OF ROPE ¬ ALL[NIL]];
Error:    ERROR [reason: ROPE]; 
File Write Operations
WriteMapsToAIS: PROC [maps: SampleMaps, name: ROPE, stream: STREAM ¬ NIL];
Write AIS file(s) from the given pixel map(s). Proper suffixes added to name.
If stream is non-NIL, write progress reports.
SaveSampleMapToFile: PROC [source: SampleMap, aisFileName: ROPE, comment: ROPE ¬ NIL];
Write the source to the named file, with optional comment.
File Read Operations
ReadFile: PROC [
baseName: ROPE,
aisX, aisY: CARDINAL ¬ 0,
aisW, aisH: CARDINAL ¬ LAST[CARDINAL],
maps: SampleMaps ¬ NIL]
RETURNS [SampleMaps];
Return a SampleMaps consisting of the selected window (default=all) of the ais file.
Data will be put in maps if it is non-NIL and big enough.
Read8BitFile: PROC [
name: ROPE,
aisX, aisY: CARDINAL ¬ 0,
aisW, aisH: CARDINAL ¬ LAST[CARDINAL],
maps: SampleMaps ¬ NIL]
RETURNS [SampleMaps];
Return a SampleMaps consisting of the selected window (default=all) of the b&w ais file.
Data will be put in maps if it is non-NIL and big enough.
Read24BitFile: PROC [
rName, gName, bName: ROPE,
aisX, aisY: CARDINAL ¬ 0,
aisW, aisH: CARDINAL ¬ LAST[CARDINAL],
maps: SampleMaps ¬ NIL]
RETURNS [SampleMaps];
Return a SampleMaps consisting of the selected window (default=all) of the rgb ais files.
Data will be put in maps if it is non-NIL and big enough.
ReadPixelArray: PROC [aisFileName: ROPE] RETURNS [PixelArray];
Return a pixel array equivalent to the named, 8-bit, AIS file.
Dump File Operations
ReadDumpFile: PROC [
fileName: ROPE,
maps: SampleMaps ¬ NIL,
ascii: BOOL ¬ FALSE,
nChannels: NAT ¬ 0,
width, height: NAT ¬ 0,
contiguous: BOOL ¬ TRUE]
RETURNS [SampleMaps];
Read the dump file into the given sample maps, allocating maps if initially NIL.
!Error if file size exceeds given maps size.
If nChannels, width, or height = 0, they are read from a header presumed to contain
3 integers (the number of 8 bit channels, the width and height of the image).
If ascii, the file is a sequence of Ascii numbers, otherwise the file contains
16 bit header information (if any) and 8 bit pixel values.
If nChannels = 3, the channels are read contiguously (rgbrgbrgb ...) or separately
(rrr...ggg...bbb...), depending on the contiguous argument.
Viewing Procedures
ViewFile: PROC [
maps: SampleMaps,
baseName: ROPE,
center, noPlace: BOOL ¬ FALSE,
aisX, aisY: CARDINAL ¬ 0,
aisW, aisH: CARDINAL ¬ LAST[CARDINAL]]
RETURNS [error: ROPE];
Display the named file according to suffix conventions:
Foo --> {Foo-red.ais, Foo-grn(or green).ais, Foo-blu(or blue).ais}
Foo.ais --> Foo.ais
The image is the subset of the file given by [aisX, aisY, aisW, aisH], clipped to cd's box.
If center, the image is centered within maps.
If not center and not noPlace, then the image is placed in cd at the same position from where
it was saved originally, assuming placement information is contained in the AIS file.
View8BitFile: PROC [
maps: SampleMaps,
name: ROPE,
center, noPlace: BOOL ¬ FALSE,
aisX, aisY: CARDINAL ¬ 0,
aisW, aisH: CARDINAL ¬ LAST[CARDINAL]]
RETURNS [error: ROPE];
Display an 8-bit AIS file as an 8 bit image in maps.
The image is the subset of the file given by [aisX, aisY, aisW, aisH], clipped to map.box.
If center, the image is centered within maps.
If not center and not noPlace, then the image is placed in maps at the same position from
where it was saved originally, assuming placement information is contained in the AIS file.
View24BitFile: PROC [
maps: SampleMaps,
rName, gName, bName: ROPE,
center, noPlace: BOOL ¬ FALSE,
aisX, aisY: CARDINAL ¬ 0,
aisW, aisH: CARDINAL ¬ LAST[CARDINAL]]
RETURNS [error: ROPE];
Display three 8-bit AIS files as a 24 bit image in maps.
The image is the subset of the file given by [aisX, aisY, aisW, aisH], clipped to maps.box.
If center, the image is centered within maps.
If not center and not noPlace, then the image is placed in maps at the same position from
where it was saved originally, assuming placement information is contained in the AIS files.
Display: PROC [
context: Context,
pa: ImagerPixelArray.PixelArray,
op: ImagerColor.ColorOperator,
center: BOOL ¬ TRUE];
Display the pixel array, optionally centered, in the given context.
ViewDitherFile: PROC [fileName: ROPE, context: Context, center, cmapInit: BOOL]
RETURNS [error: ROPE];
Display an 8-bit AIS file on the colordisplay using a dithered context.
If center, the image is centered on the colordisplay.
If cmapInit, the color map is initialized.
     
ViewGrayFile: PROC [fileName: ROPE, context: Context, center, cmapInit: BOOL]
RETURNS [error: ROPE];
Display an 8-bit AIS file on the colordisplay using a grayscale context.
If center, the image is centered on the colordisplay.
If cmapInit, the color map is initialized.
     
ViewColorFiles: PROC [r, g, b: ROPE, center, cmapInit: BOOL ¬ TRUE]
RETURNS [error: ROPE];
Display a set of three AIS files on the colordisplay using a color-dither context.
Interpress Operations
LogError: InterpressInterpreter.LogProc;
Error proc for Interpress.DoPage.
OpenInterpress: PROC [name: ROPE] RETURNS [master: InterpressInterpreter.Master];
ViewIpFile: PROC [
name: ROPE,
scale: RealPair ¬ [1.0, 1.0],
shift: RealPair ¬ [0.0, 0.0],
cmapInit: BOOL ¬ TRUE]
RETURNS [error: ROPE];
Display an Interpress file on the given context;
initialize cmap if cmapInit.
Miscellany
GetColorAISNames: PROC [name: ROPE] RETURNS [ARRAY [0..3) OF ROPE];
Return the AIS file names given name without the hyphenation and suffix;
i.e., if name is "Foo", return "Foo-red.ais", "Foo-grn.ais", and "Foo-blu.ais".
Alternative hyphenations are "r" or "red", "g", "grn" or "green", and "b", "blu", or "blue".
[NIL, NIL, NIL] is returned if the appropriate files do not exits.
Parse: PROC [fileName: ROPE] RETURNS [FileInfo];
Parse input filename to determine type of file (bad, ip, bw, or color) even if fileName has no
extension; name1 is returned with proper extension; if file type is color, then name1, name2,
and name3 are names of red, green, and blue ais files.
END.