home *** CD-ROM | disk | FTP | other *** search
/ Black Box 4 / BlackBox.cdr / grphutil / leadjpeg.arj / LEADECOM.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-05  |  13.9 KB  |  385 lines

  1. /****************************************************************************/
  2. /* FILE NAME: LEADECOM.C SOFTWARE DECOMPRESS FILE TO FILE                   */
  3. /* PROGRAMER: MOHAMMAD DAHER                                                */
  4. /* DATE:      03/12/1992                                                    */
  5. /*                                                                          */
  6. /*     COPYRIGHT (c) LEAD Technologies Inc. ALL RIGHTS RESEVED              */
  7. /****************************************************************************/
  8.  
  9. #include <stdio.h>
  10. #include <dos.h>
  11. #include"v:\leadview\toolkit\L_Bitmap.h"
  12. #include"v:\leadview\toolkit\L_error.h"
  13. #include"v:\leadview\toolkit\toolapp.h"  
  14.  
  15. #define OK 1
  16. #define BAD_COMMAND -2
  17. #define TARGAOLD 1
  18. #define VGA   2
  19.  
  20. #if __BORLANDC__
  21.     extern unsigned _stklen = 13000U;
  22. #endif
  23.  
  24. int format = TGA24;
  25.  
  26. main(int argc, char *argv[])
  27. {
  28.   FILEINFO FileInformation;
  29.   struct find_t file;
  30.   int result;
  31.   int i;
  32.   char string[256];
  33.   int mode,page;
  34.   int error;
  35.   char outfile[128], infile[128], pathname[128];
  36.   int wild_flag = 0;
  37.  
  38.   if(argc<=2)
  39.   {
  40.       printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  41.       printf("              8701 Mallard Creek Rd.\n");
  42.       printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  43.       printf("\nIf you find this utility suitable for your use, please register this program\n");
  44.       printf("for $49.00 and receive the latest version.\n");
  45.       printf("Send $129.00 and receive in addition to the above, LEADVIEW, an easy to use\n");
  46.       printf("user interface that incorporates image compression/decompression, file\n"); 
  47.       printf("conversion to and from 8bit TGA, 16bit TGA, 24bit TGA, 32bit TGA, 8bit TIFF,\n"); 
  48.       printf("24bit TIFF, 4bit BMP, 8bit BMP 24bit BMP, PCX, GIF, BIN with resize/flip/rotate\n"); 
  49.       printf("options, and a communication module. A DOS version (which can be used from\n");   
  50.       printf("within a TSR taking only 6K of conventional memory) or Windows 3.X version is\n"); 
  51.       printf("available.\n\n");
  52.       printf("Other LEAD products include LEADVIEW Turbo and LEADVIEW 255 hardware\n");
  53.       printf("accelerator board (faster versions of LEADVIEW supporting real-time\n");
  54.       printf("compression/decompression) and LEADTOOLS, a run-time library of 'C' routines \n");
  55.       printf("for DOS or LEADTOOLS DLL for Windows 3.x that gives developers the ability to\n");
  56.       printf("incorporate compression, decompression, and conversion features into their\n");
  57.       printf("own applications.\n\n"); 
  58.       L_SleepKey(20);
  59.       printf("\nDOS - File to file software decompresion utility Version 3.1\n");
  60.       printf("USEAGE: LEADECOM <source file> <target file> [/option1]\n");
  61.       printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  62.       printf("<target file> is any DOS file name\n");
  63.       printf("[option1] /TGA8 decompress to 8bits color mapped TGA image file format\n");
  64.       printf("          /TGA16 decompress to 16bits TGA image file format\n");
  65.       printf("          default /TGA24 decompress to 24bits TGA image file format\n");
  66.       printf("          /TGA32 decompress to 32bits TGA image file format\n");
  67.       printf("          /TIF24 decompress to 24bits TIF image file format\n");
  68.       printf("          /TIF8 decompress to 8bits color mapped TIF image file format\n");
  69.       printf("          /BMP24 decompress to 24bits Windows BMP image file format\n");
  70.       printf("          /BMP8 decompress to 8bits color mapped Windows BMP image file format\n");
  71.       printf("          /PM24 decompress to 24bits OS/2 BMP image file format\n");
  72.       printf("          /PM8 decompress to 8bits color mapped OS/2 BMP image file format\n");
  73.       printf("          /PCX decompress to 8bits color mapped PCX image file format\n");
  74.       printf("          /GIF decompress to 8bits color mapped GIF image file format\n");
  75.       printf("DOS wildcards are also supported for <source file> and <target file>\n");
  76.       printf("EXAMPLE LEADECOM *.cmp *.TGA /TGA24\n");
  77.       printf("  will decompress all cmp files to 24bits TGA files.\n");
  78.       if(argc==1)
  79.          printf("ERROR NO <source file> and <target file> specified");
  80.       else
  81.          printf("ERROR NO <target file> specified");
  82.       exit(0);
  83.   }
  84.   
  85.   
  86.   strupr(argv[1]);
  87.   strupr(argv[2]);
  88.   
  89.   if ( find_wildletter(argv[1]) == 1)
  90.      {
  91.        if (find_wildletter(argv[2]) == 1)
  92.           wild_flag = 1;
  93.      }
  94.   
  95.   for (i = 3; i<=argc; i++)
  96.     {
  97.        strupr(argv[i]);
  98.        if(argv[i][0]=='/')
  99.           if(get_value(argv[i]+1)==BAD_COMMAND)
  100.            {
  101.              printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  102.              printf("              8701 Mallard Creek Rd.\n");
  103.              printf("              Charlotte NC 28262      Tel# (704)549-5532\n");
  104.              L_SleepKey(1);
  105.              printf("\nDOS - File to file software decompresion utility Version 3.1\n");
  106.              printf("USEAGE: LEADECOM <source file> <target file> [/option1]\n");
  107.              printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  108.              printf("<target file> is any DOS file name\n");
  109.              printf("[option1] /TGA8 decompress to 8bits color mapped TGA image file format\n");
  110.              printf("          /TGA16 decompress to 16bits TGA image file format\n");
  111.              printf("          default /TGA24 decompress to 24bits TGA image file format\n");
  112.              printf("          /TGA32 decompress to 32bits TGA image file format\n");
  113.              printf("          /TIF24 decompress to 24bits TIF image file format\n");
  114.              printf("          /TIF8 decompress to 8bits color mapped TIF image file format\n");
  115.              printf("          /BMP24 decompress to 24bits Windows BMP image file format\n");
  116.              printf("          /BMP8 decompress to 8bits color mapped Windows BMP image file format\n");
  117.              printf("          /PM24 decompress to 24bits OS/2 BMP image file format\n");
  118.              printf("          /PM8 decompress to 8bits color mapped OS/2 BMP image file format\n");
  119.              printf("          /PCX decompress to 8bits color mapped PCX image file format\n");
  120.              printf("          /GIF decompress to 8bits color mapped GIF image file format\n");
  121.              printf("DOS wildcards are also supported for <source file> and <target file>\n");
  122.              printf("EXAMPLE LEADECOM *.cmp *.TGA /TGA24\n");
  123.              printf("  will decompress all cmp files to 24bits TGA files.\n");
  124.              if(argc==1)
  125.                 printf("ERROR NO <source file> and <target file> specified");
  126.              else
  127.                 printf("ERROR NO <target file> specified");
  128.   
  129.              printf("\nInvalid option %s",argv[i]);
  130.              exit(0);
  131.            }
  132.     }
  133.     
  134.     
  135.     get_pathname(argv[1], pathname);
  136.     result = _dos_findfirst(argv[1], 0 , &file);
  137.               /* _dosfindfirst will return a 0 if succesfull */
  138.               /*   and any other value if not       */
  139.   
  140.     if (result)   /* if result has any value rather that 0 then  */
  141.                   /* False = 0    True= any other value */
  142.                   /* and when the function is succesful it return a 0 */
  143.         printf("leadcomp: no such file %s\n",argv[1]);
  144.     else
  145.        while(!result)  /* Stop when _dos_findnext returns */
  146.                        /*   a value other than a 0        */
  147.                        /* becuse False =0 and when the
  148.                        /* function is succesful it returns a 0) */
  149.        {
  150.         strcpy(infile, pathname);
  151.         strcat(infile, file.name);
  152.         if (L_FileInfo(infile,&FileInformation)==SUCCESS)
  153.            {
  154.                if (wild_flag == 1)
  155.                   get_outfilename(file.name, argv[2], outfile);
  156.   
  157.                else
  158.                   strcpy(outfile, argv[2]);
  159.               printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  160.               printf("              8701 Mallard Creek Rd.\n");
  161.               printf("              Charlotte NC 28262      Tel# (704)549-5532\n");
  162.               printf("\nDOS - File to file software decompresion utility Version 3.1\n");
  163.               printf("\nDecompressing image file %s to %s", infile, outfile);
  164.               if( (FileInformation.Format == FILE_CMP) ||
  165.                 ( FileInformation.Format == FILE_JFIF) ||
  166.                 ( FileInformation.Format == FILE_JTIF) )
  167.                 {
  168.                    if((format==TGA8) || (format==TGA16) || (format==TGA24) ||
  169.                       (format==TGA32) )
  170.                         error=L_DecompressTGA(infile,outfile,format);
  171.                    else if( (format==TIF8) || (format==TIF24) )
  172.                         error=L_DecompressTIF(infile,outfile,format);
  173.                    else if( (format==BMP8) || (format==BMP24) || (format==PM8) ||
  174.                          (format==PM24) )
  175.                         error=L_DecompressBMP(infile,outfile,format);
  176.                    else if( (format==PCX8))
  177.                         error=L_DecompressPCX(infile,outfile,format);
  178.                    else if( (format==GIF8))
  179.                          error=L_DecompressGIF(infile,outfile,format);
  180.   
  181.                 }
  182.  
  183.                if(error!=SUCCESS)
  184.                 {
  185.                    printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  186.                    printf("              8701 Mallard Creek Rd.\n");
  187.                    printf("              Charlotte NC 28262      Tel# (704)549-5532\n");
  188.                    printf("\nDOS - File to file software decompresion utility Version 3.1\n");
  189.                    printf("\nERROR %d DECOMPRESSING IMAGE FILE %s\n",error,file.name);
  190.                 }
  191.            }
  192.           else
  193.            {
  194.               printf("\nleadcomp: error opening file %s\n",file.name);
  195.               putch(7);
  196.            }
  197.         result = _dos_findnext(&file);
  198.        }
  199. }
  200.   
  201.   
  202.   
  203.   
  204. get_value(string)
  205. char *string;
  206. {
  207.   int ret=OK;
  208.   if     ( string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  209.         && string[3] == '8' )
  210.       {
  211.          format=TGA8;
  212.       }
  213.   else if (   string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  214.             && string[3] == '1' && string[4] == '6')
  215.    {
  216.       format=TGA16;
  217.    }
  218.   else if (   string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  219.            && string[3] == '2' && string[4] == '4')
  220.    {
  221.       format=TGA24;
  222.    }
  223.   else if (   string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  224.            && string[3] == '3' && string[4] == '2')
  225.    {
  226.       format=TGA32;
  227.    }
  228.   else if (   string[0] == 'T' && string[1] == 'I' && string[2] == 'F'
  229.            && string[3] == '8')
  230.    {
  231.       format=TIF8;
  232.    }
  233.   else if (   string[0] == 'T' && string[1] == 'I' && string[2] == 'F'
  234.            && string[3] == '2' && string[4] == '4')
  235.    {
  236.       format=TIF24;
  237.    }
  238.   else if (   string[0] == 'B' && string[1] == 'M' && string[2] == 'P'
  239.            && string[3] == '8')
  240.    {
  241.       format=BMP8;
  242.    }
  243.   else if (   string[0] == 'B' && string[1] == 'B' && string[2] == 'P'
  244.            && string[3] == '2' && string[4] == '4')
  245.    {
  246.       format=BMP24;
  247.    }
  248.   else if (   string[0] == 'P' && string[1] == 'M'
  249.            && string[3] == '8' )
  250.    {
  251.       format=PM8;
  252.    }
  253.   else if (   string[0] == 'P' && string[1] == 'M' 
  254.            && string[3] == '2' && string[4] == '4')
  255.    {
  256.       format=PM24;
  257.    }
  258.   else if (   string[0] == 'P' && string[1] == 'C' && string[2] == 'X')
  259.    {
  260.       format=PCX8;
  261.    }
  262.   else if (   string[0] == 'G' && string[1] == 'I' && string[2] == 'F' )
  263.    {
  264.       format=GIF8;
  265.    }
  266.   else
  267.       return(ret);
  268.  
  269. return(ret);
  270. }
  271.  
  272.  
  273.  
  274. get_outfilename(from_file, as_file, to_file)
  275. char from_file[], as_file[], to_file[];
  276. {
  277.   char ext1[20], name1[128], ext2[20], name2[128];
  278.   int i, q, j, ext1_flag = 0, ext2_flag = 0;
  279.   int x, x1;
  280.   
  281.   ext1[0] = 0, ext2[0] = 0, name1[0] = 0, name2[0] = 0;
  282.   for (i = strlen(from_file)-1; i >= 0; i--)
  283.     if (from_file[i] == '.' && from_file[i+1] != '.' && from_file[i-1] != '.')
  284.      {
  285.          ext1_flag = 1;
  286.          break;
  287.       }
  288.   
  289.   strcpy(name1, from_file);
  290.   name1[i] = 0;
  291.   if (ext1_flag == 1)
  292.     strcpy(ext1, from_file+i+1);
  293.   for (i = strlen(as_file)-1; i >= 0; i--)
  294.     if (as_file[i] == '.' && as_file[i+1] != '.' && as_file[i-1] != '.')
  295.      {
  296.         ext2_flag = 1;
  297.         break;
  298.      }
  299.   
  300.   strcpy(name2, as_file);
  301.   name2[i] = 0;
  302.   if (ext2_flag == 1)
  303.      strcpy(ext2, as_file+i+1);
  304.   
  305.   for (i = 0, q = 0; i < strlen(name2); i++)
  306.       {
  307.        if (name2[i] == '*')
  308.            {
  309.            to_file[i] = 0;
  310.            strcat(to_file+i, name1);
  311.            i = i + strlen(name1+q);
  312.            goto exit0;
  313.            }
  314.        if (name2[i] == '?')
  315.           {
  316.           to_file[i] = name1[i];
  317.           q++;
  318.           } 
  319.        else
  320.           to_file[i] = name2[i];
  321.       }
  322.   
  323.    to_file[i] = 0;
  324.    exit0:
  325.   
  326.    to_file[i] = '.';
  327.    i++;
  328.    for (j = 0, q = 0; j < strlen(ext2); i++, j++)
  329.     {
  330.        if (ext2[j] == '*')
  331.         {
  332.            to_file[i] = 0;
  333.            strcat(to_file, ext1+q);
  334.            return(0);
  335.         }
  336.        if (name2[i] == '?')
  337.           {
  338.           to_file[i] = ext1[j];
  339.           q++;
  340.           } 
  341.        else
  342.           to_file[i] = ext2[j];
  343.     }
  344.     to_file[i] = 0;
  345.     if(to_file[i-1] == '.')
  346.        to_file[i-1] = 0;
  347.   
  348.   return(0);
  349. }
  350.   
  351.  
  352. find_wildletter(string)
  353. char string[];
  354. {
  355. int i;
  356.  
  357. for (i = 0; i < strlen(string); i++)
  358.     if (string[i] == '*')
  359.        return(1);
  360.  
  361. return(0);
  362. }
  363.  
  364. get_pathname(in, pathname)
  365. char in[], pathname[];
  366. {
  367. int i;
  368.  
  369. strcpy(pathname, in);
  370.  
  371. for (i = strlen(in)-1; i >= 0; i--)
  372.     {
  373.     if (in[i] == '\\' || in[i] == ':')
  374.        break;
  375.     }
  376.  
  377. if (i == 0)
  378.    pathname[0] = 0;
  379. else
  380.    pathname[i+1] = 0;
  381. }
  382.  
  383.  
  384.  
  385.