home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_11 / cips911.exe / CIPS.C < prev    next >
C/C++ Source or Header  |  1991-04-06  |  10KB  |  329 lines

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