Charles.Forsyth20060303-partialeea662d19 years agoHistory
157 lines · 3.8 KB · Text
RawDownload
.TH IMAGEFILE 2.SH NAMEimagefile: readgif, readjpg, readpicfile, readpng, readxbitmap, remap \- processing external image file formats.SH SYNOPSIS.EXinclude "imagefile.m"; gifreader  := load RImagefile RImagefile->READGIFPATH;jpgreader  := load RImagefile RImagefile->READJPGPATH;xbmreader  := load RImagefile RImagefile->READXBMPATH;picreader  := load RImagefile RImagefile->READPICPATH;pngreader := load RImagefile RImagefile->READPNGPATH; imageremap := load Imageremap Imageremap->PATH; Rawimage: adt{    r:         Draw->Rect;    cmap:      array of byte;    nchans:    int;    chans:     array of array of byte;    chandesc:  int;     init:      fn(bufio: Bufio);    read:      fn(fd: ref Bufio->Iobuf): (ref Rawimage, string);    readmulti: fn(fd: ref Bufio->Iobuf):                (array of ref Rawimage, string);}; init:          fn(bufio: Bufio);writeimage:    fn(fd: ref Bufio->Iobuf, image: ref Draw->Image)                                : string; remap:         fn(i: ref RImagefile->Rawimage, d: ref Draw->Display,                errdiff: int): (ref Draw->Image, string);.EE.SH DESCRIPTIONThe.B Rawimage.B adtof module.B RImagefiledefines an internal representationand routines for reading images such as GIF and JPEG files.To read a set of files of a given format, load the appropriate module,pass its.B initfunction an implementation of the.B Bufiomodule, and pass.B readan.B Bufio->Iobuffor each file..B Readreturns a tuple: a.B ref.B Rawimagethat holds the image and an error string.If the.B Rawimageis.BR nil ,the error string will report the reason.Files (particularly GIF files) are often incorrectly encoded but yield usable pictures,so even if a.B Rawimageis returned, the error string may still report problems..PPSome image file types (eg, GIF) support having several images in a single file.They can be read in all at once using.BR readmulti ,which returns a tuple with the array of images, and an error string as above..PPThe.B Rawimageis always defined as one or more bytes per pixel, with.B nchanschannels of data stored in the array.BR chans .The.B chandescfield, described below, specifies the contents of.BR chans .Therectangle.B rdescribes the shape of the picture..PPThe.B Rawimagetype can be converted to a regular.B Image(see.IR draw-image (2))by calling module.BR Imageremap 'sfunction.B remap..B Remapis passed the.BR Rawimage ,a.B Displayon which to create the image, and a flag that specifies whether to apply Floyd-Steinbergerror diffusion code to the result, for smoother rendering of colours at the cost ofsome noise in the image..PPHow to remap is defined by the.B RImagefileitself: the field.B chandescspecifies the type of the various.B chansof data:.B RImagefile->CRGBspecifies a 3-colour RGB image with no colour map;.B RImagefile->CYa monotone (luminance-only, grey-scale) image with no colour map;and.B RImagefile->CRGB1a single-channel image with RGB colour map in.BR cmap .The file readers set.B chandescas appropriate for the format of the file..PPThe writing of image files is defined by the module .BR WImagefile.To initialize the module, call its.B init function with an instance of the.B Bufiomodule and pass its .B writeimagefunction a.B Bufio->Iobufrepresenting the output stream and an image of type.B Draw->Image..PPThese functions are split into separate modules to give applications control overthe memory they need to process images..SH SOURCE.B /appl/lib/readgif.b.br.B /appl/lib/readjpg.b.br.B /appl/lib/readxbitmap.b.br.B /appl/lib/readpicfile.b.br.B /appl/lib/readpng.b.SH NOTESThe JPEG reader handles only the Baseline sequential format as defined bythe JFIF 1.02 file exchange format..PPFunctions to write these formats are as yet unimplemented.