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

  1.        /***********************************************
  2.        *
  3.        *       file d:\cips\side.c
  4.        *
  5.        *       Functions: This file contains
  6.        *          main
  7.        *
  8.        *       Purpose:        
  9.        *          This file contains the main calling
  10.        *          routine for a program which
  11.        *          takes two images and pastes them
  12.        *          together side by side or top to bottom
  13.        *          into a new image file.
  14.        *
  15.        *          There are three files: two input files
  16.        *          (file and file2), and one output
  17.        *          file (file3).
  18.        *
  19.        *       External Calls:
  20.        *          gin.c - get_image_name
  21.        *          numcvrt.c - get_integer
  22.        *                      int_convert
  23.        *          tiff.c - read_tiff_header
  24.        *          cutp.c - cut_image_piece
  25.        *                   paste_image_piece
  26.        *
  27.        *       Modifications:
  28.        *          19 April 1992 - created
  29.        *
  30.        *************************************************/
  31.  
  32. #include "d:\cips\cips.h"
  33.  
  34.  
  35.  
  36. short the_image[ROWS][COLS];
  37. short out_image[ROWS][COLS];
  38.  
  39. main(argc, argv)
  40.    int argc;
  41.    char *argv[];
  42. {
  43.  
  44.    char     method[80], name[80], name2[80], name3[80];
  45.    int      a, b, count, il, ie, ll, le,
  46.             il2, ie2, ll2, le2,
  47.             il3, ie3, ll3, le3,
  48.             length, length2, length3,
  49.             width, width2, width3;
  50.    struct   tiff_header_struct image_header,
  51.                                image_header2,
  52.                                image_header3;
  53.  
  54.    _setvideomode(_TEXTC80); /* MSC 6.0 statements */
  55.    _setbkcolor(1);
  56.    _settextcolor(7);
  57.    _clearscreen(_GCLEARSCREEN);
  58.  
  59.        /***********************************************
  60.        *
  61.        *       Interpret the command line parameters.
  62.        *
  63.        ************************************************/
  64.  
  65.    if(argc < 5 || argc > 5){
  66.     printf(
  67.      "\n"
  68.      "\n usage: side in-file-1 in-file-2 out-file method"
  69.      "\n        where method is Top-to-bottom or Side-by-side"
  70.      "\n");
  71.     exit(0);
  72.    }
  73.  
  74.    strcpy(name,   argv[1]);
  75.    strcpy(name2,  argv[2]);
  76.    strcpy(name3,  argv[3]);
  77.    strcpy(method, argv[4]);
  78.  
  79.    if(does_not_exist(name)){
  80.       printf("\nERROR: Input file %s does not exist", name);
  81.       printf(
  82.        "\n"
  83.        "\n usage: side in-file-1 in-file-2 out-file method"
  84.        "\n        where method is Top-to-bottom or Side-by-side"
  85.        "\n");
  86.       exit(2);
  87.    }
  88.  
  89.    if(does_not_exist(name2)){
  90.       printf("\nERROR: Input file %s does not exist", name2);
  91.       printf(
  92.        "\n"
  93.        "\n usage: side in-file-1 in-file-2 out-file method"
  94.        "\n        where method is Top-to-bottom or Side-by-side"
  95.        "\n");
  96.       exit(3);
  97.    }
  98.  
  99.    if(method[0] != 't'   &&
  100.       method[0] != 'T'   &&
  101.       method[0] != 's'   &&
  102.       method[0] != 'S'){
  103.       printf("\nERROR: Did not choose a valid method");
  104.       printf(
  105.        "\n"
  106.        "\n usage: side in-file-1 in-file-2 out-file method"
  107.        "\n        where method is Top-to-bottom or Side-by-side"
  108.        "\n");
  109.       exit(4);
  110.    }
  111.  
  112.        /***********************************************
  113.        *
  114.        *       Look at the headers of the two input
  115.        *       files.  The output file will hold
  116.        *       most of the two inputs.
  117.        *
  118.        *       Allocate the output file to hold both
  119.        *       input files no matter which is larger
  120.        *       in either dimension.
  121.        *
  122.        ************************************************/
  123.  
  124.    read_tiff_header(name, &image_header);
  125.    round_off_image_size(&image_header,
  126.                         &length, &width);
  127.    read_tiff_header(name2, &image_header2);
  128.    round_off_image_size(&image_header2,
  129.                         &length2, &width2);
  130.  
  131.    if(method[0] == 'T' || method[0] == 't'){
  132.       length3 = length + length2;
  133.       width3  = width;
  134.       if(width2 > width3) width3 = width2;
  135.    }
  136.    else{
  137.       width3  = width + width2;
  138.       length3 = length;
  139.       if(length2 > length3) length3 = length2;
  140.    }
  141.  
  142.    image_header3.image_length   = length3*ROWS;
  143.    image_header3.image_width    = width3*COLS;
  144.    image_header3.lsb            = 1;
  145.    image_header3.bits_per_pixel = 8;
  146.    image_header3.strip_offset   = 1000;
  147.    create_allocate_tiff_file(name3, &image_header3,
  148.                              out_image);
  149.  
  150.        /***********************************************
  151.        *
  152.        *   Loop through the two input images.  Cut
  153.        *   each image array from them and paste the
  154.        *   arrays into the output image.  Paste the
  155.        *   second input image to the left of the
  156.        *   first for the side by side option and
  157.        *   the second image below the first for the
  158.        *   top to bottom option.
  159.        *
  160.        ************************************************/
  161.  
  162.        
  163.        /***********************************************
  164.        *    
  165.        *   First do the side by side option.
  166.        *
  167.        ************************************************/
  168.  
  169.    if(method[0] == 'S' || method[0] == 's'){
  170.       il    = 1;
  171.       ie    = 1;
  172.       ll    = 101;
  173.       le    = 101;
  174.       count = 1;
  175.  
  176.              /****************************************
  177.              *    
  178.              *   Copy the first input file into the
  179.              *   left side of the output file.
  180.              *
  181.              *****************************************/
  182.  
  183.       for(a=0; a<length; a++){
  184.          for(b=0; b<width; b++){
  185.             printf("\ncut and paste %d of %d", 
  186.                      count++, length*width);
  187.             cut_image_piece(name, the_image,
  188.                             il+a*ROWS, ie+b*COLS,
  189.                             ll+a*ROWS, le+b*COLS);
  190.             paste_image_piece(name3, name, the_image, out_image,
  191.                             il+a*ROWS, ie+b*COLS,
  192.                             ll+a*ROWS, le+b*COLS);
  193.          }  /* ends loop over b */
  194.       }  /* ends loop over a */
  195.  
  196.       il2   = 1;
  197.       ie2   = 1;
  198.       ll2   = 101;
  199.       le2   = 101;
  200.       il3   = 1;
  201.       ie3   = 1+COLS*width;
  202.       ll3   = 101;
  203.       le3   = 101+COLS*width;
  204.       count = 1;
  205.  
  206.  
  207.              /****************************************
  208.              *    
  209.              *   Copy the second input file into the
  210.              *   right side of the output file.
  211.              *
  212.              *****************************************/
  213.  
  214.       for(a=0; a<length2; a++){
  215.          for(b=0; b<width2; b++){
  216.             printf("\ncut and paste %d of %d", 
  217.                      count++, length2*width2);
  218.             cut_image_piece(name2, the_image,
  219.                             il2+a*ROWS, ie2+b*COLS,
  220.                             ll2+a*ROWS, le2+b*COLS);
  221.             paste_image_piece(name3, name, the_image, out_image,
  222.                             il3+a*ROWS, ie3+b*COLS,
  223.                             ll3+a*ROWS, le3+b*COLS);
  224.          }  /* ends loop over b */
  225.       }  /* ends loop over a */
  226.    }  /* ends if side-by-side method */
  227.  
  228.        
  229.        /***********************************************
  230.        *    
  231.        *   Now do the top to bottom option.
  232.        *
  233.        ************************************************/
  234.  
  235.    if(method[0] == 'T' || method[0] == 't'){
  236.       il    = 1;
  237.       ie    = 1;
  238.       ll    = 101;
  239.       le    = 101;
  240.       count = 1;
  241.  
  242.              /****************************************
  243.              *    
  244.              *   Copy the first input file into the
  245.              *   top half of the output file.
  246.              *
  247.              *****************************************/
  248.  
  249.       for(a=0; a<length; a++){
  250.          for(b=0; b<width; b++){
  251.             printf("\ncut and paste %d of %d", 
  252.                      count++, length*width);
  253.             cut_image_piece(name, the_image,
  254.                             il+a*ROWS, ie+b*COLS,
  255.                             ll+a*ROWS, le+b*COLS);
  256.             paste_image_piece(name3, name, the_image, out_image,
  257.                             il+a*ROWS, ie+b*COLS,
  258.                             ll+a*ROWS, le+b*COLS);
  259.          }  /* ends loop over b */
  260.       }  /* ends loop over a */
  261.  
  262.       il2   = 1;
  263.       ie2   = 1;
  264.       ll2   = 101;
  265.       le2   = 101;
  266.       il3   = 1 + length * ROWS;
  267.       ie3   = 1;
  268.       ll3   = 101 + length * ROWS;
  269.       le3   = 101;
  270.       count = 1;
  271.  
  272.              /****************************************
  273.              *    
  274.              *   Copy the second input file into the
  275.              *   bottom half of the output file.
  276.              *
  277.              *****************************************/
  278.  
  279.       for(a=0; a<length2; a++){
  280.          for(b=0; b<width2; b++){
  281.             printf("\ncut and paste %d of %d", 
  282.                      count++, length2*width2);
  283.             cut_image_piece(name2, the_image,
  284.                             il2+a*ROWS, ie2+b*COLS,
  285.                             ll2+a*ROWS, le2+b*COLS);
  286.             paste_image_piece(name3, name, the_image, out_image,
  287.                             il3+a*ROWS, ie3+b*COLS,
  288.                             ll3+a*ROWS, le3+b*COLS);
  289.          }  /* ends loop over b */
  290.       }  /* ends loop over a */
  291.    }  /* ends top-to-bottom method */
  292.  
  293. }  /* ends main */
  294.