home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_08 / phil5.c < prev    next >
Text File  |  1991-06-21  |  8KB  |  275 lines

  1.  
  2. Listing 5 - Changes to the Function display_using_halftoning (file
  3. ht.c)
  4.  
  5.  
  6.  
  7. display_using_halftoning(in_image, file_name,
  8.          il, ie, ll, le, threshold, invert,
  9.          image_colors, image_header, monitor_type,
  10.          print, show_hist, color_transform)
  11.  
  12.    char  color_transform[], file_name[], monitor_type[];
  13.    int   image_colors, invert,
  14.          il, ie, ll, le, threshold,
  15.          print, show_hist;
  16.    short in_image[ROWS][COLS];
  17.    struct tiff_header_struct *image_header;
  18.  
  19. {
  20.    char response[80];
  21.  
  22.    int  a,
  23.         b,
  24.         channel,
  25.         color,
  26.         count,
  27.         data_color,
  28.         display_mode,
  29.         horizontal,
  30.         i,
  31.         j,
  32.         k,
  33.         l,
  34.         line_color,
  35.         max_horizontal,
  36.         max_vertical,
  37.         not_finished,
  38.         one,
  39.         vertical,
  40.         x,
  41.         x_offset,
  42.         y,
  43.         y_offset,
  44.         zero;
  45.  
  46.    float area, new_grays;
  47.  
  48.    unsigned long histogram[256], new_hist[256];
  49.  
  50.  
  51.        if(  (show_hist == 1)  &&
  52.             (color_transform[0] != 'H'))
  53.           zero_histogram(histogram);
  54.          /*******************************************
  55.          *
  56.          *   Use the monitor type to set the vertical
  57.          *   horizontal and display_mode parameters.
  58.          *   Also set the values for one and zero.
  59.          *   one and zero will vary depending on the
  60.          *   monitor type.
  61.          *
  62.          ********************************************/
  63.  
  64.  
  65.       if(  (monitor_type[0] == 'M')  ||
  66.            (monitor_type[0] == 'm')){
  67.          vertical     = 3;
  68.          horizontal   = 2;
  69.          display_mode = _HRESBW;
  70.          one          = 1;
  71.          zero         = 0;
  72.       }
  73.  
  74.       if(  (monitor_type[0] == 'C')  ||
  75.            (monitor_type[0] == 'c')){
  76.          vertical     = 3;
  77.          horizontal   = 2;
  78.          display_mode = _MRES4COLOR;
  79.          one          = 3;
  80.          zero         = 1;
  81.       }
  82.  
  83.       if(  (monitor_type[0] == 'V')  ||
  84.            (monitor_type[0] == 'v')){
  85.          vertical     = 6;
  86.          horizontal   = 4;
  87.          display_mode = _VRES16COLOR;
  88.          one          = 5;
  89.          zero         = 1;
  90.       }
  91.  
  92.       if(  (monitor_type[0] == 'E')  ||
  93.            (monitor_type[0] == 'e')){
  94.          vertical     = 6;
  95.          horizontal   = 3;
  96.          display_mode = _ERESCOLOR;
  97.          one          = 5;
  98.          zero         = 1;
  99.       }
  100.  
  101.       max_horizontal = (image_header->image_length+50)/100;
  102.       max_vertical   = (image_header->image_width+50)/100;
  103.  
  104.       if(horizontal > max_horizontal) horizontal = max_horizontal;
  105.       if(vertical > max_vertical) vertical = max_vertical;
  106.       if(print == 1){
  107.          vertical   = 1;
  108.          horizontal = 1;
  109.       }
  110.  
  111.  
  112.  
  113.         /****************************************
  114.         *
  115.         *   If color transform wants histogram
  116.         *   equalization, then read in the
  117.         *   image arrays and calculate the
  118.         *   histogram.   Zero both the histogram
  119.         *   and the new_hist.  You will need the
  120.         *   new_hist if you want to display the
  121.         *   equalized hist.
  122.         *
  123.         *****************************************/
  124.  
  125.       if(color_transform[0] == 'H'){
  126.          count = 1;
  127.          zero_histogram(histogram);
  128.          zero_histogram(new_hist);
  129.          for(a=0; a<vertical; a++){
  130.             for(b=0; b<horizontal; b++){
  131.  
  132.                x = a*100;
  133.                y = b*100;
  134.  
  135.                printf("\nHT> Calculating histogram");
  136.                printf(" %d of %d",count,vertical*horizontal);
  137.                count++;
  138.  
  139.                read_tiff_image(file_name, in_image, il+y,
  140.                             ie+x, ll+y, le+x);
  141.                calculate_histogram(in_image, histogram);
  142.  
  143.             }  /* ends loop over b */
  144.          }  /* ends loop over a */
  145.       }  /* ends if display_mode == H */
  146.  
  147.  
  148.  
  149.  
  150.            /* set graphics mode */
  151.       if(print == 0)
  152.          _setvideomode(display_mode); /* MSC 6.0 */
  153.       else{
  154.          printf("\n\nHT> Calculating for printing ");
  155.          printf("\nHT> Counting from 0 to 99\n");
  156.       }
  157.  
  158.         /*********************************************
  159.         *
  160.         *   Loop over horizontal and vertical. Read
  161.         *   the image array and display it after
  162.         *   calculating the half tone values.
  163.         *
  164.         *
  165.         *   If you want to show the histogram AND
  166.         *   do not want to do hist equalization
  167.         *   then calculate the hist from the 
  168.         *   original image array.
  169.         *
  170.         *   If you want to do hist equalization
  171.         *   then calculate the new_hist AFTER
  172.         *   the image has been equalized.
  173.         *
  174.         *   We will equalize the histogram down
  175.         *   to half the original shades of gray
  176.         *   and will cut the threshold in half.
  177.         *
  178.         *****************************************/
  179.  
  180.  
  181.  
  182.       for(i=0; i<horizontal; i++){
  183.          for(j=0; j<vertical; j++){
  184.             read_tiff_image(file_name, in_image, il+i*100,
  185.                            ie+j*100, ll+i*100, le+j*100);
  186.  
  187.             if(   (show_hist == 1)  &&
  188.                   (color_transform[0] != 'H'))
  189.                calculate_histogram(in_image, histogram);
  190.  
  191.             if(color_transform[0] == 'H'){
  192.  
  193.                area = ((long)(vertical))*((long)(horizontal));
  194.                area = area*10000.0;
  195.                new_grays = image_colors/2;
  196.  
  197.                perform_histogram_equalization(in_image,
  198.                         histogram, new_grays, area);
  199.  
  200.                calculate_histogram(in_image, new_hist);
  201.  
  202.             }  /* ends if color_transform == S */
  203.  
  204.             if(color_transform[0] == 'H')
  205.                half_tone(in_image, threshold/2, eg, ep, i, j,
  206.                       one, zero, invert, print);
  207.  
  208.             else
  209.                half_tone(in_image, threshold, eg, ep, i, j,
  210.                       one, zero, invert, print);
  211.  
  212.          }  /* ends loop over j */
  213.       }  /*  ends loop over i */
  214.  
  215.  
  216.  
  217.          /***************************
  218.          *
  219.          *   if show_hist == 1 then
  220.          *   display the histogram
  221.          *   in the lower right hand
  222.          *   corner of screen
  223.          *
  224.          ****************************/
  225.  
  226.       if(  (show_hist == 1)   &&
  227.            (print == 0)){
  228.  
  229.          if(monitor_type[0] == 'V'){
  230.             y_offset   = 470;
  231.             x_offset   = 380;
  232.             line_color = 3;
  233.             data_color = 8;
  234.          }
  235.  
  236.          if(monitor_type[0] == 'E'){
  237.             y_offset   = 310;
  238.             x_offset   = 380;
  239.             line_color = 3;
  240.             data_color = 8;
  241.          }
  242.  
  243.          if(monitor_type[0] == 'M'){
  244.             y_offset   = 190;
  245.             x_offset   = 60;
  246.             line_color = 1;
  247.             data_color = 1;
  248.          }
  249.  
  250.          if(monitor_type[0] == 'C'){
  251.             y_offset   = 190;
  252.             x_offset   = 60;
  253.             line_color = 1;
  254.             data_color = 3;
  255.          }
  256.  
  257.          if(color_transform[0] == 'S')
  258.             display_histogram(histogram, x_offset,
  259.                    y_offset, line_color, data_color);
  260.  
  261.          if(color_transform[0] == 'H')
  262.             display_histogram(new_hist, x_offset,
  263.                    y_offset, line_color, data_color);
  264.  
  265.       }  /* ends if show_hist == 1 and print == 0 */
  266.  
  267.  
  268.  
  269.       if(print == 1) printf("\n\nHT> Hit ENTER to continue");
  270.       read_string(response);
  271.       clear_text_screen();
  272.  
  273. }
  274.  
  275.