DIRECTORY ConvertToRasters, Imager, Interpress, ImagerSmoothContext, ImagerSmoothContextExtras, ImagerSample, ImagerPixel, Rope, PrintColor, ImagerBackdoor, CedarProcess, VM, ConvertRasterObject, SF, ImagerPixelArray, ImagerInterpress, ImagerColor, ImagerBox, ImagerColorFns, ImagerTransformation, ImagerMaskCapture, VMSideDoor; ConvertToRastersImpl: CEDAR PROGRAM IMPORTS Interpress, ImagerSmoothContext, ImagerPixel, ImagerSmoothContextExtras, Imager, ImagerBackdoor, CedarProcess, VM, ConvertRasterObject, Rope, ImagerPixelArray, ImagerInterpress, ImagerColor, ImagerColorFns, ImagerTransformation, ImagerMaskCapture, ImagerBox, VMSideDoor EXPORTS ConvertToRasters ~ BEGIN OPEN ConvertToRasters; ROPE: TYPE ~ Rope.ROPE; Context: TYPE ~ Imager.Context; PixelMap: TYPE ~ ImagerPixel.PixelMap; ColorCorrection: TYPE = PrintColor.ColorCorrection; Convert: PUBLIC PROC [action: PROC[Imager.Context], rasterSpec: RasterSpec, proc: RasterProc] RETURNS [nBands: NAT] = { pm: PixelMap _ NIL; inch: REAL = 0.0254; -- inches->meters conversion factor nLines: NAT ~ rasterSpec.sSize; line: NAT _ 0; stop: BOOLEAN _ FALSE; ctx: Context; samplesPerPixel: NAT _ SELECT rasterSpec.type FROM rgb => 3, gray => 1, cmyk => 4, ENDCASE => ERROR; pixels: ImagerPixel.PixelBuffer _ ImagerPixel.ObtainScratchPixels[samplesPerPixel, rasterSpec.fSize]; CedarProcess.SetPriority[background]; nBands _ 1; WHILE line VMSideDoor.rmPages/4 THEN failed _ TRUE ELSE [ctx, pm] _ CreateContext[rasterSpec, pm, 1 ! VM.CantAllocate => {failed _ TRUE; CONTINUE}]; IF failed THEN { nBands _ nBands+1; ctx _ NIL; } ELSE EXIT; ENDLOOP; Imager.TranslateT[ctx, [0,(line-nLines+bandSize)]]; Imager.DoSave[ctx, do]; FOR j: NAT IN [0..bandLines) DO ImagerPixel.GetPixels[self: pm, initIndex: [s: j, f: 0], delta: [s: 0, f: 1], pixels: pixels, start: 0, count: rasterSpec.fSize]; IF proc[pixels] THEN {stop _ TRUE; EXIT}; ENDLOOP; IF stop THEN EXIT; line _ line+bandLines; ENDLOOP; ImagerPixel.ReleaseScratchPixels[pixels]; RETURN[nBands]; }; ToPixelMap: PUBLIC PROC [action: PROC[Imager.Context], rasterSpec: RasterSpec] RETURNS[PixelMap] = { ctx: Context; pm: PixelMap; CedarProcess.SetPriority[background]; [ctx, pm] _ CreateContext[rasterSpec, NIL, 1]; action[ctx]; RETURN[pm]; }; CreateContext: PROC [rs: RasterSpec, pm: PixelMap _ NIL, defaultScale: REAL] RETURNS [Context, PixelMap] ~ { context: Context _ ImagerSmoothContext.Create[ size: [s: rs.sSize, f: rs.fSize], scanMode: rs.scanMode, initialScale: defaultScale, cacheFonts: TRUE, surfaceUnitsPerPixel: rs.surfaceUnitsPerPixel]; samplesPerPixel: NAT; components: LIST OF ATOM ; maxSample: ImagerPixel.PixelProc = {RETURN[rs.maxPixel]}; SELECT rs.type FROM gray => {samplesPerPixel _ 1; components _ LIST[$Intensity]}; rgb => {samplesPerPixel _ 3; components _ LIST[$Red, $Green, $Blue]}; cmyk => {samplesPerPixel _ 4; components _ LIST[$Cyan, $Magenta, $Yellow, $Black]}; ENDCASE => ERROR; IF pm=NIL THEN --allows us to reuse the pixelmap pm _ ImagerPixel.NewPixelMap[samplesPerPixel, [[0,0],[s: rs.sSize, f: rs.fSize]], maxSample]; ImagerSmoothContext.SetOutputBuffer[context, pm, components]; ImagerSmoothContextExtras.SetColorCorrection[context, rs.colorCorrection]; Imager.SetColor[context, Imager.MakeGray[0]]; --set the master to white Imager.MaskRectangle[context, ImagerBackdoor.GetBounds[context]]; Imager.SetColor[context, Imager.MakeGray[1]]; --set the current color to black RETURN[context, pm]; }; FromIP: PUBLIC PROC [ip: ROPE, ppiF,ppiS: REAL, page: NAT _ 1, rasterSpec: RasterSpec, proc: RasterProc, x,y,w,h: REAL _ 0] RETURNS[nBands: NAT] = { log: Interpress.LogProc = {}; master: Interpress.Master _ Interpress.Open[ip, log]; do: PROC[context: Imager.Context] = { Imager.Scale2T[context, [x: ppiF/metersPerInch, y: ppiS/metersPerInch]]; IF w#0 AND h#0 THEN Imager.ClipRectangle[context, [0,0,w*metersPerInch,h*metersPerInch], FALSE]; Imager.TranslateT[context, [-x*metersPerInch,-y*metersPerInch]]; Interpress.DoPage[master, page, context, log]; }; nBands _ Convert[do, rasterSpec, proc]; Interpress.Close[master]; }; metersPerInch: REAL = 0.0254; FromIPToPixelMap: PUBLIC PROC [ip: ROPE, ppiF,ppiS: REAL, page: NAT _ 1, rasterSpec: RasterSpec, x,y,w,h: REAL _ 0] RETURNS[PixelMap] = { log: Interpress.LogProc = {}; master: Interpress.Master _ Interpress.Open[ip, log]; do: PROC[context: Imager.Context] = { Imager.Scale2T[context, [x: ppiF/metersPerInch, y: ppiS/metersPerInch]]; IF w#0 AND h#0 THEN Imager.ClipRectangle[context, [0,0,w*metersPerInch,h*metersPerInch], FALSE]; Imager.TranslateT[context, [-x*metersPerInch,-y*metersPerInch]]; Interpress.DoPage[master, page, context, log]; }; pm: PixelMap _ ToPixelMap[do, rasterSpec]; Interpress.Close[master]; RETURN[pm]; }; AISFromPixelMap: PUBLIC PROC[aisRoot: ROPE, pm: PixelMap] = { SELECT pm.samplesPerPixel FROM 1 => ConvertRasterObject.AISFromPixelMap[Rope.Cat[aisRoot, ".ais"], pm, 0]; 3 => { ConvertRasterObject.AISFromPixelMap[Rope.Cat[aisRoot, "-red.ais"], pm, 0]; ConvertRasterObject.AISFromPixelMap[Rope.Cat[aisRoot, "-grn.ais"], pm, 1]; ConvertRasterObject.AISFromPixelMap[Rope.Cat[aisRoot, "-blu.ais"], pm, 2]; }; 4 => { ConvertRasterObject.AISFromPixelMap[Rope.Cat[aisRoot, "-cyan.ais"], pm, 0]; ConvertRasterObject.AISFromPixelMap[Rope.Cat[aisRoot, "-magenta.ais"], pm, 1]; ConvertRasterObject.AISFromPixelMap[Rope.Cat[aisRoot, "-yellow.ais"], pm, 2]; ConvertRasterObject.AISFromPixelMap[Rope.Cat[aisRoot, "-black.ais"], pm, 3]; }; ENDCASE => ERROR; }; pointsPerInch: REAL = Imager.pointsPerInch; IPToRasterIP: PUBLIC PROC[ipIn, ipOut: ROPE, ppiF,ppiS: REAL, page: NAT _ 1, rasterSpec: RasterSpec, x,y,w,h: REAL _ 0, tx,ty: REAL _ 0] = { pm: PixelMap _ FromIPToPixelMap[ipIn, ppiF,ppiS, page, rasterSpec, x,y,w,h]; pa: ImagerPixelArray.PixelArray _ ImagerPixelArray.FromPixelMap[pm, pm.box, rasterSpec.scanMode, TRUE]; ip: ImagerInterpress.Ref _ ImagerInterpress.Create[ipOut]; op: ImagerColor.ColorOperator _ SELECT rasterSpec.type FROM rgb => ImagerColor.NewColorOperatorRGB[maxIn: rasterSpec.maxPixel+1], gray => ImagerColor.NewColorOperatorGrayLinear[sWhite: 255, sBlack: 0, sampleTableSize: rasterSpec.maxPixel+1, sampleTableProc: NIL], cmyk => ImagerColorFns.NewColorOperatorCMYK[maxIn: rasterSpec.maxPixel+1], ENDCASE => ERROR; action: PROC[context: Imager.Context] = { Imager.TranslateT[context, [tx*pointsPerInch,ty*pointsPerInch]]; Imager.SetSampledColor[context, pa, NIL, op]; Imager.MaskRectangle[context, [x: 0, y: 0,w: rasterSpec.fSize, h: rasterSpec.sSize]]; }; ImagerInterpress.DoPage[ip, action, Imager.metersPerPoint]; ImagerInterpress.Close[ip]; }; IPWindow: PUBLIC PROC[ip: ROPE, page: NAT _ 1, tol: REAL _ 0.02] RETURNS [x,y,w,h: REAL] = { ppi: REAL _ 1/tol; m: Imager.Transformation _ ImagerTransformation.Scale[ppi/0.0254]; n: Imager.Transformation _ ImagerTransformation.PostScale[m, 0.0254]; -- back to inches master: Interpress.Master _ Interpress.Open[ip, NIL]; Operator: PROC [context: Imager.Context] ~ { Imager.SetColor[context, Imager.black]; Imager.SetStrokeEnd[context, square]; Imager.SetStrokeWidth[context, 0.0]; Imager.SetAmplifySpace[context, 1.0]; Interpress.DoPage[master, page, context, NIL]; }; b: SF.Box _ ImagerMaskCapture.CaptureBounds[Operator, m ! ImagerMaskCapture.Cant => RESUME]; r: ImagerBox.Rectangle _ ImagerTransformation.InverseTransformRectangle[ n, ImagerBox.RectangleFromBox[[b.min.s, b.min.f, b.max.s, b.max.f]]]; RETURN[x: r.x, y: r.y, w: r.w, h: r.h]; }; CreateRasterSpec: PUBLIC PROC [type: RasterType, fSize, sSize: NAT, colorCorrection: ColorCorrection, surfaceUnitsPerPixel: NAT _ 5, scanMode: Imager.ScanMode _ Imager.defaultScanMode,maxPixel: NAT _ 255] RETURNS [RasterSpec] ~ { RETURN[[type, fSize, sSize, surfaceUnitsPerPixel, Imager.defaultScanMode,colorCorrection,maxPixel]]; }; END. zConvertToRastersImpl.mesa Copyright Σ 1987, 1988 by Xerox Corporation. All rights reserved. Maureen Stone, May 26, 1989 5:08:11 pm PDT Doug Wyatt, April 12, 1988 7:18:34 pm PDT Tow, March 13, 1989 7:13:16 pm PST Takes an Interpress Master and generates color correct rasters Interpress to Rasters Convenience procedures for Interpress, AIS Makes and Interpress master with the pixel map imaged at 0,0. Uses the appropriate color operator depending on pm.samplesPerPixel: GrayLinear, RGBLinear or CMYKLinear. SetSampledColor: PROC [context: Context, pa: PixelArray, m: Transformation _ NIL, colorOperator: ColorOperator]; Κυ˜code•Mark outsideHeaderšœ™KšœB™BKšœ*™*K™)K™"—K™K™>K™šΟk ˜ KšœΎ˜Ύ—K˜KšΠblœœ˜#KšœŽ˜•Kšœ˜šœ œ˜K˜Kšœœœ˜Kšœ œ˜Kšœ œ˜&Kšœœ˜3—head™š Οnœ œ œ<œ œ˜wKšœœ˜Kšœœ Οc#˜8Kšœœ˜Jšœœ˜Kšœœœ˜K˜ šœœœ˜2Jšœ œœ˜1—Jšœe˜eJšœ%˜%J˜ šœ œ˜Jšœœ˜Jšœ˜šœ ,˜0Jšœœœ˜Jšœ$˜$Jšœ œ˜'Jšœ˜š œœœ$œœ)˜mJšœ ˜Jšœ/œœœ˜a—šœœ˜Kšœ˜Kšœœ˜ Kšœ˜—Kšœœ˜ Kšœ˜—Kšœ3˜3Kšœ˜šœœœ˜Kšœ˜Kšœœ œœ˜)Kšœ˜—Kšœœœ˜J˜Jšœ˜—Jšœ)˜)Jšœ ˜K˜K™—šŸ œ œ œ*œ˜dKšœ ˜ Kšœ ˜ Jšœ%˜%Kšœ&œ˜.Kšœ ˜ Kšœ˜ K˜—K˜š Ÿ œœ!œœœ˜lšœ.˜.Kšœ8˜8Kšœ(œ˜-Kšœ/˜/—Jšœœ˜Jšœ œœœ˜Jšœ$œ˜9šœ ˜Jšœ+œ˜=Jšœ*œ˜EJšœ+œ$˜SJšœ˜—šœœœ !˜0Kšœ]˜]—Kšœ=˜=KšœJ˜JKšœ. ˜GK˜AKšœ.  ˜NKšœ˜K˜——šœ*™*šŸœœœœ œœ9œœ œ˜”Kšœ˜Kšœ5˜5šœœ˜%KšœH˜HKšœœœFœ˜`Kšœ@˜@Kšœ.˜.Kšœ˜—Kšœ'˜'K˜˜K™——Kšœœ ˜šŸœœœœ œœ'œœ˜‰Kšœ˜Kšœ5˜5šœœ˜%KšœH˜HKšœœœFœ˜`Kšœ@˜@Kšœ.˜.Kšœ˜—Kšœ*˜*Kšœ˜Kšœ˜ K˜—šŸœ œ œ˜=šœ˜K˜K˜K˜JK˜JK˜JK˜—˜K˜KK˜NK˜MK˜LK˜—Kšœœ˜—K˜—Kšœœ˜+šŸ œ œœ œœ'œ œ ˜ŒK™¨KšŸœœ9œ ™qKšœL˜LKšœaœ˜gKšœ:˜:šœ œ˜;KšœE˜EKšœ€œ˜…KšœJ˜JKšœœ˜—šœœ˜)Kšœ@˜@K˜-KšœU˜UK˜—Kšœ;˜;K˜K˜—šŸœ œœœ œ œ œ˜\Kšœœ ˜JšœC˜CJšœF ˜WJšœ0œ˜5šŸœœ˜,J˜'J˜%J˜$J˜%Jšœ)œ˜.Jšœ˜—šœœ2˜7Jšœœ˜$—šœH˜HJšœE˜E—Jšœ"˜(K˜—š Ÿœ œ"œ:œCœœ˜εKšœ_˜eK˜——Kšœ˜—…—€)