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

  1. /*
  2.  *    DuplicateImage()    -    duplicates fields in Image struct
  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 3.0
  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.  *    5/5/94        mm        first cut
  36.  */
  37.  
  38. #include "combine.h"
  39. #include "defines.h"
  40.  
  41.  
  42. Image *DuplicateImage(image,columns,rows,copy_pixels)
  43. Image
  44.   *image;
  45.  
  46. unsigned int
  47.   columns,
  48.   rows,
  49.   copy_pixels;
  50. {
  51.   Image
  52.     *copy_image;
  53.  
  54.   register int
  55.     i;
  56.  
  57.   /*
  58.   ** Allocate space for Image struct
  59.   */
  60.  
  61.   copy_image=(Image *) malloc(sizeof(Image));
  62.  
  63.   if (copy_image == (Image *) NULL)
  64.     return((Image *) NULL);
  65.   *copy_image=(*image);
  66.  
  67.   if (image->comments != (char *) NULL)
  68.   { 
  69.       copy_image->comments=(char *)
  70.         malloc(((strlen(image->comments)+1)*sizeof(char)));
  71.  
  72.       if (copy_image->comments == (char *) NULL)
  73.         return((Image *) NULL);
  74.  
  75.       (void) strcpy(copy_image->comments,image->comments);
  76.    }
  77.  
  78.   copy_image->columns=columns;
  79.   copy_image->rows=rows;
  80.  
  81.   if (image->colormap != (RGB *) NULL)
  82.   {
  83.       copy_image->colormap=(RGB *)
  84.         malloc(image->colors*sizeof(RGB));
  85.  
  86.       if (copy_image->colormap == (RGB *) NULL)
  87.         return((Image *) NULL);
  88.  
  89.       for (i=0; i < image->colors; i++)
  90.         copy_image->colormap[i]=image->colormap[i];
  91.   }
  92.  
  93.   if (image->signature != (char *) NULL)
  94.   {
  95.       copy_image->signature=(char *)
  96.         malloc(((strlen(image->signature)+1)*sizeof(char)));
  97.  
  98.       if (copy_image->signature == (char *) NULL)
  99.         return((Image *) NULL);
  100.  
  101.       (void) strcpy(copy_image->signature,image->signature);
  102.    }
  103.  
  104.   if (!copy_pixels)
  105.     copy_image->packets=copy_image->columns*copy_image->rows;
  106.  
  107.   copy_image->pixels=(Runlength *)
  108.     malloc((unsigned int) copy_image->packets*sizeof(Runlength));
  109.  
  110.   if (copy_image->pixels == (Runlength *) NULL)
  111.     return((Image *) NULL);
  112.  
  113.   if (copy_pixels)
  114.   {
  115.       register Runlength
  116.         *p,
  117.         *q;
  118.  
  119.       if ((image->columns != columns) || (image->rows != rows))
  120.         return((Image *) NULL);
  121.  
  122.       p=image->pixels;
  123.       q=copy_image->pixels;
  124.       for (i=0; i < image->packets; i++)
  125.       {
  126.         *q=(*p);
  127.         p++;
  128.         q++;
  129.       }
  130.    }
  131.   return(copy_image);
  132. }
  133.