home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 343_02 / main422.c < prev    next >
C/C++ Source or Header  |  1992-04-18  |  4KB  |  128 lines

  1.  
  2.  
  3.        /***********************************************
  4.        *
  5.        *       file d:\cips\main422.c
  6.        *
  7.        *       Functions: This file contains
  8.        *          main
  9.        *
  10.        *       Purpose:
  11.        *          This file contains the main calling
  12.        *          routine for a program which shrinks
  13.        *          a 400x400 image down to a 200x200
  14.        *          image.
  15.        *
  16.        *       External Calls:
  17.        *          gin.c - get_image_name
  18.        *          numcvrt.c - get_integer
  19.        *                      int_convert
  20.        *          tiff.c - read_tiff_header
  21.        *          scale.c - shrink_image_array
  22.        *
  23.        *       Modifications:
  24.        *          18 April 1992 - created
  25.        *
  26.        *************************************************/
  27.  
  28. #include "d:\cips\cips.h"
  29.  
  30.  
  31.  
  32. short the_image[ROWS][COLS];
  33. short out_image[ROWS][COLS];
  34.  
  35. main(argc, argv)
  36.    int argc;
  37.    char *argv[];
  38. {
  39.  
  40.    char     method[80], name[80], name2[80];
  41.    int      count, length, width;
  42.    struct   tiff_header_struct image_header;
  43.  
  44.    _setvideomode(_TEXTC80); /* MSC 6.0 statements */
  45.    _setbkcolor(1);
  46.    _settextcolor(7);
  47.    _clearscreen(_GCLEARSCREEN);
  48.  
  49.        /***********************************************
  50.        *
  51.        *       Interpret the command line parameters.
  52.        *
  53.        ************************************************/
  54.  
  55.    if(argc < 4 || argc > 4){
  56.     printf(
  57.      "\n"
  58.      "\n usage: main422 in-file out-file method"
  59.      "\n        where the in-file should be 400x400"
  60.      "\n        and the out-file will be 200x200"
  61.      "\n        method can be Average, Median, Corner"
  62.      "\n");
  63.     exit(0);
  64.    }
  65.  
  66.    strcpy(name,   argv[1]);
  67.    strcpy(name2,  argv[2]);
  68.    strcpy(method, argv[3]);
  69.  
  70.    if(method[0] != 'A' &&
  71.       method[0] != 'a' &&
  72.       method[0] != 'M' &&
  73.       method[0] != 'm' &&
  74.       method[0] != 'C' &&
  75.       method[0] != 'c'){
  76.       printf("\nERROR: Did not enter a valid method"
  77.              "\n       The valid methods are:"
  78.              "\n       Average, Median, Corner");
  79.       exit(-2);
  80.    }
  81.  
  82.    if(does_not_exist(name2)){
  83.       printf("\n\n output file does not exist %s", name2);
  84.       read_tiff_header(name, &image_header);
  85.       round_off_image_size(&image_header,
  86.                            &length, &width);
  87.       image_header.image_length = 2*ROWS;
  88.       image_header.image_width  = 2*COLS;
  89.       create_allocate_tiff_file(name2, &image_header,
  90.                                 out_image);
  91.    }  /* ends if does_not_exist */
  92.  
  93.        /***********************************************
  94.        *
  95.        *   Read and shrink each 200x200 area of the  
  96.        *   input image and write them to the output  
  97.        *   image.                        
  98.        *
  99.        ************************************************/
  100.  
  101.    count = 1;
  102.  
  103.    printf(" %d", count++);
  104.    shrink_image_array(name, name2, the_image,
  105.                       out_image, 1, 1, 101, 101,
  106.                       1, 1, 101, 101,
  107.                       2, method);
  108.  
  109.    printf(" %d", count++);
  110.    shrink_image_array(name, name2, the_image,
  111.                       out_image, 1, 201, 101, 301,
  112.                       1, 101, 101, 201,
  113.                       2, method);
  114.  
  115.    printf(" %d", count++);
  116.    shrink_image_array(name, name2, the_image,
  117.                       out_image, 201, 1, 301, 101,
  118.                       101, 1, 201, 101, 
  119.                       2, method);
  120.  
  121.    printf(" %d", count++);
  122.    shrink_image_array(name, name2, the_image,
  123.                       out_image, 201, 201, 301, 301, 
  124.                       101, 101, 201, 201, 
  125.                       2, method);
  126.  
  127. }  /* ends main  */
  128.