home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / leadtool.zip / LEADCOMP.C < prev    next >
Text File  |  1992-07-20  |  15KB  |  460 lines

  1. #include <stdio.h>
  2. #include <dos.h>
  3. #include"v:\leadview\toolkit\L_Bitmap.h"
  4. #include"v:\leadview\toolkit\L_error.h"
  5. #include"v:\leadview\toolkit\toolapp.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 = LEAD, qqfactor = PQ1, palette = NoVGAPalette;
  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.  
  30.  L_SetCheckStatus(NO_CHECK);
  31.  if(argc<=2)
  32.   {
  33.      printf("COPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  34.      printf("              8701 Mallard Creek Rd.\n");
  35.      printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  36.      printf("LEADTOOLS DEMO is for Evaluation purposes only. Your license to use this\n");
  37.      printf("software will expire after 3 weeks from the date you receive it.\n");
  38.      printf("You are free to distribute this demo copy of LEADTOOLS as long as all files\n");
  39.      printf("listed (DEMO.C DEMO36.EXE LEADSHOW.C LEADSHOW.EXE LEADCOMP.C\n");
  40.      printf("LEADCOMP.EXE LEADECOM.C LEADECOM.EXE) are all included. You may not distribute\n");
  41.      printf("any of the files separately.\n");
  42.      printf("If you do not have the above list of files please contact LEAD Technologies Inc.\n");
  43.      printf("for the complete list.\n");
  44.      printf("All .EXE programs are not designed as end user products.  They all are a quick\n");
  45.      printf("collection of calls to LEADTOOLS functions.  Menus were not included to avoid\n");
  46.      printf("confusion when evaluating the code as to the processing calls verses the\n");
  47.      printf("menuing code..........................PRESS ANY KEY TO CONTINUE.\n");
  48.      L_SleepKey(20);
  49.      printf("\nDOS - File to file software compression utility Version 3.6\n");
  50.      printf("USEAGE: LEADCOMP <source file> <target file> [/option1] [/option2] \n");
  51.      printf("<source file> is any TARGA, GIF, PCX, 8 or 24 bits TIF, 8 or 24 bits BMP\n");
  52.      printf("<target file> is any DOS file name\n");
  53.      printf("[option1] /LP (LEAD compression with VGA palette.)\n");
  54.      printf("          /L default (LEAD compression without the VGA palette.)\n");
  55.      printf("          /L2JFIF (LEAD JFIF LEAD JPEG Interchange File Format 4:2:2)\n");
  56.      printf("          /L1JFIF (LEAD JFIF LEAD JPEG Interchange File Format 4:1:1)\n");
  57.      printf("          /JFIF (JFIF JPEG Interchange File Format)\n");
  58.      printf("          /L2JTIF (LEAD JTIF JPEG TIF 4:2:2)\n");
  59.      printf("          /L1JTIF (LEAD JTIF JPEG TIF 4:1:1)\n");
  60.      printf("          /JTIF (JTIF JPEG TIF)\n");
  61.      printf("[option2] /# any number from 2 to 255\n");
  62.      printf("          or the following options for LEAD compression only\n");
  63.      printf("          /PQ1  default LEAD Perfect Quality compression option1\n");
  64.      printf("          /PQ2  default LEAD Perfect Quality compression option2\n");
  65.      printf("          /QFS LEAD Quality by far more important than Size\n");
  66.      printf("          /QMS LEAD Quality more important than Size\n");
  67.      printf("          /QS  LEAD Quality and Size are equally Important\n");
  68.      printf("          /SQS LEAD Size more important than Quality sharp\n");
  69.      printf("          /SQT LEAD Size more important than Quality less Tiling\n");
  70.      printf("          /MCQ LEAD Maximum Compression, keep Quality as good as possible\n");
  71.      printf("EXAMPLE   LEADCOMP *.TGA *.cmp /LP /PQ2   will compress all TGA files to LEAD\n");
  72.      printf("with palette at LEAD Perfect Quality compression option2.\n");
  73.      if(argc==1)
  74.         printf("ERROR NO <source file> and <target file> specified");
  75.      else
  76.         printf("ERROR NO <target file> specified");
  77.      exit(0);
  78.   }
  79.  else
  80.     if(argv[1][0]=='/')
  81.      {
  82.         printf("Error Bad source file %s",argv[1]);
  83.         exit(0);
  84.      }
  85.     else if(argv[2][0]=='/')
  86.      {
  87.         printf("Error Bad source file %s",argv[1]);
  88.         exit(0);
  89.      }
  90.  
  91.  
  92.  strupr(argv[1]);
  93.  strupr(argv[2]);
  94.     
  95.  if ( find_wildletter(argv[1]) == 1)
  96.   {
  97.      if (find_wildletter(argv[2]) == 1)
  98.         wild_flag = 1;
  99.   }
  100.  for (i = 3; i<=argc; i++)
  101.    {
  102.       strupr(argv[i]);
  103.       if(argv[i][0]=='/')
  104.       if(get_value(argv[i]+1)==BAD_COMMAND)
  105.          {
  106.             printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  107.             printf("              8701 Mallard Creek Rd.\n");
  108.             printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  109.             L_SleepKey(1);
  110.             printf("\nDOS - File to file software compression utility Version 3.6\n");
  111.             printf("USEAGE: LEADCOMP <source file> <target file> [/option1] [/option2] \n");
  112.             printf("<source file> is any TARGA, GIF, PCX, 8 or 24 bits TIF, 8 or 24 bits BMP\n");
  113.             printf("<target file> is any DOS file name\n");
  114.             printf("[option1] /LP (LEAD compression with VGA palette.)\n");
  115.             printf("          /L default (LEAD compression without the VGA palette.)\n");
  116.             printf("          /L2JFIF (LEAD JFIF LEAD JPEG Interchange File Format 4:2:2)\n");
  117.             printf("          /L1JFIF (LEAD JFIF LEAD JPEG Interchange File Format 4:1:1)\n");
  118.             printf("          /JFIF (JFIF JPEG Interchange File Format)\n");
  119.             printf("          /L1JTIF (LEAD JTIF JPEG TIF 4:2:2)\n");
  120.             printf("          /L2JTIF (LEAD JTIF JPEG TIF 4:1:1)\n");
  121.             printf("          /JTIF (JTIF JPEG TIF)\n");
  122.             printf("[option2] /# any number from 2 to 255\n");
  123.             printf("          or the following options for LEAD compression only\n");
  124.             printf("          /PQ1  default LEAD Perfect Quality compression option1\n");
  125.             printf("          /PQ2  default LEAD Perfect Quality compression option2\n");
  126.             printf("          /QFS LEAD Quality by far more important than Size\n");
  127.             printf("          /QMS LEAD Quality more important than Size\n");
  128.             printf("          /QS  LEAD Quality and Size are equally Important\n");
  129.             printf("          /SQS LEAD Size more important than Quality sharp\n");
  130.             printf("          /SQT LEAD Size more important than Quality less Tiling\n");
  131.             printf("          /MCQ LEAD Maximum Compression, keep Quality as good as possible\n");
  132.             printf("          /MC  LEAD Maximum Compression\n");
  133.             printf("EXAMPLE   LEADCOMP *.TGA *.cmp /LP /PQ2    will compress all TGA files to LEAD\n");
  134.             printf("with palette at LEAD Perfect Quality compression option2.\n");
  135.             printf("\nInvalid option %s",argv[i]);
  136.             exit(0);
  137.          }
  138.    }
  139.    get_pathname(argv[1], pathname);
  140.    result = _dos_findfirst(argv[1], 0 , &file);
  141.    if (result) 
  142.        printf("LEADCOMP: no such file %s\n",argv[1]);
  143.    else
  144.        while(!result)  /* Stop when _dos_findnext returns */
  145.          {
  146.             strcpy(infile, pathname);
  147.             strcat(infile, file.name);
  148.             if ( (L_FileInfo(infile,&FileInformation)==SUCCESS) && (FileInformation.BitsPerPixel >=8) )
  149.                {
  150.                  if (wild_flag == 1)
  151.                     get_outfilename(file.name, argv[2], outfile);
  152.                  else
  153.                     strcpy(outfile, argv[2]);
  154.                  printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  155.                  printf("              8701 Mallard Creek Rd.\n");
  156.                  printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  157.                  printf("\nDOS - File to file software compression utility Version 3.6\n");
  158.                  printf("\nCompressing image file %s to %s", infile, outfile);
  159.                  if( FileInformation.Format == FILE_TGA)
  160.                   {
  161.                       error=L_CompressTGA(infile,outfile,format,qqfactor,palette);
  162.                   }
  163.                  else if( FileInformation.Format == FILE_TIF)
  164.                   {
  165.                      error=L_CompressTIF(infile,outfile,format,qqfactor,palette);
  166.                   }
  167.                  else if( FileInformation.Format == FILE_BMP)
  168.                   {
  169.                      error=L_CompressBMP(infile,outfile,format,qqfactor,palette);
  170.                   }
  171.                  else if( FileInformation.Format == FILE_OS2)
  172.                   {
  173.                      error=L_CompressBMP(infile,outfile,format,qqfactor,palette);
  174.                   }
  175.                  else if( FileInformation.Format == FILE_PCX)
  176.                   {
  177.                      error=L_CompressPCX(infile,outfile,format,qqfactor,palette);
  178.                   }
  179.                  else if( FileInformation.Format == FILE_GIF)
  180.                   {
  181.                      error=L_CompressGIF(infile,outfile,format,qqfactor,palette);
  182.                   }
  183.                
  184.                  if(error!=SUCCESS)
  185.                   {
  186.                       printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
  187.                       printf("              8701 Mallard Creek Rd.\n");
  188.                       printf("              Charlotte NC 28262      Tel# (704)549-5532\n\n");
  189.                       printf("\nDOS - File to file software compression utility Version 3.6\n");
  190.                       printf("\nERROR %d COMPRESSING IMAGE FILE %s\n",error,file.name);
  191.                   }
  192.                }
  193.               else
  194.                {
  195.                   printf("\nLEADCOMP: error opening file %s\n",file.name);
  196.                   putch(7);
  197.                }
  198.             result = _dos_findnext(&file);
  199.          }
  200.  
  201. }
  202.  
  203.  
  204.  
  205.  
  206. get_value(string)
  207. char *string;
  208. {
  209.   char *exttab[20], *extptr1;
  210.   int pathlen1, ret = OK, source;
  211.  
  212.   exttab[0] = "LP";
  213.   exttab[1] = "L";
  214.   exttab[2] = "L2JFIF";
  215.   exttab[3] = "L1JFIF";
  216.   exttab[4] = "JFIF";
  217.   exttab[5] = "L2JTIF";
  218.   exttab[6] = "L1JTIF";
  219.   exttab[7] = "JTIF";
  220.   exttab[8] = "PQ1";
  221.   exttab[9] = "PQ2";
  222.   exttab[10] = "QFS";
  223.   exttab[11] = "QMS";
  224.   exttab[12] = "QS";
  225.   exttab[13] = "SQS";
  226.   exttab[14] = "SQT";
  227.   exttab[15] = "MCQ";
  228.   exttab[16] = "MC";
  229.   exttab[17] = "SAVE";
  230.   exttab[18] = "NOSAVE";
  231.   
  232.   extptr1 = string;
  233.   
  234.   for (source = 0; source < 19; ++source)
  235.    {
  236.       if (!strcmp(extptr1, exttab[source]))
  237.          break;
  238.    }
  239.   
  240.    if (source >= 19)
  241.      {
  242.        qqfactor = atoi(string);
  243.        if (qqfactor <= 0 || qqfactor > 255)
  244.           return(BAD_COMMAND);
  245.        return(OK);
  246.      }
  247.   
  248.     switch (source)
  249.       {
  250.          case  0:
  251.                format = LEAD;
  252.                palette = SaveVGAPalette;
  253.                break;
  254.   
  255.          case  1:
  256.                format = LEAD;
  257.                palette = NoVGAPalette;
  258.                break;
  259.   
  260.          case  2:
  261.                format = LEAD2JFIF;
  262.                qqfactor = 5;
  263.                break;
  264.   
  265.          case  3:
  266.                format = LEAD1JFIF;
  267.                qqfactor = 5;
  268.                break;
  269.  
  270.          case  4:
  271.                format = JFIF;
  272.                qqfactor = 5;
  273.                break;
  274.  
  275.          case  5:
  276.                format = LEAD2JTIF;
  277.                qqfactor = 5;
  278.                break;
  279.   
  280.          case  6:
  281.                format = LEAD1JTIF;
  282.                qqfactor = 5;
  283.                break;
  284.  
  285.          case  7:
  286.                format = JTIF;
  287.                qqfactor = 5;
  288.                break;
  289.  
  290.          case  8:
  291.                qqfactor = PQ1;
  292.                break;
  293.   
  294.          case  9:
  295.                qqfactor = PQ2;
  296.                break;
  297.   
  298.          case  10:
  299.                qqfactor = QFS;
  300.                break;
  301.   
  302.          case  11:
  303.                qqfactor = QMS;
  304.                break;
  305.   
  306.          case  12:
  307.                qqfactor = QS;
  308.                break;
  309.   
  310.          case  13:
  311.                qqfactor = SQS;
  312.                break;
  313.   
  314.          case  14:
  315.                qqfactor = SQT;
  316.                break;
  317.   
  318.   
  319.          case  15:
  320.                qqfactor = MCQ;
  321.                break;
  322.   
  323.          case  16:
  324.                qqfactor = MC;
  325.                break;
  326.   
  327.          case  17:
  328.                palette = SaveVGAPalette;
  329.                break;
  330.   
  331.          case  18:
  332.                palette = NoVGAPalette;
  333.                break;
  334.   
  335.   
  336.         default:
  337.                ret = BAD_COMMAND;
  338.                break;
  339.       }
  340.   
  341.   return(ret);
  342. }
  343.  
  344.  
  345.  
  346.  
  347. get_outfilename(from_file, as_file, to_file)
  348. char from_file[], as_file[], to_file[];
  349. {
  350.   char ext1[120], name1[128], ext2[120], name2[128];
  351.   int i, q, j, ext1_flag = 0, ext2_flag = 0;
  352.   int x, x1;
  353.   
  354.   ext1[0] = 0, ext2[0] = 0, name1[0] = 0, name2[0] = 0;
  355.   for (i = strlen(from_file)-1; i >= 0; i--)
  356.     if (from_file[i] == '.' && from_file[i+1] != '.' && from_file[i-1] != '.')
  357.      {
  358.          ext1_flag = 1;
  359.          break;
  360.       }
  361.   
  362.   strcpy(name1, from_file);
  363.   name1[i] = 0;
  364.   if (ext1_flag == 1)
  365.     strcpy(ext1, from_file+i+1);
  366.   for (i = strlen(as_file)-1; i >= 0; i--)
  367.     if (as_file[i] == '.' && as_file[i+1] != '.' && as_file[i-1] != '.')
  368.      {
  369.         ext2_flag = 1;
  370.         break;
  371.      }
  372.   
  373.   strcpy(name2, as_file);
  374.   name2[i] = 0;
  375.   if (ext2_flag == 1)
  376.      strcpy(ext2, as_file+i+1);
  377.   
  378.   for (i = 0, q = 0; i < strlen(name2); i++)
  379.       {
  380.        if (name2[i] == '*')
  381.            {
  382.            to_file[i] = 0;
  383.            strcat(to_file+i, name1);
  384.            i = i + strlen(name1+q);
  385.            goto exit0;
  386.            }
  387.        if (name2[i] == '?')
  388.           {
  389.           to_file[i] = name1[i];
  390.           q++;
  391.           } 
  392.        else
  393.           to_file[i] = name2[i];
  394.       }
  395.   
  396.    to_file[i] = 0;
  397.    exit0:
  398.   
  399.    to_file[i] = '.';
  400.    i++;
  401.    for (j = 0, q = 0; j < strlen(ext2); i++, j++)
  402.     {
  403.        if (ext2[j] == '*')
  404.         {
  405.            to_file[i] = 0;
  406.            strcat(to_file, ext1+q);
  407.            return(0);
  408.         }
  409.        if (name2[i] == '?')
  410.           {
  411.           to_file[i] = ext1[j];
  412.           q++;
  413.           } 
  414.        else
  415.           to_file[i] = ext2[j];
  416.     }
  417.     to_file[i] = 0;
  418.     if(to_file[i-1] == '.')
  419.        to_file[i-1] = 0;
  420.   
  421.   return(0);
  422. }
  423.   
  424.  
  425.  
  426.   
  427. find_wildletter(string)
  428. char string[];
  429. {
  430.   int i;
  431.   
  432.   for (i = 0; i < strlen(string); i++)
  433.    if (string[i] == '*')
  434.          return(1);
  435.   
  436.   return(0);
  437. }
  438.  
  439.  
  440. get_pathname(in, pathname)
  441. char in[], pathname[];
  442. {
  443.   int i;
  444.  
  445.   strcpy(pathname, in);
  446.   for (i = strlen(in)-1; i >= 0; i--)
  447.     {
  448.        if (in[i] == '\\' || in[i] == ':')
  449.           break;
  450.     }
  451.  
  452.   if (i == 0)
  453.      pathname[0] = 0;
  454.   else
  455.      pathname[i+1] = 0;
  456. }
  457.  
  458.  
  459.  
  460.