home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Web / Utilities / wwwcount-2.3 / combine / uncmpimg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-19  |  2.0 KB  |  73 lines

  1. #include "combine.h"
  2. #include "defines.h"
  3.  
  4. /*
  5. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  6. %                                                                             %
  7. %                                                                             %
  8. %                                                                             %
  9. %   U n C o m p r e s s I m a g e                                             %
  10. %                                                                             %
  11. %                                                                             %
  12. %                                                                             %
  13. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  14. %
  15. %  Function UncompressImage uncompresses runlength-encoded pixels packets to
  16. %  a rectangular array of pixels.
  17. %
  18. %  The format of the UncompressImage routine is:
  19. %
  20. %      status=UncompressImage(image)
  21. %
  22. %  A description of each parameter follows:
  23. %
  24. %    o status: Function UncompressImage returns True if the image is
  25. %      uncompressed otherwise False.
  26. %
  27. %    o image: The address of a structure of type Image.
  28. %
  29. %
  30. */
  31. unsigned int UncompressImage(image)
  32. Image
  33.   *image;
  34. {
  35.   register int
  36.     i,
  37.     j,
  38.     length;
  39.  
  40.   register Runlength
  41.     *p,
  42.     *q;
  43.  
  44.   Runlength
  45.     *uncompressed_pixels;
  46.  
  47.   if (image->packets == (image->columns*image->rows))
  48.     return(True);
  49.   /*
  50.     Uncompress runlength-encoded packets.
  51.   */
  52.   uncompressed_pixels=(Runlength *) realloc((char *) image->pixels,
  53.     image->columns*image->rows*sizeof(Runlength));
  54.   if (uncompressed_pixels == (Runlength *) NULL)
  55.     return(False);
  56.   image->pixels=uncompressed_pixels;
  57.   p=image->pixels+image->packets-1;
  58.   q=uncompressed_pixels+image->columns*image->rows-1;
  59.   for (i=0; i < image->packets; i++)
  60.   {
  61.     length=p->length;
  62.     for (j=0; j <= length; j++)
  63.     {
  64.       *q=(*p);
  65.       q->length=0;
  66.       q--;
  67.     }
  68.     p--;
  69.   }
  70.   image->packets=image->columns*image->rows;
  71.   return(True);
  72. }
  73.