INTERFACE PPM; (* Parameters and basic operatiosn on PPM image files (see "man n ppm"). *) IMPORT Rd, Wr, Thread; CONST NChannels = 3; CONST Extension = ".ppm"; CONST MaxMaxVal = 128*256-1; CONST DefaultMaxVal = 255; TYPE Writer <: WriterPublic; WriterPublic = OBJECT METHODS init( wr: Wr.T; width, height: CARDINAL; maxVal: CARDINAL := 255; binary: BOOLEAN := TRUE ): Writer RAISES {Thread.Alerted, Wr.Failure}; (* Begins writing a PPM file. The output format is binary ("P6") if "binary = TRUE" and "maxVal <= 255", else it is ascii decimal ("P3"). *) put(READONLY s: ARRAY [0..2] OF CARDINAL) RAISES {Thread.Alerted, Wr.Failure}; (* Writes "s" as the next pixel of the image file. *) finish() RAISES {Thread.Alerted, Wr.Failure}; (* Flushes the image file and checks whether the correct number of pixels were written. *) END; TYPE Reader <: ReaderPublic; ReaderPublic = OBJECT METHODS init( rd: Rd.T; VAR NX, NY: CARDINAL; VAR maxVal: CARDINAL; ): Reader RAISES {Rd.Failure, Thread.Alerted}; (* Begins parsing a PPM image from "rd". The format may be either binary ("P6") or ascii decimal ("P3"). In either case, the iamge's maximum pixel value is returned in "maxVal". *) get(VAR s: ARRAY [0..2] OF CARDINAL) RAISES {Rd.Failure, Thread.Alerted}; (* Reads the next image pixel. *) finish() RAISES {Rd.Failure, Thread.Alerted}; (* Checks whether the correct numebr fo pixels were read. *) END; END PPM.