home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_09_05 / 9n05125a < prev    next >
Text File  |  1991-03-18  |  9KB  |  300 lines

  1. /*****************************************************
  2. *   file c:\cips\display.c
  3. *
  4. *   Purpose:  These functions display images on
  5. *   a the monitor.
  6. *
  7. *       External Calls:
  8. *          cips.c - clear_text_screen
  9. *
  10. *       Modifications:
  11. *          17 June 1987 - created
  12. *          August 1990 - extension modifications for use
  13. *              in the C Image Processing System.
  14. ********************************************************/
  15.  
  16. #include "d:\cips\cips.h"
  17.  
  18. /***************************
  19.  *   display_image(...
  20.  ****************************/
  21.  
  22. display_image(file_name, image, il, ie, ll, le,
  23.               image_header, monitor_type,
  24.               color_transform, invert,
  25.               image_colors, display_colors)
  26.    char    color_transform[],
  27.            file_name[],
  28.            monitor_type[];
  29.    int     display_colors,
  30.            image_colors,
  31.            invert,
  32.            il,
  33.            ie,
  34.            ll,
  35.            le;
  36.    short   image[ROWS][COLS];
  37.    struct  tiff_header_struct *image_header;
  38. {
  39.    char  channels[80],
  40.          response[80];
  41.  
  42.    int   a,
  43.          b,
  44.          c,
  45.          channel,
  46.          display_mode,
  47.          key,
  48.          horizontal,
  49.          max_horizontal,
  50.          max_vertical,
  51.          not_finished,
  52.          r,
  53.          vertical;
  54.  
  55.    unsigned int block,
  56.                 color,
  57.                 i,
  58.                 j,
  59.                 x,
  60.                 y;
  61.  
  62.  
  63.    not_finished = 1;
  64.    while(not_finished){
  65.  
  66.  
  67.       if(display_colors == 16){
  68.          if(monitor_type[0] == 'V'){
  69.             horizontal   = 4;
  70.             vertical     = 6;
  71.             display_mode = _VRES16COLOR; /* MSC 6.0 */
  72.          }  /* ends if V */
  73.          if(monitor_type[0] == 'E'){
  74.             horizontal   = 3;
  75.             vertical     = 6;
  76.             display_mode = _ERESCOLOR; /* MSC 6.0 */
  77.          }  /* ends if E */
  78.  
  79.       }  /* ends if colors == 16 */
  80.  
  81.       else{
  82.          horizontal   = 2;
  83.          vertical     = 2;
  84.          display_mode = _MAXCOLORMODE; /* MSC 6.0 */
  85.       }
  86.  
  87.       max_horizontal = (image_header->image_length+50)/100;
  88.       max_vertical   = (image_header->image_width+50)/100;
  89.  
  90.       if(horizontal > max_horizontal) horizontal = max_horizontal;
  91.       if(vertical > max_vertical) vertical = max_vertical;
  92.  
  93.  
  94.         /* set graphics mode */
  95.  
  96.    _setvideomode(display_mode); /* MSC 6.0 */
  97.    if(display_colors == 16) map_16_shades_of_gray(display_mode);
  98.  
  99.    /****************************************
  100.    *   Loop over this size and
  101.    *   read and display ROWSxCOLS arrays.
  102.    *****************************************/
  103.  
  104.       for(a=0; a<vertical; a++){
  105.          for(b=0; b<horizontal; b++){
  106.             x = a*100;
  107.             y = b*100;
  108.             read_tiff_image(file_name, image, il+y, 
  109.                             ie+x, ll+y, le+x);
  110.             display_image_portion(image, x, y, display_colors, 
  111.                                   image_colors, invert);
  112.          }        /* ends loop over b */
  113.       }        /* ends loop over a */
  114.  
  115.       read_string(response);
  116.       printf("\nEnter 0 to quit 1 to do again");
  117.       get_integer(¬_finished);
  118.  
  119.           /* set display back to text mode */
  120.       clear_text_screen();
  121.  
  122.    }  /* ends while not_finished  */
  123. }  /* ends main  */
  124.  
  125.  
  126.  /**********************************
  127.  *   display_menu_for_display_image(
  128.  ************************************/
  129.  
  130. display_menu_for_display_image(image_colors,
  131.              display_colors, invert,
  132.              color_transform, monitor_type)
  133.    char color_transform[], monitor_type[];
  134.    int  *invert, *image_colors, *display_colors;
  135. {
  136.    char response[80];
  137.    int  int_response, not_finished, r;
  138.  
  139.    not_finished = 1;
  140.    while(not_finished){
  141.       printf("\n\nDISPLAY> Enter choice (0 for no change) ");
  142.       printf("\nDISPLAY> 1. Invert is %d (1=on 0=off)", *invert);
  143.       printf("\nDISPLAY> 2. Color Transform-- %s", 
  144.              color_transform);
  145.       printf("\nDISPLAY> 3. Input image has %d colors", 
  146.              *image_colors);
  147.       printf("\nDISPLAY> 4. Display will show %d colors", 
  148.              *display_colors);
  149.       printf("\nDISPLAY> 5. Monitor type is %s",
  150.              monitor_type);
  151.       printf("\nDISPLAY> _\b");
  152.       get_integer(&r);
  153.  
  154.       if(r == 0){
  155.          not_finished = 0;
  156.       }
  157.  
  158.       if(r == 1){
  159.          printf(
  160.             "\nDISPLAY> Enter 1 for invert on 0 for invert off");
  161.          printf("\nDISPLAY> ___");
  162.          get_integer(&int_response);
  163.          *invert = int_response;
  164.       }  /* ends if r == 1 */
  165.  
  166.       if(r == 2){
  167.          printf("\nDISPLAY> Enter the new color transform mode ");
  168.          printf(
  169.              "\nDISPLAY> (S) Straight mode   (M) Modified mode");
  170.          printf("\nDISPLAY> _\b");
  171.          read_string(response);
  172.          if((response[0] == 'S') ||
  173.             (response[0] == 's'))
  174.                strcpy(color_transform, "Straight mode");
  175.          else
  176.                strcpy(color_transform, "Modified mode");
  177.       }  /* ends if r == 2  */
  178.  
  179.       if(r == 3){
  180.          printf(
  181.          "\nDISPLAY> Enter the number of colors in the input image"
  182.           );
  183.          printf("\nDISPLAY> ___");
  184.          get_integer(&int_response);
  185.          *image_colors = int_response;
  186.       }  /* ends if r == 3 */
  187.  
  188.       if(r == 4){
  189.          printf( 
  190.           "\nDISPLAY> Enter the number of colors for the display");
  191.          printf("\nDISPLAY> ___");
  192.          get_integer(&int_response);
  193.          *display_colors = int_response;
  194.       }  /* ends if r == 4 */
  195.  
  196.       if(r == 5){
  197.          printf("\nDISPLAY> Enter the new monitor type");
  198.          printf(
  199.              "\nDISPLAY> (E) EGA     (V) VGA");
  200.          printf("\nDISPLAY> _\b");
  201.          read_string(response);
  202.          if((response[0] == 'E') ||
  203.             (response[0] == 'e'))
  204.                strcpy(monitor_type, "EGA");
  205.          else
  206.                strcpy(monitor_type, "VGA");
  207.       }  /* ends if r == 5  */
  208.  
  209.  
  210.    }  /* ends while not_finished  */
  211. }  /* ends display_menu  */
  212.  
  213.  
  214.  /********************************
  215.  *   display_image_portion(...
  216.  *********************************/
  217.  
  218. display_image_portion(image, x, y, display_colors, image_colors,
  219.                       invert)
  220.    int      invert, display_colors, image_colors;
  221.    short    image[ROWS][COLS];
  222.    unsigned int x, y;
  223. {
  224.    unsigned int color, i, j;
  225.  
  226.       if(invert == 1){
  227.          if(image_colors == 256){
  228.             for(i=0; i<ROWS; i++)
  229.                for(j=0; j<COLS; j++)
  230.                   image[i][j] = 255 - image[i][j];
  231.          }  /* ends if image_colors = 256 */
  232.  
  233.          if(image_colors == 16){
  234.             for(i=0; i<ROWS; i++)
  235.                for(j=0; j<COLS; j++)
  236.                   image[i][j] = 15 - image[i][j];
  237.          }  /* ends if image_colors = 16 */
  238.  
  239.       }  /* ends if invert == 1 */
  240.  
  241.  
  242.       for(i=0; i<ROWS; i++){
  243.          for(j=0; j<COLS; j++){
  244.  
  245.             if( (display_colors == 16) &&
  246.                 (image_colors  == 256))
  247.                color = image[i][j]/16;
  248.             if( (display_colors == 16) &&
  249.                 (image_colors  == 16))
  250.                color = image[i][j];
  251.             if( (display_colors == 256) &&
  252.                 (image_colors  == 256))
  253.                color = image[i][j];
  254.             if( (display_colors == 256) &&
  255.                 (image_colors  == 16))
  256.                color = image[i][j]*16;
  257.  
  258.             _setcolor(color);    /* MSC 6.0 statements */
  259.             _setpixel(j+x, i+y);
  260.  
  261.             /*my_set_pixel(j+x, i+y, color);*/
  262.          }  /* ends loop over j  */
  263.       }     /* ends loop over i  */
  264.  
  265. }  /* ends display_image_portion  */
  266.  
  267.  
  268. /**********************************************
  269. *   map_16_shades_of_gray(...
  270. *
  271. *   This function maps 16 shades of gray into
  272. *   the first 16 color indices.  This allows
  273. *   you to display a true "black and white"
  274. *   image on a color monitor.
  275. *********************************************/
  276.  
  277. map_16_shades_of_gray(display_mode)
  278.    int display_mode;
  279. {
  280.    /* all MSC 6.0 statements */
  281. _setvideomode(display_mode);
  282. _remappalette(0,  0x000000L);
  283. _remappalette(1,  0x040404L);
  284. _remappalette(2,  0x080808L);
  285. _remappalette(3,  0x0c0c0cL);
  286. _remappalette(4,  0x101010L);
  287. _remappalette(5,  0x141414L);
  288. _remappalette(6,  0x181818L);
  289. _remappalette(7,  0x1c1c1cL);
  290. _remappalette(8,  0x202020L);
  291. _remappalette(9,  0x242424L);
  292. _remappalette(10, 0x282828L);
  293. _remappalette(11, 0x2c2c2cL);
  294. _remappalette(12, 0x303030L);
  295. _remappalette(13, 0x343434L);
  296. _remappalette(14, 0x383838L);
  297. _remappalette(15, 0x3f3f3fL);
  298. }
  299.  
  300.