home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / hdf3_2r2.lha / HDF3.2r2 / util / hdfrseq.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-28  |  18.7 KB  |  741 lines

  1. /***************************************************************************
  2. *
  3. *
  4. *                         NCSA HDF version 3.2r2
  5. *                            October 30, 1992
  6. *
  7. * NCSA HDF Version 3.2 source code and documentation are in the public
  8. * domain.  Specifically, we give to the public domain all rights for future
  9. * licensing of the source code, all resale rights, and all publishing rights.
  10. *
  11. * We ask, but do not require, that the following message be included in all
  12. * derived works:
  13. *
  14. * Portions developed at the National Center for Supercomputing Applications at
  15. * the University of Illinois at Urbana-Champaign, in collaboration with the
  16. * Information Technology Institute of Singapore.
  17. *
  18. * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
  19. * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
  20. * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
  21. *
  22. ****************************************************************************
  23. */
  24.  
  25. #ifdef RCSID
  26. static char RcsId[] = "@(#)$Revision: 1.3 $";
  27. #endif
  28. /*
  29. $Header: /hdf/hdf/v3.2r2/util/RCS/hdfrseq.c,v 1.3 1992/08/24 15:02:30 dilg beta koziol $
  30.  
  31. $Log: hdfrseq.c,v $
  32.  * Revision 1.3  1992/08/24  15:02:30  dilg
  33.  * Ripped out all Sunview code.  Sunview is no longer supported.
  34.  *
  35.  * Revision 1.2  1992/07/15  21:48:48  sxu
  36.  * No change.
  37.  *
  38.  * Revision 1.1  1992/06/09  16:29:42  dilg
  39.  * Initial revision
  40.  *
  41. */
  42. /*    hdfrseq
  43. *  Sequencer for NCSA Hierarchical Data Format files
  44. *
  45. *  Display images on a remote ICR terminal 
  46. *  in sequence, suitable for onscreen animation.  Can expand the image size
  47. *  on the fly.
  48. *
  49. *  This version now supports displaying an image in a window on a Silicon
  50. *  Graphics Iris 4D workstation.  There are bugs in this code (possibly due
  51. *  to evolving system software combined with old code).
  52. *
  53. *  National Center for Supercomputing Applications
  54. *  University of Illinois, Urbana-Champaign
  55. *
  56. *  by Tim Krauskopf
  57. *  first version of seq 7/11/86
  58. *  modifications        2/20/87
  59. *  re-write             6/21/88
  60. *  Iris 4D support      6/24/89  Mike Krogh
  61. *  Line padding        9/25/89  Chin-Chau Low
  62. *  In-between versions re-written by Gaige B. Paulsen and Swami Natarajan
  63. *  ANSI-fication & relegation to remote-only use
  64. *            6/9/92   Doug Ilg
  65. *
  66. *  This program is in the public domain
  67. *
  68. */
  69. #include "hdf.h"             /* HDF includes */
  70.  
  71. #ifdef IRIS4
  72. #include <gl.h>
  73. #include <device.h>
  74. #endif
  75.  
  76.  
  77. #ifndef IRIS4
  78. #define  SCRX    1152
  79. #define  SCRY    900
  80. #endif
  81.  
  82. #ifdef IRIS4
  83. #define  SCRX    1280
  84. #define  SCRY    1024
  85. #endif
  86.  
  87.  
  88. #define  LUSAGE   printf("\nUsage: %s [-s] [-l] [-e exp] [-p xwhere ywhere] file1 file2 . . .\n",argv[0])
  89. #define  RUSAGE   printf("\nUsage: %s [-s] [-l] [-e exp] file1 file2 . . .\n",argv[0])
  90. #define USAGE   if (remote) { RUSAGE; } else { LUSAGE; }
  91.  
  92.  
  93.  
  94. int 
  95.     oldcf=0,                /* old value of compression flag */
  96.     oldx=0,oldy=0,          /* old values of xdim and ydim */
  97.     coldx=0,coldy=0,        /* old values of xdim and ydim for CI8s */
  98.     xwhere=0,ywhere=0,      /* where to put it on the screen */
  99.     step=0,                 /* single step? */
  100.     remote=0,               /* should use ICR for remote display */
  101.     large=0,                /* should make images as large as possible */
  102.     center=1,               /* should center the images */
  103.     startpic=1,             /* for parameter counts */
  104.     oldxs=0,oldys=0,        /* old sizes */
  105.     xsize=0,ysize=0,        /* what final size on screen, after blow-up */
  106.     xfact=1,yfact=1;        /* what factor for blowing up the picture */
  107.  
  108. int32 xdim=0,ydim=0;          /* size of image on disk */
  109.  
  110. #ifdef NEEDPAD
  111. int xpad;
  112. #endif
  113.  
  114. #ifdef IRIS4
  115. int GID;
  116. unsigned short *img=NULL;
  117. int WINDOW_OPEN=0;
  118. int16 idev,qvalue;
  119. int attached=1;
  120. #endif
  121.  
  122.  
  123. char 
  124.     rgb[768],                   /* storage for a palette */
  125.     *wherebig=NULL,             /* where to store small image */
  126.     *wheresmall=NULL;           /* where to store image-related stuff */
  127.  
  128. #ifdef PROTOTYPE
  129. int main(int, char **);
  130. int getspace(void);
  131. int getpix(void);
  132. int largeset(void);
  133. int showpic(char *);
  134. int piximage(int);
  135. int rimage(int);
  136. int bigimg(unsigned char *, unsigned char *);
  137. int rleit(char *, char *, int);
  138. #else
  139. int main();
  140. int getspace();
  141. int getpix();
  142. int largeset();
  143. int showpic();
  144. int piximage();
  145. int rimage();
  146. int bigimg();
  147. int rleit();
  148. #endif /* PROTOTYPE */
  149.  
  150. /*************************************************************************/
  151. /*  hdfseq
  152. *   Load the images from the specified files.
  153. *   Create the internal storage if needed.
  154. *
  155. *   Search pattern for files:
  156. *       RIG images in file
  157. *       RI8 and CI8 images in file
  158. */
  159. #ifdef PROTOTYPE
  160. int main(int argc, char *argv[])
  161. #else
  162. int main(argc,argv)
  163.     int argc;
  164.     char *argv[];
  165. #endif /* PROTOTYPE  */
  166.     {
  167.     int i,filearg;
  168.  
  169. /*
  170. *  Check to see if we are displaying on a local console or on a
  171. *  remote ICR.  This program does double duty.
  172. */
  173.     i = strlen(argv[0]);
  174.     if (strncmp("hdfseq",argv[0]+i-6,6))
  175.         remote=1;
  176.  
  177. /*
  178. *  Are there enough parameters?  Give user information on calling.
  179. */
  180.     if (argc < 2) {
  181.         printf("%s,  version: 1.0   date: December 1, 1988\n",argv[0]);
  182.                 if (remote) {
  183.         printf(" This utility displays sequences of raster-8 images\n");
  184.                 printf(" from HDF files on a remote device using NCSA's\n");
  185.         printf(" Interactive Color Raster protocol.\n\n");
  186.                 }
  187.                 if (!remote) {
  188. #ifdef SUN
  189.                 printf(" This utility displays sequences of raster-8 images\n");
  190.                 printf(" from HDF files on the Sun console running Sunview.\n");
  191. #endif
  192. #ifdef IRIS4
  193.                 printf(" This utility displays sequences of raster-8 images\n");
  194.                 printf(" from HDF files on the Iris console running 4Sight.\n");
  195. #endif
  196.         printf("\n");
  197.                 }
  198.         USAGE;
  199.         puts(" -l              make image as large as possible");
  200.         puts(" -e expansion    expand image by a certain factor");
  201.         if (!remote) puts(" -p xloc yloc    position on screen");
  202.         puts(" -s              step through images");
  203.         exit(1);
  204.     }
  205.  
  206. /*
  207. *  work on parms
  208. */
  209.     for (i=1; i<argc; i++) {                /* look at each parm */
  210.         if (*argv[i] == '-') 
  211.             switch ( *(argv[i]+1)) {
  212.                 case 'p':                   /* special position on screen */
  213.                     center=0;               /* don't center */
  214.                     xwhere = atoi(argv[++i]);
  215.                     ywhere = atoi(argv[++i]);
  216.                     if (xwhere > SCRX || ywhere > SCRY) {
  217.                         puts("\n Invalid position ");
  218.                         USAGE;
  219.                         exit(1);
  220.                     }
  221.                     startpic+=3;
  222.                     break;
  223.                 case 'e':
  224.                     xfact = yfact = atoi(argv[++i]);
  225.                     if (xfact < 1) {
  226.                         xfact = 1;
  227.                         yfact = 1;
  228.                     }
  229.                     startpic+=2;
  230.                     break;
  231.                 case 'l':                   /* large pic */
  232.                     large=1;
  233.                     startpic++;
  234.                     break;
  235.                 case 's':                   /* step through pics */
  236.                     step = 1;
  237.                     startpic++;
  238.                     break;
  239.                 default:
  240.                     USAGE;
  241.                     exit(1);
  242.             }
  243.     }
  244.  
  245.  
  246. /*
  247. *  Process each of the files in the command string.
  248. *
  249. */
  250.     for (filearg = startpic; filearg < argc; filearg++)
  251.         showpic(argv[filearg]);
  252.  
  253.  
  254. #ifdef IRIS4
  255.     if ((!remote) && (img)) /* make sure we have an image */
  256.         while(1) {
  257.             idev=qread(&qvalue);
  258.             if (idev==REDRAW) {
  259.                 reshapeviewport();
  260.                 if (img != NULL) {
  261.                     rectwrite(0,0,(xdim-1),(ydim-1),img);
  262.                     swapbuffers();
  263.                 }
  264.             }
  265.         }
  266. #endif
  267.  
  268.     exit(0);
  269. }
  270.  
  271. /*************************************************************************/
  272. /*  getspace
  273. *  Provide enough space in the space pointers for the operations
  274. *  to all work.
  275. */
  276. #ifdef PROTOTYPE
  277. getspace(void)
  278. #else
  279. getspace()
  280. #endif /* PROTOTYPE  */
  281.     {
  282.  
  283. /*  
  284. *  Don't allocate anything if the image is the same size as before.
  285. */
  286.     if (oldx != xdim || oldy != ydim) {
  287.         oldx = xdim; oldy = ydim; 
  288.  
  289.         if (wheresmall)
  290.             free(wheresmall);
  291.  
  292.         if (NULL == (wheresmall = (char *)malloc(xdim*ydim))) {
  293.             puts(" Cannot allocate memory, fatal error");
  294.             exit(1);
  295.         }
  296.  
  297.     }
  298.     return(0);
  299. }
  300.  
  301.  
  302.  
  303. #ifdef IRIS4
  304. /*
  305. *  Allocate the space for the image if displaying locally
  306. */
  307. #ifdef PROTOTYPE
  308. getpix(void)
  309. #else
  310. getpix()
  311. #endif /* PROTOTYPE  */
  312. {
  313. /*
  314. *  Allocation will take place because xsize and ysize will
  315. *  be set before calling this routine.
  316. *
  317. */
  318.     if (!remote && (oldxs != xsize || oldys != ysize)) {
  319.         oldxs = xsize ; oldys = ysize;
  320.         if (img)
  321.             free(img);
  322.         if ((img = (unsigned short *)malloc(xdim*ydim*sizeof(short))) == NULL) {
  323.             puts(" Cannot allocate memory, fatal error");
  324.             exit(1);
  325.         } 
  326.  
  327.     }
  328.     return(0);
  329. }
  330. #endif
  331.  
  332.  
  333.  
  334. /*************************************************************************/
  335. /*  largeset
  336. *  Set up the xfact, yfact, xsize and ysize for expanding the image
  337. *  locally.  
  338. *
  339. */
  340. #ifdef PROTOTYPE
  341. largeset(void)
  342. #else
  343. largeset()
  344. #endif /* PROTOTYPE  */
  345.     {
  346.  
  347.     if (large) {
  348.         xfact = SCRX/xdim;      /* how much blow-up can we do? */
  349.         yfact = SCRY/ydim;      /* calculate expansion factor  */
  350.         if (xfact > yfact)
  351.             xfact = yfact;
  352.         else
  353.             yfact = xfact;
  354.     }
  355.  
  356.     xsize = xfact*xdim;         /* re-calculate actual pixel dimensions */
  357.     ysize = yfact*ydim;
  358.  
  359. #ifdef NEEDPAD            /* add padding for byte boundary */
  360.     xpad = BYTEBOUND - xsize % BYTEBOUND;
  361.     if (xpad == BYTEBOUND) xpad = 0;
  362.     else xsize += xpad;
  363. #ifdef DEBUG
  364.     printf("xpad %d\n",xpad);
  365. #endif /*DEBUG*/
  366.     return(xfact > 1 || yfact > 1 || xpad > 0);    /* is expansion necessary? */
  367. #endif /*NEEDPAD*/
  368.  
  369. #ifndef NEEDPAD            /* make sure there is only 1 return stmt */
  370.     return(xfact > 1 || yfact > 1); /* is expansion necessary? */
  371. #endif /*NEEDPAD*/
  372. }
  373.  
  374.  
  375. /*************************************************************************/
  376. /*  showpic
  377. *  For each file, search for the components that we can display.
  378. *  Display them according to the remote flag on or off.
  379. *
  380. */
  381. #ifdef PROTOTYPE
  382. showpic(char *filename)
  383. #else
  384. showpic(filename)
  385.     char *filename;
  386. #endif /* PROTOTYPE  */
  387.     {
  388.     int ispal, r8_exists;
  389.  
  390.  
  391.     oldx = xdim; oldy = ydim;       /* save old values */
  392.  
  393.     if (-1==DFishdf(filename)) {
  394.         printf("\'%s\' is not an HDF Format Data File.\n", filename);
  395.         return(0);
  396.     }
  397. /*
  398. *  Search for all RIGs in this file.
  399. *  Process each RIG and display.
  400. */
  401.     r8_exists = FALSE;
  402.     while (1) {
  403.         if (DFR8getdims(filename, &xdim, &ydim, &ispal)<0) {
  404.             if (!r8_exists)
  405.                 printf("There are no 8-bit images in the file %s\n",filename);
  406.             break;      /* all RIGs processed */
  407.         }
  408.         r8_exists = TRUE;         /* at least one 8-bit image found */
  409.  
  410. #ifdef DEBUG
  411.     printf("xdim %d ydim %d\n",xdim,ydim);
  412. #endif /*DEBUG*/
  413. #ifdef IRIS4
  414.         if (!remote) {
  415.             largeset();         /* set expansion needs */
  416.             getspace();         /* get local space for pre-expansion */
  417.             getpix();               /* allocate memory */
  418.         }
  419. #endif
  420.  
  421.         if (remote)
  422.             getspace();         /* get space for image in mem */
  423.     
  424.  
  425. /*
  426. *  Try to successfully load the palette and image from the file
  427. */
  428.         if (!DFR8getimage(filename, (uint8 *)wheresmall, xdim, ydim, (uint8 *)rgb)) {
  429.             if (remote) 
  430.                 rimage(ispal);      /* display remote image with [palette] */
  431. #ifdef IRIS4
  432.             else
  433.                 piximage(ispal);    /* display image on Iris with [palette] */
  434. #endif
  435.         }
  436.         else puts(" Error loading image");
  437.  
  438.     }
  439.  
  440.     return(0);
  441.  
  442. }
  443.  
  444.  
  445.  
  446. #ifdef IRIS4
  447. /***********************************************************************/
  448. /*  piximage
  449. *  On the Iris console, display the image as the parameters specify.
  450. *  Handles centering (center)
  451. *  Uses xwhere and ywhere, xsize and ysize.
  452. *  Performs expansion if xfact or yfact > 1
  453. *  Takes the palette from the rgb[] if asked to.
  454. *  Will pause if step=1.
  455. */
  456. #ifdef PROTOTYPE
  457. piximage(int usepal)
  458. #else
  459. piximage(usepal)
  460. int usepal;
  461. #endif /* PROTOTYPE  */
  462. {
  463.     char *pp;
  464.     int r,g,b;
  465.     int j,j1,j2,k;
  466.  
  467.  
  468. /*
  469. *  compute centering values, based on new size
  470. */
  471.     if (center) {
  472.         xwhere = (SCRX-xsize)/2;
  473.         ywhere = (SCRY-ysize)/2;
  474.         if (xwhere < 0) 
  475.             xwhere = 0;
  476.         if (ywhere < 0)
  477.             ywhere = 0;
  478.     }
  479.  
  480.     if (!WINDOW_OPEN) {
  481.         WINDOW_OPEN=1;
  482.         if (step) {
  483.             printf("Press <enter> to step through images or");
  484.             printf(" 'Q' to quit.\n");
  485.         }
  486.         prefposition(xwhere,(xwhere+xsize),ywhere,(ywhere+ysize));
  487.         GID = winopen("hdfseq");  /* open the window */
  488.         shademodel(FLAT);             /* don't worry about shading */
  489.         doublebuffer();
  490.         multimap();
  491.         gconfig();
  492.         setmap(4);
  493.         color(BLACK);
  494.         clear();
  495.         qdevice(REDRAW);
  496.         if (step) {
  497.             qdevice(QKEY);
  498.             qdevice(RETKEY);
  499.             qdevice(INPUTCHANGE);
  500.         }
  501.     }
  502.  
  503. /*
  504. * Process window movement events.
  505. */
  506.     while (qtest()) {
  507.         idev=qread(&qvalue);
  508.         if (idev==REDRAW) {
  509.             reshapeviewport();
  510.             if (img != NULL) {
  511.                 rectwrite(0,0,(xdim-1),(ydim-1),img);
  512.                 swapbuffers();
  513.             }
  514.         }
  515.         if (idev==INPUTCHANGE)
  516.             attached=qvalue;
  517.     }
  518.  
  519. /*
  520. *  Do the image expansion, if called for.
  521. */
  522.     if (xfact > 1 || yfact > 1)
  523.         rectzoom((float32)xfact,(float)yfact);  /* let the iris scale it */
  524.  
  525. /*
  526. *  Set the display palette to the new palette.
  527. */
  528.  
  529.     if (usepal) {
  530.         pp = rgb;
  531.         for (j=0; j<256; j++) {
  532.             r = (int)(*pp++);
  533.             g = (int)(*pp++);
  534.             b = (int)(*pp++);
  535.             mapcolor(j,r,g,b);  /* change the system palette */
  536.         }
  537.     }
  538.  
  539. /*
  540. * Convert image data to iris pixel format
  541. * flip it upside down and convert to short integers.
  542. */
  543.  
  544.     for (j=0; j<ydim; j++) {
  545.         j1 = (ydim-j-1)*xdim;
  546.         j2 = j*xdim;
  547.         for (k=0; k<xdim; k++)
  548.             *(img+j1+k) = (short)(*(wheresmall+j2+k));
  549.     }
  550.  
  551.     rectwrite(0,0,(xdim-1),(ydim-1),img);
  552.     swapbuffers();
  553.  
  554.     if (step) {
  555.         while(1) {
  556.             idev=qread(&qvalue);
  557.             if (idev==REDRAW) {
  558.                 reshapeviewport();
  559.                 if (img != NULL) {
  560.                     rectwrite(0,0,(xdim-1),(ydim-1),img);
  561.                     swapbuffers();
  562.                 }
  563.             }
  564.             if (idev==QKEY)
  565.                 exit(0);
  566.             if (idev==RETKEY)
  567.                 break;
  568.             if (idev==INPUTCHANGE)
  569.                 attached=qvalue;
  570.         }
  571.     }
  572.  
  573. }
  574. #endif
  575.  
  576.  
  577.  
  578.  
  579. /*****************************************************************************/
  580. /*  rimage
  581. *  Remote display of the image using the ICR.
  582. *  Just print the codes to stdout using the protocol.
  583. */
  584. #ifdef PROTOTYPE
  585. rimage(int usepal)
  586. #else
  587. rimage(usepal)
  588.     int usepal;
  589. #endif /* PROTOTYPE  */
  590.     {
  591.     int i,j,newxsize;
  592.     char *space,*thisline,*thischar;
  593.     register unsigned char c;
  594.  
  595. /*
  596. *  Open the window with the W command
  597. */
  598.  
  599. (void)printf("\033^W;%d;%d;%d;%d;0;rseq^",xwhere,ywhere,xdim*xfact,ydim*yfact);
  600.  
  601. /*
  602. *  If a palette should be used, send it with the M command.
  603. */
  604.     if (usepal) {
  605.         (void)printf("\033^M;0;256;768;rseq^");  /* start map */
  606.  
  607.         thischar = rgb;
  608.         for (j=0; j<768; j++) {
  609.             c = *thischar++;
  610.             if (c > 31 && c < 123) {
  611.                 putchar(c);
  612.             }
  613.             else {
  614.                 putchar((c>>6)+123);
  615.                 putchar((c & 0x3f) + 32);
  616.             }
  617.         }
  618.     }
  619.  
  620. /*
  621. *  Send the data for the image with RLE encoding for efficiency.
  622. *  Encode each line and send it.
  623. */
  624.     space = (char *)malloc(ydim+100);
  625.     thisline = wheresmall;
  626.  
  627.     for (i = 0; i < ydim; i++) {
  628.         newxsize = rleit(thisline,space,xdim);
  629.         thisline += xdim;               /* increment to next line */
  630.  
  631.         (void)printf("\033^R;0;%d;%d;%d;rseq^",i*xfact,xfact,newxsize); 
  632.  
  633.         thischar = space;
  634.         for (j = 0; j < newxsize; j++) {
  635.  
  636. /***********************************************************************/
  637. /*  Encoding of bytes:
  638. *
  639. *  123 precedes #'s 0-63
  640. *  124 precedes #'s 64-127
  641. *  125 precedes #'s 128-191
  642. *  126 precedes #'s 192-255
  643. *  overall:  realchar = (specialchar - 123)*64 + (char-32)
  644. *            specialchar = r div 64 + 123
  645. *            char = r mod 64 + 32
  646. */
  647. /***********************************************************************/
  648.  
  649.             c = *thischar++;      /* get byte to send */
  650.  
  651.             if (c > 31 && c < 123) {
  652.                 putchar(c);
  653.             }
  654.             else {
  655.                 putchar((c>>6)+123);
  656.                 putchar((c & 0x3f) + 32);
  657.             }
  658.         }
  659.     }
  660.  
  661. /*
  662. *  pause for the user
  663. */
  664.     if (step) {
  665.         printf("Press return to continue, 'q' return to quit");
  666.         if ('q' == getchar())
  667.             exit(0);
  668.     }
  669.  
  670.     free(space);
  671.     return(0);
  672. }
  673.  
  674.  
  675.  
  676. /********************************************************************/
  677. /*  rleit
  678. *  compress the data to go out with a simple run-length encoded scheme.
  679. *
  680. */
  681. #ifdef PROTOTYPE
  682. int rleit(char *buf, char *bufto, int len)
  683. #else
  684. int rleit(buf,bufto,len)
  685.     int len;
  686.     char *buf,*bufto;
  687. #endif /* PROTOTYPE  */
  688.     {
  689.     register char *p,*q,*cfoll,*clead;
  690.     char *begp;
  691.     int i;
  692.  
  693.     p = buf;
  694.     cfoll = bufto;              /* place to copy to */
  695.     clead = cfoll + 1;
  696.     
  697.     begp = p;
  698.     while (len > 0) {           /* encode stuff until gone */
  699.         
  700.         q = p + 1;
  701.         i = len-1;
  702.         while (*p == *q && i+120 > len && i) {
  703.             q++;
  704.             i--;
  705.         }
  706.         
  707.         if (q > p + 2) {        /* three in a row */
  708.             if (p > begp) {
  709.                 *cfoll = p - begp;
  710.                 cfoll = clead;
  711.             }
  712.             *cfoll++ = 128 | (q-p);     /* len of seq */
  713.             *cfoll++ = *p;      /* char of seq */
  714.             len -= q-p;         /* subtract len of seq */
  715.             p = q;
  716.             clead = cfoll+1;
  717.             begp = p;
  718.         }
  719.         else {
  720.             *clead++ = *p++;    /* copy one char */
  721.             len--;
  722.             if (p > begp + 120) {
  723.                 *cfoll = p - begp;
  724.                 cfoll = clead++;
  725.                 begp = p;
  726.             }
  727.         }
  728.         
  729.     }
  730. /*
  731. *  fill in last bytecount
  732. */
  733.     if (p > begp) 
  734.         *cfoll = (p - begp);
  735.     else
  736.         clead--;                    /* don't need count position */
  737.     
  738.     return((int)(clead - bufto));   /* how many stored as encoded */
  739. }
  740.  
  741.