DIRECTORY G2dBasic, Imager, ImagerPixel, ImagerSample, SF; CtBasic: CEDAR DEFINITIONS IMPORTS ~ BEGIN IntegerPair: TYPE ~ G2dBasic.IntegerPair; -- RECORD [x, y: INTEGER ¬ 0] RealPair: TYPE ~ G2dBasic.Pair; -- RECORD [x, y: REAL ¬ 0.0] Context: TYPE ~ Imager.Context; Rectangle: TYPE ~ Imager.Rectangle; -- RECORD [x, y, w, h: REAL] PixelMap: TYPE ~ ImagerPixel.PixelMap; SampleBuffer: TYPE ~ ImagerSample.SampleBuffer; SampleMap: TYPE ~ ImagerSample.SampleMap; Box: TYPE ~ SF.Box; -- RECORD [min, max: Vec ¬ [0, 0]] Vec: TYPE ~ SF.Vec; -- RECORD [s, f: INTEGER] RGB: TYPE ~ RECORD [r, g, b: BYTE ¬ 0]; Channel: TYPE ~ RECORD [ type: ATOM ¬ NIL, -- use of channel map: SampleMap ¬ NIL -- channel image ]; SampleMaps: TYPE ~ REF SampleMapsRep; SampleMapsRep: TYPE ~ RECORD [ x, y, w, h: NAT ¬ 0, -- the box, derived from the sample maps box: Box ¬ [[0,0], [0,0]], -- read only: dimensions of maps size: Vec ¬ [0, 0], -- read only: size of maps bpp: NAT ¬ 8, -- bits per pixel: 8, 24 or other nChannels: NAT ¬ 0, -- number of sample maps element: SEQUENCE maxLength: NAT OF Channel ]; PixelArray: TYPE ~ REF PixelArrayRep; PixelArrayRep: TYPE ~ RECORD [ bpp: NAT ¬ 8, -- bits per pixel x, y, w, h: NAT ¬ 0, -- dimensions of array box: Box ¬ [[0,0], [0,0]], -- read only: dimensions of maps size: Vec ¬ [0, 0], -- read only: size of maps element: SEQUENCE maxLength: NAT OF SampleBuffer ]; GetBpp: PROC RETURNS [NAT]; SampleMapsFromPixelMap: PROC [pixelMap: PixelMap] RETURNS [SampleMaps]; SampleMapsFromMaps: PROC [map1, map2, map3: SampleMap] RETURNS [SampleMaps]; CreateMaps: PROC [bpp: NAT, x, y, w, h: NAT, allocateMaps: BOOL ¬ TRUE] RETURNS [SampleMaps]; CopyOfMaps: PROC [maps: SampleMaps, x, y, w, h: NAT] RETURNS [SampleMaps]; ClipMaps: PROC [maps: SampleMaps, x, y, w, h: NAT]; MoveMaps: PROC [maps: SampleMaps, srcMin, dstMin, size: Vec]; ShiftMaps: PROC [maps: SampleMaps, delta: Vec] RETURNS [SampleMaps]; FillMaps: PROC [maps: SampleMaps, bw, r, g, b: CARDINAL ¬ 0]; CopyMaps: PROC [src, dst: SampleMaps]; CopyClippedMaps: PROC [src, dst: SampleMaps, srcBox, dstBox: Box]; ReIndexMaps: PUBLIC PROC [maps: SampleMaps, delta: Vec ¬ [0, 0], box: Box ¬ SF.maxBox]; ReleaseDescriptors: PROC [maps: SampleMaps]; ValueProc: TYPE ~ PROC [x, y: INTEGER, clientData: REF ¬ NIL] RETURNS [value: BYTE]; FillBWMap: PROC [map: SampleMap, color: CARDINAL]; PutBWPixel: PROC [map: SampleMap, x, y: INTEGER, value: CARDINAL]; GetBWPixel: PROC [map: SampleMap, x, y: INTEGER] RETURNS [CARDINAL]; PutBWBox: PROC [map: SampleMap, x0, y0, x1, y1: INTEGER, value: CARDINAL]; PutBWLine: PROC [map: SampleMap, x0, y0, x1, y1: INTEGER, value: CARDINAL]; PutBWScanLine: PROC [map: SampleMap, y: INTEGER, proc: ValueProc, clientData: REF ¬ NIL]; PutBWFrame: PROC [map: SampleMap, proc: ValueProc, clientData: REF ¬ NIL]; RGBProc: TYPE ~ PROC [x, y: INTEGER, clientData: REF ¬ NIL] RETURNS [rgb: RGB]; FillRGBMap: PROC [maps: SampleMaps, rgb: RGB]; PutRGBPixel: PROC [maps: SampleMaps, x, y: INTEGER, rgb: RGB]; GetRGBPixel: PROC [maps: SampleMaps, x, y: INTEGER] RETURNS [RGB]; PutRGBBox: PROC [maps: SampleMaps, x0, y0, x1, y1: INTEGER, rgb: RGB]; PutRGBLine: PROC [maps: SampleMaps, x0, y0, x1, y1: INTEGER, rgb: RGB]; PutRGBScanLine: PROC [maps: SampleMaps, y: INTEGER, proc: RGBProc, clientData: REF ¬ NIL]; PutRGBFrame: PROC [maps: SampleMaps, proc: RGBProc, clientData: REF ¬ NIL]; InitializePixelArray: PROC [box: Box, bpp: NAT ¬ 8] RETURNS [PixelArray]; AllocatePixelArray: PROC [box: Box, bpp: NAT ¬ 8] RETURNS [PixelArray]; PixelArrayFromSampleMap: PROC [map: SampleMap] RETURNS [PixelArray]; SampleMapFromPixelArray: PROC [pa: PixelArray] RETURNS [SampleMap]; TransferPixelArrayToMap: PROC [pa: PixelArray, map: SampleMap]; PixelArrayBoxToMap: PROC [pa: PixelArray, map: SampleMap, x1, y1, x2, y2: INTEGER]; BoxFromPixelArray: PROC [pa: PixelArray] RETURNS [Box]; DoToPixelArray: PROC [ pa: PixelArray, proc: ValueProc, map: SampleMap ¬ NIL, clientData: REF ¬ NIL]; IntersectionOfPixelArrays: PROC [pa1, pa2, pa3, pa4: PixelArray ¬ NIL] RETURNS [Box]; SetPixelArrayRange: PROC [pa: PixelArray, box: Box]; CopyPixelArray: PROC [in: PixelArray] RETURNS [copy: PixelArray]; BoxFromXYWH: PROC [x, y, w, h: INTEGER] RETURNS [Box]; XYWHFromBox: PROC [box: Box] RETURNS [x, y, w, h: INTEGER]; RectangleFromXYs: PROC [x0, y0, x1, y1: INTEGER] RETURNS [Rectangle]; BoxFromRectangle: PROC [rectangle: Rectangle] RETURNS [Box]; DoWithSampleMapsFromContext: PROC [context: Context, action: PROC [maps: SampleMaps]]; ContextFromSampleMaps: PROC [maps: SampleMaps, ignoreColormap: BOOL ¬ FALSE] RETURNS [Context]; TransformContextToMap: PROC [context: Context, map: SampleMap]; PairFromMapCoords: PROC [x, y: INTEGER, map: SampleMap, fit: BOOL ¬ TRUE] RETURNS [RealPair]; MapCoordsFromPair: PROC [pair: RealPair, map: SampleMap, fit: BOOL ¬ TRUE] RETURNS [IntegerPair]; END. Π CtBasic.mesa Copyright Σ 1985, 1992 by Xerox Corporation. All rights reserved. Bloomenthal, July 3, 1992 1:23 pm PDT Andrew Glassner November 14, 1990 3:14 pm PST Types Similar to ImagerPixel.PixelMap, but more descriptive. The client may set element.type (see Create[] or SampleMapsfromPixelMap[] for defaults). An array of pixels, each accessed more quickly than via a SampleMap. Elements are stored by row, then column; that is, pixelArray[y][x]. Miscellany Return the bits per pixel for the current hardware device. Sample Maps Operations Convert pixelMap to SampleMaps with nchannels = samplesPerPixel. for nChannels = 1, the type of the single map is $BW. for nChannels = 3, the types of the three maps are $Red, $Green, $Blue. for other nChannels, the types are $Unknown. Create SampleMaps from the three maps. Create the appropriate sample maps of the given size. Create the a new SampleMaps of the given size; nChannels, maps, bpp are same as input. Equivalent to ReIndexMaps[maps, [0, 0], BoxFromXYWH[x, y, w, h]]. Move samples in maps; from srcMin to dstMin, for a size of size. Shift the maps by delta. Fill the appropriate pixel maps (if 8 bpp, fill with bw, else with r, g, b). Copy src to dst through the intersection of their boxes. Clip the src and translate it to upper left of the clipped dst. Set box, size, x, y, w, and h of maps, and clip the maps to box; see ImagerSample.ReIndex. Release the descriptors of the maps to ImagerSample pool. Unsafe to use maps after this call. 8 Bit Operations Fill the pixel map with color. Write value to (x, y). Read from (x, y) the 8 or 16 bit value. Fill the box with value. Draw a one pixel wide line from (x0, y0) to (x1, y1). Write scanline-y to the 8 or 16 bit color display; buffers the line to improve efficiency. Write entire frame to the 8 or 16 bit color display; buffers each line to improve efficiency. This is approximately 3 times faster than calling PutPixel[] for each pixel. 24 Bit Operations Fill maps with r, g, b; no-op if maps is not 24 bpp. Write to (x, y) the 24 bit r, g, b value; no-op if maps is not 24 bpp. Read from (x, y) the 24 bit r, g, b value; no-op if maps is not 24 bpp. Fill the box with the r, g, b values. No-op if maps is not 24 bpp. Draw a one pixel wide line from (x0, y0) to (x1, y1). No-op if maps is not 24 bpp. Write scanline-y to the 24 bit color display; buffers the line to improve efficiency. No-op if maps is not 24 bpp. Write entire frame to the 24 bit color display; buffers each line to improve efficiency. No-op if maps is not 24 bpp. This is approximately 3 times faster than calling PutRGBPixel[] for each pixel. Pixel Array Operations Return an empty pixel array dimensioned to box. Return a pixel array dimensioned to box, and allocate the internal buffers. Return a pixel array equivalent to the input sample map. Return a sample map equivalent to the pixel array. Write the contents of pa into map. Write the contents of pa into map for the given region. Return the box describing the pixel array. Perform proc on pa's pixels; if map is not NIL, then update map at same time. Return the intersection of two pixel arrays. Redefine the range (x, y, w, h) of the pixel array. Create a copy of the pixel array. Box/Rectangle Operations Box conversion. Box conversion. Return a rectangle given its limits (no right/left or top/bottom ordering presumed). A convenience conversion procedure. Imager Context Operations Apply action to sample maps obtained from context; usually called from a Viewer PaintProc. action should not perform any Imager operations on context (Imager operations should be performed, instead, on a context obtained from ContextFromSampleMaps[]). The origin of maps is at the upper left. Create a context sized as maps and with a backing raster from maps. The origin of the context is at the lower left. Transform a presumed unit (+1, +1) context to coincide with map. Coordinate System Transformations Given the sample map coordinates, return the coordinates in a [-1..1] space. If fit, then stretch map to fit [-1..1], else clip map to square before transforming. Given coordinates in a [-1..1] space, return the sample map coordinates. If fit, then stretch map to fit [-1..1], else clip map to square before transforming. Κ‘–"cedarcode" style•NewlineDelimiter ™šœ ™ Jšœ Οeœ6™BJ™%J™-J™—JšΟk œ1˜:J™šΠblœžœž ˜Jšžœ˜—J˜Jšœž˜headšΟl™Jš œžœΟcΠcs‘’‘œ‘˜IJš œ žœ‘’‘’‘œ‘˜AJšœ žœ˜!Jšœ žœ‘’‘’‘˜CJšœ žœ˜(Jšœžœ˜/Jšœ žœ˜*Jš œžœžœ ‘’‘œ‘˜>š œžœžœ ‘’‘’‘˜5J˜—šžœžœžœ žœ˜*J˜—šœ žœžœ˜Jšœ žœžœ‘˜*Jšœžœ‘˜*J˜J˜—Jšœ žœžœ˜&šœžœžœ˜Jšœžœ ‘(˜CJšœ ‘ ˜@Jšœ‘˜5Jšœ žœ ‘!˜7Jšœžœ ‘˜2Jšœ žœ žœžœ˜/J˜J™6J™XJ˜—Jšœ žœžœ˜&šœžœžœ˜Jšœ žœ ‘˜'Jšœžœ ‘˜1Jšœ ‘ ˜@Jšœ‘˜5Jšœ žœ žœžœ ˜4J˜J™DJ™C——š  ™ šΟnœžœžœžœ˜J™:——š ™š£œžœžœ˜Gšœ@™@J™5J™GJ™,—J™—š£œžœžœ˜LJšœ&™&J™—š £ œžœžœžœžœžœ˜GJšžœ˜J™5J˜—š£ œžœ žœžœ˜JJ™VJ˜—š£œžœ žœ˜3J™AJ˜—š£œžœ/˜=J™@J™—š£ œžœ žœ˜DJ™J™—š£œžœ!žœ˜=J™LJ™—š£œžœ˜&J™8J˜—š£œžœ-˜BJ™?J™—šΠbn œžœžœ4žœ ˜WJ™ZJ™—š£œžœ˜,J™^——š ™šœ žœΟsžœ₯œ₯žœ₯œ ₯žœžœ₯ž₯œžœ˜TJ™—š£ œžœžœ˜2J™J™—š£ œžœžœ žœ˜BJ™J™—š £ œžœžœžœžœ˜DJ™'J™—š£œžœ"žœ žœ˜JJ™J™—š£ œžœ"žœ žœ˜KJ™5J™—š£ œ₯ž₯œ₯œžœžœžœ˜YJ™ZJ™—š£ œžœ/žœžœ˜JJ™]J™L——š ™šœ žœžœžœžœžœžœžœ˜OJ™—š£ œžœžœ˜.J™4J™—š£ œžœžœžœ˜>J™FJ™—š £ œžœžœžœžœ˜BJ™GJ˜—š£ œžœ$žœžœ˜FJ™CJ™—š£ œžœ$žœžœ˜GJ™SJ™—š£œ₯žœ₯œ ₯œ₯žœ₯œ₯œ₯œ ₯ž₯œ₯žœ˜ZJ™UJ™J˜—š£ œžœ/žœžœ˜KJ™XJ™J™O——š ™š£œžœžœžœ˜IJ™/J™—š£œžœžœžœ˜GJ™KJ™—š£œžœžœ˜DJ™8J™—š£œžœžœ ˜CJ™2J™—š£œžœ"˜?J™"J˜—š£œžœ2žœ˜SJ™7J˜—š£œžœžœ˜7J™*J™—š€œžœ˜Jšœ˜Jšœ˜Jšœžœ˜Jšœ žœžœ˜Jšœ+₯œ™MJ™—š£œžœ#žœžœ˜UJ™,J™—š£œžœ˜4J™3J™—š£œžœžœ˜AJ™!——š ™š£ œžœžœžœ˜6J™J™—š£ œžœ žœžœ˜;J™J™—š£œžœžœžœ ˜EJ™TJ™—š£œžœžœ˜