mirror of
https://github.com/google/brotli.git
synced 2024-11-25 04:50:05 +00:00
Merge pull request #109 from szabadka/master
Expose the quality parameter to the bro.cc tool.
This commit is contained in:
commit
682facef7b
@ -17,13 +17,15 @@ $BRO
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
for file in $INPUTS; do
|
for file in $INPUTS; do
|
||||||
echo "Roundtrip testing $file"
|
for quality in 1 6 9 11; do
|
||||||
|
echo "Roundtrip testing $file at quality $quality"
|
||||||
compressed=${file}.bro
|
compressed=${file}.bro
|
||||||
uncompressed=${file}.unbro
|
uncompressed=${file}.unbro
|
||||||
$BRO -f -i $file -o $compressed
|
$BRO -f -q $quality -i $file -o $compressed
|
||||||
$BRO -f -d -i $compressed -o $uncompressed
|
$BRO -f -d -i $compressed -o $uncompressed
|
||||||
diff -q $file $uncompressed
|
diff -q $file $uncompressed
|
||||||
# Test the streaming version
|
# Test the streaming version
|
||||||
cat $file | $BRO | $BRO -d >$uncompressed
|
cat $file | $BRO -q $quality | $BRO -d >$uncompressed
|
||||||
diff -q $file $uncompressed
|
diff -q $file $uncompressed
|
||||||
done
|
done
|
||||||
|
done
|
||||||
|
27
tools/bro.cc
27
tools/bro.cc
@ -27,10 +27,23 @@
|
|||||||
#include "../enc/streams.h"
|
#include "../enc/streams.h"
|
||||||
|
|
||||||
|
|
||||||
|
static bool ParseQuality(const char* s, int* quality) {
|
||||||
|
if (s[0] >= '0' && s[0] <= '9') {
|
||||||
|
*quality = s[0] - '0';
|
||||||
|
if (s[1] >= '0' && s[1] <= '9') {
|
||||||
|
*quality = *quality * 10 + s[1] - '0';
|
||||||
|
return s[2] == 0;
|
||||||
|
}
|
||||||
|
return s[1] == 0;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
static void ParseArgv(int argc, char **argv,
|
static void ParseArgv(int argc, char **argv,
|
||||||
char **input_path,
|
char **input_path,
|
||||||
char **output_path,
|
char **output_path,
|
||||||
int *force,
|
int *force,
|
||||||
|
int *quality,
|
||||||
int *decompress) {
|
int *decompress) {
|
||||||
*force = 0;
|
*force = 0;
|
||||||
*input_path = 0;
|
*input_path = 0;
|
||||||
@ -73,6 +86,13 @@ static void ParseArgv(int argc, char **argv,
|
|||||||
*output_path = argv[k + 1];
|
*output_path = argv[k + 1];
|
||||||
++k;
|
++k;
|
||||||
continue;
|
continue;
|
||||||
|
} else if (!strcmp("--quality", argv[k]) ||
|
||||||
|
!strcmp("-q", argv[k])) {
|
||||||
|
if (!ParseQuality(argv[k + 1], quality)) {
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
|
++k;
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
goto error;
|
goto error;
|
||||||
@ -80,7 +100,7 @@ static void ParseArgv(int argc, char **argv,
|
|||||||
return;
|
return;
|
||||||
error:
|
error:
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"Usage: %s [--force] [--decompress]"
|
"Usage: %s [--force] [--quality n] [--decompress]"
|
||||||
" [--input filename] [--output filename]\n",
|
" [--input filename] [--output filename]\n",
|
||||||
argv[0]);
|
argv[0]);
|
||||||
exit(1);
|
exit(1);
|
||||||
@ -122,8 +142,10 @@ int main(int argc, char** argv) {
|
|||||||
char *input_path = 0;
|
char *input_path = 0;
|
||||||
char *output_path = 0;
|
char *output_path = 0;
|
||||||
int force = 0;
|
int force = 0;
|
||||||
|
int quality = 11;
|
||||||
int decompress = 0;
|
int decompress = 0;
|
||||||
ParseArgv(argc, argv, &input_path, &output_path, &force, &decompress);
|
ParseArgv(argc, argv, &input_path, &output_path, &force,
|
||||||
|
&quality, &decompress);
|
||||||
FILE* fin = OpenInputFile(input_path);
|
FILE* fin = OpenInputFile(input_path);
|
||||||
FILE* fout = OpenOutputFile(output_path, force);
|
FILE* fout = OpenOutputFile(output_path, force);
|
||||||
if (decompress) {
|
if (decompress) {
|
||||||
@ -135,6 +157,7 @@ int main(int argc, char** argv) {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
brotli::BrotliParams params;
|
brotli::BrotliParams params;
|
||||||
|
params.quality = quality;
|
||||||
brotli::BrotliFileIn in(fin, 1 << 16);
|
brotli::BrotliFileIn in(fin, 1 << 16);
|
||||||
brotli::BrotliFileOut out(fout);
|
brotli::BrotliFileOut out(fout);
|
||||||
if (!BrotliCompress(params, &in, &out)) {
|
if (!BrotliCompress(params, &in, &out)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user