home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* FILE NAME: LEADCOMP.C SOFTWARE COMPRESS FILE TO FILE */
- /* PROGRAMER: MOHAMMAD DAHER */
- /* DATE: 03/12/1992 */
- /* */
- /* COPYRIGHT (c) LEAD Technologies Inc. ALL RIGHTS RESEVED */
- /****************************************************************************/
-
- #include <stdio.h>
- #include <dos.h>
- #include"v:\leadview\toolkit\L_Bitmap.h"
- #include"v:\leadview\toolkit\L_error.h"
- #include"v:\leadview\toolkit\toolapp.h"
-
- #define OK 1
- #define BAD_COMMAND -2
- #define TARGAOLD 1
- #define VGA 2
-
- #if __BORLANDC__
- extern unsigned _stklen = 13000U;
- #endif
-
- int format = LEAD, qqfactor = PQ1, palette = NoVGAPalette;
-
- main(int argc, char *argv[])
- {
- FILEINFO FileInformation;
- struct find_t file;
- int result;
- int i;
- char string[256];
- int mode,page;
- int error;
- char outfile[128], infile[128], pathname[128];
- int wild_flag = 0;
-
- if(argc<=2)
- {
- printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
- printf(" 8701 Mallard Creek Rd.\n");
- printf(" Charlotte NC 28262 Tel# (704)549-5532\n\n");
- printf("\nIf you find this utility suitable for your use, please register this program\n");
- printf("for $49.00 and receive the latest version.\n");
- printf("Send $129.00 and receive in addition to the above, LEADVIEW, an easy to use\n");
- printf("user interface that incorporates image compression/decompression, file\n");
- printf("conversion to and from 8bit TGA, 16bit TGA, 24bit TGA, 32bit TGA, 8bit TIFF,\n");
- printf("24bit TIFF, 4bit BMP, 8bit BMP 24bit BMP, PCX, GIF, BIN with resize/flip/rotate\n");
- printf("options, and a communication module. A DOS version (which can be used from\n");
- printf("within a TSR taking only 6K of conventional memory) or Windows 3.X version is\n");
- printf("available.\n\n");
- printf("Other LEAD products include LEADVIEW Turbo and LEADVIEW 255 hardware\n");
- printf("accelerator board (faster versions of LEADVIEW supporting real-time\n");
- printf("compression/decompression) and LEADTOOLS, a run-time library of 'C' routines \n");
- printf("for DOS or LEADTOOLS DLL for Windows 3.x that gives developers the ability to\n");
- printf("incorporate compression, decompression, and conversion features into their\n");
- printf("own applications.\n\n");
- L_SleepKey(20);
- printf("\nDOS - File to file software compression utility Version 3.1\n");
- printf("USEAGE: LEADCOMP <source file> <target file> [/option1] [/option2] \n");
- printf("<source file> is any TARGA, GIF, PCX, 8 or 24 bits TIF, 8 or 24 bits BMP\n");
- printf("<target file> is any DOS file name\n");
- printf("[option1] /LP (LEAD compression with VGA palette.)\n");
- printf(" /L default (LEAD compression without the VGA palette.)\n");
- printf(" /LJF (LEAD JFIF LEAD JPEG Interchange File Format)\n");
- printf(" /JF (JFIF JPEG Interchange File Format)\n");
- printf(" /LJT (LEAD JTIF JPEG TIF)\n");
- printf(" /JT (JTIF JPEG TIF)\n");
- printf("[option2] /# any number from 2 to 255\n");
- printf(" or the following options for LEAD compression only\n");
- printf(" /PQ1 default LEAD Perfect Quality compression option1\n");
- printf(" /PQ2 default LEAD Perfect Quality compression option2\n");
- printf(" /QFS LEAD Quality by far more important than Size\n");
- printf(" /QMS LEAD Quality more important than Size\n");
- printf(" /QS LEAD Quality and Size are equally Important\n");
- printf(" /SQS LEAD Size more important than Quality sharp\n");
- printf(" /SQT LEAD Size more important than Quality less Tiling\n");
- printf(" /MCQ LEAD Maximum Compression, keep Quality as good as possible\n");
- printf(" /MC LEAD Maximum Compression\n");
- printf("EXAMPLE SCF2F *.TGA *.cmp /LP /PQ2 will compress all TGA files to LEAD\n");
- printf("with palette at LEAD Perfect Quality compression option2.\n");
- if(argc==1)
- printf("ERROR NO <source file> and <target file> specified");
- else
- printf("ERROR NO <target file> specified");
- exit(0);
- }
- strupr(argv[1]);
- strupr(argv[2]);
-
- if ( find_wildletter(argv[1]) == 1)
- {
- if (find_wildletter(argv[2]) == 1)
- wild_flag = 1;
- }
- for (i = 3; i<=argc; i++)
- {
- strupr(argv[i]);
- if(argv[i][0]=='/')
- if(get_value(argv[i]+1)==BAD_COMMAND)
- {
- printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
- printf(" 8701 Mallard Creek Rd.\n");
- printf(" Charlotte NC 28262 Tel# (704)549-5532\n\n");
- L_SleepKey(1);
- printf("\nDOS - File to file software compression utility Version 3.1\n");
- printf("USEAGE: SCF2F <source file> <target file> [/option1] [/option2] \n");
- printf("<source file> is any TARGA, GIF, PCX, 8 or 24 bits TIF, 8 or 24 bits BMP\n");
- printf("<target file> is any DOS file name\n");
- printf("[option1] /LP (LEAD compression with VGA palette.)\n");
- printf(" /L default (LEAD compression without the VGA palette.)\n");
- printf(" /LJF (LEAD JFIF LEAD JPEG Interchange File Format)\n");
- printf(" /JF (JFIF JPEG Interchange File Format)\n");
- printf(" /LJT (LEAD JTIF JPEG TIF)\n");
- printf(" /JT (JTIF JPEG TIF)\n");
- printf("[option2] /# any number from 2 to 255\n");
- printf(" or the following options for LEAD compression only\n");
- printf(" /PQ1 default LEAD Perfect Quality compression option1\n");
- printf(" /PQ2 default LEAD Perfect Quality compression option2\n");
- printf(" /QFS LEAD Quality by far more important than Size\n");
- printf(" /QMS LEAD Quality more important than Size\n");
- printf(" /QS LEAD Quality and Size are equally Important\n");
- printf(" /SQS LEAD Size more important than Quality sharp\n");
- printf(" /SQT LEAD Size more important than Quality less Tiling\n");
- printf(" /MCQ LEAD Maximum Compression, keep Quality as good as possible\n");
- printf(" /MC LEAD Maximum Compression\n");
- printf("EXAMPLE SCF2F *.TGA *.cmp /LP /PQ2 will compress all TGA files to LEAD\n");
- printf("with palette at LEAD Perfect Quality compression option2.\n");
- printf("\nInvalid option %s",argv[i]);
- exit(0);
- }
- }
- get_pathname(argv[1], pathname);
- result = _dos_findfirst(argv[1], 0 , &file);
- if (result)
- printf("SCF2F: no such file %s\n",argv[1]);
- else
- while(!result) /* Stop when _dos_findnext returns */
- {
- strcpy(infile, pathname);
- strcat(infile, file.name);
- if ( (L_FileInfo(infile,&FileInformation)==SUCCESS) && (FileInformation.BitsPerPixel >=8) )
- {
- if (wild_flag == 1)
- get_outfilename(file.name, argv[2], outfile);
- else
- strcpy(outfile, argv[2]);
- printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
- printf(" 8701 Mallard Creek Rd.\n");
- printf(" Charlotte NC 28262 Tel# (704)549-5532\n\n");
- printf("\nDOS - File to file software compression utility Version 3.1\n");
- printf("\nCompressing image file %s to %s", infile, outfile);
- if( FileInformation.Format == FILE_TGA)
- {
- error=L_CompressTGA(infile,outfile,format,qqfactor,palette);
- }
- else if( FileInformation.Format == FILE_TIF)
- {
- error=L_CompressTIF(infile,outfile,format,qqfactor,palette);
- }
- else if( FileInformation.Format == FILE_BMP)
- {
- error=L_CompressBMP(infile,outfile,format,qqfactor,palette);
- }
- else if( FileInformation.Format == FILE_OS2)
- {
- error=L_CompressBMP(infile,outfile,format,qqfactor,palette);
- }
- else if( FileInformation.Format == FILE_PCX)
- {
- error=L_CompressPCX(infile,outfile,format,qqfactor,palette);
- }
- else if( FileInformation.Format == FILE_GIF)
- {
- error=L_CompressGIF(infile,outfile,format,qqfactor,palette);
- }
-
- if(error!=SUCCESS)
- {
- printf("\nCOPYRIGHT (C) LEAD Technologies, Inc. 1991,1992 ALL RIGHTS RESERVED.\n");
- printf(" 8701 Mallard Creek Rd.\n");
- printf(" Charlotte NC 28262 Tel# (704)549-5532\n\n");
- printf("\nDOS - File to file software compression utility Version 3.1\n");
- printf("\nERROR %d COMPRESSING IMAGE FILE %s\n",error,file.name);
- }
- }
- else
- {
- printf("\nSCF2F: error opening file %s\n",file.name);
- putch(7);
- }
- result = _dos_findnext(&file);
- }
-
- }
-
-
-
-
- get_value(string)
- char *string;
- {
- char *exttab[17], *extptr1;
- int pathlen1, ret = OK, source;
-
- exttab[0] = "LP";
- exttab[1] = "L";
- exttab[2] = "LJF";
- exttab[3] = "JF";
- exttab[4] = "LJT";
- exttab[5] = "JT";
- exttab[6] = "PQ1";
- exttab[7] = "PQ2";
- exttab[8] = "QFS";
- exttab[9] = "QMS";
- exttab[10] = "QS";
- exttab[11] = "SQS";
- exttab[12] = "SQT";
- exttab[13] = "MCQ";
- exttab[14] = "MC";
- exttab[15] = "SAVE";
- exttab[16] = "NOSAVE";
-
- extptr1 = string;
-
- for (source = 0; source < 17; ++source)
- {
- if (!strcmp(extptr1, exttab[source]))
- break;
- }
-
- if (source >= 17)
- {
- qqfactor = atoi(string);
- if (qqfactor <= 0 || qqfactor > 255)
- return(BAD_COMMAND);
- return(OK);
- }
-
- switch (source)
- {
- case 0:
- format = LEAD;
- palette = SaveVGAPalette;
- break;
-
- case 1:
- format = LEAD;
- palette = NoVGAPalette;
- break;
-
- case 2:
- format = LEADJFIF;
- break;
-
- case 3:
- format = JFIF;
- break;
-
- case 4:
- format = LEADJTIF;
- break;
-
- case 5:
- format = JTIF;
- break;
-
- case 6:
- qqfactor = PQ1;
- break;
-
- case 7:
- qqfactor = PQ2;
- break;
-
- case 8:
- qqfactor = QFS;
- break;
-
- case 9:
- qqfactor = QMS;
- break;
-
- case 10:
- qqfactor = QS;
- break;
-
- case 11:
- qqfactor = SQS;
- break;
-
- case 12:
- qqfactor = SQT;
- break;
-
-
- case 13:
- qqfactor = MCQ;
- break;
-
- case 14:
- qqfactor = MC;
- break;
-
- case 15:
- palette = SaveVGAPalette;
- break;
-
- case 16:
- palette = NoVGAPalette;
- break;
-
-
- default:
- ret = BAD_COMMAND;
- break;
- }
-
- return(ret);
- }
-
-
-
-
- get_outfilename(from_file, as_file, to_file)
- char from_file[], as_file[], to_file[];
- {
- char ext1[120], name1[128], ext2[120], name2[128];
- int i, q, j, ext1_flag = 0, ext2_flag = 0;
- int x, x1;
-
- ext1[0] = 0, ext2[0] = 0, name1[0] = 0, name2[0] = 0;
- for (i = strlen(from_file)-1; i >= 0; i--)
- if (from_file[i] == '.' && from_file[i+1] != '.' && from_file[i-1] != '.')
- {
- ext1_flag = 1;
- break;
- }
-
- strcpy(name1, from_file);
- name1[i] = 0;
- if (ext1_flag == 1)
- strcpy(ext1, from_file+i+1);
- for (i = strlen(as_file)-1; i >= 0; i--)
- if (as_file[i] == '.' && as_file[i+1] != '.' && as_file[i-1] != '.')
- {
- ext2_flag = 1;
- break;
- }
-
- strcpy(name2, as_file);
- name2[i] = 0;
- if (ext2_flag == 1)
- strcpy(ext2, as_file+i+1);
-
- for (i = 0, q = 0; i < strlen(name2); i++)
- {
- if (name2[i] == '*')
- {
- to_file[i] = 0;
- strcat(to_file+i, name1);
- i = i + strlen(name1+q);
- goto exit0;
- }
- if (name2[i] == '?')
- {
- to_file[i] = name1[i];
- q++;
- }
- else
- to_file[i] = name2[i];
- }
-
- to_file[i] = 0;
- exit0:
-
- to_file[i] = '.';
- i++;
- for (j = 0, q = 0; j < strlen(ext2); i++, j++)
- {
- if (ext2[j] == '*')
- {
- to_file[i] = 0;
- strcat(to_file, ext1+q);
- return(0);
- }
- if (name2[i] == '?')
- {
- to_file[i] = ext1[j];
- q++;
- }
- else
- to_file[i] = ext2[j];
- }
- to_file[i] = 0;
- if(to_file[i-1] == '.')
- to_file[i-1] = 0;
-
- return(0);
- }
-
-
-
-
- find_wildletter(string)
- char string[];
- {
- int i;
-
- for (i = 0; i < strlen(string); i++)
- if (string[i] == '*')
- return(1);
-
- return(0);
- }
-
-
- get_pathname(in, pathname)
- char in[], pathname[];
- {
- int i;
-
- strcpy(pathname, in);
- for (i = strlen(in)-1; i >= 0; i--)
- {
- if (in[i] == '\\' || in[i] == ':')
- break;
- }
-
- if (i == 0)
- pathname[0] = 0;
- else
- pathname[i+1] = 0;
- }
-
-
-