home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_10_01 / cips1001.exe / CIPS.C next >
Text File  |  1991-04-20  |  11KB  |  368 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.        *          edge2.c - homogeneity
  39.        *                    difference_edge
  40.        *                    contrast_edge
  41.        *          edge3.c - gaussian_edge
  42.        *                    enhance_edges
  43.        *
  44.        *       Modifications:
  45.        *          26 June 1990 - created
  46.        *
  47.        *************************************************/
  48.  
  49. #include "d:\cips\cips.h"
  50.  
  51.  
  52. short the_image[ROWS][COLS];
  53. short out_image[ROWS][COLS];
  54.  
  55. main()
  56. {
  57.  
  58.    char caption[80],
  59.         color_transform[80],
  60.         monitor_type[80],
  61.         name[80],
  62.         name2[80],
  63.         rep[80];
  64.  
  65.  
  66.    int  color,
  67.         detect_threshold,
  68.         detect_type,
  69.         display_colors,
  70.         file_d,
  71.         first_element,
  72.         first_line,
  73.         high,
  74.         horizontal,
  75.         i,
  76.         ie,
  77.         il,
  78.         image_colors,
  79.         invert,
  80.         j,
  81.         le,
  82.         ll,
  83.         not_finished,
  84.         print,
  85.         response,
  86.         show_hist,
  87.         size,
  88.         threshold,
  89.         vertical;
  90.  
  91.    long     mean_of_pixels;
  92.    unsigned long histogram[256];
  93.    struct   tiff_header_struct image_header;
  94.  
  95.  
  96.    clear_text_screen();
  97.  
  98.  
  99.    not_finished   =  1;
  100.    response       = 99;
  101.  
  102.    il             = 1;
  103.    ie             = 1;
  104.    ll             = ROWS+1;
  105.    le             = COLS+1;
  106.  
  107.    print          =   0;
  108.    threshold      = 128;
  109.    detect_type    =   1;
  110.    display_colors =  16;
  111.    image_colors   = 256;
  112.    invert         =   0;
  113.    vertical       =   3;
  114.    horizontal     =   3;
  115.    show_hist      =   0;
  116.    size           =   7;
  117.    high           = 100;
  118.    detect_threshold = 1;
  119.    strcpy(color_transform, "Straight mode");
  120.    strcpy(monitor_type, "VGA");
  121.  
  122.  
  123.    strcpy(name,  "d:/pix/adam256.tif");
  124.    strcpy(name2, "d:/pix/output.tif");
  125.  
  126.      while(not_finished){
  127.  
  128.         show_menu();
  129.  
  130.         get_integer(&response);
  131.  
  132.         switch (response){
  133.  
  134.         case 1:/* display image header */
  135.          get_image_name(name);
  136.          read_tiff_header(name, &image_header);
  137.          printf("\n\nCIPS> The image header is:");
  138.          printf("\n\t\twidth=%ld length=%ld  start=%ld  bits=%ld",
  139.               image_header.image_width,
  140.               image_header.image_length,
  141.               image_header.strip_offset,
  142.               image_header.bits_per_pixel);
  143.          printf("\nCIPS> Hit Enter to continue");
  144.          read_string(rep);
  145.         break;
  146.  
  147.         case 2:/* display 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.          show_image(the_image, il, ie);
  152.          break;
  153.  
  154.         case 3:   /* print image numbers */
  155.          get_image_name(name);
  156.          get_parameters(&il, &ie, &ll, &le);
  157.          read_tiff_image(name, the_image, il, ie, ll, le);
  158.          print_image(the_image, name, 1, 1, 1, 100, 18,
  159.                      il, ie);
  160.         break;
  161.  
  162.         case 4:   /* display image */
  163.          get_image_name(name);
  164.          read_tiff_header(name, &image_header);
  165.          get_parameters(&il, &ie, &ll, &le);
  166.          display_menu_for_display_image(&image_colors,
  167.                    &display_colors, &invert,
  168.                    color_transform, monitor_type,
  169.                    &show_hist);
  170.          display_image(name, the_image, il, ie,
  171.                    ll, le, &image_header, monitor_type,
  172.                    color_transform, invert,
  173.                    image_colors, display_colors, show_hist);
  174.         break;
  175.  
  176.         case 5:   /* display image using halftoning */
  177.          get_image_name(name);
  178.          read_tiff_header(name, &image_header);
  179.          get_parameters(&il, &ie, &ll, &le);
  180.          display_menu_for_display_image(&image_colors,
  181.                    &display_colors, &invert,
  182.                    color_transform, monitor_type,
  183.                    &show_hist);
  184.          get_threshold_value(&threshold, &print);
  185.          display_using_halftoning(the_image, name,
  186.                    il, ie, ll, le, threshold,
  187.                    invert, image_colors, &image_header,
  188.                    monitor_type, print, show_hist,
  189.                    color_transform);
  190.         break;
  191.  
  192.         case 6:   /* print graphics image */
  193.          get_image_name(name);
  194.          read_tiff_header(name, &image_header);
  195.          get_parameters(&il, &ie, &ll, &le);
  196.          display_menu_for_display_image(&image_colors,
  197.                    &display_colors, &invert,
  198.                    color_transform, monitor_type,
  199.                    &show_hist);
  200.          get_graphics_caption(caption);
  201.          print_graphics_image(the_image, out_image, name,
  202.                    il, ie, ll, le, image_colors,
  203.                    invert, caption, show_hist,
  204.                    color_transform);
  205.         break;
  206.  
  207.         case 7:   /* print or display histogram numbers */
  208.          get_image_name(name);
  209.          read_tiff_header(name, &image_header);
  210.          get_parameters(&il, &ie, &ll, &le);
  211.          display_menu_for_histogram(&print, &vertical,
  212.                    &horizontal);
  213.          calculate_area_histogram(histogram, vertical,
  214.                    horizontal, the_image, name,
  215.                    il, ie, ll, le);
  216.          if(print == 0)
  217.             show_histogram(histogram);
  218.          if(print == 1)
  219.             print_histogram(histogram, name);
  220.         break;
  221.  
  222.         case 8:  /* perform edge detection */
  223.            printf("\nCIPS> Enter input image name\n");
  224.            get_image_name(name);
  225.            printf("\nCIPS> Enter output image name\n");
  226.            get_image_name(name2);
  227.            get_parameters(&il, &ie, &ll, &le);
  228.            get_edge_options(&detect_type, &detect_threshold,
  229.                             &high, &size);
  230.            if(detect_type == 1  ||
  231.               detect_type == 2  ||
  232.               detect_type == 3)
  233.               detect_edges(name, name2, the_image, out_image,
  234.                            il, ie, ll, le, detect_type,
  235.                            detect_threshold, high);
  236.            if(detect_type == 4)
  237.               quick_edge(name, name2, the_image, out_image,
  238.                          il, ie, ll, le, detect_threshold,
  239.                          high);
  240.            if(detect_type == 5)
  241.                 homogeneity(name, name2, the_image, out_image,
  242.                          il, ie, ll, le, detect_threshold,
  243.                          high);
  244.            if(detect_type == 6)
  245.                 difference_edge(name, name2, the_image, out_image,
  246.                               il, ie, ll, le, detect_threshold,
  247.                               high);
  248.            if(detect_type == 7)
  249.                 contrast_edge(name, name2, the_image, out_image,
  250.                             il, ie, ll, le, detect_threshold,
  251.                             high);
  252.            if(detect_type == 8)
  253.                 gaussian_edge(name, name2, the_image, out_image,
  254.                              il, ie, ll, le, size, 
  255.                             detect_threshold, high);
  256.          break;
  257.  
  258.         case 9:
  259.            printf("\nCIPS> Enter input image name\n");
  260.            get_image_name(name);
  261.            printf("\nCIPS> Enter output image name\n");
  262.            get_image_name(name2);
  263.            get_parameters(&il, &ie, &ll, &le);
  264.            printf("\nCIPS> Enter high threshold parameter");
  265.            printf(" \n\t___\b\b\b");
  266.            get_integer(&high);
  267.            enhance_edges(name, name2, the_image, out_image,
  268.                   il, ie, ll, le, high);
  269.          break;
  270.  
  271.  
  272.         case 20:  /* exit system */
  273.          not_finished = 0;
  274.         break;
  275.  
  276.         default:
  277.          printf("\nCould not understand response, try again");
  278.         break;
  279.  
  280.      }               /* ends switch response          */
  281.   }               /* ends while not finished */
  282. }               /* ends main                  */
  283.  
  284.  
  285.  
  286.  
  287.    /******************************************************
  288.    *
  289.    *   clear_text_screen()
  290.    *
  291.    *   This calls Microsoft C functions to clear the text
  292.    *   screen and set a blue background with gray text.
  293.    *
  294.    *******************************************************/
  295.  
  296.  
  297. clear_text_screen()
  298. {
  299.    _setvideomode(_TEXTC80);      /* MSC 6.0 statements */
  300.    _setbkcolor(1);
  301.    _settextcolor(7);
  302.    _clearscreen(_GCLEARSCREEN);
  303. }  /* ends clear_text_screen */
  304.  
  305.  
  306.  
  307.  
  308.    /******************************************************
  309.    *
  310.    *   show_image(...
  311.    *
  312.    *   This function displays the image numbers on the
  313.    *   screen as text.  It displays 20 rows  with 18
  314.    *   columns each.
  315.    *
  316.    *******************************************************/
  317.  
  318. show_image(image, il, ie)
  319.    int   il, ie;
  320.    short image[ROWS][COLS];
  321. {
  322.    int i, j;
  323.    printf("\n   ");
  324.    for(i=0; i<18; i++)
  325.       printf("-%3d", i+ie);
  326.  
  327.    for(i=0; i<20; i++){
  328.       printf("\n%2d>", i+il);
  329.       for(j=0; j<18; j++)
  330.          printf("-%3d", image[i][j]);
  331.    }
  332.  
  333.    printf("\nPress enter to continue");
  334.    get_integer(&i);
  335.  
  336. }  /* ends show_image  */
  337.  
  338.  
  339.  
  340.  
  341.  
  342.    /******************************************************
  343.    *
  344.    *   show_menu(..
  345.    *
  346.    *   This function displays the CIPS main menu.
  347.    *
  348.    *******************************************************/
  349. show_menu()
  350. {
  351.  
  352.         printf("\n\n\nWelcome to CIPS");
  353.         printf("\nThe C Image Processing System");
  354.         printf("\nThese are you choices:\n");
  355.         printf("\n\t1.  Display image header");
  356.         printf("\n\t2.  Show image numbers");
  357.         printf("\n\t3.  Print image numbers");
  358.         printf("\n\t4.  Display image (VGA & EGA only)");
  359.         printf("\n\t5.  Display or print image using halftoning");
  360.         printf("\n\t6.  Print graphics image using dithering");
  361.         printf("\n\t7.  Print or display histogram numbers");
  362.         printf("\n\t8.  Perform edge detection");
  363.         printf("\n\t9.  Perform edge enhancement");
  364.         printf("\n\t20. Exit system");
  365.         printf("\n\nEnter choice _\b");
  366.  
  367. }    /* ends show_menu */
  368.