home *** CD-ROM | disk | FTP | other *** search
/ Big Green CD 8 / BGCD_8_Dev.iso / NEXTSTEP / UNIX / Web / Utilities / wwwcount-2.3 / combine / cropim.c < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-02  |  1.9 KB  |  131 lines

  1. /*
  2.  *    CropImage()    -    crops an image
  3.  *
  4.  *    RCS:
  5.  *        $Revision: 2.3 $
  6.  *        $Date: 1996/05/03 02:21:34 $
  7.  *
  8.  *    Security:
  9.  *        Unclassified
  10.  *
  11.  *    Description:
  12.  *        Adapted from ImageMagick
  13.  *
  14.  *    Input Parameters:
  15.  *        type    identifier    description
  16.  *
  17.  *        text
  18.  *
  19.  *    Output Parameters:
  20.  *        type    identifier    description
  21.  *
  22.  *        text
  23.  *
  24.  *    Return Values:
  25.  *        value    description
  26.  *
  27.  *    Side Effects:
  28.  *        text
  29.  *
  30.  *    Limitations and Comments:
  31.  *        text
  32.  *
  33.  *    Development History:
  34.  *        when    who        why
  35.  *    08/10/94    muquit    first cut
  36.  */
  37.  
  38. #include "combine.h"
  39.  
  40. Image *CropImage(image,crop_info)
  41. Image
  42.   *image;
  43.  
  44. RectangleInfo
  45.   *crop_info;
  46. {
  47.   Image
  48.     *cropped_image;
  49.  
  50.   register int
  51.     x,
  52.     y;
  53.  
  54.   register Runlength
  55.     *p,
  56.     *q;
  57.  
  58.     /*
  59.     ** make a copy of the image
  60.     */
  61.  
  62.     cropped_image=DuplicateImage(image,crop_info->width,
  63.         crop_info->height,False);
  64.  
  65.     if (cropped_image == (Image *) NULL)
  66.     {
  67.         (void) fprintf (stderr,
  68.             "Unable to crop image, Memory allocation failed\n");
  69.         return((Image *) NULL);
  70.     }
  71.  
  72.     p=image->pixels;
  73.     image->runlength=p->length+1;
  74.  
  75.     for (x=0; x < (crop_info->y*image->columns+crop_info->x); x++)
  76.         if (image->runlength != 0)
  77.             image->runlength--;
  78.         else
  79.         {
  80.             p++;
  81.             image->runlength=p->length;
  82.         }
  83.  
  84.     q=cropped_image->pixels;
  85.  
  86.     for (y=0; y < (cropped_image->rows-1); y++)
  87.     {
  88.         for (x=0; x < cropped_image->columns; x++)
  89.         {
  90.             if (image->runlength != 0)
  91.                 image->runlength--;
  92.             else
  93.             {
  94.                 p++;
  95.                 image->runlength=p->length;
  96.             }
  97.             *q=(*p);
  98.             q->length=0;
  99.             q++;
  100.         }
  101.  
  102.     for (x=0; x < (image->columns-cropped_image->columns); x++)
  103.         if (image->runlength != 0)
  104.             image->runlength--;
  105.         else
  106.         {
  107.           p++;
  108.           image->runlength=p->length;
  109.         }
  110.     }
  111.  
  112.     /*
  113.     ** dump last scanline
  114.     */
  115.  
  116.     for (x=0; x < cropped_image->columns; x++)
  117.     {
  118.         if (image->runlength != 0)
  119.             image->runlength--;
  120.         else
  121.         {
  122.             p++;
  123.             image->runlength=p->length;
  124.         }
  125.         *q=(*p);
  126.         q->length=0;
  127.         q++;
  128.     }
  129.   return(cropped_image);
  130. }
  131.