home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / t / tiff_11b.zip / TIF_DEMO.C < prev    next >
C/C++ Source or Header  |  1992-12-23  |  14KB  |  403 lines

  1. /*.............................. TIF_DEMO.C ................. 12-23-92 .....*/
  2. /* This program demonstrates the use of the TIFF reading and display        */
  3. /* capabilities of the VSA256 Version 1.1b Graphics Library and the         */
  4. /* TIFF256 Graphics Library Extensions Version 1.0                          */
  5. /*                                                                          */
  6. /* TO RUN:  - Enter VESA video mode                                         */
  7. /*          - Hit any key to continue or ESC to exit program                */
  8. /*          - Enter x,y image origin                                        */
  9. /*          - Enter full TIFF file name including path and extension        */
  10. /*          - Image is now drawn                                            */
  11. /*          - Hit any key to repeat sequence or ESC to exit program         */
  12. /*                                                                          */
  13. /* NOTE: Sometimes your input is not visible, depending on the Color Look   */
  14. /*       Up Table that is active due to last image ploted.  Keep typing,    */
  15. /*       your input will be accepted anyway.                                */
  16. /*..........................................................................*/
  17.  
  18. #include <io.h>             /* Required to support TIFF256 Graphics Library */
  19. #include <stdio.h>          /* Required to support TIFF256 Graphics Library */
  20. #include <fcntl.h>          /* Required to support TIFF256 Graphics Library */
  21. #include<math.h>
  22. #include<limits.h>
  23.  
  24. #include "tiff.h"           /* Required to support TIFF256 Graphics Library */
  25. #include "vsa.h"            /* Required to support VSA256 Graphics Library  */
  26.  
  27. #ifndef _MSC_VER
  28. /*.....                This is line for Borland C Only !               .....*/
  29. extern unsigned _stklen = 10000;
  30. #endif
  31.  
  32. void main()
  33. {
  34.     int a,b,r0,c0,bug,i;
  35.     unsigned vmode,xx,yy,x0,y0,ya;
  36.     char filename[100],key;
  37.     ya = 4;
  38. /*..........................................................................*/
  39. /*               Initialize video mode and VSA256 environment.              */
  40. /*               Valid modes are: 100h, 101h, 103h, and 105h.               */
  41. /*..........................................................................*/
  42.     bug = 0;
  43.     printf("\n");
  44.     printf("Input VESA standard Video Mode (hex)\n");
  45.     printf("(100, 101, 103, or 105): ");
  46.     scanf("%x",&vmode);
  47.     if(vmode == 0x666)
  48.         {
  49.             printf("Welcome to the Trident Bug Patch for Video Mode 103\n");
  50.             printf("Please enter Character Height in pixels (Try 16): ");
  51.             scanf("%d",&bug);
  52.             vmode = 0x103;
  53.         }
  54.     if((i = vsa_init(vmode)) != 0)
  55.         {
  56.             printf("Error Initializing Requested Video Mode!\n");
  57.             if(i==1) printf("  - Did You Load Correct VESA Driver (TSR) ??\n");
  58.             if(i==2) printf("  - VESA BIOS Extensions (Driver) Not Loaded !!\n");
  59.             if(i==3) printf("  - Requested Video Mode Not Supported by this Card!\n");
  60.             if(i==4) printf("  - Mode Not an SVGA Mode Supported by this Card!\n");
  61.             if(i==5) printf("  - VESA Driver Not Returning Mode Information!\n");
  62.             if(i==6) printf("  - Text I/O Not Supported by your VESA BIOS TSR!\n");
  63.             return;
  64.         }
  65.     if(bug != 0)
  66.         YCharSize = bug;
  67.     xx = XResolution;
  68.     yy = YResolution;
  69.     vsa_set_text_cursor_mode(1);
  70.     r0 = 0.85*YCharResolution;
  71.     c0 = 0.5*XCharResolution - 17;
  72. /*..........................................................................*/
  73. /*             Draw color look up table at bottom of screen.                */
  74. /*..........................................................................*/
  75.     rainbow_lut();
  76.     tf_set_prime_colors();
  77. HERE:
  78.     a = .125*xx;
  79.     b = .91*yy;
  80.     color_bar(a,b);
  81. /*..........................................................................*/
  82. /*                   Draw Prime Colors at screen right.                     */
  83. /*..........................................................................*/
  84.     a = xx - 11*XCharSize;
  85.     b = ya*YCharSize;
  86.     prime_list(a,b);
  87. /*..........................................................................*/
  88. /*                          Draw a banner                                   */
  89. /*..........................................................................*/
  90.     banner(ya);
  91. /*..........................................................................*/
  92. /*                         Outline Screen                                   */
  93. /*..........................................................................*/
  94.     vsa_set_color(TF_Red);
  95.     vsa_move_to(0,0);
  96.     vsa_rect(xx-1,yy-1);
  97.     vsa_move_to(1,1);
  98.     vsa_rect(xx-2,yy-2);
  99. /*..........................................................................*/
  100. /*         Wait for any key to continue; if ESC key, quit program.          */
  101. /*..........................................................................*/
  102.     vsa_write_string(r0,c0,TF_Yellow,
  103.                                      "Press ESC to exit, Any other key to continue ...   ");
  104.     key = getch();
  105.     if(key == 27)
  106.         goto BAIL;
  107. /*..........................................................................*/
  108. /*                   Get picture start coordinates.                         */
  109. /*..........................................................................*/
  110.     vsa_set_text_color(TF_Red);
  111.     vsa_set_text_cursor(r0,c0);
  112.     vsa_write_string_alt("                                                   ");
  113.     vsa_set_text_cursor(r0,c0);
  114.     vsa_write_string_alt("Input picture origin (x0,y0): ");
  115.     scanf("%d,%d",&x0,&y0);
  116.     x0 += 5;
  117.     y0 += ya*YCharSize+4;
  118. /*..........................................................................*/
  119. /*                            Open TIFF File.                               */
  120. /*..........................................................................*/
  121. FILENAME:
  122.     vsa_set_text_color(TF_Green);
  123.     vsa_set_text_cursor(r0,c0);
  124.     vsa_write_string_alt("                                                   ");
  125.     vsa_set_text_cursor(r0,c0);
  126.     vsa_write_string_alt("Input full Filename: ");
  127.     scanf("%s",filename);
  128.   if(tf_open_file(filename) == -1)
  129.         goto FILENAME;
  130. /*..........................................................................*/
  131. /*                      Get TIFF File information.                          */
  132. /*..........................................................................*/
  133.     if(tf_get_file_info() == 1)
  134.         {
  135.             printf("Error\n");
  136.             return;
  137.         }
  138. /*..........................................................................*/
  139. /*  Prior to reading the image information, set defaults for all globals.   */
  140. /*..........................................................................*/
  141.     tf_set_defaults();
  142. /*..........................................................................*/
  143. /* Read image information.  Globals are set, pointers to image data are     */
  144. /* extracted.                                                               */
  145. /*..........................................................................*/
  146.     if(tf_read_ifd() == 1)
  147.         goto NOTSUPPORTED;
  148. /*..........................................................................*/
  149. /*                 Display TIFF image starting at (x0,y0).                  */
  150. /*..........................................................................*/
  151.     tf_display_image(x0,y0);
  152. /*..........................................................................*/
  153. /*                 Restore Prime Color Values.                              */
  154. /*..........................................................................*/
  155.     tf_set_prime_colors();
  156. /*..........................................................................*/
  157. /*                            Frame new image.                              */
  158. /*..........................................................................*/
  159.     vsa_set_color(TF_White);
  160.     vsa_move_to(x0-2,y0-2);
  161.     vsa_rect(x0+(unsigned)TF_ImageWidth+1,y0+(unsigned)TF_ImageLength+1);
  162.     vsa_set_color(TF_Black);
  163.     vsa_move_to(x0-1,y0-1);
  164.     vsa_rect(x0+(unsigned)TF_ImageWidth,y0+(unsigned)TF_ImageLength);
  165. /*..........................................................................*/
  166. /*                 Update Image Statistics                                  */
  167. /*..........................................................................*/
  168.     a = .70*xx;
  169.     b = .60*yy;
  170.     image_stats(a,b);
  171. /*..........................................................................*/
  172. /*                        Close opened TIFF file.                           */
  173. /*..........................................................................*/
  174. NOTSUPPORTED:
  175.     tf_close_file();
  176.     goto HERE;
  177. /*..........................................................................*/
  178. /*                       Restore text video mode and Bail Out.              */
  179. /*..........................................................................*/
  180. BAIL:
  181.     vsa_set_svga_mode(0x3);
  182.     tf_about();
  183.     return;                       /*.....            End main            .....*/
  184. }
  185.  
  186.  
  187. rainbow_lut()
  188. {
  189.     int i,start,count;
  190.     unsigned char color_array[768];
  191.     for(i=0;i<224;i++)
  192.         {
  193.             color_array[3*i+2]=0;
  194.             color_array[3*i+1]=0;
  195.             color_array[3*i]=0;
  196.         }
  197. /*................................ RED .....................................*/
  198.     for(i=0;i<56;i++)
  199.         {
  200.                 color_array[3*i] = 63*sin((i*6.28)/112.0);
  201.         }
  202. /*............................... BLUE .....................................*/
  203.     for(i=0;i<126;i++)
  204.         {
  205.                 color_array[3*i+2] = 63*sin((i*6.28)/252.0);
  206.         }
  207. /*............................... GREEN ....................................*/
  208.     for(i=96;i<210;i++)
  209.         {
  210.                 color_array[3*i+1] = 63*sin(((i-90)*6.28)/252.0);
  211.         }
  212. /*................................ RED .....................................*/
  213.     for(i=140;i<224;i++)
  214.         {
  215.                 color_array[3*i]   = 63*sin(((i-140)*6.28)/280.0);
  216.         }
  217.     start = 32;
  218.     count = 224;
  219.     vsa_write_color_block(start,count,color_array);
  220.     return 0;
  221. }
  222.  
  223.  
  224. color_bar(x0,y0)
  225. int x0,y0;
  226. {
  227.     char text[100];
  228.     unsigned char row,col;
  229.     int i;
  230.     unsigned xx,yy,a,b;
  231.     float c;
  232.     xx = XResolution;
  233.     yy = YResolution;
  234. /*..........................................................................*/
  235. /*     Draw outline for color bar.                                          */
  236. /*..........................................................................*/
  237.     vsa_set_color(15);
  238.     vsa_move_to(x0-1,y0-1);
  239.     a = .75*xx;
  240.     b = .065*yy;
  241.     vsa_rect(x0+a+1,y0+b+1);
  242.     c = (float)a/256;
  243.     for(i=0;i<256;i++)
  244.         {
  245.             vsa_set_color((unsigned char)i);
  246.             vsa_move_to(x0+(unsigned)(i*c),y0);
  247.             vsa_rect_fill(x0+(unsigned)(c+i*c),y0+b);
  248.         }
  249.     return 0;
  250. }
  251.  
  252. prime_list(x0,y0)
  253. int x0,y0;
  254. {
  255.     unsigned char row,col;
  256.     int i;
  257.     unsigned xxx,yyy;
  258.  
  259.     xxx = x0 + 9*XCharSize;
  260.     yyy = y0;
  261.  
  262.     row = (y0)/YCharSize;
  263.     col = (x0)/XCharSize;
  264.     vsa_set_color(TF_Black);
  265.     vsa_write_string(row,col,TF_Black,"Black =  ");
  266.     vsa_move_to(xxx,yyy);
  267.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  268.  
  269.     row ++;
  270.   yyy += YCharSize;
  271.     vsa_set_color(TF_Red);
  272.     vsa_write_string(row,col,TF_Red,"Red =    ");
  273.     vsa_move_to(xxx,yyy);
  274.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  275.  
  276.     row ++;
  277.   yyy += YCharSize;
  278.     vsa_set_color(TF_Orange);
  279.     vsa_write_string(row,col,TF_Orange,"Orange = ");
  280.     vsa_move_to(xxx,yyy);
  281.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  282.  
  283.     row ++;
  284.   yyy += YCharSize;
  285.     vsa_set_color(TF_Yellow);
  286.     vsa_write_string(row,col,TF_Yellow,"Yellow = ");
  287.     vsa_move_to(xxx,yyy);
  288.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  289.  
  290.     row ++;
  291.   yyy += YCharSize;
  292.     vsa_set_color(TF_Green);
  293.     vsa_write_string(row,col,TF_Green,"Green =  ");
  294.     vsa_move_to(xxx,yyy);
  295.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  296.  
  297.     row ++;
  298.   yyy += YCharSize;
  299.     vsa_set_color(TF_Aqua);
  300.     vsa_write_string(row,col,TF_Aqua,"Aqua =   ");
  301.     vsa_move_to(xxx,yyy);
  302.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  303.  
  304.     row ++;
  305.   yyy += YCharSize;
  306.     vsa_set_color(TF_Blue);
  307.     vsa_write_string(row,col,TF_Blue,"Blue =   ");
  308.     vsa_move_to(xxx,yyy);
  309.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  310.  
  311.     row ++;
  312.   yyy += YCharSize;
  313.     vsa_set_color(TF_Violet);
  314.     vsa_write_string(row,col,TF_Violet,"Violet = ");
  315.     vsa_move_to(xxx,yyy);
  316.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  317.  
  318.     row ++;
  319.   yyy += YCharSize;
  320.     vsa_set_color(TF_White);
  321.     vsa_write_string(row,col,TF_White,"White =  ");
  322.     vsa_move_to(xxx,yyy);
  323.     vsa_rect_fill(xxx+XCharSize,yyy+YCharSize-4);
  324.  
  325.     return 0;
  326. }
  327.  
  328. image_stats()
  329. {
  330.     char text[100];
  331.     unsigned char row,col;
  332.  
  333.     row = 1;
  334.     col = 39;
  335.  
  336.     sprintf(text,"Width  = %d     ",TF_ImageWidth);
  337.     vsa_write_string(row,col,TF_White,text);
  338.     row++;
  339.     sprintf(text,"Length = %d     ",TF_ImageLength);
  340.     vsa_write_string(row,col,TF_White,text);
  341.     row++;
  342.     row = 1;
  343.     col = 55;
  344.     if(TF_PhotometricInterpretation < 2)
  345.         {
  346.             vsa_write_string(row,col,TF_White,"Color Model = Bilevel or");
  347.             row++;
  348.             vsa_write_string(row,col,TF_White,"              GrayScale ");
  349.             row++;
  350.             sprintf(text,"%d Bits Per Pixel        ",TF_BitsPerSample[0]);
  351.             vsa_write_string(row,col,TF_White,text);
  352.             row++;
  353.         }
  354.     if(TF_PhotometricInterpretation == 2)
  355.         {
  356.             vsa_write_string(row,col,TF_White,"Color Model = True Color");
  357.             row++;
  358.             vsa_write_string(row,col,TF_White,"24 Bits Per Pixel       ");
  359.             row++;
  360.             vsa_write_string(row,col,TF_White,"(8 bits each R,G,B)     ");
  361.             row++;
  362.         }
  363.     if(TF_PhotometricInterpretation == 3)
  364.         {
  365.             vsa_write_string(row,col,TF_White,"Color Model = Palette   ");
  366.             row++;
  367.             sprintf(text,"%d Bits Per Pixel        ",TF_BitsPerSample[0]);
  368.             vsa_write_string(row,col,TF_White,text);
  369.             row++;
  370.             vsa_write_string(row,col,TF_White,"                        ");
  371.             row++;
  372.         }
  373.     if(TF_PhotometricInterpretation > 3)
  374.         vsa_write_string(row,col,TF_White,"Color Model = Unknown   ");
  375.     return 0;
  376. }
  377.  
  378. banner(ya)
  379. unsigned ya;
  380. {
  381.     unsigned char row,col;
  382.     char text[100];
  383.     unsigned xx,yy;
  384.     xx = XResolution;
  385.     yy = YResolution;
  386.     vsa_move_to(0,0);
  387.     vsa_set_color(TF_Red);
  388.     vsa_rect(xx-1,ya*YCharSize);
  389.     vsa_move_to(38*XCharSize,0);
  390.     vsa_line_to(38*XCharSize,ya*YCharSize);
  391.     vsa_move_to(38*XCharSize+1,0);
  392.     vsa_line_to(38*XCharSize+1,ya*YCharSize);
  393.     row = 1;
  394.     col = 2;
  395.     sprintf(text,"TIFF256 GRAPHICS LIBRARY EXTENSIONS");
  396.     vsa_write_string(row,col,TF_Green,text);
  397.     sprintf(text,"           VERSION 1.0");
  398.     vsa_write_string(row+1,col,TF_Green,text);
  399.     sprintf(text,"    Copyright Spyro Gumas 1992");
  400.     vsa_write_string(row+2,col,TF_Green,text);
  401.     return 0;
  402. }
  403.