home *** CD-ROM | disk | FTP | other *** search
/ The Programmer Disk / The Programmer Disk (Microforum).iso / xpro / vc / pro16 / sdf2f.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-25  |  20.2 KB  |  541 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include"include\L_Bitmap.h"
  4. #include"include\L_error.h"
  5. #include"include\L_toolap.h"  
  6.  
  7. #define OK 1
  8. #define BAD_COMMAND -2
  9. #define TARGAOLD 1
  10. #define VGA   2
  11.  
  12. #if __BORLANDC__
  13.     extern unsigned _stklen = 13000U;
  14. #endif
  15.  
  16. int format = TGA24;
  17.  
  18. main(int argc, char *argv[])
  19. {
  20.   FILEINFO FileInformation;
  21.   struct find_t file;
  22.   int result;
  23.   int i;
  24.   char string[256];
  25.   int mode,page;
  26.   int error;
  27.   char outfile[128], infile[128], pathname[128];
  28.   int wild_flag = 0;
  29.   char path[200];
  30.   BITMAPHANDLE CompBitmap; /* A Bitmap used to decompress to 8bit formats */
  31.  
  32. #if !defined(FOR_386)
  33.    L_SetDecompressFormatJTIF();
  34.    L_SetDecompressFormatJFIFCMP();
  35. #endif
  36.  
  37.   strcpy(path, argv[0]);
  38.  
  39.   for (i = strlen(path)-1; i > 0; i--)
  40.    {
  41.    if (path[i] == '\\' || path[i] == ':')
  42.       break;
  43.    }
  44.      path[i+1] = 0;
  45.   i=0;
  46.  
  47.   L_SetCheckStatus(NO_CHECK);
  48.  
  49.   if(argc<=2)
  50.   {
  51.       printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  52.       printf("              8701 Mallard Creek Rd.\n");
  53.       printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  54. #if defined(FOR_386)
  55.       printf("\nDOS32 - File to file software decompresion utility Version 1.2\n");
  56. #else
  57.       printf("\nDOS - File to file software decompresion utility Version 5.0\n");
  58.       printf("\nThis version has a limit of image width not to exceed 1500 pixels.\n");
  59. #endif
  60.       L_SleepKey(2);
  61.       printf("USEAGE: SDF2F <source file> <target file> [/option1]\n");
  62.       printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  63.       printf("<target file> is any DOS file name\n");
  64.       printf("[option1] /TGA8 decompress to 8bits color mapped TGA image file format\n");
  65.       printf("          /TGA16 decompress to 16bits TGA image file format\n");
  66.       printf("          default /TGA24 decompress to 24bits TGA image file format\n");
  67.       printf("          /TGA32 decompress to 32bits TGA image file format\n");
  68.       printf("          /TIF24 decompress to 24bits TIF image file format\n");
  69.       printf("          /TIF16 decompress to 16bits TIF image file format\n");
  70.       printf("          /TIF8 decompress to 8bits color mapped TIF image file format\n");
  71.       printf("          /BMP24 decompress to 24bits Windows BMP image file format\n");
  72.       printf("          /BMP8 decompress to 8bits color mapped Windows BMP image file format\n");
  73.       printf("          /PM24 decompress to 24bits OS/2 BMP image file format\n");
  74.       printf("          /PM8 decompress to 8bits color mapped OS/2 BMP image file format\n");
  75.       printf("          /PCX8 decompress to 8bits color mapped PCX image file format\n");
  76.       printf("          /PCX24 decompress to 24bits PCX image file format\n");
  77.       printf("          /GIF decompress to 8bits color mapped GIF image file format\n");
  78.       printf("DOS wildcards are also supported for <source file> and <target file>\n");
  79.       printf("EXAMPLE SDF2F *.cmp *.TGA /TGA24\n");
  80.       printf("  will decompress all cmp files to 24bits TGA files.\n");
  81.       if(argc==1)
  82.          printf("ERROR NO <source file> and <target file> specified");
  83.       else
  84.          printf("ERROR NO <target file> specified");
  85.       exit(0);
  86.   }
  87.  else
  88.     if(argv[1][0]=='/')
  89.      {
  90.         printf("Error Bad source file %s",argv[1]);
  91.         exit(0);
  92.      }
  93.     else if(argv[2][0]=='/')
  94.      {
  95.         printf("Error Bad source file %s",argv[1]);
  96.         exit(0);
  97.      }
  98.   
  99.   
  100.   strupr(argv[1]);
  101.   strupr(argv[2]);
  102.   
  103.   if ( find_wildletter(argv[1]) == 1)
  104.      {
  105.        if (find_wildletter(argv[2]) == 1)
  106.           wild_flag = 1;
  107.      }
  108.   
  109.   for (i = 3; i<=argc; i++)
  110.     {
  111.        strupr(argv[i]);
  112.        if(argv[i][0]=='/')
  113.           if(get_value(argv[i]+1)==BAD_COMMAND)
  114.            {
  115.              printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  116.              printf("              8701 Mallard Creek Rd.\n");
  117.              printf("              Charlotte NC 28262      Tel# (704)549-5532\n");
  118. #if defined(FOR_386)
  119.              printf("\nDOS32 - File to file software decompresion utility Version 1.2\n");
  120. #else
  121.              printf("\nDOS - File to file software decompresion utility Version 5.0\n");
  122.              printf("\nThis version has a limit of image width not to exceed 1500 pixels.\n");
  123. #endif
  124.              L_SleepKey(2);
  125.              printf("USEAGE: SDF2F <source file> <target file> [/option1]\n");
  126.              printf("<source file> is any LEAD, JFIF, or JTIF compressed file formats\n");
  127.              printf("<target file> is any DOS file name\n");
  128.              printf("[option1] /TGA8 decompress to 8bits color mapped TGA image file format\n");
  129.              printf("          /TGA16 decompress to 16bits TGA image file format\n");
  130.              printf("          default /TGA24 decompress to 24bits TGA image file format\n");
  131.              printf("          /TGA32 decompress to 32bits TGA image file format\n");
  132.              printf("          /TIF24 decompress to 24bits TIF image file format\n");
  133.              printf("          /TIF16 decompress to 16bits TIF image file format\n");
  134.              printf("          /TIF8 decompress to 8bits color mapped TIF image file format\n");
  135.              printf("          /BMP24 decompress to 24bits Windows BMP image file format\n");
  136.              printf("          /BMP8 decompress to 8bits color mapped Windows BMP image file format\n");
  137.              printf("          /PM24 decompress to 24bits OS/2 BMP image file format\n");
  138.              printf("          /PM8 decompress to 8bits color mapped OS/2 BMP image file format\n");
  139.              printf("          /PCX8 decompress to 8bits color mapped PCX image file format\n");
  140.              printf("          /PCX24 decompress to 24bits color mapped PCX image file format\n");
  141.              printf("          /GIF decompress to 8bits color mapped GIF image file format\n");
  142.              printf("DOS wildcards are also supported for <source file> and <target file>\n");
  143.              printf("EXAMPLE SDF2F *.cmp *.TGA /TGA24\n");
  144.              printf("  will decompress all cmp files to 24bits TGA files.\n");
  145.              if(argc==1)
  146.                 printf("ERROR NO <source file> and <target file> specified");
  147.              else
  148.                 printf("ERROR NO <target file> specified");
  149.   
  150.              printf("\nInvalid option %s",argv[i]);
  151.              exit(0);
  152.            }
  153.     }
  154.     
  155.     
  156.     get_pathname(argv[1], pathname);
  157.     result = _dos_findfirst(argv[1], 0 , &file);
  158.               /* _dosfindfirst will return a 0 if succesfull */
  159.               /*   and any other value if not       */
  160.   
  161.     if (result)   /* if result has any value rather that 0 then  */
  162.                   /* False = 0    True= any other value */
  163.                   /* and when the function is succesful it return a 0 */
  164.         printf("leadcomp: no such file %s\n",argv[1]);
  165.     else
  166.        while(!result)  /* Stop when _dos_findnext returns */
  167.                        /*   a value other than a 0        */
  168.                        /* becuse False =0 and when the
  169.                        /* function is succesful it returns a 0) */
  170.        {
  171.         strcpy(infile, pathname);
  172.         strcat(infile, file.name);
  173.         if (L_FileInfo(infile,&FileInformation)==SUCCESS)
  174.            {
  175.               if (wild_flag == 1)
  176.                  get_outfilename(file.name, argv[2], outfile);
  177.               else
  178.                  strcpy(outfile, argv[2]);
  179.  
  180.               printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  181.               printf("              8701 Mallard Creek Rd.\n");
  182.               printf("              Charlotte NC 28262      Tel# (704)549-5532\n");
  183. #if defined(FOR_386)
  184.               printf("\nDOS32 - File to file software decompresion utility Version 1.2\n");
  185. #else
  186.               printf("\nDOS - File to file software decompresion utility Version 5.0\n");
  187.               printf("\nThis version has a limit of image width not to exceed 1500 pixels.\n");
  188. #endif
  189.               printf("\nDecompressing image file %s to %s\n", infile, outfile);
  190.               if( (FileInformation.Format == FILE_CMP) ||
  191.                 ( FileInformation.Format == FILE_JFIF) ||
  192.                 ( FileInformation.Format == FILE_JTIF) )
  193.                 {
  194.                    if((format==TGA8) || (format==TGA16) || (format==TGA24) ||
  195.                       (format==TGA32) )
  196.                      {
  197.                         if (format==TGA8)
  198.                          {
  199.                           L_InitBitmap( &CompBitmap, 0, 0, 0);
  200.                           if ( (error=L_DecompressBitmap ( infile,
  201.                                                         &CompBitmap, BIT24 )) == SUCCESS )
  202.                              {
  203.                               if ( (error=L_SaveTGABitmap( outfile,
  204.                                                          &CompBitmap,8 )) == SUCCESS )
  205.                                  {
  206.                                    printf("File: %s Decompressed to %s (TGA).\n ",infile,outfile);
  207.                                  }
  208.                                 else
  209.                                  {
  210.                                   printf("Error Saving Bitmap to disk. Press any key to continue. ");
  211.                                  }
  212.                                 L_FreeBitmap(&CompBitmap);
  213.                              }
  214.                             else
  215.                              {
  216.                               printf("Error: %d Decompressing to the BitMap. Press any key to continue.", error);
  217.                              }
  218.                          }
  219.                         else
  220.                          error=L_DecompressTGA(infile,outfile,format);
  221.                      }
  222.                    else if( (format==TIF8) || (format==TIF24) )
  223.                         if (format==TIF8)
  224.                          {
  225.                           L_InitBitmap( &CompBitmap, 0, 0, 0);
  226.                           if ( (error=L_DecompressBitmap ( infile,
  227.                                                         &CompBitmap, BIT24 )) == SUCCESS )
  228.                              {
  229.                               if ( (error=L_SaveTIFBitmap( outfile,
  230.                                                          &CompBitmap,8, 0 )) == SUCCESS )
  231.                                  {
  232.                                    printf("File: %s Decompressed to %s (TIF).\n ",infile,outfile);
  233.                                  }
  234.                                 else
  235.                                  {
  236.                                   printf("Error Saving Bitmap to disk. Press any key to continue. ");
  237.                                  }
  238.                                 L_FreeBitmap(&CompBitmap);
  239.                              }
  240.                             else
  241.                              {
  242.                               printf("Error: %d Decompressing to the BitMap. Press any key to continue.", error);
  243.                              }
  244.                          }
  245.                         else
  246.                          error=L_DecompressTIF(infile,outfile,format);
  247.                    else if( (format==BMP8) || (format==BMP24) || (format==PM8) ||
  248.                          (format==PM24) )
  249.                         if (format==TIF8)
  250.                          {
  251.                           L_InitBitmap( &CompBitmap, 0, 0, 0);
  252.                           if ( (error=L_DecompressBitmap ( infile,
  253.                                                         &CompBitmap, BIT24 )) == SUCCESS )
  254.                              {
  255.                               if ( (error=L_SaveBMPBitmap( outfile,
  256.                                                          &CompBitmap,8,format )) == SUCCESS )
  257.                                  {
  258.                                    printf("File: %s Decompressed to %s (BMP).\n ",infile,outfile);
  259.                                  }
  260.                                 else
  261.                                  {
  262.                                   printf("Error Saving Bitmap to disk. Press any key to continue. ");
  263.                                  }
  264.                                 L_FreeBitmap(&CompBitmap);
  265.                              }
  266.                             else
  267.                              {
  268.                               printf("Error: %d Decompressing to the BitMap. Press any key to continue.", error);
  269.                              }
  270.                          }
  271.                         else
  272.                          error=L_DecompressBMP(infile,outfile,format);
  273.                    else if( (format==PCX8) || (format ==PCX24) )
  274.                         if (format==PCX8)
  275.                          {
  276.                           L_InitBitmap( &CompBitmap, 0, 0, 0);
  277.                           if ( (error=L_DecompressBitmap ( infile,
  278.                                                         &CompBitmap, BIT24 )) == SUCCESS )
  279.                              {
  280.                               if ( (error=L_SavePCXBitmap( outfile,
  281.                                                          &CompBitmap,8 )) == SUCCESS )
  282.                                  {
  283.                                    printf("File: %s Decompressed to %s (PCX).\n",infile,outfile);
  284.                                  }
  285.                                 else
  286.                                  {
  287.                                   printf("Error Saving Bitmap to disk. Press any key to continue. ");
  288.                                  }
  289.                                 L_FreeBitmap(&CompBitmap);
  290.                              }
  291.                             else
  292.                              {
  293.                               printf("Error: %d Decompressing to the BitMap. Press any key to continue.", error);
  294.                              }
  295.                          }
  296.                         else
  297.                         error=L_DecompressPCX(infile,outfile,format);
  298.                    else if( (format==GIF8))
  299.                          {
  300.                           L_InitBitmap( &CompBitmap, 0, 0, 0);
  301.                           if ( (error=L_DecompressBitmap ( infile,
  302.                                                         &CompBitmap, BIT24 )) == SUCCESS )
  303.                              {
  304.                               if ( (error=L_SaveGIFBitmap( outfile,
  305.                                                          &CompBitmap,8 )) == SUCCESS )
  306.                                  {
  307.                                    printf("File: %s Decompressed to %s (GIF).\n",infile,outfile);
  308.                                  }
  309.                                 else
  310.                                  {
  311.                                   printf("Error Saving Bitmap to disk. Press any key to continue. ");
  312.                                  }
  313.                                 L_FreeBitmap(&CompBitmap);
  314.                              }
  315.                             else
  316.                              {
  317.                               printf("Error: %d Decompressing to the BitMap. Press any key to continue.", error);
  318.                              }
  319.                          }
  320.                 }
  321.                if(error!=SUCCESS)
  322.                 {
  323.                    printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  324.                    printf("              8701 Mallard Creek Rd.\n");
  325.                    printf("              Charlotte NC 28262      Tel# (704)549-5532\n");
  326. #if defined(FOR_386)
  327.                    printf("\nDOS32 - File to file software decompresion utility Version 1.2\n");
  328. #else
  329.                    printf("\nDOS - File to file software decompresion utility Version 5.0\n");
  330.                    printf("\nThis version has a limit of image width not to exceed 1500 pixels.\n");
  331. #endif
  332.                    printf("\nERROR %d DECOMPRESSING IMAGE FILE %s\n",error,file.name);
  333.                 }
  334.            }
  335.           else
  336.            {
  337.               printf("\nleadcomp: error opening file %s\n",file.name);
  338.               putch(7);
  339.            }
  340.         result = _dos_findnext(&file);
  341.        }
  342.  
  343. exit(0);
  344. }
  345.   
  346.   
  347.   
  348.   
  349. get_value(string)
  350. char *string;
  351. {
  352.   int ret=OK;
  353.   if     ( string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  354.         && string[3] == '8' )
  355.       {
  356.          format=TGA8;
  357.       }
  358.   else if (   string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  359.             && string[3] == '1' && string[4] == '6')
  360.    {
  361.       format=TGA16;
  362.    }
  363.   else if (   string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  364.            && string[3] == '2' && string[4] == '4')
  365.    {
  366.       format=TGA24;
  367.    }
  368.   else if (   string[0] == 'T' && string[1] == 'G' && string[2] == 'A'
  369.            && string[3] == '3' && string[4] == '2')
  370.    {
  371.       format=TGA32;
  372.    }
  373.   else if (   string[0] == 'T' && string[1] == 'I' && string[2] == 'F'
  374.            && string[3] == '8')
  375.    {
  376.       format=TIF8;
  377.    }
  378.   else if (   string[0] == 'T' && string[1] == 'I' && string[2] == 'F'
  379.            && string[3] == '1' && string[4] == '6')
  380.    {
  381.       format=TIF16;
  382.    }
  383.  
  384.   else if (   string[0] == 'T' && string[1] == 'I' && string[2] == 'F'
  385.            && string[3] == '2' && string[4] == '4')
  386.    {
  387.       format=TIF24;
  388.    }
  389.   else if (   string[0] == 'B' && string[1] == 'M' && string[2] == 'P'
  390.            && string[3] == '8')
  391.    {
  392.       format=BMP8;
  393.    }
  394.   else if (   string[0] == 'B' && string[1] == 'M' && string[2] == 'P'
  395.            && string[3] == '2' && string[4] == '4')
  396.    {
  397.       format=BMP24;
  398.    }
  399.   else if (   string[0] == 'P' && string[1] == 'M'
  400.            && string[3] == '8' )
  401.    {
  402.       format=PM8;
  403.    }
  404.   else if (   string[0] == 'P' && string[1] == 'M' 
  405.            && string[3] == '2' && string[4] == '4')
  406.    {
  407.       format=PM24;
  408.    }
  409.   else if (   string[0] == 'P' && string[1] == 'C' && string[2] == 'X' && string[3] == '8')
  410.    {
  411.       format=PCX8;
  412.    }
  413.   else if (   string[0] == 'P' && string[1] == 'C' && string[2] == 'X' && string[3] == '2' && string[4] == '4')
  414.    {
  415.       format=PCX24;
  416.    }
  417.  
  418.   else if (   string[0] == 'G' && string[1] == 'I' && string[2] == 'F' )
  419.    {
  420.       format=GIF8;
  421.    }
  422.   else
  423.       return(BAD_COMMAND);
  424.  
  425. return(ret);
  426. }
  427.  
  428.  
  429.  
  430. get_outfilename(from_file, as_file, to_file)
  431. char from_file[], as_file[], to_file[];
  432. {
  433.   char ext1[20], name1[128], ext2[20], name2[128];
  434.   int i, q, j, ext1_flag = 0, ext2_flag = 0;
  435.   int x, x1;
  436.   
  437.   ext1[0] = 0, ext2[0] = 0, name1[0] = 0, name2[0] = 0;
  438.   for (i = strlen(from_file)-1; i >= 0; i--)
  439.     if (from_file[i] == '.' && from_file[i+1] != '.' && from_file[i-1] != '.')
  440.      {
  441.          ext1_flag = 1;
  442.          break;
  443.       }
  444.   
  445.   strcpy(name1, from_file);
  446.   name1[i] = 0;
  447.   if (ext1_flag == 1)
  448.     strcpy(ext1, from_file+i+1);
  449.   for (i = strlen(as_file)-1; i >= 0; i--)
  450.     if (as_file[i] == '.' && as_file[i+1] != '.' && as_file[i-1] != '.')
  451.      {
  452.         ext2_flag = 1;
  453.         break;
  454.      }
  455.   
  456.   strcpy(name2, as_file);
  457.   name2[i] = 0;
  458.   if (ext2_flag == 1)
  459.      strcpy(ext2, as_file+i+1);
  460.   
  461.   for (i = 0, q = 0; i < strlen(name2); i++)
  462.       {
  463.        if (name2[i] == '*')
  464.            {
  465.            to_file[i] = 0;
  466.            strcat(to_file+i, name1);
  467.            i = i + strlen(name1+q);
  468.            goto exit0;
  469.            }
  470.        if (name2[i] == '?')
  471.           {
  472.           to_file[i] = name1[i];
  473.           q++;
  474.           } 
  475.        else
  476.           to_file[i] = name2[i];
  477.       }
  478.   
  479.    to_file[i] = 0;
  480.    exit0:
  481.   
  482.    to_file[i] = '.';
  483.    i++;
  484.    for (j = 0, q = 0; j < strlen(ext2); i++, j++)
  485.     {
  486.        if (ext2[j] == '*')
  487.         {
  488.            to_file[i] = 0;
  489.            strcat(to_file, ext1+q);
  490.            return(0);
  491.         }
  492.        if (name2[i] == '?')
  493.           {
  494.           to_file[i] = ext1[j];
  495.           q++;
  496.           } 
  497.        else
  498.           to_file[i] = ext2[j];
  499.     }
  500.     to_file[i] = 0;
  501.     if(to_file[i-1] == '.')
  502.        to_file[i-1] = 0;
  503.   
  504.   return(0);
  505. }
  506.   
  507.  
  508. find_wildletter(string)
  509. char string[];
  510. {
  511. int i;
  512.  
  513. for (i = 0; i < strlen(string); i++)
  514.     if (string[i] == '*')
  515.        return(1);
  516.  
  517. return(0);
  518. }
  519.  
  520. get_pathname(in, pathname)
  521. char in[], pathname[];
  522. {
  523. int i;
  524.  
  525. strcpy(pathname, in);
  526.  
  527. for (i = strlen(in)-1; i >= 0; i--)
  528.     {
  529.     if (in[i] == '\\' || in[i] == ':')
  530.        break;
  531.     }
  532.  
  533. if (i == 0)
  534.    pathname[0] = 0;
  535. else
  536.    pathname[i+1] = 0;
  537. }
  538.  
  539.  
  540.  
  541.