/* ciimaskprogramexamples.c * Copyright Ó 1993 by Xerox Corporation. All rights reserved. * Michael Plass, June 1, 1993 11:52:35 am PDT */ #include "cii.h" /********************************************************************** ** ** ** This MaskProgram decodes a mask description of the form ** ** ** ** {{ } 0 } ** ** ** ** All quantities are unsigned bytes; fLength is run length, and ** ** fStart is the starting point of the box, relating to the fMin ** ** of the whole box. A 0 byte indicates the start of a new ** ** scanline. For example, the encoding ** ** 3 5 3 12 0 ** ** 3 5 3 12 0 ** ** 3 5 3 12 0 ** ** 3 6 3 11 0 ** ** 6 7 0 ** ** 2 9 0 ** ** should yield the following shape: ** ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ** ** | | | | | |X|X|X| | | | |X|X|X| ** ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ** ** | | | | | |X|X|X| | | | |X|X|X| ** ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ** ** | | | | | |X|X|X| | | | |X|X|X| ** ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ** ** | | | | | | |X|X|X| | |X|X|X| | ** ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ** ** | | | | | | | |X|X|X|X|X|X| | | ** ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ** ** | | | | | | | | | |X|X| | | | | ** ** +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ ** ** The MaskProgram may be broken down as follows: ** ** (R0: sMin, R1: fMin, R2: sMax, R3: fMax) ** ** L1S4 R4 := initial fMin ** ** L2S5 R5 := initial sMax ** ** =1S6 R6 := 1 ** ** {L0-5X while sMin ~= sMaxInitial do ** ** L0+6S2 sMax:=sMin+1 ** ** {F1X while (A:=fetchbyte()) ~= 0 do ** ** S3 R3:=A ** ** F1+4 A:=fetchbyte()+fMinInitial ** ** S1 R1:=A (this is fMin) ** ** +3S3 R3:=A+R3 (this is fMax) ** ** E emit(sMin, fMin, sMax, fMax) ** ** } end ** ** L2S0 sMin:=sMax ** ** } end ** ** ** **********************************************************************/ char* bytewiseRunLengthProgramString = "L1S4L2S5=1S6{L0-5XL0+6S2{F1XS3F1+4S1+3S3E}L2S0}"; static unsigned char exampleMask[] = { 3, 5, 3, 12, 0, 3, 5, 3, 12, 0, 3, 5, 3, 12, 0, 3, 6, 3, 11, 0, 6, 7, 0, 2, 9, 0 }; static CII_RES ExampleAt(CII_Handle dev, CII_MaskProgram prog, int sMin, int fMin) { return CII_MaskDeviceBoxes(dev, sMin, fMin, sMin+6, fMin+15, /* the mask's bounds */ 2, /* box order - we assert these boxes are well-behaved */ prog, /* the mask program for decoding run */ sizeof(exampleMask), /* the bytecount for the data */ exampleMask /* the data for the mask program */ ); } static void BoxesExample(CII_Handle dev) { int i; CII_MaskProgram prog; /* We make the CII_MaskProgram once, and use it over and over. */ CII_MakeMaskProgram(dev, 1, 1, bytewiseRunLengthProgramString, &prog); i=0; while (i<600) { ExampleAt(dev, prog, i+50, i); i=i+10; }; CII_DestroyMaskProgram(dev, prog); } extern void XR_run_ciimaskprogramexamples() { CII_Handle dev = (CII_Handle)CII_TestDevice(); float t[6]; CII_GetInitialMatrix(dev, t); CII_SetMatrix(dev, t); BoxesExample(dev); CII_Destroy(dev); }