home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_06 / phillips.exe / CIPS.C < prev    next >
Text File  |  1990-09-08  |  9KB  |  294 lines

  1.  
  2.        /***********************************************
  3.        *
  4.        *       file d:\cips\cips.c
  5.        *
  6.        *       Functions: This file contains
  7.        *          main
  8.        *          clear_text_screen
  9.        *          show_menu
  10.        *          show_image
  11.        *
  12.        *       Purpose:
  13.        *          This file contains the main calling
  14.        *          routine in the C Image Processing System.
  15.        *
  16.        *       External Calls:
  17.        *          numcvrt.c - get_integer
  18.        *          gin.c - get_image_name
  19.        *          rtiff.c - read_tiff_image
  20.        *          tiff.c - read_tiff_header
  21.        *          rstring.c - read_string
  22.        *          display.c - display_image
  23.        *                      display_menu_for_display_image
  24.        *          pi.c - print_image
  25.        *          ht.c - display_using_halftoning
  26.        *                 get_threshold_value
  27.        *          djet.c - print_graphics_image
  28.        *                   get_graphics_caption
  29.        *          hist.c - display_menu_for_histogram
  30.        *                   calculate_area_histogram
  31.        *                   print_histogram
  32.        *                   show_histogram
  33.        *
  34.        *       Modifications:
  35.        *          26 June 1990 - created
  36.        *
  37.        *************************************************/
  38.  
  39. #include "d:\cips\cips.h"
  40.  
  41.  
  42.  
  43. short the_image[ROWS][COLS];
  44. short out_image[ROWS][COLS];
  45.  
  46. main()
  47. {
  48.  
  49.    char caption[80],
  50.         color_transform[80],
  51.         monitor_type[80],
  52.         name[80],
  53.         name2[80],
  54.         rep[80];
  55.  
  56.    int  color,
  57.         display_colors,
  58.         file_d,
  59.         first_element,
  60.         first_line,
  61.         horizontal,
  62.         i,
  63.         ie,
  64.         il,
  65.         image_colors,
  66.         invert,
  67.         j,
  68.         le,
  69.         ll,
  70.         not_finished,
  71.         print,
  72.         response,
  73.         show_hist,
  74.         threshold,
  75.         vertical;
  76.  
  77.    long     mean_of_pixels;
  78.    unsigned long histogram[256];
  79.    struct   tiff_header_struct image_header;
  80.  
  81.    clear_text_screen();
  82.  
  83.    not_finished   =  1;
  84.    response       = 99;
  85.  
  86.    il             = 1;
  87.    ie             = 1;
  88.    ll             = ROWS+1;
  89.    le             = COLS+1;
  90.  
  91.    print          =   0;
  92.    threshold      = 128;
  93.    display_colors = 16;
  94.    image_colors   = 16;
  95.    invert         =  0;
  96.    vertical       =  3;
  97.    horizontal     =  3;
  98.    show_hist      =  0;
  99.    strcpy(color_transform, "Straight mode");
  100.    strcpy(monitor_type, "VGA");
  101.  
  102.  
  103.    strcpy(name, "d:/pix/adam256.tif");
  104.  
  105.      while(not_finished){
  106.  
  107.         show_menu();
  108.  
  109.         get_integer(&response);
  110.  
  111.         switch (response){
  112.  
  113.         case 1:/* display image header */
  114.          get_image_name(name);
  115.          read_tiff_header(name, &image_header);
  116.          printf("\n\nCIPS> The image header is:");
  117.          printf("\n\t\twidth=%ld length=%ld  start=%ld  bits=%ld",
  118.               image_header.image_width,
  119.               image_header.image_length,
  120.               image_header.strip_offset,
  121.               image_header.bits_per_pixel);
  122.          printf("\nCIPS> Hit Enter to continue");
  123.          read_string(rep);
  124.          break;
  125.  
  126.         case 2:/* display image numbers */
  127.          get_image_name(name);
  128.          get_parameters(&il, &ie, &ll, &le);
  129.          read_tiff_image(name, the_image, il, ie, ll, le);
  130.          show_image(the_image, il, ie);
  131.          break;
  132.  
  133.         case 3:   /* print image numbers */
  134.          get_image_name(name);
  135.          get_parameters(&il, &ie, &ll, &le);
  136.          read_tiff_image(name, the_image, il, ie, ll, le);
  137.          print_image(the_image, name, 1, 1, 1, 100, 18,
  138.                      il, ie);
  139.          break;
  140.  
  141.         case 4:   /* display image */
  142.          get_image_name(name);
  143.          read_tiff_header(name, &image_header);
  144.          get_parameters(&il, &ie, &ll, &le);
  145.          display_menu_for_display_image(&image_colors,
  146.                    &display_colors, &invert,
  147.                    color_transform, monitor_type,
  148.                    &show_hist);
  149.          display_image(name, the_image, il, ie,
  150.                    ll, le, &image_header, monitor_type,
  151.                    color_transform, invert,
  152.                    image_colors, display_colors, show_hist);
  153.          break;
  154.  
  155.         case 5:   /* display image using halftoning */
  156.          get_image_name(name);
  157.          read_tiff_header(name, &image_header);
  158.          get_parameters(&il, &ie, &ll, &le);
  159.          display_menu_for_display_image(&image_colors,
  160.                    &display_colors, &invert,
  161.                    color_transform, monitor_type,
  162.                    &show_hist);
  163.          get_threshold_value(&threshold, &print);
  164.          display_using_halftoning(the_image, name,
  165.                    il, ie, ll, le, threshold,
  166.                    invert, image_colors, &image_header,
  167.                    monitor_type, print, show_hist,
  168.                    color_transform);
  169.          break;
  170.  
  171.         case 6:   /* print graphics image */
  172.          get_image_name(name);
  173.          read_tiff_header(name, &image_header);
  174.          get_parameters(&il, &ie, &ll, &le);
  175.          display_menu_for_display_image(&image_colors,
  176.                    &display_colors, &invert,
  177.                    color_transform, monitor_type,
  178.                    &show_hist);
  179.          get_graphics_caption(caption);
  180.          print_graphics_image(the_image, out_image, name,
  181.                    il, ie, ll, le, image_colors,
  182.                    invert, caption, show_hist,
  183.                    color_transform);
  184.          break;
  185.         case 7:   /* print or display histogram numbers */
  186.          get_image_name(name);
  187.          read_tiff_header(name, &image_header);
  188.          get_parameters(&il, &ie, &ll, &le);
  189.          display_menu_for_histogram(&print, &vertical,
  190.                    &horizontal);
  191.          calculate_area_histogram(histogram, vertical,
  192.                    horizontal, the_image, name,
  193.                    il, ie, ll, le);
  194.          if(print == 0)
  195.             show_histogram(histogram);
  196.          if(print == 1)
  197.             print_histogram(histogram, name);
  198.          break;
  199.  
  200.         case 20:  /* exit system */
  201.          not_finished = 0;
  202.          break;
  203.  
  204.         default:
  205.          printf("\nCould not understand response, try again");
  206.          break;
  207.  
  208.      }               /* ends switch response          */
  209.   }               /* ends while not finished */
  210. }               /* ends main                  */
  211.  
  212.  
  213.  
  214.  
  215.    /******************************************************
  216.    *
  217.    *   clear_text_screen()
  218.    *
  219.    *   This calls Microsoft C functions to clear the text
  220.    *   screen and set a blue background with gray text.
  221.    *
  222.    *******************************************************/
  223.  
  224.  
  225. clear_text_screen()
  226. {
  227.    _setvideomode(_TEXTC80);      /* MSC 6.0 statements */
  228.    _setbkcolor(1);
  229.    _settextcolor(7);
  230.    _clearscreen(_GCLEARSCREEN);
  231. }  /* ends clear_text_screen */
  232.  
  233.  
  234.  
  235.  
  236.    /******************************************************
  237.    *
  238.    *   show_image(...     
  239.    *
  240.    *   This function displays the image numbers on the 
  241.    *   screen as text.  It displays 20 rows  with 18   
  242.    *   columns each.
  243.    *
  244.    *******************************************************/
  245.  
  246. show_image(image, il, ie)
  247.    int   il, ie;
  248.    short image[ROWS][COLS];
  249. {
  250.    int i, j;
  251.    printf("\n   ");
  252.    for(i=0; i<18; i++)
  253.       printf("-%3d", i+ie);
  254.  
  255.    for(i=0; i<20; i++){
  256.       printf("\n%2d>", i+il);
  257.       for(j=0; j<18; j++)
  258.          printf("-%3d", image[i][j]);
  259.    }
  260.  
  261.    printf("\nPress enter to continue");
  262.    get_integer(&i);
  263.  
  264. }  /* ends show_image  */
  265.  
  266.  
  267.  
  268.  
  269.  
  270.    /******************************************************
  271.    *
  272.    *   show_menu(..
  273.    *
  274.    *   This function displays the CIPS main menu.      
  275.    *
  276.    *******************************************************/
  277. show_menu()
  278. {
  279.  
  280.         printf("\n\n\nWelcome to CIPS");
  281.         printf("\nThe C Image Processing System"); 
  282.         printf("\nThese are you choices:\n");
  283.         printf("\n\t1.  Display image header");
  284.         printf("\n\t2.  Show image numbers");
  285.         printf("\n\t3.  Print image numbers");
  286.         printf("\n\t4.  Display image (VGA & EGA only)");
  287.         printf("\n\t5.  Display or print image using halftoning");
  288.         printf("\n\t6.  Print graphics image using dithering");
  289.         printf("\n\t7.  Print or display histogram numbers");
  290.         printf("\n\t20. Exit system");
  291.         printf("\n\nEnter choice _\b");
  292.  
  293. }    /* ends show_menu */
  294.