Merge pull request #109 from szabadka/master

Expose the quality parameter to the bro.cc tool.
This commit is contained in:
szabadka 2015-05-11 14:15:05 +02:00
commit 682facef7b
2 changed files with 36 additions and 11 deletions

View File

@ -17,13 +17,15 @@ $BRO
"""
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
uncompressed=${file}.unbro
$BRO -f -i $file -o $compressed
$BRO -f -q $quality -i $file -o $compressed
$BRO -f -d -i $compressed -o $uncompressed
diff -q $file $uncompressed
# Test the streaming version
cat $file | $BRO | $BRO -d >$uncompressed
cat $file | $BRO -q $quality | $BRO -d >$uncompressed
diff -q $file $uncompressed
done
done

View File

@ -27,10 +27,23 @@
#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,
char **input_path,
char **output_path,
int *force,
int *quality,
int *decompress) {
*force = 0;
*input_path = 0;
@ -73,6 +86,13 @@ static void ParseArgv(int argc, char **argv,
*output_path = argv[k + 1];
++k;
continue;
} else if (!strcmp("--quality", argv[k]) ||
!strcmp("-q", argv[k])) {
if (!ParseQuality(argv[k + 1], quality)) {
goto error;
}
++k;
continue;
}
}
goto error;
@ -80,7 +100,7 @@ static void ParseArgv(int argc, char **argv,
return;
error:
fprintf(stderr,
"Usage: %s [--force] [--decompress]"
"Usage: %s [--force] [--quality n] [--decompress]"
" [--input filename] [--output filename]\n",
argv[0]);
exit(1);
@ -122,8 +142,10 @@ int main(int argc, char** argv) {
char *input_path = 0;
char *output_path = 0;
int force = 0;
int quality = 11;
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* fout = OpenOutputFile(output_path, force);
if (decompress) {
@ -135,6 +157,7 @@ int main(int argc, char** argv) {
}
} else {
brotli::BrotliParams params;
params.quality = quality;
brotli::BrotliFileIn in(fin, 1 << 16);
brotli::BrotliFileOut out(fout);
if (!BrotliCompress(params, &in, &out)) {