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

  1. /****************************************************************************/
  2. /* FILE NAME: LEADCOMP.C SOFTWARE COMPRESS 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 = LEAD, qqfactor = PQ1, palette = NoVGAPalette;
  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("\nCOPYRIGHT (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 compression utility Version 3.1\n");
  60.      printf("USEAGE: LEADCOMP <source file> <target file> [/option1] [/option2] \n");
  61.      printf("<source file> is any TARGA, GIF, PCX, 8 or 24 bits TIF, 8 or 24 bits BMP\n");
  62.      printf("<target file> is any DOS file name\n");
  63.      printf("[option1] /LP (LEAD compression with VGA palette.)\n");
  64.      printf("          /L default (LEAD compression without the VGA palette.)\n");
  65.      printf("          /LJF (LEAD JFIF LEAD JPEG Interchange File Format)\n");
  66.      printf("          /JF (JFIF JPEG Interchange File Format)\n");
  67.      printf("          /LJT (LEAD JTIF JPEG TIF)\n");
  68.      printf("          /JT (JTIF JPEG TIF)\n");
  69.      printf("[option2] /# any number from 2 to 255\n");
  70.      printf("          or the following options for LEAD compression only\n");
  71.      printf("          /PQ1  default LEAD Perfect Quality compression option1\n");
  72.      printf("          /PQ2  default LEAD Perfect Quality compression option2\n");
  73.      printf("          /QFS LEAD Quality by far more important than Size\n");
  74.      printf("          /QMS LEAD Quality more important than Size\n");
  75.      printf("          /QS  LEAD Quality and Size are equally Important\n");
  76.      printf("          /SQS LEAD Size more important than Quality sharp\n");
  77.      printf("          /SQT LEAD Size more important than Quality less Tiling\n");
  78.      printf("          /MCQ LEAD Maximum Compression, keep Quality as good as possible\n");
  79.      printf("          /MC  LEAD Maximum Compression\n");
  80.      printf("EXAMPLE   SCF2F *.TGA *.cmp /LP /PQ2    will compress all TGA files to LEAD\n");
  81.      printf("with palette at LEAD Perfect Quality compression option2.\n");
  82.      if(argc==1)
  83.         printf("ERROR NO <source file> and <target file> specified");
  84.      else
  85.         printf("ERROR NO <target file> specified");
  86.      exit(0);
  87.   }
  88.  strupr(argv[1]);
  89.  strupr(argv[2]);
  90.     
  91.  if ( find_wildletter(argv[1]) == 1)
  92.   {
  93.      if (find_wildletter(argv[2]) == 1)
  94.         wild_flag = 1;
  95.   }
  96.  for (i = 3; i<=argc; i++)
  97.    {
  98.       strupr(argv[i]);
  99.       if(argv[i][0]=='/')
  100.       if(get_value(argv[i]+1)==BAD_COMMAND)
  101.          {
  102.             printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  103.             printf("              8701 Mallard Creek Rd.\n");
  104.             printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  105.             L_SleepKey(1);
  106.             printf("\nDOS - File to file software compression utility Version 3.1\n");
  107.             printf("USEAGE: SCF2F <source file> <target file> [/option1] [/option2] \n");
  108.             printf("<source file> is any TARGA, GIF, PCX, 8 or 24 bits TIF, 8 or 24 bits BMP\n");
  109.             printf("<target file> is any DOS file name\n");
  110.             printf("[option1] /LP (LEAD compression with VGA palette.)\n");
  111.             printf("          /L default (LEAD compression without the VGA palette.)\n");
  112.             printf("          /LJF (LEAD JFIF LEAD JPEG Interchange File Format)\n");
  113.             printf("          /JF (JFIF JPEG Interchange File Format)\n");
  114.             printf("          /LJT (LEAD JTIF JPEG TIF)\n");
  115.             printf("          /JT (JTIF JPEG TIF)\n");
  116.             printf("[option2] /# any number from 2 to 255\n");
  117.             printf("          or the following options for LEAD compression only\n");
  118.             printf("          /PQ1  default LEAD Perfect Quality compression option1\n");
  119.             printf("          /PQ2  default LEAD Perfect Quality compression option2\n");
  120.             printf("          /QFS LEAD Quality by far more important than Size\n");
  121.             printf("          /QMS LEAD Quality more important than Size\n");
  122.             printf("          /QS  LEAD Quality and Size are equally Important\n");
  123.             printf("          /SQS LEAD Size more important than Quality sharp\n");
  124.             printf("          /SQT LEAD Size more important than Quality less Tiling\n");
  125.             printf("          /MCQ LEAD Maximum Compression, keep Quality as good as possible\n");
  126.             printf("          /MC  LEAD Maximum Compression\n");
  127.             printf("EXAMPLE   SCF2F *.TGA *.cmp /LP /PQ2    will compress all TGA files to LEAD\n");
  128.             printf("with palette at LEAD Perfect Quality compression option2.\n");
  129.             printf("\nInvalid option %s",argv[i]);
  130.             exit(0);
  131.          }
  132.    }
  133.    get_pathname(argv[1], pathname);
  134.    result = _dos_findfirst(argv[1], 0 , &file);
  135.    if (result) 
  136.        printf("SCF2F: no such file %s\n",argv[1]);
  137.    else
  138.        while(!result)  /* Stop when _dos_findnext returns */
  139.          {
  140.             strcpy(infile, pathname);
  141.             strcat(infile, file.name);
  142.             if ( (L_FileInfo(infile,&FileInformation)==SUCCESS) && (FileInformation.BitsPerPixel >=8) )
  143.                {
  144.                  if (wild_flag == 1)
  145.                     get_outfilename(file.name, argv[2], outfile);
  146.                  else
  147.                     strcpy(outfile, argv[2]);
  148.                  printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  149.                  printf("              8701 Mallard Creek Rd.\n");
  150.                  printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  151.                  printf("\nDOS - File to file software compression utility Version 3.1\n");
  152.                  printf("\nCompressing image file %s to %s", infile, outfile);
  153.                  if( FileInformation.Format == FILE_TGA)
  154.                   {
  155.                       error=L_CompressTGA(infile,outfile,format,qqfactor,palette);
  156.                   }
  157.                  else if( FileInformation.Format == FILE_TIF)
  158.                   {
  159.                      error=L_CompressTIF(infile,outfile,format,qqfactor,palette);
  160.                   }
  161.                  else if( FileInformation.Format == FILE_BMP)
  162.                   {
  163.                      error=L_CompressBMP(infile,outfile,format,qqfactor,palette);
  164.                   }
  165.                  else if( FileInformation.Format == FILE_OS2)
  166.                   {
  167.                      error=L_CompressBMP(infile,outfile,format,qqfactor,palette);
  168.                   }
  169.                  else if( FileInformation.Format == FILE_PCX)
  170.                   {
  171.                      error=L_CompressPCX(infile,outfile,format,qqfactor,palette);
  172.                   }
  173.                  else if( FileInformation.Format == FILE_GIF)
  174.                   {
  175.                      error=L_CompressGIF(infile,outfile,format,qqfactor,palette);
  176.                   }
  177.                
  178.                  if(error!=SUCCESS)
  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\n");
  183.                       printf("\nDOS - File to file software compression utility Version 3.1\n");
  184.                       printf("\nERROR %d COMPRESSING IMAGE FILE %s\n",error,file.name);
  185.                   }
  186.                }
  187.               else
  188.                {
  189.                   printf("\nSCF2F: error opening file %s\n",file.name);
  190.                   putch(7);
  191.                }
  192.             result = _dos_findnext(&file);
  193.          }
  194.  
  195. }
  196.  
  197.  
  198.  
  199.  
  200. get_value(string)
  201. char *string;
  202. {
  203.   char *exttab[17], *extptr1;
  204.   int pathlen1, ret = OK, source;
  205.   
  206.   exttab[0] = "LP";
  207.   exttab[1] = "L";
  208.   exttab[2] = "LJF";
  209.   exttab[3] = "JF";
  210.   exttab[4] = "LJT";
  211.   exttab[5] = "JT";
  212.   exttab[6] = "PQ1";
  213.   exttab[7] = "PQ2";
  214.   exttab[8] = "QFS";
  215.   exttab[9] = "QMS";
  216.   exttab[10] = "QS";
  217.   exttab[11] = "SQS";
  218.   exttab[12] = "SQT";
  219.   exttab[13] = "MCQ";
  220.   exttab[14] = "MC";
  221.   exttab[15] = "SAVE";
  222.   exttab[16] = "NOSAVE";
  223.   
  224.   extptr1 = string;
  225.   
  226.   for (source = 0; source < 17; ++source)
  227.    {
  228.       if (!strcmp(extptr1, exttab[source]))
  229.          break;
  230.    }
  231.   
  232.    if (source >= 17)
  233.      {
  234.        qqfactor = atoi(string);
  235.        if (qqfactor <= 0 || qqfactor > 255)
  236.           return(BAD_COMMAND);
  237.        return(OK);
  238.      }
  239.   
  240.     switch (source)
  241.       {
  242.          case  0:
  243.                format = LEAD;
  244.                palette = SaveVGAPalette;
  245.                break;
  246.   
  247.          case  1:
  248.                format = LEAD;
  249.                palette = NoVGAPalette;
  250.                break;
  251.   
  252.          case  2:
  253.                format = LEADJFIF;
  254.                break;
  255.   
  256.          case  3:
  257.                format = JFIF;
  258.                break;
  259.   
  260.          case  4:
  261.                format = LEADJTIF;
  262.                break;
  263.   
  264.          case  5:
  265.                format = JTIF;
  266.                break;
  267.   
  268.          case  6:
  269.                qqfactor = PQ1;
  270.                break;
  271.   
  272.          case  7:
  273.                qqfactor = PQ2;
  274.                break;
  275.   
  276.          case  8:
  277.                qqfactor = QFS;
  278.                break;
  279.   
  280.          case  9:
  281.                qqfactor = QMS;
  282.                break;
  283.   
  284.          case  10:
  285.                qqfactor = QS;
  286.                break;
  287.   
  288.          case  11:
  289.                qqfactor = SQS;
  290.                break;
  291.   
  292.          case  12:
  293.                qqfactor = SQT;
  294.                break;
  295.   
  296.   
  297.          case  13:
  298.                qqfactor = MCQ;
  299.                break;
  300.   
  301.          case  14:
  302.                qqfactor = MC;
  303.                break;
  304.   
  305.          case  15:
  306.                palette = SaveVGAPalette;
  307.                break;
  308.   
  309.          case  16:
  310.                palette = NoVGAPalette;
  311.                break;
  312.   
  313.   
  314.         default:
  315.                ret = BAD_COMMAND;
  316.                break;
  317.       }
  318.   
  319.   return(ret);
  320. }
  321.  
  322.  
  323.  
  324.  
  325. get_outfilename(from_file, as_file, to_file)
  326. char from_file[], as_file[], to_file[];
  327. {
  328.   char ext1[120], name1[128], ext2[120], name2[128];
  329.   int i, q, j, ext1_flag = 0, ext2_flag = 0;
  330.   int x, x1;
  331.   
  332.   ext1[0] = 0, ext2[0] = 0, name1[0] = 0, name2[0] = 0;
  333.   for (i = strlen(from_file)-1; i >= 0; i--)
  334.     if (from_file[i] == '.' && from_file[i+1] != '.' && from_file[i-1] != '.')
  335.      {
  336.          ext1_flag = 1;
  337.          break;
  338.       }
  339.   
  340.   strcpy(name1, from_file);
  341.   name1[i] = 0;
  342.   if (ext1_flag == 1)
  343.     strcpy(ext1, from_file+i+1);
  344.   for (i = strlen(as_file)-1; i >= 0; i--)
  345.     if (as_file[i] == '.' && as_file[i+1] != '.' && as_file[i-1] != '.')
  346.      {
  347.         ext2_flag = 1;
  348.         break;
  349.      }
  350.   
  351.   strcpy(name2, as_file);
  352.   name2[i] = 0;
  353.   if (ext2_flag == 1)
  354.      strcpy(ext2, as_file+i+1);
  355.   
  356.   for (i = 0, q = 0; i < strlen(name2); i++)
  357.       {
  358.        if (name2[i] == '*')
  359.            {
  360.            to_file[i] = 0;
  361.            strcat(to_file+i, name1);
  362.            i = i + strlen(name1+q);
  363.            goto exit0;
  364.            }
  365.        if (name2[i] == '?')
  366.           {
  367.           to_file[i] = name1[i];
  368.           q++;
  369.           } 
  370.        else
  371.           to_file[i] = name2[i];
  372.       }
  373.   
  374.    to_file[i] = 0;
  375.    exit0:
  376.   
  377.    to_file[i] = '.';
  378.    i++;
  379.    for (j = 0, q = 0; j < strlen(ext2); i++, j++)
  380.     {
  381.        if (ext2[j] == '*')
  382.         {
  383.            to_file[i] = 0;
  384.            strcat(to_file, ext1+q);
  385.            return(0);
  386.         }
  387.        if (name2[i] == '?')
  388.           {
  389.           to_file[i] = ext1[j];
  390.           q++;
  391.           } 
  392.        else
  393.           to_file[i] = ext2[j];
  394.     }
  395.     to_file[i] = 0;
  396.     if(to_file[i-1] == '.')
  397.        to_file[i-1] = 0;
  398.   
  399.   return(0);
  400. }
  401.   
  402.  
  403.  
  404.   
  405. find_wildletter(string)
  406. char string[];
  407. {
  408.   int i;
  409.   
  410.   for (i = 0; i < strlen(string); i++)
  411.    if (string[i] == '*')
  412.          return(1);
  413.   
  414.   return(0);
  415. }
  416.  
  417.  
  418. get_pathname(in, pathname)
  419. char in[], pathname[];
  420. {
  421.   int i;
  422.  
  423.   strcpy(pathname, in);
  424.   for (i = strlen(in)-1; i >= 0; i--)
  425.     {
  426.        if (in[i] == '\\' || in[i] == ':')
  427.           break;
  428.     }
  429.  
  430.   if (i == 0)
  431.      pathname[0] = 0;
  432.   else
  433.      pathname[i+1] = 0;
  434. }
  435.  
  436.  
  437.  
  438.