ConvertToRasters.mesa
Copyright Ó 1987, 1988 by Xerox Corporation. All rights reserved.
Maureen Stone, May 26, 1989 4:37:48 pm PDT
Doug Wyatt, April 12, 1988 3:53:34 pm PDT
Generate (color corrected) rasters from an action proc. Special case added for Interpress.
DIRECTORY
Rope USING [ROPE],
PrintColor USING [ColorCorrection],
Imager USING [ScanMode, Context, defaultScanMode],
ImagerPixel USING [PixelBuffer, PixelMap];
ConvertToRasters: CEDAR DEFINITIONS
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
PixelMap: TYPE ~ ImagerPixel.PixelMap;
Context: TYPE ~ Imager.Context;
ColorCorrection: TYPE ~ PrintColor.ColorCorrection;
RasterProc: TYPE ~ PROC [raster: ImagerPixel.PixelBuffer] RETURNS [stop: BOOLEANFALSE];
Delivers one scanline worth of pixels
RasterType: TYPE ~ {rgb, gray, cmyk};
RasterSpec: TYPE ~ RECORD[
type: RasterType,
fSize, sSize: NAT, -- size of raster
surfaceUnitsPerPixel: NAT ← 5, -- controls smoothing. Make 1 for none
scanMode: Imager.ScanMode ← Imager.defaultScanMode,
colorCorrection: ColorCorrection ← NIL, --see PrintColorTransformations
maxPixel: NAT ← 255
];
Basic Conversion Routines
Convert: PROC [action: PROC[Context], rasterSpec: RasterSpec, proc: RasterProc] RETURNS [nBands: NAT];
Creates rasters by calling action to image onto the ImagerSmoothContext (set rasterSpec.surfaceUnitsPerPixel ← 1 if no smoothing is desired).
The RasterSpec specifies the size and type of the context. The coordinate system is pixels.
These procedures work by creating a PixelMap of fSize by sSize by bytes/pixel (1, 3 or 4).
For high resolution images, it may be necessary to make the image in bands rather than allocate one giant PixelMap. The value of nBands will be determined by catching VM.CantAllocate and increasing nBands until the allocate succeeds.
Using bands will call the action proc nBands times (classic time/space tradeoff). The
The RasterSpec should always specify the size of the entire PixelMap.
ToPixelMap: PROC [action: PROC[Context], rasterSpec: RasterSpec] RETURNS [PixelMap];
Rather than using a RasterProc, returns the entire PixelMap.
Use ConvertRasterObject to turn the PixelMap into an AIS file or other raster format.
Convenience procedures for Interpress, AIS
Convert from an interpress master to a raster.
x,y,w,h specify a window on the Interpress master in inches.
If w,h are 0, assume the whole page. Client is responsible for making everything fit.
FromIP: PROC [ip: ROPE, ppiF,ppiS: REAL, page: NAT ← 1, rasterSpec: RasterSpec, proc: RasterProc, x,y,w,h: REAL ← 0] RETURNS[nBands: NAT];
FromIPToPixelMap: PROC [ip: ROPE, ppiF,ppiS: REAL, page: NAT ← 1, rasterSpec: RasterSpec, x,y,w,h: REAL ← 0]
RETURNS [PixelMap];
AISFromPixelMap: PROC[aisRoot: ROPE, pm: PixelMap];
makes 1, 3 or 4 AIS files depending on pm.samplesPerPixel. File names are aisRoot.ais, aisRoot-red.ais, -grn.ais, -blu.ais or aisRoot-cyan.ais, -magenta.ais, -yellow.ais -black.ais
IPToRasterIP: PROC[ipIn, ipOut: ROPE, ppiF,ppiS: REAL, page: NAT ← 1, rasterSpec: RasterSpec, x,y,w,h: REAL ← 0, tx,ty: REAL ← 0];
Makes an Interpress master with the pixel map imaged at tx,ty (inches). Uses the appropriate color operator depending on pm.samplesPerPixel: GrayLinear, RGBLinear or CMYKLinear.
This calls FromIPToPixelMap so the rasters must fit in VM.
IPWindow: PROC[ip: ROPE, page: NAT ← 1, tol: REAL ← 0.02] RETURNS [x,y,w,h: REAL];
Renders the IP file through ImagerMaskCapture and returns a window on the area which has the printable stuff in it. The tolerance is expressed in inches. The bigger the tolerance the faster this will run. The returned box is guaranteed to be big enough.
CreateRasterSpec: PROC[type: RasterType, fSize, sSize: NAT, colorCorrection: ColorCorrection, surfaceUnitsPerPixel: NAT ← 5, scanMode: Imager.ScanMode ← Imager.defaultScanMode,maxPixel: NAT ← 255] RETURNS[RasterSpec];
END.