INTERFACE PGM; (* Parameters and basic operations on PGM image files (see "man n pgm"). *) IMPORT Rd, Wr, Thread; CONST NChannels = 1; CONST Extension = ".pgm"; 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 PGM file. The output format is binary ("P5") if "binary = TRUE" and "maxVal <= 255", else it is ascii decimal ("P2"). *) put(s: 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 PGM image from "rd". The format may be either binary ("P5") or ascii decimal ("P2"). In either case, the iamge's maximum pixel value is returned in "maxVal". *) get(VAR s: CARDINAL) RAISES {Rd.Failure, Thread.Alerted}; (* Reads the next image pixel. *) finish() RAISES {Rd.Failure, Thread.Alerted}; (* Checks whether the correct numebr of pixels were read. *) END; END PGM.