home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_11 / 1011096a < prev    next >
Text File  |  1992-09-02  |  4KB  |  124 lines

  1.        /***********************************************
  2.        *
  3.        *       file d:\cips\cutp.c
  4.        *
  5.        *       Functions: This file contains
  6.        *          cut_image_piece
  7.        *          paste_image_piece
  8.        *          check_cut_and_paste_limits
  9.        *
  10.        *       Purpose:
  11.        *          These functions cut pieces out
  12.        *          of images and paste them back into
  13.        *          images.
  14.        *
  15.        *       External Calls:
  16.        *          wtiff.c - does_not_exist
  17.        *                    round_off_image_size
  18.        *                    create_allocate_tiff_file
  19.        *                    write_array_into_tiff_image
  20.        *          tiff.c - read_tiff_header
  21.        *          rtiff.c - read_tiff_image
  22.        *
  23.        *       Modifications:
  24.        *          3 April 1992 - created
  25.        *
  26.        *************************************************/
  27.  
  28. #include "d:\cips\cips.h"
  29.  
  30.      /*******************************************
  31.      *
  32.      *   cut_image_piece(...
  33.      *
  34.      *   This function cuts out a rectangular
  35.      *   piece of an image.  This rectangle can
  36.      *   be any shape so long as no dimension
  37.      *   is greater than ROWS or COLS.
  38.      *
  39.      *******************************************/
  40.  
  41.  
  42. cut_image_piece(name, the_image, il, ie, ll, le)
  43.    char   name[];
  44.    int    il, ie, ll, le;
  45.    short  the_image[ROWS][COLS];
  46. {
  47.    if(does_not_exist(name)){
  48.       printf("\n\ncut_image_piece>> ERROR "
  49.              "image file does not exist %s", name);
  50.       return(-1);
  51.    }  /* ends if does_not_exist */
  52.  
  53.    read_tiff_image(name, the_image, il, ie, ll, le);
  54.  
  55. }  /* ends cut_image_piece */
  56.  
  57.  
  58.  
  59.  
  60.      /*******************************************
  61.      *
  62.      *   paste_image_piece(...
  63.      *
  64.      *   This function pastes a rectangular
  65.      *   piece of an image into another image.
  66.      *   This rectangle can be any shape so long
  67.      *   as no dimension is greater than ROWS or COLS.
  68.      *   The rectangle to be pasted into the image
  69.      *   is described by the il, ie, ll, le
  70.      *   parameters.
  71.      *
  72.      *   You pass is the out_image array just in
  73.      *   case you need to allocate the destination
  74.      *   image.
  75.      *
  76.      *******************************************/
  77.  
  78.  
  79. paste_image_piece(dest_name, source_name, the_image,
  80.                   out_image, il, ie, ll, le)
  81.    char   dest_name[], source_name[];
  82.    int    il, ie, ll, le;
  83.    short  the_image[ROWS][COLS],
  84.           out_image[ROWS][COLS];
  85.  
  86. {
  87.    struct tiff_header_struct image_header;
  88.  
  89.    if(does_not_exist(dest_name)){
  90.       printf("\n\ncut_image_piece>> "
  91.              "image file does not exist %s", dest_name);
  92.       read_tiff_header(source_name, &image_header);
  93.       create_allocate_tiff_file(dest_name, &image_header,
  94.                                 out_image);
  95.    }  /* ends if does_not_exist */
  96.  
  97.    write_array_into_tiff_image(dest_name, the_image,
  98.                                il, ie, ll, le);
  99.  
  100. }  /* ends paste_image_piece */
  101.  
  102.  
  103.  
  104.      /*******************************************
  105.      *
  106.      *   check_cut_and_paste_limits(...
  107.      *
  108.      *   This function looks at the line and
  109.      *   element parameters and ensures that they
  110.      *   are not bigger than ROWS and COLS.  If
  111.      *   they are bigger, the last element or
  112.      *   last line parameters are reduced.
  113.      *
  114.      *******************************************/
  115.  
  116. check_cut_and_paste_limits(il, ie, ll, le)
  117.    int *il, *ie, *ll, *le;
  118. {
  119.    if((*ll - *il) > ROWS)
  120.       *ll = *il + ROWS;
  121.    if((*le - *ie) > COLS)
  122.       *le = *ie + COLS;
  123. }  /* ends check_cut_and_paste_limits */
  124.