home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / leaddemo.zip / TOOL.C < prev    next >
C/C++ Source or Header  |  1992-08-05  |  100KB  |  2,114 lines

  1. /*****************************************************************************
  2.  *  Last Modified:  3/26/92                                                   *
  3.  *  Filenanme   : DEMO.C                                                     *
  4.  *                 This is an example program that demonstrates use          *
  5.  *                 of the most commonly called LEADTOOLS functions.          *
  6.  *                 This  will be a guideline for developers to call          *
  7.  *                 and use LEADTOOLS compression/decompression,              *
  8.  *                 viewing, conversion, and all the BitMap load, flip,       *
  9.  *                 reverse functions for both TARGA and VGA/SuperVGA         *
  10.  *                 graphics card.                                            *
  11.  *                                                                           *
  12.  *                 This example uses both TARGA and VGA display in the same  *
  13.  *                 program. If your application uses only the TARGA display  *
  14.  *                 then do not use the L_Load???Screen() functions (where    *
  15.  *                 ??? is the file format). Also, if you are writing only    *
  16.  *                 for VGA display, then do not use the L_Load???Targa()     *
  17.  *                 functions. If both are used, then the EXE file will be    *
  18.  *                 larger than necessary since these routine are not         *
  19.  *                 applicable to the hardware.                               *
  20.  *                                                                           *
  21.  ****************************************************************************/
  22.  
  23. /********* INCLUDES  *********/
  24. #include  "V:\LEADVIEW\TOOLKIT\toolapp.h"  /* Application tools for the toolkit */
  25. #include  "V:\LEADVIEW\TOOLKIT\l_error.h"  /* Error return codes                */
  26. #include  "V:\LEADVIEW\TOOLKIT\l_bitmap.h" /* Bitmap file information           */
  27. #include  <ctype.h>                /* Standard C header files           */
  28. #include  <conio.h>
  29. #include  <stdio.h>
  30. #include  <stdlib.h>
  31. #include  <string.h>
  32.  
  33. #if __BORLANDC__
  34.     extern unsigned _stklen = 13000U;
  35. #endif
  36.  
  37. /* A define used in get_qfactor for transforming the characters typed for
  38. LEAD's Compression formats enhanced options to their equivalent
  39. integer defines. */
  40.  
  41. #define NUMEXTENSIONS 9
  42.  
  43.  
  44. /*********************** Global Variables ***********************/
  45. char screen_buffer[4000]; /* Holds the TEXT in a text mode screen */
  46.  
  47. char screen_clear[4000];  /* Holds the a blank text screen        */
  48. char clear_line[160];     /* Holds the a blank line buffer        */
  49. int mode, page;                    /* Holds the current video text mode and
  50.                                       page */
  51. int curcolumn, currow;             /* Current cursor column and row        */
  52.  
  53.  
  54. /********************** Decalare Functions ********************/
  55. int get_qfactor(char *string);     /* Convert the characters typed for the
  56.                                       ImageQfactor to the equivalent integer
  57.                                       defines. */
  58. void printscreen(void);            /* Prints the user input screen         */
  59. void getint(int *);                /* Gets an integer from the keyboard    */
  60. void getstring(char *answer);      /* Gets a string from the keyboard      */
  61. void ClearTheScreen(void);         /* Blanks the screen                    */
  62. void RestoreInputScreen(void);     /* Restores the main menu               */
  63.    
  64.  
  65.  
  66. /****************************************************************************
  67.  *                                main()                                    *
  68.  ****************************************************************************/
  69. void main()
  70. {
  71.   int TARGA_FLAG;       /* Flag used to verify if a TARGA board is present */
  72.   int function_type;    /* Switch to determine which function to call      */
  73.   int ret;              /* Function return values                          */
  74.   int videotype;        /* To determine the VGA/SuperVGA graphics card type */
  75.   int width;            /* Image width       */
  76.   int height;           /* Image height      */
  77.   int BitsPerPixel;     /* As it says        */
  78.   int alloc_bitmap = 0; /* Flag to determine if there is a BitMap allocated
  79.                            in memory                                       */
  80.  
  81.   int compress_format; /* Compression method to be used, either
  82.                           LEAD, JFIF, or JTIF */
  83.   int qfactor;         /* To determine the degree of compression for
  84.                           CMP, JFIF and JTIF */
  85.  
  86.   int new_width,       /* For resizing an image */
  87.       new_height; 
  88.   int xpos, ypos;      /* For viewing image at different locations on
  89.                           the screen */
  90.   int save_palette;    /* Flag for saving the VGA palette in a compressed
  91.                           file or not */
  92.   int output_format;   /* For saving an image into the desired file format */
  93.   int video_size;      /* Select a video mode */
  94.   int video_memory;    /* Amount of video memory in KBytes
  95.                           available in the VGA/SuperVGA card */
  96.   int input_format;    /* For selecting the input file format in the
  97.                           file to file conversion process */
  98.  
  99.   char input_filename[160], /* Strings for input and output DOS file names */
  100.        output_filename[160];
  101.  
  102.   char compress_qfactor[100]; /* String for entering compression Q factor */
  103.   
  104.   BITMAPHANDLE Bitmap;    /* The main BITMAPHANLE used in the program */
  105.   BITMAPHANDLE NewBitmap; /* A BitMap handle used for the resizing,
  106.                              optimizing, and viewing functions */
  107.  
  108.   FILEINFO     FileInfo;  /* Structure that L_FileInfo will fill to return
  109.                              important information about an image file */
  110.  
  111.   int format; /* used for BMP windows or PM */
  112.  
  113.   /* Initialize the TARGA graphics environment. This function must be called
  114.      before any other function to communicate with the TARGA. */
  115.   if (L_TARGAInit() <= 0)
  116.       {
  117.        printf("TARGA board initialization error or TARGA not present!\n");
  118.        printf("Do not atempt to use any of the TARGA functions!\n\n");
  119.        printf("Press any key to continue.\n" );
  120.        putch(7);
  121.        getch();
  122.        TARGA_FLAG=0;
  123.       }
  124.       else
  125.         TARGA_FLAG=1;
  126.  
  127.  /* Set current video display mode and page. The purpose of this function is
  128.     to allow the developer to run his program in any of the text modes and
  129.     pages.  Call the L_GetVideoMode function before loading a graphical
  130.     image which requires the graphics adapter to chage from text mode to
  131.     graphic mode. Then load the image. When finished, use this function
  132.     to chage back to the same text mode and reference page as before
  133.     calling the L_GetVideoMode.                                   */
  134.     L_SetVideoMode(3, 0);
  135.  
  136.     printscreen(); /* Prints out the main menu on the screen      */
  137.  
  138.     for(;;)       /* Loops until user enters 100 to exit program */
  139.         {
  140.          RestoreInputScreen();      /* Restore the input screen and
  141.                                        set the cursor position to 0,24 */
  142.  
  143.          getint(&function_type);    /* Get user input                  */
  144.  
  145.          switch (function_type)     /* Main switch on user's input     */
  146.          {
  147.           case 1:/* Case load TGA file to a BitMap           */
  148.                  /* If a BitMap exists we need to free it    */
  149.                    if (alloc_bitmap == 1)
  150.                    {
  151.                     L_FreeBitmap( &Bitmap );
  152.                     alloc_bitmap = 0;
  153.                    }
  154.                    printf("Input file name: ");
  155.                    getstring(input_filename);
  156.                    /* Load the TGA filename directly into the BitMap handle.*/
  157.                    if ( (ret=L_LoadTGATarga( input_filename,
  158.                                              &Bitmap,OUTPUT_BITMAP,
  159.                                              TYPE_NOCONV, 0, 0 )) == SUCCESS )
  160.                    { /* It alocated a BitMap sucessfully */
  161.                      alloc_bitmap = 1;
  162.                      printf("%s loaded to the BitMap. Press any key to continue.",input_filename);
  163.                    }
  164.                    else 
  165.                    { /* An error occured while loading the TGA file */
  166.                      printf("Error: %d loading TGA to BitMap. Press any key to continue.", ret);
  167.                      putch(7);
  168.                    }
  169.           break;
  170.  
  171.           case 2:/* Case save a BitMap to TGA file */
  172.                  /* Make sure BitMap is being used and filled with image data */
  173.                  if (alloc_bitmap == 1)
  174.                   {
  175.                     printf("Output file name: ");
  176.                     getstring(output_filename);
  177.                     printf("BitsPerPixel (8, 16, 24 or 32): ");
  178.                     getint(&BitsPerPixel);
  179.                     /* Save the image Data in BitMap to a TGA file */
  180.                     if ( (ret=L_SaveTGABitmap( output_filename,
  181.                                                &Bitmap,BitsPerPixel )) == SUCCESS )
  182.                      {
  183.                       printf("%s saved OK.  Press any key to continue.",output_filename);
  184.                      }
  185.                      else
  186.                      { /* Error saving the TGA BitMap to the file */
  187.                       printf("Error: %d saving BitMap to TGA. Press any key to continue.", ret);
  188.                       putch(7);
  189.                      }
  190.                   }
  191.                   else
  192.                    { /* Trying to save an empty BitMap */
  193.                      printf("Error: No image in the BitMap allocated. Press any key to continue.");
  194.                      putch(7);
  195.                     }
  196.           break;
  197.  
  198.           case 3:/* Case load a PCX file to the BitMap */
  199.                  /* Make sure BitMap used and is filled with image */
  200.                  if (alloc_bitmap == 1)
  201.                   {
  202.                    L_FreeBitmap( &Bitmap );
  203.                    alloc_bitmap = 0;
  204.                   }
  205.                   printf("Input file name: ");
  206.                   getstring(input_filename);
  207.                   /* Load the PCX filename directly into the BitMap handle.*/
  208.                   if ( (ret=L_LoadPCXScreen( input_filename,
  209.                                              &Bitmap, OUTPUT_BITMAP,
  210.                                              TYPE_NOCONV, 0, 0 )) == SUCCESS )
  211.                    {/* If the PCX file was successfuly loaded to the BitMap */
  212.                      alloc_bitmap = 1;
  213.                      printf("%s loaded to BitMap. Press any key to continue.",input_filename);
  214.                    }
  215.                   else
  216.                    {
  217.                     printf("Error: %d loading PCX to BitMap. Press any key to continue.", ret);
  218.                     putch(7);
  219.                    }
  220.           break;
  221.  
  222.           case 4:/* Case save a BitMap to a PCX file */
  223.                  /* Make sure BitMap is already being used and is filled with image data */
  224.                  if (alloc_bitmap == 1)
  225.                   {
  226.                    printf("Output file name: ");
  227.                    getstring(output_filename);
  228.                    printf("BitsPerPixel (1, 4, or 8): ");
  229.                    getint(&BitsPerPixel);
  230.                    /* Save the image Data in BitMap to a PCX file*/
  231.                    if ( (ret=L_SavePCXBitmap( output_filename,&Bitmap,
  232.                                               BitsPerPixel )) == SUCCESS )
  233.                     {
  234.                       printf("%s saved OK.  Press any key to continue.",output_filename);
  235.                     }
  236.                    else
  237.                     {
  238.                      printf("Error: %d saving BitMap to PCX. Press any key to continue.", ret);
  239.                      putch(7);
  240.                    }
  241.                   }
  242.                  else
  243.                   {  /* Trying to save an empty BitMap */
  244.                    printf("Error: No image in the BitMap allocated. Press any key to continue.");
  245.                    putch(7);
  246.                   }
  247.           break;
  248.  
  249.           case 5:/* Case Load GIF to BitMap */
  250.                  /* If a BitMap is already being used we need to free it */
  251.                  if (alloc_bitmap == 1)
  252.                   {
  253.                    L_FreeBitmap( &Bitmap );
  254.                    alloc_bitmap = 0;
  255.                   }
  256.                   printf("Input file name: ");
  257.                   getstring(input_filename);
  258.                   /* Load a GIF file to a BitMap */
  259.                   if ( (ret=L_LoadGIFScreen( input_filename,
  260.                                              &Bitmap, OUTPUT_BITMAP,
  261.                                              TYPE_NOCONV, 0, 0 )) == SUCCESS )
  262.                    {
  263.                     alloc_bitmap = 1;
  264.                     printf("%s loaded to BitMap. Press any key to continue.",input_filename);
  265.                    }
  266.                   else
  267.                    {
  268.                     printf("Error: %d loading GIF to the BitMap. Press any key to continue.", ret);
  269.                     putch(7);
  270.                    }
  271.           break;
  272.  
  273.           case 6:/* Case save a BitMap as GIF file */
  274.                  /* Make sure BitMap is already being used and filled with image data */
  275.                  if (alloc_bitmap == 1)
  276.                   {
  277.                    printf("Output file name: ");
  278.                    getstring(output_filename);
  279.                    /* Saving the BitMap to a GIF file */
  280.                    if ( (ret=L_SaveGIFBitmap( output_filename,
  281.                                              &Bitmap, 8 )) == SUCCESS )
  282.                     {
  283.                      printf("%s saved OK.  Press any key to continue.",output_filename);
  284.                     }
  285.                    else
  286.                     {
  287.                      printf("Error: %d saving the BitMap to GIF. Press any key to continue.", ret);
  288.                      putch(7);
  289.                     }
  290.                   }
  291.                  else
  292.                   {
  293.                    printf("Error: No image in the BitMap allocated. Press any key to continue.");
  294.                    putch(7);
  295.                   }
  296.           break;
  297.  
  298.           case 7:/* Case Load a TIF file to a BitMap */
  299.                  /* If a BitMap is already being used free it */
  300.                  if (alloc_bitmap == 1)
  301.                   {
  302.                    L_FreeBitmap( &Bitmap );
  303.                    alloc_bitmap = 0;
  304.                   }
  305.                   printf("Input file name: ");
  306.                   getstring(input_filename);
  307.                   /* Load the TIF file to a BitMap */
  308.                  if ( (ret=L_LoadTIFScreen( input_filename, &Bitmap,
  309.                                             OUTPUT_BITMAP, TYPE_NOCONV, 0, 0 )) == SUCCESS )
  310.                   {
  311.                    alloc_bitmap = 1;
  312.                    printf("%s loaded to BitMap. Press any key to continue.",input_filename);
  313.                   }
  314.                  else
  315.                   {
  316.                    printf("Error: %d loading TIF to the BitMap. Press any key to continue.", ret);
  317.                    putch(7);
  318.                   }
  319.           break;
  320.  
  321.           case 8:/* Case save a BitMap to a TIF file */
  322.                  /* Make sure BitMap is already being used and is filled with image data */
  323.                  if (alloc_bitmap == 1)
  324.                   {
  325.                    printf("Output file name: ");
  326.                    getstring(output_filename);
  327.                    printf("BitsPerPixel (1, 8, or 24): ");
  328.                    getint(&BitsPerPixel);
  329.                    /* Save the BitMap to a TIF file */
  330.                    if ( (ret=L_SaveTIFBitmap( output_filename, &Bitmap,
  331.                                               BitsPerPixel )) == SUCCESS )
  332.                     {
  333.                      printf("%s saved OK.  Press any key to continue.",output_filename);
  334.                     }
  335.                    else
  336.                     {
  337.                      printf("Error: %d saving the BitMap to TIF. Press any key to continue.", ret);
  338.                      putch(7);
  339.                     }
  340.                   }
  341.                  else
  342.                   {
  343.                    printf("Error: No image in the BitMap allocated. Press any key to continue.");
  344.                    putch(7);
  345.                   }
  346.           break;
  347.  
  348.           case 9:/* Case Load a BMP file to a BitMap */
  349.                  /* If a BitMap is already being used free it */
  350.                  if (alloc_bitmap == 1)
  351.                   {
  352.                    L_FreeBitmap( &Bitmap );
  353.                    alloc_bitmap = 0;
  354.                   }
  355.                  printf("Input file name: ");
  356.                  getstring(input_filename);
  357.                  /* Load a BMP file to the BitMap */
  358.                  if ( (ret=L_LoadBMPScreen( input_filename, &Bitmap,
  359.                                             OUTPUT_BITMAP, TYPE_NOCONV, 0, 0 )) == SUCCESS )
  360.                   {
  361.                    alloc_bitmap = 1;
  362.                    printf("%s loaded to BitMap. Press any key to continue.",input_filename);
  363.                   }
  364.                  else
  365.                  {
  366.                   printf("Error: %d loading BMP to the BitMap. Press any key to continue.", ret);
  367.                   putch(7);
  368.                  }
  369.           break;
  370.  
  371.           case 10:/* Case save a BitMap to a BMP file */
  372.                   /* Make sure BitMap is already being used and is filled with image data */
  373.                   if (alloc_bitmap == 1)
  374.                    {
  375.                     printf("Output file name: ");
  376.                     getstring(output_filename);
  377.                     printf("BitsPerPixel (4, 8, or 24): ");
  378.                     getint(&BitsPerPixel);
  379.                     printf("type 0 for (WINDOWS BMP), or 1 for (PM BMP): ");
  380.                     getint(&format);
  381.                     if(format==0)
  382.                        format=TYPE_WIN;
  383.                     else if(format==1)
  384.                         format=TYPE_OS2;
  385.                      else
  386.                         {
  387.                          printf("%d not a valid option",format);
  388.                          getch();
  389.                          break;
  390.                         }
  391.                     /* Save the BitMap to a BMP file */
  392.                     if ( (ret=L_SaveBMPBitmap( output_filename,&Bitmap,
  393.                                              BitsPerPixel, format )) == SUCCESS )
  394.                      {
  395.                       printf("%s saved OK.  Press any key to continue.",output_filename);
  396.                      }
  397.                     else
  398.                      {
  399.                       printf("Error: %d saving the BitMap to BMP. Press any key to continue.", ret);
  400.                       putch(7);
  401.                      }
  402.                    }
  403.                   else
  404.                    {
  405.                     printf("Error: No image in the BitMap allocated. Press any key to continue.");
  406.                     putch(7);
  407.                    }
  408.           break;
  409.  
  410.           case 11:/* Decompress a compressed file to a BitMap*/
  411.                   /* If a BitMap is already being used free it */
  412.                   if (alloc_bitmap == 1)
  413.                    {
  414.                     L_FreeBitmap( &Bitmap );
  415.                     alloc_bitmap = 0;
  416.                    }
  417.                   printf("Input file name: ");
  418.                   getstring(input_filename);
  419.                   /* Decompress a LEAD, JTIF, or JFIF compressed file format
  420.                      directly to a BitMap*/
  421.                  L_InitBitmap( &Bitmap, 0, 0, 0);
  422.                  if ( (ret=L_DecompressBitmap ( input_filename,
  423.                                                 &Bitmap, BIT24 )) == SUCCESS )
  424.                   {
  425.                    alloc_bitmap = 1;
  426.                    printf("Image decompressed to a BitMap. Press any key to continue.");
  427.                   }
  428.                  else
  429.                   {
  430.                    printf("Error: %d Decompressing to the BitMap. Press any key to continue.", ret);
  431.                    putch(7);
  432.                   }
  433.           break;
  434.           
  435.           case 12:/* Case compress a BitMap to a compressed format */
  436.                   /* Make sure BitMap is already being used and is filled with image data */
  437.                   if (alloc_bitmap == 1)
  438.                    {
  439.                     printf("Output file name: ");
  440.                     getstring(output_filename);
  441.                     printf("Compress format 0 - LEAD, 1 - JFIF, 2 - JTIF, 3 - LEAD1JFIF, 4 - LEAD1JTIF,\n");
  442.                     printf("5 - LEAD2JFIF, 6 - LEAD2JTF: ");
  443.                     getint(&compress_format);
  444.                     printf("Qfactor 1 to 255 or LEAD defined PQ1, PQ2, QFS, QMS, QS, SQS, SQT, MCQ, MC ");
  445.                     getstring(compress_qfactor);
  446.                     strupr(compress_qfactor);
  447.                     /* Check for a correct Qfactor entered */
  448.                     if ( (qfactor = get_qfactor(compress_qfactor)) == ERROR_QFACTOR)
  449.                      {
  450.                       printf("Bad qfactor. Press any key to continue.");
  451.                       putch(7);
  452.                       break;
  453.                      }
  454.                     /* If the user selected the LEAD compressed file format
  455.                        then ask to see if he/she would also like to save the
  456.                        VGA palette */
  457.                     if (compress_format != 0)
  458.                         save_palette = 0;
  459.                     else
  460.                      {
  461.                       printf("Save VGA palette? 0 - No, 1 - YES: ");
  462.                       getint(&save_palette);
  463.                       while( (save_palette != 0) && (save_palette != 1) )
  464.                        {
  465.                         printf("Save VGA palette? 0 - No, 1 - YES: ");
  466.                         getint(&save_palette);
  467.                        }
  468.                      }
  469.                     /* Compress the BitMap to a compressed file */
  470.                     if ( (ret = L_CompressBitmap ( &Bitmap,
  471.                                                 output_filename, compress_format,
  472.                                                 qfactor, save_palette )) == SUCCESS )
  473.                      {
  474.                       printf("BitMap compressed. Press any key to continue.");
  475.                      }
  476.                     else
  477.                      {
  478.                       printf("Error: %d compressing the BitMap. Press any key to continue.", ret);
  479.                       putch(7);
  480.                      }
  481.                    }
  482.                   else
  483.                    {
  484.                     printf("Error: No image in the BitMap allocated. Press any key to continue.");
  485.                     putch(7);
  486.                    }
  487.           break;
  488.  
  489.           case 13: /* Case Flip a BitMap */
  490.                    /* Flip vertical      */
  491.                    /* Make sure BitMap is already being used and is filled with image data */
  492.                    if ( alloc_bitmap == 0 )
  493.                     {
  494.                      printf("Error: No storage has been allocated for a BitMap. Press any key to continue.");
  495.                      putch(7);
  496.                      break;
  497.                     }
  498.                     /* Flip an image in the BitMap (top to bottom) */
  499.                     if ( (ret = L_FlipBitmap( &Bitmap )) == SUCCESS)
  500.                      {
  501.                       printf("Image fliped. Press any key to continue.");
  502.                      }
  503.                     else
  504.                      {
  505.                       printf("Error: %d could not flip image. Press any key to continue.", ret);
  506.                       putch(7);
  507.                      }
  508.           break;
  509.  
  510.           case 14: /* Case reverse an image in a BitMap */
  511.                    /* Flip horizontal                   */
  512.                    /* Make sure BitMap is already being used and is filled with image data */
  513.                    if ( alloc_bitmap == 0 )
  514.                     {
  515.                      printf("Error: No image in the BitMap allocated. Press any key to continue.");
  516.                      putch(7);
  517.                      break;
  518.                     }
  519.                     /* Reverse an image in a BitMap (left to right) */
  520.                     if ( (ret = L_ReverseBitmap( &Bitmap )) == SUCCESS)
  521.                      {
  522.                       printf("Image reversed. Press any key to continue.");
  523.                      }
  524.                     else
  525.                      {
  526.                       printf("Error: %d Reversing the image. Press any key to continue.", ret);
  527.                       putch(7);
  528.                      }
  529.           break;
  530.  
  531.          case 15: /* Case resize the image in the BitMap */
  532.                   /* Make sure BitMap is already being used and is filled with image data */
  533.                   if ( alloc_bitmap == 0 )
  534.                    {
  535.                     printf("Error: No image in the BitMap allocated. Press any key to continue.");
  536.                     putch(7);
  537.                     break;
  538.                    }
  539.                    printf("New BitMap width: ");
  540.                    getint(&new_width);
  541.                    printf("New BitMap height: ");
  542.                    getint(&new_height);
  543.                   /* Will alocate room and initialize a new Bitmap while keeping
  544.                      the original BitMap. Then the original BitMap location is released. */
  545.                   /* Initialize fields in a BitMap handle.                       */
  546.                      L_InitBitmap( &NewBitmap, new_width, new_height,
  547.                                    Bitmap.BitsPerPixel ) ;
  548.           
  549.                   /* Allocate storage to hold an image in a BitMap handle.       */
  550.                   if ( (ret = L_AllocateBitmap( &NewBitmap,
  551.                                              TYPE_NOCONV   )) == SUCCESS )
  552.                    {
  553.                    /* Resizes image currently in BitMap handle, to the output BitMap
  554.                       handle. Since the new BitMap structure contains the new width
  555.                       and height just call L_ResizeBitmap()                      */
  556.                     if ( (ret = L_ResizeBitmap( &Bitmap, &NewBitmap ))
  557.                                                                   == SUCCESS )
  558.                      {
  559.                       L_FreeBitmap( &Bitmap );    /* Free the old BitMap */
  560.                       L_CopyBitmapHandle( &Bitmap, &NewBitmap ); /* Copy the old BitMap handle
  561.                                                                     to the new one */
  562.                       printf("BitMap resized in NewBitMap.");
  563.                      }
  564.                     else
  565.                      {
  566.                       printf("Error: %d Resizing the BitMap. Press any key to continue.", ret);
  567.                       putch(7);
  568.                      }
  569.                    }
  570.                   else
  571.                    {
  572.                     printf("Error: %d Alloctating a new bitmap for resizing. Press any key to continue.", ret);
  573.                     putch(7);
  574.                   }
  575.          break;
  576.  
  577.         case 16: /* Rotate an image in a bitmap */
  578.                  if ( alloc_bitmap == 0 )
  579.                   {
  580.                    printf("Error: No image in the BitMap allocated. Press any key to continue.");
  581.                    putch(7);
  582.                    break;
  583.                   }
  584.                  printf("Rotate by (degrees):");
  585.                  getint( &xpos ) ;
  586.                  printf("Resize? (0=No, 1=Yes):");
  587.                  getint( &output_format ) ;
  588.                  L_RotateBitmap( &Bitmap, xpos, output_format ) ;
  589.                  printf("Bitmap Rotated! Press any key to continue.\n");
  590.         break;
  591.  
  592.          case 17: /* Case optimize an image for 256 colors */
  593.                   /* Make sure BitMap is already being used and is filled with image data */
  594.                   if ( alloc_bitmap == 0 )
  595.                    {
  596.                     printf("Error: No image in the BitMap allocated. Press any key to continue.");
  597.                     putch(7);
  598.                     break;
  599.                    }
  600.                    /* Make sure that the image needs to be optimized
  601.                       to 256 colors */
  602.                    if (Bitmap.BitsPerPixel >= 16)
  603.                     {
  604.                     /* Selecting the best 256 colors to represent the image.
  605.                        This function will allocate and put the 256 color image
  606.                        in NewBitmap */
  607.                      if ( (ret = L_OptimizeBitmap ( &Bitmap, &NewBitmap, NO_DITHERING, 256 )) == SUCCESS)
  608.                       {
  609.                        /* Free the storage for the old BitMap */
  610.                        L_FreeBitmap( &Bitmap );    
  611.                        /* Copy the old BitMap handle to the new one */
  612.                        L_CopyBitmapHandle( &Bitmap, &NewBitmap );
  613.                        printf("Bitmap optimized.  Press any key to continue.");
  614.                       }
  615.                      else
  616.                       {
  617.                        printf("Error: %d Optimizing the BitMap.  Press any key to continue.", ret);
  618.                        putch(7);
  619.                       }
  620.                     }
  621.                    else
  622.                     { /* You cannot optimize 4 or 8 bits/pixel image */
  623.                      printf("Cannot optimize a %d bits/pixel BitMap. Press any key to continue.",Bitmap.BitsPerPixel);
  624.                      putch(7);
  625.                     }
  626.          break;
  627.  
  628.  
  629.          case 18: /* Case clear a BitMap */
  630.                   /* Make sure BitMap is already being used and is filled with image data */
  631.                   if ( alloc_bitmap == 0 )
  632.                    {
  633.                     printf("Error: No image in BitMap allocated. Press any key to continue.");
  634.                     putch(7);
  635.                     break;
  636.                    }
  637.                    /* Clear the BitMap and fill it with zeros */
  638.                    if ( (ret = L_ClearBitmap( &Bitmap )) == SUCCESS )
  639.                     {
  640.                      printf("BitMap cleared and filled with zeros OK. Press any key to continue.");
  641.                     }
  642.                    else
  643.                     {
  644.                      printf("Error: %d Clearing the BitMap. Press any key to continue.", ret);
  645.                      putch(7);
  646.                     }
  647.          break;
  648.  
  649.          case 19: /* Case change BitMap bosition */
  650.                   /* Make sure BitMap is already being used and is filled with image data */
  651.                   if ( alloc_bitmap == 0 )
  652.                    {
  653.                     printf("Error: No image in BitMap allocated. Press any key to continue.");
  654.                     putch(7);
  655.                     break;
  656.                    }
  657.                    printf("New BitMap X position: ");
  658.                    getint(&xpos);
  659.                    printf("New BitMap Y position: ");
  660.                    getint(&ypos);
  661.                    /* Set new X, Y positions in a BitMap handle.
  662.                       The X and Y positions will be used as the starting
  663.                       offset when displaying this BitMap */
  664.                    L_SetBitmapPos( &Bitmap, xpos, ypos);
  665.                    printf("Set BitMap position OK.  Press any key to continue.");
  666.          break;
  667.  
  668.          case 20: /* Case view BitMap to TARGA */
  669.                   /* Is a TARGA installed OK? */
  670.                  if (TARGA_FLAG)
  671.                   {
  672.                    /* Make sure BitMap is already being used and is filled with image data */
  673.                    if ( alloc_bitmap == 0 )
  674.                     {
  675.                      printf("Error: No image in the BitMap allocated. Press any key to continue.");
  676.                      putch(7);
  677.                      break;
  678.                     }
  679.                     /* View the BitMap to the TARGA graphics adapter */
  680.                     if ( (ret = L_ViewBitmapTarga( &Bitmap, 0, 0 )) == SUCCESS )
  681.                      {
  682.                       printf("BitMap viewed to TARGA successfully.  Press any key to continue.");
  683.                      }
  684.                     else
  685.                      {
  686.                       printf("Error: %d viewing to the TARGA screen.  Press any key to continue.", ret);
  687.                       putch(7);
  688.                      }
  689.                   }
  690.                  else
  691.                   {
  692.                    printf("Error: TARGA board initialization.  Press any key to continue.");
  693.                    putch(7);
  694.                   }
  695.          break;
  696.  
  697.          case 21: /* Case view a BitMap on the VGA/SuperVGA screen */
  698.                   /* Make sure BitMap is already being used and is filled with image data */
  699.                   if ( alloc_bitmap == 0 )
  700.                    {
  701.                     printf("Error: No image in the BitMap allocated. Press any key to continue.");
  702.                     putch(7);
  703.                     break;
  704.                    }
  705.                    /* Make sure that the image has no more than 256 colors */
  706.                      printf("New viewing screen width 0 for no resize: ");
  707.                      getint(&new_width);
  708.                      printf("New viewing screen height 0 for no resize: ");
  709.                      getint(&new_height);
  710.                      /* View the BitMap with the new width and height.
  711.                         This will display the image with the new width and height
  712.                         but will not change the original BitMap's width and height */
  713.                     if( L_ViewBitmapScreen(&Bitmap,new_width,new_height) == ERROR_NOT_256_COLOR )
  714.                        {
  715.                        ClearTheScreen();
  716.                        printf("This is a %d bit/pixel image containing more that 256 colors.\n", Bitmap.BitsPerPixel);
  717.                        printf("A VGA/SuperVGA card can only handle up to 256 colors.\n");
  718.                        printf("To be able to view the image you must first optimize the BitMap.\n");
  719.                        printf("This will find the best 256 colors to represent this image.\n\n");                   
  720.                        printf("\nPress any key to continue.");
  721.                        putch(7);
  722.                        }
  723.          break;
  724.  
  725.          case 22: /* Case view TGA file to TARGA screen */
  726.                   /* Is a TARGA installed OK? */
  727.                   if (TARGA_FLAG)
  728.                    {
  729.                     printf("Input file name: ");
  730.                     getstring(input_filename);
  731.                     printf("Starting X display position, or 0 for normal position: ");
  732.                     getint(&xpos);
  733.                     printf("Starting Y display position, or 0 for normal position: ");
  734.                     getint(&ypos);
  735.                     printf("Display width, or 0 for current Width in the file: ");
  736.                     getint(&width);
  737.                     printf("Display height, or 0 for current Height in the file: ");
  738.                     getint(&height);
  739.                     if ( (ret = L_ShowTGATarga(input_filename,width,height,xpos, ypos)) ==SUCCESS)
  740.                      {
  741.                       printf("%s successfully loaded to TARGA. Press any key to continue.",input_filename);
  742.                      }  
  743.                     else
  744.                      {
  745.                       printf("Error: %d Viewing to the TARGA. Press any key to continue.", ret);
  746.                       putch(7);
  747.                      }
  748.                   }
  749.                  else
  750.                   {
  751.                    printf("Error: TARGA board initialization.  Press any key to continue.");
  752.                    putch(7);
  753.                   }
  754.          break;
  755.  
  756.          case 23: /* Case view TGA file to VGA screen */
  757.                   printf("Input file name: ");
  758.                   getstring(input_filename);
  759.                   /* See if the file is a valid format and fill the FileInfo structure */
  760.                   if (L_FileInfo(input_filename, &FileInfo) == SUCCESS)
  761.                    {
  762.                     if (FileInfo.Format == FILE_TGA)
  763.                      {
  764.                         {
  765.                          printf("Starting X display position, or 0 for normal position: ");
  766.                          getint(&xpos);
  767.                          printf("Starting Y display position, or 0 for normal position: ");
  768.                          getint(&ypos);
  769.                          printf("Display width, or 0 for current Width in the file: ");
  770.                          getint(&width);
  771.                          printf("Display height, or 0 for current Height in the file: ");
  772.                          getint(&height);
  773.                          if ( (ret = L_ShowTGAScreen(input_filename,width,height,
  774.                                                                xpos, ypos)) == SUCCESS)
  775.                           {
  776.                             /* Displayed to VGA OK */
  777.                             ;
  778.                           }
  779.                          else
  780.                           {
  781.                           if( ret == ERROR_NOT_256_COLOR )
  782.                              {/* If the TGA file a 16, 24, or 32 bits/pixel file
  783.                                  we have to load into a BitMap then optimize the BitMap and
  784.                                  then view the BitMap */
  785.                               ClearTheScreen();
  786.                               printf("\n%s is a %d bit/pixel image containing more that 256 colors.\n", input_filename,FileInfo.BitsPerPixel);
  787.                               printf("A VGA/SuperVGA card can only handle up to 256 colors.\n");
  788.                               printf("To be able to view this file you must load the file to \n");
  789.                               printf("the BitMap. Then run optimize the BitMap.\n");
  790.                               printf("This will find the best 256 colors to represent the image.");
  791.                               printf("Afterwards, you can view the BitMap to the screen.\n\n");
  792.                               printf("Press any key to continue.");
  793.                               putch(7);
  794.                              }
  795.                           else
  796.                              {
  797.                              printf("Error: %d viewing VGA. Press any key to continue.", ret);
  798.                              putch(7);
  799.                              }
  800.                           }
  801.                         }
  802.                      }  
  803.                     else
  804.                      {
  805.                       printf("Error: %s invalid TGA file format. Press any key to continue.", input_filename);
  806.                       putch(7);
  807.                      }
  808.                    }
  809.                   else
  810.                    {
  811.                       printf("Error: %s not a supported file format. Press any key to continue.", input_filename);
  812.                       putch(7);
  813.                    }
  814.          break;
  815.  
  816.          case 24: /* Case view PCX file to TARGA */
  817.                   /* Is a TARGA installed OK */
  818.                   if (TARGA_FLAG)
  819.                    {
  820.                     printf("Input file name: ");
  821.                     getstring(input_filename);
  822.                     printf("Starting X display position, or 0 for normal position: ");
  823.                     getint(&xpos);
  824.                     printf("Starting Y display position, or 0 for normal position: ");
  825.                     getint(&ypos);
  826.                     printf("Display width, or 0 for current Width in the file: ");
  827.                     getint(&width);
  828.                     printf("Display height, or 0 for current Height in the file: ");
  829.                     getint(&height);
  830.                     if ( (ret = L_ShowPCXTarga(input_filename,width,
  831.                                                       height,xpos, ypos)) ==SUCCESS)
  832.                      {
  833.                       printf("%s successfully loaded to TARGA. Press any key to continue.",input_filename);
  834.                      }
  835.                     else
  836.                      {
  837.                       printf("Error: %d viewing to the TARGA. Press any key to continue.", ret);
  838.                       putch(7);
  839.                      }
  840.                   }
  841.                  else
  842.                   {
  843.                    printf("Error: TARGA board initialization.  Press any key to continue.");
  844.                    putch(7);
  845.                   }
  846.          break;
  847.  
  848.          case 25: /* Case view PCX file to VGA */
  849.                   printf("Input file name: ");
  850.                   getstring(input_filename);
  851.                   printf("Starting X display position, or 0 for normal position: ");
  852.                   getint(&xpos);
  853.                   printf("Starting Y display position, or 0 for normal position: ");
  854.                   getint(&ypos);
  855.                   printf("Display width, or 0 for current Width in the file: ");
  856.                   getint(&width);
  857.                   printf("Display height, or 0 for current Height in the file: ");
  858.                   getint(&height);
  859.                   if ( (ret = L_ShowPCXScreen(input_filename,width,height,
  860.                                                             xpos, ypos)) ==SUCCESS)
  861.                    {
  862.                     /* displayed to VGA OK */
  863.                     ;
  864.                    }
  865.                   else
  866.                    {
  867.                     printf("Error: %d viewing to VGA. Press any key to continue.", ret);
  868.                     putch(7);
  869.                    }
  870.          break;
  871.  
  872.          case 26: /* Case view GIF file to TARGA */
  873.                   /* Is a TARGA installed OK */
  874.                   if (TARGA_FLAG)
  875.                    {
  876.                     printf("Input file name: ");
  877.                     getstring(input_filename);
  878.                     printf("Starting X display position, or 0 for normal position: ");
  879.                     getint(&xpos);
  880.                     printf("Starting Y display position, or 0 for normal position: ");
  881.                     getint(&ypos);
  882.                     printf("Display width, or 0 for current Width in the file: ");
  883.                     getint(&width);
  884.                     printf("Display height, or 0 for current Height in the file: ");
  885.                     getint(&height);
  886.                     if ( (ret = L_ShowGIFTarga(input_filename,width,height,
  887.                                                             xpos, ypos)) ==SUCCESS)
  888.                      {
  889.                       printf("%s successfully loaded to TARGA. Press any key to continue.",input_filename);
  890.                      }
  891.                     else
  892.                      {
  893.                       printf("Error: %d viewing to TARGA. Press any key to continue.", ret);
  894.                       putch(7);
  895.                      }
  896.                    }
  897.                   else
  898.                    {
  899.                     printf("Error: TARGA board initialization.  Press any key to continue.");
  900.                     putch(7);
  901.                    }
  902.          break;
  903.  
  904.         case 27: /* Case view GIF to VGA */
  905.                  printf("Input file name: ");
  906.                  getstring(input_filename);
  907.                  printf("Starting X display position, or 0 for normal position: ");
  908.                  getint(&xpos);
  909.                  printf("Starting Y display position, or 0 for normal position: ");
  910.                  getint(&ypos);
  911.                  printf("Display width, or 0 for current Width in the file: ");
  912.                  getint(&width);
  913.                  printf("Display height, or 0 for current Height in the file: ");
  914.                  getint(&height);
  915.                  if ( (ret = L_ShowGIFScreen(input_filename,width,height,
  916.                                                          xpos, ypos)) ==SUCCESS)
  917.                   {
  918.                    /* displayed to VGA OK */
  919.                    ;
  920.                   }
  921.                  else
  922.                   {
  923.                    printf("Error: %d viewing VGA. Press any key to continue.", ret);
  924.                    putch(7);
  925.                   }
  926.         break;
  927.  
  928.         case 28: /* Case view TIF to TARGA */
  929.                   /* Is a TARGA installed OK */
  930.                   if (TARGA_FLAG)
  931.                    {
  932.                     printf("Input file name: ");
  933.                     getstring(input_filename);
  934.                     printf("Starting X display position, or 0 for normal position: ");
  935.                     getint(&xpos);
  936.                     printf("Starting Y display position, or 0 for normal position: ");
  937.                     getint(&ypos);
  938.                     printf("Display width, or 0 for current Width in the file: ");
  939.                     getint(&width);
  940.                     printf("Display height, or 0 for current Height in the file: ");
  941.                     getint(&height);
  942.                     if ( (ret = L_ShowTIFTarga(input_filename,width,height,
  943.                                                             xpos, ypos)) ==SUCCESS)
  944.                      {
  945.                       printf("%s successfully loaded to TARGA. Press any key to continue.",input_filename);
  946.                      }
  947.                     else
  948.                      {
  949.                       printf("Error: %d viewing to the TARGA. Press any key to continue.", ret);
  950.                       putch(7);
  951.                      }
  952.                    }
  953.                   else
  954.                    {
  955.                     printf("Error: TARGA board initialization.  Press any key to continue.");
  956.                     putch(7);
  957.                    }
  958.         break;
  959.  
  960.         case 29: /* Case view TIF to VGA */
  961.                  printf("Input file name: ");
  962.                  getstring(input_filename);
  963.                  /* See if the file is a valid format and fill the FileInfo structure */
  964.                   if (L_FileInfo(input_filename, &FileInfo) == SUCCESS)
  965.                    {
  966.                     if (FileInfo.Format == FILE_TIF)
  967.                      {
  968.                         {
  969.                          printf("Starting X display position, or 0 for normal position: ");
  970.                          getint(&xpos);
  971.                          printf("Starting Y display position, or 0 for normal position: ");
  972.                          getint(&ypos);
  973.                          printf("Display width, or 0 for current Width in the file: ");
  974.                          getint(&width);
  975.                          printf("Display height, or 0 for current Height in the file: ");
  976.                          getint(&height);
  977.                          if ( (ret = L_ShowTIFScreen(input_filename,width,height,
  978.                                                                xpos, ypos)) ==SUCCESS)
  979.                           {
  980.                             /* Displayed to VGA OK */
  981.                             ;
  982.                           }
  983.                          else
  984.                           {
  985.                           if( ret == ERROR_NOT_256_COLOR )
  986.                              {/* If the TGA file a 16, 24, or 32 bits/pixel file
  987.                                  we have to load into a BitMap then optimize the BitMap and
  988.                                  then view the BitMap */
  989.                               ClearTheScreen();
  990.                               printf("\n%s is a %d bit/pixel image containing more that 256 colors.\n", input_filename,FileInfo.BitsPerPixel);
  991.                               printf("A VGA/SuperVGA card can only handle up to 256 colors.\n");
  992.                               printf("To be able to view this file you must load the file to \n");
  993.                               printf("the BitMap. Then run optimize the BitMap.\n");
  994.                               printf("This will find the best 256 colors to represent the image.");
  995.                               printf("Afterwards, you can view the BitMap to the screen.\n\n");
  996.                               printf("Press any key to continue.");
  997.                               putch(7);
  998.                              }
  999.                           else
  1000.                              {
  1001.                              printf("Error: %d viewing VGA. Press any key to continue.", ret);
  1002.                              putch(7);
  1003.                              }
  1004.                           }
  1005.                         }
  1006.                      }  
  1007.                     else
  1008.                      {
  1009.                       printf("Error: %s Invalid TIF file format. Press any key to continue.",input_filename);
  1010.                       putch(7);
  1011.                      }
  1012.                    }
  1013.                   else
  1014.                    {
  1015.                       printf("Error: %s not a supported file format. Press any key to continue.", input_filename);
  1016.                      putch(7);
  1017.                    }
  1018.         break;
  1019.  
  1020.         case 30: /* Case view BMP to TARGA */
  1021.                   /* Is a TARGA installed OK */
  1022.                   if (TARGA_FLAG)
  1023.                    {
  1024.                     printf("Input file name: ");
  1025.                     getstring(input_filename);
  1026.                     printf("Starting X display position, or 0 for normal position: ");
  1027.                     getint(&xpos);
  1028.                     printf("Starting Y display position, or 0 for normal position: ");
  1029.                     getint(&ypos);
  1030.                     printf("Display width, or 0 for current Width in the file: ");
  1031.                     getint(&width);
  1032.                     printf("Display height, or 0 for current Heigth in the file: ");
  1033.                     getint(&height);
  1034.                     if ( (ret = L_ShowBMPTarga(input_filename,width,height,
  1035.                                                             xpos, ypos)) ==SUCCESS)
  1036.                      {
  1037.                       printf("%s successfully loaded to TARGA. Press any key to continue.",input_filename);
  1038.                      }
  1039.                     else
  1040.                      {
  1041.                       printf("Error: %d viewing to the TARGA. Press any key to continue.", ret);
  1042.                       putch(7);
  1043.                      }
  1044.                    }
  1045.                   else
  1046.                    {
  1047.                     printf("Error: TARGA board initialization. Press any key to continue.");
  1048.                     putch(7);
  1049.                    }
  1050.         break;
  1051.  
  1052.         case 31: /* Case view BMP to VGA */
  1053.                  printf("Input file name: ");
  1054.                  getstring(input_filename);
  1055.                  /* See if the file is a valid format and fill the FileInfo structure */
  1056.                   if (L_FileInfo(input_filename, &FileInfo) == SUCCESS)
  1057.                    {
  1058.                     if (FileInfo.Format == FILE_BMP)
  1059.                      {
  1060.                         {
  1061.                          printf("Starting X display position, or 0 for normal position: ");
  1062.                          getint(&xpos);
  1063.                          printf("Starting Y display position, or 0 for normal position: ");
  1064.                          getint(&ypos);
  1065.                          printf("Display width, or 0 for current Width in the file: ");
  1066.                          getint(&width);
  1067.                          printf("Display height, or 0 for current Height in the file: ");
  1068.                          getint(&height);
  1069.                          if ( (ret = L_ShowBMPScreen(input_filename,width,height,
  1070.                                                                xpos, ypos)) ==SUCCESS)
  1071.                           {
  1072.                             /* Displayed to VGA OK */
  1073.                             ;
  1074.                           }
  1075.                          else
  1076.                           {
  1077.                           if( ret == ERROR_NOT_256_COLOR )
  1078.                              {/* If the TGA file a 16, 24, or 32 bits/pixel file
  1079.                                  we have to load into a BitMap then optimize the BitMap and
  1080.                                  then view the BitMap */
  1081.                               ClearTheScreen();
  1082.                               printf("\n%s is a %d bit/pixel image containing more that 256 colors.\n", input_filename,FileInfo.BitsPerPixel);
  1083.                               printf("A VGA/SuperVGA card can only handle up to 256 colors.\n");
  1084.                               printf("To be able to view this file you must load the file to \n");
  1085.                               printf("the BitMap. Then run optimize the BitMap.\n");
  1086.                               printf("This will find the best 256 colors to represent the image.");
  1087.                               printf("Afterwards, you can view the BitMap to the screen.\n\n");
  1088.                               printf("Press any key to continue.");
  1089.                               putch(7);
  1090.                              }
  1091.                           else
  1092.                              {
  1093.                              printf("Error: %d viewing VGA. Press any key to continue.", ret);
  1094.                              putch(7);
  1095.                              }
  1096.                           }
  1097.                         }
  1098.                      }  
  1099.                     else
  1100.                      {
  1101.                       printf("Error: %s invalid BMP file format. Press any key to continue.", input_filename);
  1102.                       putch(7);
  1103.                      }
  1104.                    }
  1105.                   else
  1106.                    {
  1107.                       printf("Error: %s Not a supported file format. Press any key to continue.", input_filename);
  1108.                       putch(7);
  1109.                    }
  1110.         break;
  1111.  
  1112.         case 32: /* Case decompress or display a compressed file to TARGA screen */
  1113.                  /* Is a TARGA installed OK */
  1114.                  if (TARGA_FLAG)
  1115.                   {
  1116.                    printf("Input file name: ");
  1117.                    getstring(input_filename);
  1118.                    printf("Starting X display position, or 0 for normal position: ");
  1119.                    getint(&xpos);
  1120.                    printf("Starting Y display position, or 0 for normal position: ");
  1121.                    getint(&ypos);
  1122.                    if ( (ret = L_DecompressTARGAScreen(input_filename,
  1123.                                                             xpos, ypos)) == SUCCESS)
  1124.                     {
  1125.                      printf("Decompress %s to TARGA screen. Press any key to continue.",input_filename );
  1126.                     }
  1127.                    else
  1128.                     {
  1129.                      printf("Error: %d Decompressing to TARGA. Press any key to continue.", ret);
  1130.                      putch(7);
  1131.                     }
  1132.                   }
  1133.                 else
  1134.                  {
  1135.                   printf("Error: Cannot initialize TARGA board.  Press any key to continue.");
  1136.                   putch(7);
  1137.                  }
  1138.         break;
  1139.  
  1140.         case 33: /* Decompress a compressed file to the VGA screen */
  1141.                  printf("Input file name: ");
  1142.                  getstring(input_filename);
  1143.                  printf("Starting X display position, or 0 for normal position: ");
  1144.                  getint(&xpos);
  1145.                  printf("Starting Y display position, or 0 for normal position: ");                 getint(&ypos);
  1146.                 if ( (ret = L_DecompressVGAScreen(input_filename, xpos, ypos)) == SUCCESS)
  1147.                  {
  1148.                   /* Decompression to VGA was OK */
  1149.                   ;
  1150.                  }
  1151.                 else
  1152.                  {
  1153.                   printf("Error: %d Decompressing to VGA. Press any key to continue.", ret);
  1154.                   putch(7);
  1155.                  }
  1156.         break;
  1157.  
  1158.         case 34: /* Case compress TGA file */
  1159.                  printf("Input file name: ");
  1160.                  getstring(input_filename);
  1161.                  printf("Output file name: ");
  1162.                  getstring(output_filename);
  1163.                  printf("Compress format 0 - LEAD, 1 - JFIF, 2 - JTIF, 3 - LEAD1JFIF, 4 - LEAD1JTIF,\n");
  1164.                  printf("5 - LEAD2JFIF, 6 - LEAD2JTF: ");
  1165.                  getint(&compress_format);
  1166.                  printf("Qfactor 1 to 255 or LEAD defined PQ1, PQ2, QFS, QMS, QS, SQS, SQT, MCQ, MC ");
  1167.                  getstring(compress_qfactor);
  1168.                  if (compress_format != 0)
  1169.                   save_palette = 0;
  1170.                  else
  1171.                   {
  1172.                    printf("Save VGA palette? 0 - No, 1 - YES: ");
  1173.                    getint(&save_palette);
  1174.                    while( (save_palette != 0) && (save_palette != 1) )
  1175.                     {
  1176.                      printf("Save VGA palette? 0 - No, 1 - YES: ");
  1177.                      getint(&save_palette);
  1178.                     }
  1179.                   }
  1180.                 strupr(compress_qfactor);
  1181.                 if ( (qfactor = get_qfactor(compress_qfactor)) == ERROR_QFACTOR)
  1182.                  {
  1183.                   printf("Error: Bad qfactor. Press any key to continue.");
  1184.                   putch(7);
  1185.                   break;
  1186.                  }
  1187.                 if ( (ret = L_CompressTGA(input_filename, output_filename, compress_format,
  1188.                                         qfactor, save_palette)) == SUCCESS)
  1189.                  {
  1190.                   printf("File: %s compressed to %s. Press any key to continue.",input_filename,output_filename);
  1191.                  }
  1192.                 else
  1193.                  {
  1194.                   printf("Error: %d compressing %s. Press any key to continue.", ret,input_filename);
  1195.                   putch(7);
  1196.                  }
  1197.         break;
  1198.  
  1199.         case 35: /* Case decompress to TGA file */
  1200.                  printf("Input file name: ");
  1201.                  getstring(input_filename);
  1202.                  printf("Output file name: ");
  1203.                  getstring(output_filename);
  1204.                  printf("Output format 0 - TGA8, 1 - TGA16, 2 - TGA24, 3 - TGA32: ");
  1205.                  getint(&output_format);
  1206.                  if ( (ret = L_DecompressTGA(input_filename, output_filename, output_format))
  1207.                                            == SUCCESS)
  1208.                   {
  1209.                    printf("File: %s Decompressed to %s (TGA). Press any key to continue. ",input_filename,output_filename);
  1210.                   }
  1211.                  else
  1212.                   {
  1213.                    printf("Error: %d Decompressing to TGA. Press any key to continue. ", ret);
  1214.                    putch(7);
  1215.                   }
  1216.         break;
  1217.  
  1218.         case 36: /* Case compress PCX file */
  1219.                  printf("Input file name: ");
  1220.                  getstring(input_filename);
  1221.                  printf("Output file name: ");
  1222.                  getstring(output_filename);
  1223.                  printf("Compress format 0 - LEAD, 1 - JFIF, 2 - JTIF, 3 - LEAD1JFIF, 4 - LEAD1JTIF,\n");
  1224.                  printf("5 - LEAD2JFIF, 6 - LEAD2JTF: ");
  1225.                  getint(&compress_format);
  1226.                  printf("Qfactor 1 to 255 or LEAD defined PQ1, PQ2, QFS, QMS, QS, SQS, SQT, MCQ, MC ");
  1227.                  getstring(compress_qfactor);
  1228.                  if (compress_format != 0)
  1229.                   save_palette = 0;
  1230.                  else
  1231.                   {
  1232.                    printf("Save VGA palette? 0 - No, 1 - YES: ");
  1233.                    getint(&save_palette);
  1234.                    while( (save_palette != 0) && (save_palette != 1) )
  1235.                     {
  1236.                      printf("Save VGA palette? 0 - No, 1 - YES: ");
  1237.                      getint(&save_palette);
  1238.                     }
  1239.                   }
  1240.                  strupr(compress_qfactor);
  1241.                  if ( (qfactor = get_qfactor(compress_qfactor)) == ERROR_QFACTOR)
  1242.                   {
  1243.                    printf("Error: Bad qfactor.");
  1244.                    break;
  1245.                   }
  1246.                  if ( (ret = L_CompressPCX(input_filename, output_filename, compress_format,
  1247.                                          qfactor, save_palette)) == SUCCESS)
  1248.                   {
  1249.                    printf("File: %s compressed to %s. Press any key to continue.",input_filename,output_filename);
  1250.                   }
  1251.                  else
  1252.                   {
  1253.                    printf("Error: %d compressing %s. Press any key to continue.", ret,input_filename);
  1254.                    putch(7);
  1255.                   }
  1256.         break;
  1257.    
  1258.         case 37: /* Case decompress to PCX file*/
  1259.                  printf("Input file name: ");
  1260.                  getstring(input_filename);
  1261.                  printf("Output file name: ");
  1262.                  getstring(output_filename);
  1263.                  if ( (ret = L_DecompressPCX(input_filename, output_filename, PCX8))
  1264.                       == SUCCESS)
  1265.                   {
  1266.                    printf("%s Decompressed to %s (PCX). Press any key to continue. ",input_filename,output_filename);
  1267.                   }
  1268.                  else
  1269.                   {
  1270.                    printf("Error: %d Decompressing to PCX. Press any key to continue. ", ret);
  1271.                    putch(7);
  1272.                   }
  1273.         break;
  1274.  
  1275.         case 38: /* Case compress GIF file */
  1276.                  printf("Input file name: ");
  1277.                  getstring(input_filename);
  1278.                  printf("Output file name: ");
  1279.                  getstring(output_filename);
  1280.                  printf("Compress format 0 - LEAD, 1 - JFIF, 2 - JTIF, 3 - LEAD1JFIF, 4 - LEAD1JTIF,\n");
  1281.                  printf("5 - LEAD2JFIF, 6 - LEAD2JTF: ");
  1282.                  getint(&compress_format);
  1283.                  printf("Qfactor 1 to 255 or LEAD defined PQ1, PQ2, QFS, QMS, QS, SQS, SQT, MCQ, MC ");
  1284.                  getstring(compress_qfactor);
  1285.                  if (compress_format != 0)
  1286.                    save_palette = 0;
  1287.                  else
  1288.                   {
  1289.                    printf("Save VGA palette? 0 - No, 1 - YES: ");
  1290.                    getint(&save_palette);
  1291.                    while( (save_palette != 0) && (save_palette != 1) )
  1292.                     {
  1293.                      printf("Save VGA palette? 0 - No, 1 - YES: ");
  1294.                      getint(&save_palette);
  1295.                     }
  1296.                   }
  1297.                  strupr(compress_qfactor);
  1298.                  if ( (qfactor = get_qfactor(compress_qfactor)) == ERROR_QFACTOR)
  1299.                   {
  1300.                    printf("Error: Bad qfactor. Press any key to continue.");
  1301.                    putch(7);
  1302.                    break;
  1303.                   }
  1304.                  if ( (ret = L_CompressGIF(input_filename, output_filename, compress_format,
  1305.                                          qfactor, save_palette)) == SUCCESS)
  1306.                   {
  1307.                    printf("File: %s compressed to %s. Press any key to continue.",input_filename,output_filename);
  1308.                   }
  1309.                  else
  1310.                   {
  1311.                    printf("Error: %d compressing %s. Press any key to continue.", ret,input_filename);
  1312.                    putch(7);
  1313.                   }
  1314.         break;
  1315.        
  1316.         case 39: /* Case decompress to GIF file */
  1317.                  printf("Input file name: ");
  1318.                  getstring(input_filename);
  1319.                  printf("Output file name: ");
  1320.                  getstring(output_filename);
  1321.                  if ( (ret = L_DecompressGIF(input_filename, output_filename, GIF8))
  1322.                             == SUCCESS)
  1323.                   {
  1324.                    printf("File: %s decompressed to %s (GIF). Press any key to continue. ",input_filename,output_filename);
  1325.                   }
  1326.                  else
  1327.                   {
  1328.                    printf("Error: %d Decompressing to GIF. Press any key to continue. ", ret);
  1329.                    putch(7);
  1330.                   }
  1331.         break;
  1332.  
  1333.         case 40: /* Case compress TIF file */
  1334.                  printf("Input file name: ");
  1335.                  getstring(input_filename);
  1336.                  printf("Output file name: ");
  1337.                  getstring(output_filename);
  1338.                  printf("Compress format 0 - LEAD, 1 - JFIF, 2 - JTIF, 3 - LEAD1JFIF, 4 - LEAD1JTIF,\n");
  1339.                  printf("5 - LEAD2JFIF, 6 - LEAD2JTF: ");
  1340.                  getint(&compress_format);
  1341.                  printf("Qfactor 1 to 255 or LEAD defined PQ1, PQ2, QFS, QMS, QS, SQS, SQT, MCQ, MC ");
  1342.                  getstring(compress_qfactor);
  1343.                  if (compress_format != 0)
  1344.                    save_palette = 0;
  1345.                  else
  1346.                   {
  1347.                    printf("Save VGA palette? 0 - No, 1 - YES: ");
  1348.                    getint(&save_palette);
  1349.                    while( (save_palette != 0) && (save_palette != 1) )
  1350.                     {
  1351.                      printf("Save VGA palette? 0 - No, 1 - YES: ");
  1352.                      getint(&save_palette);
  1353.                     }
  1354.                   }
  1355.                  strupr(compress_qfactor);
  1356.                  if ( (qfactor = get_qfactor(compress_qfactor)) == ERROR_QFACTOR)
  1357.                   {
  1358.                    printf("Error: Bad qfactor. Press any key to continue.");
  1359.                    break;
  1360.                   }
  1361.                  if ( (ret = L_CompressTIF(input_filename, output_filename, compress_format,
  1362.                                          qfactor, save_palette)) == SUCCESS)
  1363.                   {
  1364.                    printf("File %s compressed to %s. Press any key to continue.",input_filename,output_filename);
  1365.                   }
  1366.                  else
  1367.                   {
  1368.                    printf("Error: %d compressing %s. Press any key to continue.", ret,input_filename);
  1369.                    putch(7);
  1370.                   }
  1371.         break;
  1372.  
  1373.         case 41: /* Case decompress to a TIF file */
  1374.                  printf("Input file name: ");
  1375.                  getstring(input_filename);
  1376.                  printf("Output file name: ");
  1377.                  getstring(output_filename);
  1378.                  printf("Output format 7 - TIF8, 8 - TIF24: ");
  1379.                  getint(&output_format);
  1380.                  if ( (ret = L_DecompressTIF(input_filename, output_filename, output_format))
  1381.                             == SUCCESS)
  1382.                   {
  1383.                    printf("File: %s Decompressed to %s (TIF). Press any key to continue. ",input_filename,output_filename);
  1384.                   }
  1385.                  else
  1386.                   {
  1387.                    printf("Error: %d Decompressiing to TIF. Press any key to continue. ", ret);
  1388.                    putch(7);
  1389.                   }
  1390.         break;
  1391.  
  1392.         case 42: /* Case compress a BMP file */
  1393.                  printf("Input file name: ");
  1394.                  getstring(input_filename);
  1395.                  printf("Output file name: ");
  1396.                  getstring(output_filename);
  1397.                  printf("Compress format 0 - LEAD, 1 - JFIF, 2 - JTIF, 3 - LEAD1JFIF, 4 - LEAD1JTIF,\n");
  1398.                  printf("5 - LEAD2JFIF, 6 - LEAD2JTF: ");
  1399.                  getint(&compress_format);
  1400.                  printf("Qfactor 1 to 255 or LEAD defined PQ1, PQ2, QFS, QMS, QS, SQS, SQT, MCQ, MC ");
  1401.                  getstring(compress_qfactor);
  1402.                  if (compress_format != 0)
  1403.                    save_palette = 0;
  1404.                  else
  1405.                   {
  1406.                    printf("Save VGA palette? 0 - No, 1 - YES: ");
  1407.                    getint(&save_palette);
  1408.                    while( (save_palette != 0) && (save_palette != 1) )
  1409.                     {
  1410.                      printf("Save VGA palette? te? 0 - No, 1 - YES: ");
  1411.                      getint(&save_palette);
  1412.                     }
  1413.                   }
  1414.                  strupr(compress_qfactor);
  1415.                  if ( (qfactor = get_qfactor(compress_qfactor)) == ERROR_QFACTOR)
  1416.                   {
  1417.                    printf("Error: Bad qfactor. Press any key to continue.");
  1418.                    break;
  1419.                   }
  1420.                  if ( (ret = L_CompressBMP(input_filename, output_filename, compress_format,
  1421.                                          qfactor, save_palette)) == SUCCESS)
  1422.                   {
  1423.                    printf("File: %s compressed to %s. Press any key to continue.",input_filename,output_filename);
  1424.                   }
  1425.                  else
  1426.                   {
  1427.                    printf("Error: %d compressing %s. Press any key to continue.", ret,input_filename);
  1428.                    putch(7);
  1429.                   }
  1430.         break;
  1431.  
  1432.         case 43: /* Case decompress to BMP file */
  1433.                  printf("Input file name: ");
  1434.                  getstring(input_filename);
  1435.                  printf("Output file name: ");
  1436.                  getstring(output_filename);
  1437.                  printf("Output format 1 -BMP4, 2 -BMP8, 3 -BMP24, 4 -PM4, 5 -PM8, 6 -PM24: ");
  1438.                  getint(&output_format);
  1439.                  if(output_format==1)
  1440.                     output_format=BMP4;
  1441.                  else if(output_format==2)
  1442.                     output_format=BMP8;
  1443.                  else if(output_format==3)
  1444.                     output_format=BMP24;
  1445.                  else if(output_format==4)
  1446.                     output_format=PM4;
  1447.                  else if(output_format==5)
  1448.                     output_format=BMP8;
  1449.                  else if(output_format==6)
  1450.                     output_format=BMP24;
  1451.                  else
  1452.                    {
  1453.                       printf("%d not a valid option",output_format);
  1454.                       getch();
  1455.                       break;
  1456.                    }
  1457.  
  1458.  
  1459.                  if ( (ret = L_DecompressBMP(input_filename, output_filename, output_format))
  1460.                            == SUCCESS)
  1461.                   {
  1462.                    printf("File: %s decompressed to %s (BMP). Press any key to continue. ",input_filename,output_filename);
  1463.                   }
  1464.                  else
  1465.                   {
  1466.                    printf("Error: %d Decompressing to BMP. Press any key to continue. ", ret);
  1467.                    putch(7);
  1468.                   }
  1469.         break;
  1470.  
  1471.         case 44: /* Case compress TARGA screen */
  1472.                  /* Is a TARGA installed OK */
  1473.                  if (TARGA_FLAG)
  1474.                   {
  1475.                    printf("Output file name: ");
  1476.                    getstring(output_filename);
  1477.                    printf("Compress format 0 - LEAD, 1 - JFIF, 2 - JTIF, 3 - LEAD1JFIF, 4 - LEAD1JTIF,\n");
  1478.                    printf("5 - LEAD2JFIF, 6 - LEAD2JTF: ");
  1479.                    getint(&compress_format);
  1480.                    printf("Qfactor 1 to 255 or LEAD defined PQ1, PQ2, QFS, QMS, QS, SQS, SQT, MCQ, MC ");
  1481.                    getstring(compress_qfactor);
  1482.                    strupr(compress_qfactor);
  1483.                    if ( (qfactor = get_qfactor(compress_qfactor)) == ERROR_QFACTOR)
  1484.                     {
  1485.                      printf("Error: Bad qfactor. Press any key to continue.");
  1486.                      putch(7);
  1487.                      break;
  1488.                     }
  1489.                    if ( (ret = L_CompressTarga(output_filename, compress_format,
  1490.                                                qfactor )) == SUCCESS )
  1491.                     {
  1492.                      printf("File: %s TARGA screen compressed. Press any key to continue.",output_filename);
  1493.                     }
  1494.                    else
  1495.                     {
  1496.                      printf("Error: %d TARGA screen compression.", ret);
  1497.                      putch(7);
  1498.                     }
  1499.                   }
  1500.                  else
  1501.                   {
  1502.                    printf("Error: Cannot initialize TARGA board.  Press any key to continue.");
  1503.                    putch(7);
  1504.                   }
  1505.         break;
  1506.  
  1507.         case 45: /* Gase get file info */
  1508.                  printf("Input file name: ");
  1509.                  getstring(input_filename);
  1510.                  if (L_FileInfo(input_filename, &FileInfo) != SUCCESS)
  1511.                   {
  1512.                    printf("Error: %s Unrecognized file format.  Press any key to continue.",input_filename);
  1513.                    putch(7);
  1514.                    break;
  1515.                   }
  1516.                   ClearTheScreen();
  1517.                   if (FileInfo.Format == FILE_PCX)
  1518.                    {
  1519.                     printf("File: %s is a PCX file format\n",input_filename);
  1520.                     printf("Width      = %d\n",FileInfo.Width);
  1521.                     printf("Height     = %d\n",FileInfo.Height);
  1522.                     printf("Bits/Pixel = %d\n",FileInfo.BitsPerPixel);
  1523.                    }
  1524.                   else
  1525.                     if (FileInfo.Format == FILE_GIF)
  1526.                   {    
  1527.                     printf("File: %s is a GIF file format\n",input_filename);
  1528.                     printf("Width      = %d\n",FileInfo.Width);
  1529.                     printf("Height     = %d\n",FileInfo.Height);
  1530.                     printf("Bits/Pixel = %d\n",FileInfo.BitsPerPixel);
  1531.  
  1532.                   }
  1533.                  else
  1534.                   if (FileInfo.Format == FILE_TIF)
  1535.                   {
  1536.                     printf("File: %s is a TIF file format\n",input_filename);
  1537.                     printf("Width      = %d\n",FileInfo.Width);
  1538.                     printf("Height     = %d\n",FileInfo.Height);
  1539.                     printf("Bits/Pixel = %d\n",FileInfo.BitsPerPixel);
  1540.  
  1541.                   }
  1542.                  else
  1543.                   if (FileInfo.Format == FILE_TGA)
  1544.                    {
  1545.                     printf("File: %s is a TGA file format\n",input_filename);
  1546.                     printf("Width      = %d\n",FileInfo.Width);
  1547.                     printf("Height     = %d\n",FileInfo.Height);
  1548.                     printf("Bits/Pixel = %d\n",FileInfo.BitsPerPixel);
  1549.                    }
  1550.                   else
  1551.                    if (FileInfo.Format == FILE_CMP)
  1552.                   {
  1553.                     printf("File: %s is a LEAD compressed file format\n",input_filename);
  1554.                     printf("Width      = %d\n",FileInfo.Width);
  1555.                     printf("Height     = %d\n",FileInfo.Height);
  1556.                     printf("Bits/Pixel = %d\n",FileInfo.BitsPerPixel);
  1557.                    }
  1558.                   else
  1559.                    if (FileInfo.Format == FILE_BMP)
  1560.                   {
  1561.                     printf("File: %s is a Windows BMP file format\n",input_filename);
  1562.                     printf("Width      = %d\n",FileInfo.Width);
  1563.                     printf("Height     = %d\n",FileInfo.Height);
  1564.                     printf("Bits/Pixel = %d\n",FileInfo.BitsPerPixel);
  1565.                   }
  1566.                   else
  1567.                    if (FileInfo.Format == FILE_OS2)
  1568.                   {
  1569.                     printf("File: %s is an OS2 BMP file format\n",input_filename);
  1570.                     printf("Width      = %d\n",FileInfo.Width);
  1571.                     printf("Height     = %d\n",FileInfo.Height);
  1572.                     printf("Bits/Pixel = %d\n",FileInfo.BitsPerPixel);
  1573.                   }
  1574.  
  1575.                  else
  1576.                   if (FileInfo.Format == FILE_JFIF)
  1577.                   {
  1578.                     printf("File: %s is a JPEG File Interchange Format (JFIF)\n",input_filename);
  1579.                     printf("Width      = %d\n",FileInfo.Width);
  1580.                     printf("Height     = %d\n",FileInfo.Height);
  1581.                     printf("Bits/Pixel = %d\n",FileInfo.BitsPerPixel);
  1582.                   }
  1583.                  else
  1584.                   if (FileInfo.Format == FILE_JTIF)
  1585.                    {
  1586.                     printf("File: %s is a JPEG TIF file format (JTIF)\n",input_filename);
  1587.                     printf("Width      = %d\n",FileInfo.Width);
  1588.                     printf("Height     = %d\n",FileInfo.Height);
  1589.                     printf("Bits/Pixel = %d\n",FileInfo.BitsPerPixel);
  1590.                    }
  1591.                  printf("\n\nPress any key to continue.");
  1592.         break;
  1593.  
  1594.         case 46: /* Case convert a file */
  1595.                  printf("Input file name: ");
  1596.                  getstring(input_filename);
  1597.                  if (L_FileInfo(input_filename, &FileInfo) != SUCCESS)  
  1598.                   {
  1599.                    printf("Error: %s Unknown file format.  Press any key to continue.",input_filename);
  1600.                    putch(7);
  1601.                    break;
  1602.                   }
  1603.                  input_format = FileInfo.Format;
  1604.                  printf("Output file name: ");
  1605.                  getstring(output_filename);
  1606.                  printf("Output file format 1 -PCX, 2 -GIF, 3 -TIF, 4 -TGA, 6 -Windows BMP, 14 -OS2 BMP : ");
  1607.                  getint(&output_format);
  1608.                  if ( (output_format != FILE_PCX) && (output_format != FILE_GIF)
  1609.                      && (output_format != FILE_TIF) && (output_format != FILE_TGA)
  1610.                      && (output_format != FILE_BMP)
  1611.                      && (output_format != FILE_OS2) )
  1612.                   {
  1613.                    printf("Error: Unknown file format. Press any key to continue.");
  1614.                    putch(7);
  1615.                    break;
  1616.                   }
  1617.                  printf("New width or 0 for same as original: ");
  1618.                  getint(&new_width);
  1619.                  printf("New height or 0 for same as original: ");
  1620.                  getint(&new_height);
  1621.                  printf("BitsPerPixel: ");
  1622.                  getint(&BitsPerPixel);
  1623.                  if (output_format == FILE_PCX)
  1624.                   {
  1625.                    if ( (BitsPerPixel != 1) && (BitsPerPixel != 4) && (BitsPerPixel != 8) )
  1626.                     {
  1627.                      printf("Error: PCX can only be 1, 4, or 8-Bits/pixel. Press any key to continue.");
  1628.                      putch(7);
  1629.                      break;
  1630.                     }
  1631.                   }
  1632.                  else
  1633.                   if (output_format == FILE_GIF)
  1634.                    {
  1635.                     if ( (BitsPerPixel != 8) )
  1636.                      {
  1637.                       printf("Error: GIF can only be 8-Bits/pixel. Press any key to continue.");
  1638.                       putch(7);
  1639.                       break;
  1640.                      }
  1641.                    }
  1642.                   else
  1643.                    if (output_format == FILE_TIF)
  1644.                     {
  1645.                      if ( (BitsPerPixel != 1) && (BitsPerPixel != 8)
  1646.                          && (BitsPerPixel != 24) )
  1647.                       {
  1648.                        printf("Error: TIF can only be 1, 8, or 24-Bits/pixel. Press any key to continue.");
  1649.                        putch(7);
  1650.                        break;
  1651.                       }
  1652.                     }
  1653.                    else
  1654.                     if (output_format == FILE_TGA)
  1655.                      {
  1656.                       if ( (BitsPerPixel != 8) && (BitsPerPixel != 16)
  1657.                           && (BitsPerPixel != 24) && (BitsPerPixel != 32) )
  1658.                        {
  1659.                         printf("Error: TGA can only be 8, 16, 24, or 32-Bits/pixel. Press any key to continue.");
  1660.                         putch(7);
  1661.                         break;
  1662.                        }
  1663.                      }
  1664.                     else
  1665.                      if (output_format == FILE_BMP || output_format == FILE_OS2)
  1666.                        {
  1667.                        if ( (BitsPerPixel != 4) && (BitsPerPixel != 8)
  1668.                            && (BitsPerPixel != 24) )
  1669.                         {
  1670.                          printf("Error: BMP can only be 4, 8, or 24 Bits/pixel. Press any key to continue.");
  1671.                          putch(7);
  1672.                          break;
  1673.                         }
  1674.                       }
  1675.                  if ( (ret=L_FileConvert( input_filename,input_format,
  1676.                                        output_filename, output_format, new_width,
  1677.                                        new_height, BitsPerPixel )) == SUCCESS)
  1678.                   {
  1679.                    printf("File: %s converted to %s successfully.", input_filename, output_filename);
  1680.                   }
  1681.                  else
  1682.                   {
  1683.                    printf("Error: %d File convert. Press any key to continue.", ret);
  1684.                    putch(7);
  1685.                   }
  1686.         break;
  1687.  
  1688.         case 47: /* Case get video information */
  1689.                  ClearTheScreen();
  1690.                  L_GetVideoInfo(&videotype, &width, &height);
  1691.                  if (videotype == VIDEO_EGA)
  1692.                    printf("\n\nVIDEO TYPE =  EGA\nWidth = %d, Height = %d",width, height);
  1693.                  else
  1694.                  if (videotype == VIDEO_VGA)
  1695.                    printf("\n\nVIDEO TYPE = Standared VGA with 256K of memory\nWidth = %d, Height = %d",width, height);
  1696.                  else
  1697.                   if (videotype == VIDEO_SVGA)
  1698.                    printf("\n\nVIDEO TYPE =  SuperVGA with 512K or more memory\nWidth = %d, Height = %d",width, height);
  1699.                  printf("\n\nPress any key to continue.");
  1700.         break;
  1701.  
  1702.         case 48: /* Case set video resolution */
  1703.         #ifdef TARGA   /* If TARGA 16,24,32 is used not a TARGA+.
  1704.                           The TARGA+ can be chages to multiple resolutions
  1705.                           I cant not chage the old TARGA 16,24,32 only TARGA+*/
  1706.                  printf("MAX VGA resolution 0-320x200, 1-640x350, 2-640x480, 3-800x600, 4-1024x768. ");
  1707.                  getint(&video_size);
  1708.                 /* Checks for legal VGA/SuperVGA resolution */
  1709.                  if ( (video_size != SIZE_320x200) && (video_size != SIZE_640x350)
  1710.                       && (video_size != SIZE_640x480) && (video_size != SIZE_800x600)
  1711.                       && (video_size != SIZE_1024x768) )
  1712.                   {
  1713.                    printf("Error: Unknown VGA resolution %d. Press any key to continue.",video_size);
  1714.                    putch(7);
  1715.                    break;
  1716.                   }
  1717.                  L_SetVGASize(video_size) ;
  1718.                  printf("VGA size set OK!  Press any key to continue.");
  1719.         #else    /** If TARGA+ is used NOT a TARGA 16, 24, 32**/
  1720.                  printf(" 0 - Set VGA resolution. 1 - Set TARGA+ resolution.");
  1721.                  getint(&input_format);
  1722.                  if (input_format == 0)
  1723.                     {
  1724.                     printf("MAX VGA resolution 0-320x200, 1-640x350, 2-640x480, 3-800x600, 4-1024x768: ");
  1725.                     getint(&video_size);
  1726.                     /* Checks for legal VGA/SuperVGA resolution */
  1727.                     if ( (video_size != SIZE_320x200) && (video_size != SIZE_640x350)
  1728.                        && (video_size != SIZE_640x480) && (video_size != SIZE_800x600)
  1729.                        && (video_size != SIZE_1024x768) )
  1730.                        {
  1731.                        printf("Error: Unknown VGA resolution %d. Press any key to continue.",video_size);
  1732.                        putch(7);
  1733.                        break;
  1734.                        }
  1735.                     L_SetVGASize(video_size) ;        /* Set new VGA resolution */
  1736.                     printf("VGA size set OK!  Press any key to continue.");
  1737.                     }
  1738.                  else if(input_format == 1)
  1739.                     {
  1740.                     ClearTheScreen();
  1741.  
  1742.                     printf("  0 - Interlaced 512x400x16.\n");        /* TARGA+ modes available */
  1743.                     printf("  1 - Noninterlaced 512x400x16.\n");
  1744.                     printf("  2 - Interlaced 512x400x32.\n");
  1745.                     printf("  3 - Noninterlaced 512x400x32.\n");
  1746.                     printf("  4 - Interlaced 512x486x16.\n");
  1747.                     printf("  5 - Noninterlaced 512x486x16.\n");
  1748.                     printf("  6 - Interlaced 512x486x32.\n");
  1749.                     printf("  7 - Noninterlaced 512x486x32.\n");
  1750.                     printf("  8 - Interlaced 640x480x16.\n");
  1751.                     printf("  9 - Noninterlaced 640x480x16.\n");
  1752.                     printf(" 10 - SquareInterlaced 640x486x16.\n");
  1753.                     printf(" 11 - SquareNoninterlaced 640x486x16.\n");
  1754.                     printf(" 12 - Interlaced 720x486x16.\n");
  1755.                     printf(" 13 - Noninterlaced 720x486x16.\n");
  1756.                     printf(" 14 - Interlaced 756x486x16.\n");
  1757.                     printf(" 15 - Noninterlaced 756x486x16.\n");
  1758.                     printf(" 16 - Interlaced 800x600x16.\n");
  1759.                     printf(" 17 - Interlaced 1024x768x16.\n");
  1760.  
  1761.                     L_SetCursor(1, 24);
  1762.                     printf("Set Targa+ Mode To: ");
  1763.                     getint(&videotype);
  1764.                     L_SetTARGAMode(videotype) ;            /* Set new TARGA+ mode */
  1765.                     printf("Targa+ mode set!  Press any key to continue.\n");
  1766.                     }
  1767.                  else
  1768.                     {
  1769.                     printf("Error: %d Unknown command number!");
  1770.                     putch(7);
  1771.                     }
  1772.         #endif
  1773.         break;
  1774.  
  1775.         case 49: /* Case set VGA memory */
  1776.                  printf("VGA memory in Kbytes: ");
  1777.                  getint(&video_memory);
  1778.                 if (video_memory < 256)
  1779.                  {
  1780.                   printf("Error: %d Unknown VGA memory size", video_memory);
  1781.                   break;
  1782.                  }
  1783.                 L_SetVideoMemory(video_memory) ;       /* Set new video memory */
  1784.                 printf("VGA memory set! Press any key to continue.\n");
  1785.         break;
  1786.  
  1787.        case 50: /* Case change brightness */
  1788.                 printf("Increase/Decrease Intensity by: ");
  1789.                 getint( &ret );
  1790.                 L_ChangeBitmapIntensity(&Bitmap, ret) ;    /* Set new intensity */
  1791.                 printf("Change Intensity Successful!");
  1792.         break;
  1793.  
  1794.         case 51: /* Case capture VGA */
  1795.                 if (alloc_bitmap == 1)       /* Free BitMap information as before */
  1796.                    {
  1797.                     L_FreeBitmap( &Bitmap );
  1798.                     alloc_bitmap = 0;
  1799.                    }
  1800.                 /* The input file name can be any file format as long as it matches the */
  1801.                 /* function call below. For this program capturing the VGA screen       */
  1802.                 /* requires that the user enter a PCX file. It then loads the file to   */
  1803.                 /* a bitmap handle. Then it will save the bitmap using L_GetScreeBitMap.*/
  1804.                 /* When it is finished, it will release the bitmap.                     */
  1805.                 printf("Input PCX file name: ");
  1806.                 getstring(input_filename);
  1807.                 printf("Starting X display position, or 0 for normal position: ");
  1808.                 getint(&xpos);
  1809.                 printf("Starting Y display position, or 0 for normal position: ");
  1810.                 getint(&ypos);
  1811.                 printf("Display width, or 0 for current Width in the file: ");
  1812.                 getint(&width);
  1813.                 printf("Display height, or 0 for current Height in the file: ");
  1814.                 getint(&height);
  1815.                                  /* Puts it on the VGA screen and Bitmap handle */
  1816.                 if ( (ret = L_LoadPCXScreen(input_filename, &Bitmap, OUTPUT_BITMAP,
  1817.                                                              TYPE_CONV, 0, 0 )) == SUCCESS)
  1818.                  {
  1819.                   if ((ret=L_ViewBitmapScreen(&Bitmap, 0, 0)) == SUCCESS)
  1820.                    {
  1821.                     if ((ret = L_GetScreenBitmap(&NewBitmap, 0, 0, 0, 0)) == SUCCESS )
  1822.                      {
  1823.                        if ((ret = L_SavePCXBitmap("screen.pcx", &NewBitmap, 8)) == SUCCESS)
  1824.                         {
  1825.                          /* Copy to screen sucessfull and is saved as screen.pcx in */
  1826.                          /* current directory at 8 bit/pixel.                       */ 
  1827.                         }
  1828.                       L_FreeBitmap(&NewBitmap); /* Release impage from the copy Bit map */
  1829.                       alloc_bitmap = 1;         /* Release image from the bitmap */
  1830.                      }
  1831.                    }
  1832.                  }
  1833.         break;
  1834.  
  1835.  
  1836.         case 99: /* inter use */
  1837.              L_SetVideoSource(VideoInputRGB);
  1838.              L_SetTARGALiveMode();
  1839.              L_SleepKey(99);
  1840.              L_GrabTARGA();
  1841.              break;
  1842.  
  1843.         case 100: /* Case exit the program */
  1844.                   if (alloc_bitmap == 1)  /* Release BitMap information before quit */
  1845.                    {
  1846.                     L_FreeBitmap(&Bitmap);
  1847.                     alloc_bitmap = 0;
  1848.                    }
  1849.                   L_TARGAEnd();
  1850.                     printf("\nEXIT DEMO\n\n\n");
  1851.                   printf("       COPYRIGHT (c) 1991 LEAD Technologies Inc. ALL RIGHTS RESERVED.\n");
  1852.                   printf("                           8701 Mallard Creek Rd.\n");
  1853.                   printf("                           Charlotte NC 28262\n");
  1854.                   printf("                           Tel # 704-549-5532\n");
  1855.                   printf("LEADTOOLS Sharwareis for Evaluation purposes only. Your license to use this\n");
  1856.                   printf("software will expire after 3 weeks from the date you receive it.\n");
  1857.                   printf("You are free to distribute this sharware copy of LEADTOOLS as long as all \n");
  1858.                   printf("files listed (TOOL.C TOOL4.EXE LEADSHOW.C LEADSHOW.EXE LEADCOMP.C\n");
  1859.                   printf("LEADCOMP.EXE LEADECOM.C LEADECOM.EXE) are all included. You may not distribute\n");
  1860.                   printf("any of the files separately.\n");
  1861.                   printf("If you do not have the above list of files please contact LEAD Technologies \n");
  1862.                   printf("Inc. for the complete list.\n");
  1863.                   printf("All .EXE programs are not designed as end user products.  They all are a quick\n");
  1864.                   printf("collection of calls to LEADTOOLS functions.  Menus were not included to avoid\n");
  1865.                   printf("confusion when evaluating the code as to the processing calls verses the\n");
  1866.                   printf("menuing code.\n");
  1867.                   exit(0);
  1868.  
  1869.         default:   /* Anything else is a wrong selection */
  1870.                printf("Wrong selection!  Press any key to continue.");
  1871.                putch(7);
  1872.                break;
  1873.        }             /* End BIG switch */
  1874.  
  1875.  L_SleepKey(99);    /* Waits 99 seconds or until key is pressed */
  1876.  
  1877. }                   /* BIG for loop  */
  1878.  
  1879. }                    /* end main(); */
  1880. /****************************END OF MAIN()***************************/
  1881.  
  1882.  
  1883. /*********** Function to get the qfactor **********/
  1884. /* Also it checks for a valid qfactor entered by the user */
  1885. int get_qfactor(char *string)   /* String to hold the Qfactor */
  1886. {
  1887.   char *exttab[NUMEXTENSIONS], *extptr1;
  1888.   int qfactor, source;
  1889.  
  1890.   /* The following is a reference table to find out which compression       */
  1891.   /* method the user wants to compress the file with.                       */
  1892.     exttab[0] = "PQ1";    /* Perfect quality compression                    */
  1893.     exttab[1] = "PQ2";    /* Perfect quality compression                    */
  1894.     exttab[2] = "QFS";   /* Quality by far more important than size         */
  1895.     exttab[3] = "QMS";   /* Quality more important than size                */
  1896.     exttab[4] = "QS";    /* Quality and size equally important              */
  1897.     exttab[5] = "SQS";   /* Size more important than quality - SHARP        */
  1898.     exttab[6] = "SQT";   /* Size more important than quality -  LESS TILING */
  1899.     exttab[7] = "MCQ";   /* Give maximum compression - HIGHT QUALITY        */
  1900.     exttab[8] = "MC";    /* Give maximum compression                        */
  1901.  
  1902. extptr1 = string;
  1903.  
  1904. for (source = 0; source < NUMEXTENSIONS; ++source)
  1905.      {if (!strcmp(extptr1, exttab[source]))
  1906.        break;
  1907.       }
  1908. /* Checks for bad qfactor */
  1909. if (source >= NUMEXTENSIONS)
  1910.    {
  1911.    qfactor = atoi(string);
  1912.    if (qfactor <= 0 || qfactor > 255)
  1913.       return(ERROR_QFACTOR);
  1914.    else
  1915.       return (qfactor);
  1916.    }
  1917. /* Else the extension is a predefined qfactor shown in the table above */
  1918. else
  1919.    {
  1920.    if (source == 0)         /* See the table above for types of compression */
  1921.       return(QFACTOR_PQ1);
  1922.    if (source == 1)
  1923.       return(QFACTOR_PQ2);
  1924.    if (source == 2)
  1925.       return(QFACTOR_QFS);
  1926.    if (source == 3)
  1927.       return(QFACTOR_QMS);
  1928.    if (source == 4)
  1929.       return(QFACTOR_QS);
  1930.    if (source == 5)
  1931.       return(QFACTOR_SQS);
  1932.    if (source == 6)
  1933.       return(QFACTOR_SQT);
  1934.    if (source == 7)
  1935.       return(QFACTOR_MCQ);
  1936.    if (source == 8)
  1937.       return(QFACTOR_MC);
  1938.    }
  1939. return(SUCCESS);
  1940. }
  1941.  
  1942. /********* Prints out the Main Menu *********/
  1943. void printscreen(void)
  1944. {
  1945.   int i;  /* For the loop to fill the BLANK screen and a */
  1946.           /* BLANK line storage array */
  1947.  
  1948. /* Fill the storage space into a BLANK screen with 0's */
  1949.   for(i=0; i<4000; i=i+2)  /* The background color */
  1950.      screen_clear[i]=0;
  1951.   for(i=1; i<4000; i=i+2)  /* The foreground color */
  1952.      screen_clear[i]=7;
  1953.  
  1954.   for(i=0; i<160; i=i+2)   /* Fill the storage space into a BLANK line */
  1955.      clear_line[i]=0;
  1956.   for(i=1; i<160; i=i+2)   /* The foreground color */
  1957.      clear_line[i]=15;
  1958.  
  1959.  /* Prints out the Main Menu */ 
  1960.    printf(" 1- Load TGA file to BitMap.             2- Save BitMap as TGA file.\n");
  1961.    printf(" 3- Load PCX file to BitMap.             4- Save BitMap as PCX file.\n");
  1962.    printf(" 5- Load GIF file to BitMap.             6- Save BitMap as GIF file.\n");
  1963.    printf(" 7- Load TIF file to BitMap.             8- Save BitMap as TIF file.\n");
  1964.    printf(" 9- Load BMP file to BitMap.            10- Save BitMap as BMP file.\n");
  1965.    printf("11- Load LEAD/JFIF/JTIF file to BitMap. 12- Save BitMap as LEAD/JFIF/JTIF file.\n");
  1966.    printf("13- Flip BitMap.      14- Reverse BitMap.  15- Resize BitMap.  16 Rotate Bitmap\n");
  1967.    printf("17- Optimize BitMap.  18- Clear BitMap.    19- Change BitMap position.\n");
  1968.    printf("20- View BitMap on TARGA.               21- View BitMap on VGA.\n");
  1969.    printf("22- View TGA file on TARGA.             23- View TGA file on VGA.\n");
  1970.    printf("24- View PCX file on TARGA.             25- View PCX file on VGA.\n");
  1971.    printf("26- View GIF file on TARGA.             27- View GIF file on VGA.\n");
  1972.    printf("28- View TIF file on TARGA.             29- View TIF file on VGA.\n");
  1973.    printf("30- View BMP file on TARGA.             31- View BMP file on VGA.\n");
  1974.    printf("32- View LEAD/JFIF/JTIF file on TARGA.  33- View LEAD/JFIF/JTIF file on VGA.\n");
  1975.    printf("34- Compress TGA file.                  35- Decompress to TGA file.\n");
  1976.    printf("36- Compress PCX file.                  37- Decompress to PCX file.\n");
  1977.    printf("38- Compress GIF file.                  39- Decompress to GIF file.\n");
  1978.    printf("40- Compress TIF file.                  41- Decompress to TIF file.\n");
  1979.    printf("42- Compress BMP file.                  43- Decompress to BMP file.\n");
  1980.    printf("44- Compress TARGA screen.              45- Get information on a file.\n");
  1981.    printf("46- Convert a file.                     47- Get VGA/SuperVGA information.\n");
  1982. #ifdef TARGA
  1983.    printf("48- Set VGA/SuperVGA Resolution.        49- Set VGA/SuperVGA memory size.\n");
  1984. #else                                            
  1985.    printf("48- Set VGA or TARGA+ Resolution.       49- Set VGA/SuperVGA memory size.\n");
  1986. #endif
  1987.    printf("50- Change BitMap brightness.           51- Capture VGA to BitMap.\n");
  1988.  
  1989.    /* Clear the input line and chage the text attribute for that line */
  1990.    L_RestoreWindow (0, 24, 79, 24, clear_line, 79, 24);
  1991.    putch('\r');
  1992.    printf("Enter your selection, or 100 to exit: ");
  1993.    
  1994.    L_GetVideoMode(&mode, &page);   /* Save the current video TEXT screen
  1995.                                       and page mode */
  1996.  
  1997.    /* Save the curent input screen screen to be able to restore when needed
  1998.       it is faster to restore the input screen using L_RestoreWindow()
  1999.       than calling printscreen() since L_RestoreWindow() function writes
  2000.       directly to video memory */ 
  2001.    L_SaveWindow (0, 0, 79, 24, screen_buffer, &curcolumn, &currow);
  2002. }
  2003.  
  2004. /**************** Restore the Main Menu and Input Screen ***************/
  2005. /* Also sets the cursor position to 0,24                               */
  2006. void RestoreInputScreen()
  2007. {
  2008.  int newmode,newpage;            /* New text mode and video page */
  2009.  
  2010.  L_GetVideoMode(&newmode, &newpage);    
  2011.  if ( (newmode != mode) || (newpage != page) )
  2012.     L_SetVideoMode(mode, page);            /* Set new video mode */
  2013.  L_RestoreWindow (0, 0, 79, 24, screen_buffer, 37, 24);
  2014.  L_SetCursor(39, 24);                      /* Sets the cursor    */
  2015. }
  2016.  
  2017. /************* Get integer value from the keyboard *************/
  2018. void getint(int *answer)         
  2019. {
  2020.    int ch, i=0;
  2021.    char string[7];
  2022.  
  2023.    string[0]='\0';
  2024.    while(i < 5)
  2025.    {
  2026.     ch = getch();  /* Character type in is stored in ch */
  2027.     if ( (ch == EOF) || (ch == '\r') || (ch == '\n') )
  2028.       {
  2029.        break;
  2030.       }
  2031.     /* Makes sure ch is a printable charcter */
  2032.     /* Also checks to see if ch is a Backspace key */
  2033.     if ( (ch != 0x08) && (ch > 32 ) )
  2034.       {
  2035.        putch(ch);
  2036.        string[i]=(char)ch;
  2037.        i++;
  2038.       }
  2039.     else
  2040.        if (ch == 0x08)
  2041.          {
  2042.          if (i > 0)
  2043.             {
  2044.              /* If ch is a Backspace then clear the curent character
  2045.                 on the screen */
  2046.              i--;
  2047.              putch(ch);
  2048.              putch(' ');
  2049.              putch(ch);
  2050.             }
  2051.          }
  2052.    }
  2053.    string[i]='\0';
  2054.    *answer=atoi(string);
  2055.    putch('\r');     /* Clears the Line */
  2056.    L_RestoreWindow (0, 24, 79, 24, clear_line, 79, 24);
  2057.    putch('\r');
  2058. }
  2059.  
  2060. /************** Get a string from the keyboard ****************/
  2061. void getstring(char *answer)
  2062. {
  2063.    int ch, i=0;          /* Counters */
  2064.    char string[128];     /* Charcter buffer */
  2065.  
  2066.    while(i < 128)
  2067.    {
  2068.     ch = getch();          /* Gets a character and stores it in ch */
  2069.     if ( (ch == EOF) || (ch == '\r') || (ch == '\n') )
  2070.      {
  2071.       break;
  2072.      }
  2073.     /* Make sure the key pressed is a printable character and
  2074.        not a Backspace */
  2075.     if ( (ch != 0x08) && (ch > 32 ) )
  2076.      {
  2077.       putch(ch);
  2078.       string[i]=(char)ch;
  2079.       i++;
  2080.      }
  2081.     else
  2082.        if (ch == 0x08)
  2083.         {
  2084.          if (i > 0)
  2085.            {
  2086.             /* If ch is a Backspace then clear the curent character
  2087.                on the screen */
  2088.             i--;
  2089.             putch(ch);
  2090.             putch(' ');
  2091.             putch(ch);
  2092.            }
  2093.         }
  2094.    }
  2095.    string[i] = '\0';
  2096.    strcpy(answer,string);
  2097.    putch('\r');      /* Clear the line */
  2098.    L_RestoreWindow (0, 24, 79, 24, clear_line, 79, 24);
  2099.    putch('\r');
  2100. }
  2101.  
  2102.  
  2103. /************* BLANK the screen ************/
  2104. void ClearTheScreen(void)
  2105. {
  2106.  int newmode,newpage;              
  2107.  
  2108.  L_GetVideoMode(&newmode, &newpage);
  2109.  if ( (newmode != mode) || (newpage != page) )
  2110.    L_SetVideoMode(mode, page);
  2111.  L_RestoreWindow (0, 0, 79, 24, screen_clear, 79, 24);
  2112.  L_SetCursor(0, 0);
  2113. }
  2114.