include "draw.m"; include "imagefile.m"; gifreader := load RImagefile RImagefile->READGIFPATH; jpgreader := load RImagefile RImagefile->READJPGPATH; imageremap:= load Imageremap Imageremap->PATH; RImagefile: module { READGIFPATH: con "/dis/lib/readgif.dis"; READJPGPATH: con "/dis/lib/readjpg.dis"; READXBMPATH: con "/dis/lib/readxbitmap.dis"; READPICPATH: con "/dis/lib/readpicfile.dis"; Rawimage: adt { r: Draw->Rect; cmap: array of byte; transp: int; # transparency flag (only for nchans=1) trindex: byte; # transparency index nchans: int; chans: array of array of byte; chandesc:int; fields: int; # defined by format }; # chandesc CRGB: con 0; # three channels, no map CY: con 1; # one channel, luminance CRGB1: con 2; # one channel, map present init: fn(bufio: Bufio); read: fn(fd: ref Bufio->Iobuf): (ref Rawimage, string); readmulti: fn(fd: ref Bufio->Iobuf): (array of ref Rawimage, string); }; WImagefile: module { WRITEGIFPATH: con "/dis/lib/writegif.dis"; init: fn(bufio: Bufio); writeimage: fn(fd: ref Bufio->Iobuf, image: ref Draw- >Image): string; }; Imageremap: module { PATH: con "/dis/lib/imageremap.dis"; remap: fn(i: ref RImagefile->Rawimage, d: ref Draw- >Display, errdiff: int): (ref Draw->Image, string); };
The Rawimage is always defined as one or more bytes per pixel, with nchans channels of data stored in the array chans. The chandesc field, described in this section, specifies the contents of chans. The rectangle r describes the shape of the picture.
The Rawimage type can be converted to a regular Image (see Image - pictures and drawing in Chapter 11) by calling function remap in the Imageremap module. The remap function is passed the Rawimage, a Display on which to create the image, and a flag that specifies whether to apply Floyd-Steinberg error diffusion code to the result for smoother rendering of colors at the cost of some noise in the image.
Remapping is defined by the RImagefile itself. The field chandesc specifies the type of the various chans of data. The file readers set chandesc as appropriate for the format of the file.
CRGB | 3-color RGB image with no color map |
CY | monotone (luminance-only, grey-scale) image with no color map |
CRGB1 | single-channel image with RGB color map in cmap |
These functions are split into separate modules to give applications control over the memory they need to process images.