home *** CD-ROM | disk | FTP | other *** search
/ Shareware Supreme Volume 6 #1 / swsii.zip / swsii / 279 / JPVIEW.ZIP / LSHOW.C < prev    next >
Text File  |  1993-02-15  |  21KB  |  602 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include <fcntl.h>
  4. #include <sys/types.h>
  5. #include <sys/stat.h>
  6. #include"v:\leadview\toolkit\L_Bitmap.h"
  7. #include"v:\leadview\toolkit\L_error.h"
  8. #include"v:\leadview\toolkit\toolapp.h"  
  9.  
  10. #define OK 1
  11. #define BAD_COMMAND -2
  12. #define TARGAOLD 1
  13. #define VGA   2
  14.  
  15. int mode,page;
  16. int Width=0,Height=0,Xorigin=-1,Yorigin=-1;
  17. int time=0;
  18. int video=VGA;
  19. int device_bits;
  20. char infile[400];
  21.  
  22.  
  23. main(int argc, char *argv[])
  24. {
  25.   FILE *Stream;
  26.   FILEINFO FileInformation;
  27.   char command[400], commandln[400];
  28.   struct find_t file;
  29.   int result;
  30.   int i;
  31.   char string[400], pathname[400];
  32.   int lines=0;
  33.   int error;
  34.   int first_option = 0;
  35.   int position, position1, kk;
  36.   char path[200];
  37.  
  38.   strcpy(path, argv[0]);
  39.  
  40.    L_SetDecompressFormatJTIF();
  41.    L_SetDecompressFormatJFIFCMP();
  42.  
  43.  
  44.   for (i = strlen(path)-1; i > 0; i--)
  45.    {
  46.    if (path[i] == '\\' || path[i] == ':')
  47.       break;
  48.    }
  49.      path[i+1] = 0;
  50.   i=0;
  51.  
  52.   #if !defined(FOR_386)
  53.   /**** load the fixed palette table to memory ****/
  54.   if ( L_LoadFixedPalette(path) != SUCCESS)
  55.     {
  56.       puts("Error: cannot load FIXEDPAL.DAT file.\n");
  57.       putch(7);
  58.       exit(0);
  59.     }
  60.   #endif
  61.               
  62.   L_GetVideoMode(&mode,&page);
  63.  
  64.   L_SetCheckStatus(NO_CHECK);
  65.  
  66.   if(argc<=1)
  67.   {
  68.      printf("\n                     LEADTOOLS DOS EVAL copy V 2.2\n");
  69.      printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  70.      printf("              8701 Mallard Creek Rd.\n");
  71.      printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  72.      L_SleepKey(2);
  73.      printf("\nDOS 32 - File to screen software deompression utility Version 3.4\n");
  74.      printf("USAGE: LSHOW <@macro file name>\n");
  75.      printf("or      LSHOW <source file> [/option1] [/option2] [/option3] [/option4]\n");
  76.      printf("                              [/option5] [/option6]\n\n");
  77.      printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  78.      printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  79.      printf("                  or TGA, TIFF, or BMP file formats\n");
  80.  
  81. #ifdef TARGA
  82.      printf("[option1] /TA for TARGA16, TARGA24, or TARGA32\n");
  83. #else
  84.      printf("[option1] /TA for TARGA+16, TARGA+32, TARGA+64\n");
  85. #endif
  86.      printf(" or       /V320  display to FAST SUPER VGA 320X200\n");
  87.      printf("          /V640  display to FAST SUPER VGA 640X480\n");
  88.      printf("          /V800  display to FAST SUPER VGA 800X600\n");
  89.      printf("          /V1024 display to FAST SUPER VGA 1024X768\n");
  90.      printf("[option2] /W# the New Width of the image displayed on the screen\n");
  91.      printf("[option3] /H# the New Height of the image displayed on the screen\n");
  92.      printf("[option4] /T# number of seconds to keep image displayed on the screen\n");
  93.      printf("[option5] /X# the X (horizontal) position of the image displayed on the screen\n");
  94.      printf("[option6] /Y# the Y (vertical) position of the image displayed on the screen\n\n");
  95.      printf("EXAMPLE LSHOW *.* /W300 /H200 /T4 /X20 /Y20\n");
  96.      printf("Will display all image files to the VGA/SuperVGA screen at the best resolution\nfor the selected image file\n");
  97.      exit(0);
  98.   }
  99.    strcpy(string,argv[1]);
  100.    get_pathname(argv[1], pathname);
  101.    if(argv[1][0]=='@')
  102.     {
  103.      i=0;
  104.      while(string[i])
  105.       {
  106.       pathname[i]=string[i+1];
  107.       i++;
  108.       }
  109.      pathname[i]= '\0';
  110.      if(Stream=fopen(pathname,"r"))
  111.       {
  112.        while(fgets(commandln, 400, Stream) != NULL)
  113.          {
  114.           Width = 0; Height = 0;
  115.           Xorigin = 0; Yorigin = 0;
  116.           first_option = 0;
  117.           position = 0;
  118.           while(sscanf(commandln+position,"%s",command)!=EOF)
  119.              {
  120.               position1 = strlen(command);
  121.               if( (position1 == 0) || (command[0]=='#') )
  122.                  break;
  123.               position = position + position1;
  124.               strupr(command);
  125.               if(command[0]=='/')
  126.                {
  127.                 get_value(command+1);
  128.                 first_option = 1;
  129.                }
  130.               else if (first_option == 0)
  131.                {
  132.                 
  133.                    strcpy(infile,command);
  134.                    getfilename(infile);
  135.                    first_option = 1;
  136.                }
  137.               else
  138.                {
  139.                 L_SetVideoMode(mode,page);
  140.                 printf("Error: invalid macro line %s\n",commandln);
  141.                 exit(0);
  142.                }
  143.               for (kk = position; kk < strlen(commandln); kk++)
  144.                   {
  145.                   if (commandln[kk] == 0x0d || commandln[kk] == 0x0a)
  146.                      {
  147.                      position1 = 0;
  148.                      break;
  149.                      }
  150.  
  151.                   if (commandln[kk] > 32)
  152.                      break;
  153.                   }
  154.  
  155.               position = kk;
  156.               if (position1 == 0)
  157.                  break;
  158.              }
  159.             if(infile[0]!='\0')
  160.             {
  161.  
  162.              if(video==VGA)
  163.                {
  164.                 L_GetVideoDeviceBits(&device_bits);
  165.                 if (L_FileInfo(infile, &FileInformation)==SUCCESS)
  166.                  {
  167.                   if( FileInformation.Format == FILE_TGA)
  168.                    {
  169.                      #if !defined(FOR_386)
  170.                      if(FileInformation.BitsPerPixel > 8)
  171.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  172.                        {
  173.                         L_SetVideoMode(mode,page);
  174.                         puts("Error: cannot load FIXED.DAT file.\n");
  175.                         putch(7);
  176.                         exit(0);
  177.                        }
  178.                      #endif
  179.  
  180.                       error=L_ShowTGAScreen(infile,Width,Height,Xorigin,Yorigin);
  181.  
  182.                      #if !defined(FOR_386)
  183.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  184.                        L_FreeRGBFixedPalette();
  185.                      #endif
  186.  
  187.                    }
  188.                   else if( FileInformation.Format == FILE_TIF)
  189.                    {
  190.                      #if !defined(FOR_386)
  191.                      if(FileInformation.BitsPerPixel > 8)
  192.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  193.                        {
  194.                         L_SetVideoMode(mode,page);
  195.                         puts("Error: cannot load FIXED.DAT file.\n");
  196.                         putch(7);
  197.                         exit(0);
  198.                        }
  199.                      #endif
  200.  
  201.                      error=L_ShowTIFScreen(infile,Width,Height,Xorigin,Yorigin);
  202.                      #if !defined(FOR_386)
  203.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  204.                        L_FreeRGBFixedPalette();
  205.                      #endif
  206.                    }
  207.                   else if( (FileInformation.Format == FILE_BMP) || (FileInformation.Format == FILE_OS2) )
  208.                    {
  209.                      #if !defined(FOR_386)
  210.                      if(FileInformation.BitsPerPixel > 8)
  211.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  212.                        {
  213.                         L_SetVideoMode(mode,page);
  214.                         puts("Error: cannot load FIXED.DAT file.\n");
  215.                         putch(7);
  216.                         exit(0);
  217.                        }
  218.                      #endif
  219.  
  220.                       error=L_ShowBMPScreen(infile,Width,Height,Xorigin,Yorigin);
  221.  
  222.                      #if !defined(FOR_386)
  223.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  224.                        L_FreeRGBFixedPalette();
  225.                      #endif
  226.  
  227.                    }
  228.                   else if( FileInformation.Format == FILE_PCX)
  229.                    {
  230.                      #if !defined(FOR_386)
  231.                      if(FileInformation.BitsPerPixel > 8)
  232.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  233.                        {
  234.                         L_SetVideoMode(mode,page);
  235.                         puts("Error: cannot load FIXED.DAT file.\n");
  236.                         putch(7);
  237.                         exit(0);
  238.                        }
  239.                      #endif
  240.  
  241.                      error=L_ShowPCXScreen(infile,Width,Height,Xorigin,Yorigin);
  242.  
  243.                      #if !defined(FOR_386)
  244.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  245.                        L_FreeRGBFixedPalette();
  246.                      #endif
  247.  
  248.                    }
  249.                   else if( FileInformation.Format == FILE_GIF)
  250.                    {
  251.                       error=L_ShowGIFScreen(infile,Width,Height,Xorigin,Yorigin);
  252.                    }
  253.                   else if( (FileInformation.Format == FILE_CMP) || (FileInformation.Format == FILE_JTIF)
  254.                            || ( FileInformation.Format == FILE_JFIF) )
  255.                    {
  256.                      #if !defined(FOR_386)
  257.                       error=L_DecompressVGAScreenFP(infile, Width, Height, Xorigin,Yorigin);
  258.                      #else
  259.                       error=L_DecompressVGAScreen(infile, Width, Height, Xorigin,Yorigin);
  260.                      #endif
  261.                    }
  262.                   if( (time>1) )
  263.                     L_SleepKey(time);
  264.                  }
  265.                }
  266.               else if(video==TARGAOLD)
  267.                {
  268.                  error=L_DecompressTARGAScreen(infile,0,0,Xorigin,Yorigin);
  269.                  if( (time>1) )
  270.                     L_SleepKey(time);
  271.                }
  272.             }
  273.           time=0;
  274.          infile[0]='\0';
  275.          }/*end while reading*/
  276.            L_SetVideoMode(mode,page);
  277.            exit(0);
  278.       }/*if*/
  279.      else
  280.       {
  281.        printf("Error: could not open macro file %s\n",pathname);
  282.        exit(0);
  283.       }
  284.    }
  285.   else
  286.    {
  287.     for (i = 2; i<=argc; i++)
  288.       {
  289.         strupr(argv[i]);
  290.         if(argv[i][0]=='/')
  291.           if(get_value(&argv[i][1])==BAD_COMMAND)
  292.             {
  293.               printf("\n                     LEADTOOLS DOS EVAL copy V 2.2");
  294.               printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  295.               printf("              8701 Mallard Creek Rd.\n");
  296.               printf("              Charlotte NC 28262\n");
  297.               printf("              tel# (704)549-5532\n");
  298.               L_SleepKey(1);
  299.               printf("\nDOS - File to screen software deompression utility Version 3.4\n");
  300.               printf("USAGE: LSHOW <source file> [/option1] [/option2] [/option3] [/option4]\n");
  301.               printf("                              [/option5] [/option6]\n\n");
  302.               printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  303.               printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  304.               printf("                  or TGA, TIFF, or BMP file formats\n");
  305.  
  306. #ifdef  TARGA
  307.               printf("[option1] /TA for TARGA16, TARGA24, or TARGA32\n");
  308. #else
  309.               printf("[option1] /TA for TARGA+16, TARGA+32, TARGA+64\n");
  310. #endif
  311.               printf(" or       /V320  display to FAST SUPER VGA 320X200\n");
  312.               printf("          /V640  display to FAST SUPER VGA 640X480\n");
  313.               printf("          /V800  display to FAST SUPER VGA 800X600\n");
  314.               printf("          /V1024 display to FAST SUPER VGA 1024X768\n");
  315.               printf("[option2] /W# the New Width of the image displayed on the screen\n");
  316.               printf("[option3] /H# the New Height of the image displayed on the screen\n");
  317.               printf("[option4] /T# number of seconds to keep image displayed on the screen\n");
  318.               printf("[option5] /X# the X (horizontal) position of the image displayed on the screen\n");
  319.               printf("[option6] /Y# the Y (vertical) position of the image displayed on the screen\n\n");
  320.               printf("EXAMPLE LSHOW *.* /W300 /H200 /T4 /X20 /Y20\n");
  321.               printf("Will display all image files to the VGA/SuperVGA screen at the best resolution\nfor the selected image file\n\n\n");
  322.               printf("BAD COMMAND %s\n",argv[i-1]);
  323.                exit(0);
  324.             }/* end if getvalue*/
  325.       }/*end for*/
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332.     result = _dos_findfirst(argv[1], 0 , &file);
  333.     if (result)   /* if result has any value rather that 0 then  */
  334.        printf("LSHOW: no such file %s\n",argv[1]);
  335.     else
  336.          while(!result)  /* Stop when _dos_findnext returns */
  337.         {
  338.            strcpy(infile, pathname);
  339.            strcat(infile, file.name);
  340.              if(video==VGA)
  341.                {
  342.                 L_GetVideoDeviceBits(&device_bits);
  343.                 if (L_FileInfo(infile, &FileInformation)==SUCCESS)
  344.                  {
  345.                   if( FileInformation.Format == FILE_TGA)
  346.                    {
  347.  
  348.                      #if !defined(FOR_386)
  349.                      if(FileInformation.BitsPerPixel > 8)
  350.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  351.                        {
  352.                         L_SetVideoMode(mode,page);
  353.                         puts("Error: cannot load FIXED.DAT file.\n");
  354.                         putch(7);
  355.                         exit(0);
  356.                        }
  357.                      #endif
  358.  
  359.                       error=L_ShowTGAScreen(infile,Width,Height,Xorigin,Yorigin);
  360.  
  361.                      #if !defined(FOR_386)
  362.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  363.                        L_FreeRGBFixedPalette();
  364.                      #endif
  365.                    }
  366.                   else if( FileInformation.Format == FILE_TIF)
  367.                    {
  368.                      #if !defined(FOR_386)
  369.                      if(FileInformation.BitsPerPixel > 8)
  370.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  371.                        {
  372.                         L_SetVideoMode(mode,page);
  373.                         puts("Error: cannot load FIXED.DAT file.\n");
  374.                         putch(7);
  375.                         exit(0);
  376.                        }
  377.                      #endif
  378.  
  379.                       error=L_ShowTIFScreen(infile,Width,Height,Xorigin,Yorigin);
  380.  
  381.                      #if !defined(FOR_386)
  382.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  383.                        L_FreeRGBFixedPalette();
  384.                      #endif
  385.  
  386.                    }
  387.                   else if( (FileInformation.Format == FILE_BMP) || (FileInformation.Format == FILE_OS2) )
  388.                    {
  389.                      #if !defined(FOR_386)
  390.                      if(FileInformation.BitsPerPixel > 8)
  391.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  392.                        {
  393.                         L_SetVideoMode(mode,page);
  394.                         puts("Error: cannot load FIXED.DAT file.\n");
  395.                         putch(7);
  396.                         exit(0);
  397.                        }
  398.                       #endif
  399.  
  400.                       error=L_ShowBMPScreen(infile,Width,Height,Xorigin,Yorigin);
  401.  
  402.                      #if !defined(FOR_386)
  403.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  404.                        L_FreeRGBFixedPalette();
  405.                      #endif
  406.                    }
  407.                   else if( FileInformation.Format == FILE_PCX)
  408.                    {
  409.                      #if !defined(FOR_386)
  410.                      if(FileInformation.BitsPerPixel > 8)
  411.                       if ( device_bits == 8 && L_LoadRGBFixedPalette(path) != SUCCESS)
  412.                        {
  413.                         L_SetVideoMode(mode,page);
  414.                         puts("Error: cannot load FIXED.DAT file.\n");
  415.                         putch(7);
  416.                         exit(0);
  417.                        }
  418.                       #endif
  419.  
  420.                       error=L_ShowPCXScreen(infile,Width,Height,Xorigin,Yorigin);
  421.  
  422.                      #if !defined(FOR_386)
  423.                      if (FileInformation.BitsPerPixel > 8 && device_bits == 8 )
  424.                        L_FreeRGBFixedPalette();
  425.                      #endif
  426.  
  427.                    }                
  428.                   else if( FileInformation.Format == FILE_GIF)
  429.                    {
  430.                       error=L_ShowGIFScreen(infile,Width,Height,Xorigin,Yorigin);
  431.                    }
  432.                   else if( (FileInformation.Format == FILE_CMP) || (FileInformation.Format == FILE_JTIF)
  433.                            || ( FileInformation.Format == FILE_JFIF) )
  434.                    {
  435.                      #if !defined(FOR_386)
  436.                        error=L_DecompressVGAScreenFP(infile, Width, Height, Xorigin,Yorigin);
  437.                      #else
  438.                        error=L_DecompressVGAScreen(infile, Width, Height, Xorigin,Yorigin);
  439.                      #endif
  440.                    }
  441.                   if( (time>1) )
  442.                     L_SleepKey(time);
  443.                  }
  444.                }
  445.                else if(video==TARGAOLD)
  446.                 {
  447.                   printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  448.                   printf("              8701 Mallard Creek Rd.\n");
  449.                   printf("              Charlotte NC 28262\n");
  450.                   printf("              tel# (704)549-5532\n");
  451.                   printf("\nDOS - File to screen software deompression utility Version 3.4\n");
  452.  #ifdef TARGA
  453.                   printf("Viewing image file %s to TARGA screen",file.name);
  454.  
  455.  #else
  456.                   printf("Viewing image file %s to TARGA+ screen",file.name);
  457.  #endif
  458.                    error=L_DecompressTARGAScreen(infile,0,0,Xorigin,Yorigin);
  459.              
  460.                 if((time >1))
  461.                    L_SleepKey(time);
  462.                  else if (error != SUCCESS)
  463.                    {
  464.                       printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  465.                       printf("              8701 Mallard Creek Rd.\n");
  466.                       printf("              Charlotte NC 28262\n");
  467.                       printf("              tel# (704)549-5532\n");
  468.                       printf("\nDOS - File to screen software deompression utility Version 3.4\n");
  469.                       printf("ERROR %d VIEWING IMAGE FILE %s\n",error,file.name);
  470.                       L_SleepKey(2);
  471.                    }
  472.                 }
  473.           result = _dos_findnext(&file);
  474.         }
  475. L_SetVideoMode(mode,page);
  476. }/*else*/
  477. exit(0);
  478. }
  479.  
  480.  
  481.  
  482. get_value(char *string)
  483. {
  484.  int ret=OK;
  485.  
  486.  if (string[0] == 'X')
  487.   {
  488.      Xorigin = atoi(string+1);
  489.      if (Xorigin < 0 || Xorigin > 1024)
  490.         return(BAD_COMMAND);
  491.      else
  492.         return(ret);
  493.   }
  494.  
  495.  if (string[0] == 'Y')
  496.   {
  497.      Yorigin = atoi(string+1);
  498.      if (Yorigin < 0 || Yorigin > 1024)
  499.         return(BAD_COMMAND);
  500.      else
  501.         return(ret);
  502.   }
  503.  
  504.  if (string[0] == 'T' && string[1] != 'A')
  505.   {
  506.      time = atoi(string+1);
  507.      if (time < 0)
  508.         return(BAD_COMMAND);
  509.      else
  510.         return(ret);
  511.   }
  512.  
  513.  if (string[0] == 'w' || string[0] == 'W')
  514.   {
  515.      Width = atoi(string+1);
  516.      if (Width < 0)
  517.         return(BAD_COMMAND);
  518.      else
  519.         return(ret);
  520.   }
  521.  
  522.  if (string[0] == 'h' || string[0] == 'H')
  523.   {
  524.      Height = atoi(string+1);
  525.      if (Height < 0)
  526.         return(BAD_COMMAND);
  527.      else
  528.         return(ret);
  529.   }
  530.  
  531.  if (string[0] == 'T' && string[1] == 'A')
  532.   {
  533.      video=TARGAOLD;
  534.      if(L_TARGAInit()==0)
  535.       {
  536. #ifdef TARGA
  537.          printf("TARGA Initialization error\n\n");
  538. #else
  539.          printf("TARGA+ Initialization error\n\n");
  540. #endif     
  541.          exit(0);
  542.       }
  543.   }
  544.  
  545.  if(string[0] == 'V')
  546.   {
  547.      video=VGA;
  548.      if(strstr(string,"V320"))
  549.         {
  550.         L_SetVideoMode(mode,page);
  551.         L_SetVGASize(SIZE_320x200);
  552.         }  
  553.      else if(strstr(string,"V640"))
  554.         {
  555.         L_SetVideoMode(mode,page);
  556.         L_SetVGASize(SIZE_640x480);
  557.         }  
  558.      else if(strstr(string,"V800"))
  559.         {
  560.         L_SetVideoMode(mode,page);
  561.         L_SetVGASize(SIZE_800x600);
  562.         }  
  563.      else if(strstr(string,"V1024"))
  564.         {
  565.         L_SetVideoMode(mode,page);
  566.         L_SetVGASize(SIZE_1024x768);
  567.         }  
  568.   }
  569.  return(ret);
  570. }
  571.  
  572.  
  573.  
  574. get_pathname(char in[], char pathname[])
  575. {
  576.  int i;
  577.  
  578.  strcpy(pathname, in);
  579.  for (i = strlen(in)-1; i >= 0; i--)
  580.   {
  581.     if( (in[i] == '\\') || (in[i] == ':') )
  582.       break;
  583.   }
  584.  
  585.  if (i == 0)
  586.     pathname[0] = 0;
  587.  else
  588.     pathname[i+1] = 0;
  589. }
  590.  
  591.  
  592. getfilename(char * name)
  593. {
  594.    int i=0;
  595.  
  596.    while(name[i]!=' ')
  597.       {
  598.        i++;
  599.       }
  600.    name[i]=='\0';
  601. }
  602.