forked from thebeansgroup/smush.py
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Al B
committed
Aug 31, 2010
1 parent
7661243
commit 37d7144
Showing
1 changed file
with
94 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,41 +1,94 @@ | ||
57a58 | ||
> -o Specify output filename. Disables -e and -d options\n\ | ||
110c111 | ||
< static int pngnq(char* filename, char* newext, char* dir, | ||
--- | ||
> static int pngnq(char* filename, char* newext, char* dir, char* outname, | ||
122a124 | ||
> char *output_file_name = NULL; | ||
135c137 | ||
< while((c = getopt(argc,argv,"hVvfn:s:d:e:g:Q:"))!=-1){ | ||
--- | ||
> while((c = getopt(argc,argv,"hVvfn:s:d:e:g:Q:o:"))!=-1){ | ||
184a187,189 | ||
> case 'o': | ||
> output_file_name = optarg; | ||
> break; | ||
211c216 | ||
< retval = pngnq(input_file_name, output_file_extension, output_directory, | ||
--- | ||
> retval = pngnq(input_file_name, output_file_extension, output_directory, output_file_name, | ||
433c438 | ||
< static int pngnq(char* filename, char* newext, char* newdir, | ||
--- | ||
> static int pngnq(char* filename, char* newext, char* newdir, char* outname, | ||
437d441 | ||
< char *outname = NULL; | ||
474,475c478,481 | ||
< { | ||
< outname = createoutname(filename,newext,newdir); | ||
--- | ||
> { | ||
> if (!outname) { | ||
> outname = createoutname(filename,newext,newdir); | ||
> } | ||
673,678d678 | ||
< /* Clean up file name */ | ||
< if(outname){ | ||
< free(outname); | ||
< outname = NULL; | ||
< } | ||
< | ||
--- pngnq-1.0/src/pngnq.c 2009-05-20 13:04:15.000000000 +0100 | ||
+++ pngnq-1.0-mod/src/pngnq.c 2010-08-31 17:03:55.000000000 +0100 | ||
@@ -55,6 +55,7 @@ | ||
-s Speed/quality: 1 = slow, best quality, 3 = good quality, 10 = fast, lower quality.\n\ | ||
-g Image gamma. 1.0 = linear, 2.2 = monitor gamma. Defaults to 1.8.\n\ | ||
-e Specify the new extension for quantized files. Default -nq8.png\n\ | ||
+ -o Specify output filename. Disables -e and -d options\n\ | ||
-d Directory to put quantized images into.\n\ | ||
-v Verbose mode. Prints status messages.\n\ | ||
-V Print version number and library versions.\n\ | ||
@@ -107,7 +108,7 @@ | ||
static mainprog_info rwpng_info; | ||
|
||
|
||
-static int pngnq(char* filename, char* newext, char* dir, | ||
+static int pngnq(char* filename, char* newext, char* dir, char* outname, | ||
int sample_factor, int n_colors, int verbose, | ||
int using_stdin, int force, int use_floyd, double force_gamma); | ||
|
||
@@ -120,6 +121,7 @@ | ||
char *input_file_name = NULL; | ||
char *output_file_extension = "-nq8.png"; | ||
char *output_directory = NULL; | ||
+ char *output_file_name = NULL; | ||
|
||
int using_stdin = FALSE; | ||
int c; /* argument character */ | ||
@@ -132,7 +134,7 @@ | ||
double force_gamma = 0; | ||
|
||
/* Parse arguments */ | ||
- while((c = getopt(argc,argv,"hVvfn:s:d:e:g:Q:"))!=-1){ | ||
+ while((c = getopt(argc,argv,"hVvfn:s:d:e:g:Q:o:"))!=-1){ | ||
switch(c){ | ||
case 's': | ||
sample_factor = atoi(optarg); | ||
@@ -182,6 +184,9 @@ | ||
case 'e': | ||
output_file_extension = optarg; | ||
break; | ||
+ case 'o': | ||
+ output_file_name = optarg; | ||
+ break; | ||
default: | ||
fprintf(stderr,PNGNQ_USAGE); | ||
exit(EXIT_FAILURE); | ||
@@ -208,7 +213,7 @@ | ||
|
||
PNGNQ_MESSAGE(" quantizing: %s \n",input_file_name); | ||
|
||
- retval = pngnq(input_file_name, output_file_extension, output_directory, | ||
+ retval = pngnq(input_file_name, output_file_extension, output_directory, output_file_name, | ||
sample_factor, n_colours, verbose, using_stdin,force,use_floyd,force_gamma); | ||
|
||
if(retval){ | ||
@@ -430,11 +435,10 @@ | ||
#endif | ||
} | ||
|
||
-static int pngnq(char* filename, char* newext, char* newdir, | ||
+static int pngnq(char* filename, char* newext, char* newdir, char* outname, | ||
int sample_factor, int n_colours, int verbose, | ||
int using_stdin, int force, int quantization_method, double force_gamma) | ||
{ | ||
- char *outname = NULL; | ||
FILE *infile = NULL; | ||
FILE *outfile = NULL; | ||
|
||
@@ -471,8 +475,10 @@ | ||
outfile = stdout; | ||
} | ||
else | ||
- { | ||
- outname = createoutname(filename,newext,newdir); | ||
+ { | ||
+ if (!outname) { | ||
+ outname = createoutname(filename,newext,newdir); | ||
+ } | ||
|
||
if (!force) { | ||
if ((outfile = fopen(outname, "rb")) != NULL) { | ||
@@ -670,12 +676,6 @@ | ||
row_pointers = rwpng_info.row_pointers = NULL; | ||
} | ||
|
||
- /* Clean up file name */ | ||
- if(outname){ | ||
- free(outname); | ||
- outname = NULL; | ||
- } | ||
- | ||
return 0; | ||
} | ||
|