home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_11 / phillips / boolean.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-29  |  6.0 KB  |  215 lines

  1. #include "cips.h"
  2.  
  3. short the_image[ROWS][COLS];
  4. short out_image[ROWS][COLS];
  5.  
  6. main(argc, argv)
  7.    int argc;
  8.    char *argv[];
  9. {
  10.  
  11.    char     name[80], name2[80], name3[80], type[80];
  12.    int      count, i, j,
  13.             il1, ie1, ll1, le1,
  14.             il2, ie2, ll2, le2,
  15.             il3, ie3, ll3, le3,
  16.             length, lw,
  17.             value, width;
  18.    struct   tiff_header_struct image_header;
  19.  
  20.    my_clear_text_screen();
  21.  
  22.        /*********************************************
  23.        *
  24.        *   Interpret the command line parameters.
  25.        *
  26.        **********************************************/
  27.  
  28.    if(argc < 5){
  29.     printf(
  30.     "\n\nNot enough parameters:"
  31.      "\n"
  32.      "\n usage: boolean in-file1 in-file2 out-file "
  33.      "type [value] [il ie]"
  34.      "\n           or "
  35.      "\n        boolean in-file1 out-file not value"
  36.      "\n"
  37.      "\n recall type: and or xor nand nor not"
  38.      "\n              You must specify a value for "
  39.      "nand & nor"
  40.      "\n"
  41.      "\n If in-file1 is only one ROWSxCOLS in size,"
  42.      "\n then specify il ie for in-file2"
  43.      "\n");
  44.     exit(0);
  45.    }
  46.  
  47.    if(strcmp("not", argv[3]) == 0){
  48.       strcpy(name,  argv[1]);
  49.       strcpy(name2, argv[2]);
  50.       strcpy(type,  argv[3]);
  51.       value =  atoi(argv[4]);
  52.    }  /* ends if not */
  53.    else{
  54.       strcpy(name,  argv[1]);
  55.       strcpy(name2, argv[2]);
  56.       strcpy(name3, argv[3]);
  57.       strcpy(type,  argv[4]);
  58.       value =  atoi(argv[5]);
  59.    }  /* ends else all other types */
  60.  
  61.    il1 = 1;
  62.    ie1 = 1;
  63.    ll1 = ROWS+1;
  64.    le1 = COLS+1;
  65.  
  66.    il2 = 1;
  67.    ie2 = 1;
  68.    ll2 = ROWS+1;
  69.    le2 = COLS+1;
  70.  
  71.    il3 = 1;
  72.    ie3 = 1;
  73.    ll3 = ROWS+1;
  74.    le3 = COLS+1;
  75.  
  76.        /*********************************************
  77.        *
  78.        *   Read the input image header and setup
  79.        *   the looping counters.
  80.        *
  81.        **********************************************/
  82.  
  83.    read_tiff_header(name, &image_header);
  84.  
  85.    length = (90 + image_header.image_length)/ROWS;
  86.    width  = (90 + image_header.image_width)/COLS;
  87.    count  = 1;
  88.    lw     = length*width;
  89.    printf("\nlength=%d  width=%d", length, width);
  90.  
  91.    if(length == 1   &&   
  92.       width  == 1   &&
  93.       strcmp("not", argv[3] != 0)){
  94.          il2 = atoi(argv[5]);
  95.          ie2 = atoi(argv[6]);
  96.          il3 = il2;
  97.          ie3 = ie2;
  98.          ll2 = il2+ROWS;
  99.          le2 = ie2+COLS;
  100.          ll3 = il3+ROWS;
  101.          le3 = ie3+COLS;
  102.    }  /* ends if length == width == 1 */
  103.  
  104.    if(length == 1   &&   
  105.       width  == 1   &&
  106.       strcmp("nand", argv[4] == 0)){
  107.          il2 = atoi(argv[6]);
  108.          ie2 = atoi(argv[7]);
  109.          il3 = il2;
  110.          ie3 = ie2;
  111.          ll2 = il2+ROWS;
  112.          le2 = ie2+COLS;
  113.          ll3 = il3+ROWS;
  114.          le3 = ie3+COLS;
  115.    }  /* ends if length == width == 1 */
  116.  
  117.    if(length == 1   &&   
  118.       width  == 1   &&
  119.       strcmp("nor", argv[4] == 0)){
  120.          il2 = atoi(argv[6]);
  121.          ie2 = atoi(argv[7]);
  122.          il3 = il2;
  123.          ie3 = ie2;
  124.          ll2 = il2+ROWS;
  125.          le2 = ie2+COLS;
  126.          ll3 = il3+ROWS;
  127.          le3 = ie3+COLS;
  128.    }  /* ends if length == width == 1 */
  129.  
  130.        /*********************************************
  131.        *
  132.        *   Loop over the input images and
  133.        *   apply the desired Boolean operator.
  134.        *
  135.        **********************************************/
  136.  
  137.    for(i=0; i<length; i++){
  138.       for(j=0; j<width; j++){
  139.          printf("\nrunning %d of %d", count, lw);
  140.          count++;
  141.  
  142.             /* AND */
  143.          if(strcmp("and", type) == 0){
  144.             and_image(name, name2, name3,
  145.                       the_image, out_image,
  146.                       il1+i*ROWS, ie1+j*COLS,
  147.                       ll1+i*ROWS, le1+j*COLS,
  148.                       il2+i*ROWS, ie2+j*COLS,
  149.                       ll2+i*ROWS, le2+j*COLS,
  150.                       il3+i*ROWS, ie3+j*COLS,
  151.                       ll3+i*ROWS, le3+j*COLS);
  152.          }  /* ends AND operation */
  153.  
  154.             /* OR */
  155.          if(strcmp("or", type) == 0){
  156.             or_image(name, name2, name3,
  157.                      the_image, out_image,
  158.                      il1+i*ROWS, ie1+j*COLS,
  159.                      ll1+i*ROWS, le1+j*COLS,
  160.                      il2+i*ROWS, ie2+j*COLS,
  161.                      ll2+i*ROWS, le2+j*COLS,
  162.                      il3+i*ROWS, ie3+j*COLS,
  163.                      ll3+i*ROWS, le3+j*COLS);
  164.          }  /* ends OR operation */
  165.  
  166.             /* XOR */
  167.          if(strcmp("xor", type) == 0){
  168.             xor_image(name, name2, name3,
  169.                       the_image, out_image,
  170.                       il1+i*ROWS, ie1+j*COLS,
  171.                       ll1+i*ROWS, le1+j*COLS,
  172.                       il2+i*ROWS, ie2+j*COLS,
  173.                       ll2+i*ROWS, le2+j*COLS,
  174.                       il3+i*ROWS, ie3+j*COLS,
  175.                       ll3+i*ROWS, le3+j*COLS);
  176.          }  /* ends XOR operation */
  177.  
  178.             /* NAND */
  179.          if(strcmp("nand", type) == 0){
  180.             nand_image(name, name2, name3,
  181.                        the_image, out_image,
  182.                        il1+i*ROWS, ie1+j*COLS,
  183.                        ll1+i*ROWS, le1+j*COLS,
  184.                        il2+i*ROWS, ie2+j*COLS,
  185.                        ll2+i*ROWS, le2+j*COLS,
  186.                        il3+i*ROWS, ie3+j*COLS,
  187.                        ll3+i*ROWS, le3+j*COLS,
  188.                        value);
  189.          }  /* ends NAND operation */
  190.  
  191.             /* NOR */
  192.          if(strcmp("nor", type) == 0){
  193.             nor_image(name, name2, name3,
  194.                       the_image, out_image,
  195.                       il1+i*ROWS, ie1+j*COLS,
  196.                       ll1+i*ROWS, le1+j*COLS,
  197.                       il2+i*ROWS, ie2+j*COLS,
  198.                       ll2+i*ROWS, le2+j*COLS,
  199.                       il3+i*ROWS, ie3+j*COLS,
  200.                       ll3+i*ROWS, le3+j*COLS,
  201.                       value);
  202.          }  /* ends NOR operation */
  203.  
  204.             /* NOT */
  205.          if(strcmp("not", type) == 0){
  206.             not_image(name, name2,
  207.                       the_image, out_image,
  208.                       il1+i*ROWS, ie1+j*COLS,
  209.                       ll1+i*ROWS, le1+j*COLS, value);
  210.          }  /* ends NOT operation */
  211.  
  212.       }  /* ends loop over j */
  213.    }  /* ends loop over i */
  214. }  /* ends main  */
  215.