Commit 99291d6c authored by Mathis Rosenhauer's avatar Mathis Rosenhauer

Remove stdout support since it creates problems on Windows.

parent 6f8b3ae7
...@@ -58,6 +58,20 @@ ...@@ -58,6 +58,20 @@
#define CHUNK 10485760 #define CHUNK 10485760
int get_param(int *param, int *iarg, char *argv[])
{
if (strlen(argv[*iarg]) == 2) {
(*iarg)++;
if (argv[*iarg][0] == '-')
return 1;
else
*param = atoi(argv[*iarg]);
} else {
*param = atoi(&argv[*iarg][2]);
}
return 0;
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
struct aec_stream strm; struct aec_stream strm;
...@@ -66,9 +80,8 @@ int main(int argc, char *argv[]) ...@@ -66,9 +80,8 @@ int main(int argc, char *argv[])
size_t total_out; size_t total_out;
int chunk, status; int chunk, status;
int input_avail, output_avail; int input_avail, output_avail;
char *outfn, *infn, *ext; char *infn, *outfn;
FILE *infp, *outfp; FILE *infp, *outfp;
int cflag;
int dflag; int dflag;
char *opt; char *opt;
int iarg; int iarg;
...@@ -78,15 +91,10 @@ int main(int argc, char *argv[]) ...@@ -78,15 +91,10 @@ int main(int argc, char *argv[])
strm.block_size = 8; strm.block_size = 8;
strm.rsi = 2; strm.rsi = 2;
strm.flags = AEC_DATA_PREPROCESS; strm.flags = AEC_DATA_PREPROCESS;
outfn = 0;
cflag = 0;
dflag = 0; dflag = 0;
iarg = 1; iarg = 1;
if (argc == 1 || (argc == 2 && argv[1][0] == '-')) while (iarg < argc - 2) {
goto FAIL;
while (iarg < argc - 1) {
opt = argv[iarg]; opt = argv[iarg];
if (opt[0] != '-') if (opt[0] != '-')
goto FAIL; goto FAIL;
...@@ -98,28 +106,29 @@ int main(int argc, char *argv[]) ...@@ -98,28 +106,29 @@ int main(int argc, char *argv[])
strm.flags &= ~AEC_DATA_PREPROCESS; strm.flags &= ~AEC_DATA_PREPROCESS;
break; break;
case 'b': case 'b':
chunk = atoi(&opt[2]); if (get_param(&chunk, &iarg, argv))
break; goto FAIL;
case 'c':
cflag = 1;
break; break;
case 'd': case 'd':
dflag = 1; dflag = 1;
break; break;
case 'j': case 'j':
strm.block_size = atoi(&opt[2]); if (get_param(&strm.block_size, &iarg, argv))
goto FAIL;
break; break;
case 'm': case 'm':
strm.flags |= AEC_DATA_MSB; strm.flags |= AEC_DATA_MSB;
break; break;
case 'n': case 'n':
strm.bits_per_sample = atoi(&opt[2]); if (get_param(&strm.bits_per_sample, &iarg, argv))
goto FAIL;
break; break;
case 'p': case 'p':
strm.flags |= AEC_PAD_RSI; strm.flags |= AEC_PAD_RSI;
break; break;
case 'r': case 'r':
strm.rsi = atoi(&opt[2]); if (get_param(&strm.rsi, &iarg, argv))
goto FAIL;
break; break;
case 's': case 's':
strm.flags |= AEC_DATA_SIGNED; strm.flags |= AEC_DATA_SIGNED;
...@@ -133,7 +142,11 @@ int main(int argc, char *argv[]) ...@@ -133,7 +142,11 @@ int main(int argc, char *argv[])
iarg++; iarg++;
} }
if (argc - iarg < 2)
goto FAIL;
infn = argv[iarg]; infn = argv[iarg];
outfn = argv[iarg + 1];
if (strm.bits_per_sample > 16) { if (strm.bits_per_sample > 16) {
if (strm.bits_per_sample <= 24 && strm.flags & AEC_DATA_3BYTE) if (strm.bits_per_sample <= 24 && strm.flags & AEC_DATA_3BYTE)
...@@ -147,7 +160,6 @@ int main(int argc, char *argv[]) ...@@ -147,7 +160,6 @@ int main(int argc, char *argv[])
out = (unsigned char *)malloc(chunk); out = (unsigned char *)malloc(chunk);
in = (unsigned char *)malloc(chunk); in = (unsigned char *)malloc(chunk);
if (in == NULL || out == NULL) if (in == NULL || out == NULL)
exit(-1); exit(-1);
...@@ -159,42 +171,23 @@ int main(int argc, char *argv[]) ...@@ -159,42 +171,23 @@ int main(int argc, char *argv[])
input_avail = 1; input_avail = 1;
output_avail = 1; output_avail = 1;
if ((infp = fopen(infn, "r")) == NULL) { if ((infp = fopen(infn, "rb")) == NULL) {
fprintf(stderr, "ERROR: cannot open file %s\n", infn); fprintf(stderr, "ERROR: cannot open input file %s\n", infn);
exit(-1); return 1;
} }
if ((outfp = fopen(outfn, "wb")) == NULL) {
if (cflag) { fprintf(stderr, "ERROR: cannot open output file %s\n", infn);
outfp = stdout; return 1;
} else {
outfn = malloc(strlen(infn) + 4);
if (outfn == NULL)
exit(-1);
if (dflag) {
if ((ext = strstr(infn, ".rz")) == NULL) {
fprintf(stderr, "ERROR: input file needs to end with .rz\n");
exit(-1);
}
strncpy(outfn, infn, ext - infn);
} else {
sprintf(outfn, "%s.rz", infn);
}
if ((outfp = fopen(outfn, "w")) == NULL)
exit(-1);
} }
if (dflag) { if (dflag)
if (aec_decode_init(&strm) != AEC_OK) { status = aec_decode_init(&strm);
fprintf(stderr, "ERROR: Initialization failed\n"); else
return 1; status = aec_encode_init(&strm);
}
} else { if (status != AEC_OK) {
if (aec_encode_init(&strm) != AEC_OK) { fprintf(stderr, "ERROR: initialization failed (%d)\n", status);
fprintf(stderr, "ERROR: Initialization failed\n"); return 1;
return 1;
}
} }
while(input_avail || output_avail) { while(input_avail || output_avail) {
...@@ -231,7 +224,7 @@ int main(int argc, char *argv[]) ...@@ -231,7 +224,7 @@ int main(int argc, char *argv[])
aec_decode_end(&strm); aec_decode_end(&strm);
} else { } else {
if ((status = aec_encode(&strm, AEC_FLUSH)) != AEC_OK) { if ((status = aec_encode(&strm, AEC_FLUSH)) != AEC_OK) {
fprintf(stderr, "ERROR: %i\n", status); fprintf(stderr, "ERROR: while flushing output (%i)\n", status);
return 1; return 1;
} }
...@@ -245,26 +238,23 @@ int main(int argc, char *argv[]) ...@@ -245,26 +238,23 @@ int main(int argc, char *argv[])
fclose(outfp); fclose(outfp);
free(in); free(in);
free(out); free(out);
if (!cflag) {
unlink(infn);
free(outfn);
}
return 0; return 0;
FAIL: FAIL:
fprintf(stderr, "Usage: %s [OPTION] SOURCE\n", argv[0]); fprintf(stderr, "NAME\n\taec - encode or decode files ");
fprintf(stderr, "\nOPTIONS (No spaces between option and parameter!)\n"); fprintf(stderr, "with Adaptive Entropy Coding\n\n");
fprintf(stderr, "-3 24 bit samples are stored in 3 bytes\n"); fprintf(stderr, "SYNOPSIS\n\taec [OPTION]... SOURCE DEST\n");
fprintf(stderr, "-N disable pre/post processing\n"); fprintf(stderr, "\nOPTIONS\n");
fprintf(stderr, "-b<size> internal buffer size in bytes\n"); fprintf(stderr, "\t-3\n\t\t24 bit samples are stored in 3 bytes\n");
fprintf(stderr, "-c write output on standard output\n"); fprintf(stderr, "\t-N\n\t\tdisable pre/post processing\n");
fprintf(stderr, "-d decode SOURCE. If -d is not used: encode.\n"); fprintf(stderr, "\t-b size\n\t\tinternal buffer size in bytes\n");
fprintf(stderr, "-j<samples> block size in samples\n"); fprintf(stderr, "\t-d\n\t\tdecode SOURCE. If -d is not used: encode.\n");
fprintf(stderr, "-m samples are MSB first. Default is LSB\n"); fprintf(stderr, "\t-j samples\n\t\tblock size in samples\n");
fprintf(stderr, "-n<bits> bits per sample\n"); fprintf(stderr, "\t-m\n\t\tsamples are MSB first. Default is LSB\n");
fprintf(stderr, "-p pad RSI to byte boundary\n"); fprintf(stderr, "\t-n bits\n\t\tbits per sample\n");
fprintf(stderr, "-r<blocks> reference sample interval in blocks\n"); fprintf(stderr, "\t-p\n\t\tpad RSI to byte boundary\n");
fprintf(stderr, "-s samples are signed. Default is unsigned\n"); fprintf(stderr, "\t-r blocks\n\t\treference sample interval in blocks\n");
fprintf(stderr, "-t use restricted set of code options\n\n"); fprintf(stderr, "\t-s\n\t\tsamples are signed. Default is unsigned\n");
fprintf(stderr, "\t-t\n\t\tuse restricted set of code options\n\n");
return 1; return 1;
} }
...@@ -9,7 +9,7 @@ if [ ! -f bench.rz ]; then ...@@ -9,7 +9,7 @@ if [ ! -f bench.rz ]; then
fi fi
rm -f dec.dat rm -f dec.dat
bsize=$(stat -c "%s" bench.dat) bsize=$(stat -c "%s" bench.dat)
utime=$(../src/utime $AEC -d -n16 -j64 -r256 -m -c bench.rz 2>&1 >dec.dat) utime=$(../src/utime $AEC -d -n16 -j64 -r256 -m bench.rz dec.dat 2>&1)
perf=$(echo "$bsize/1048576/$utime" | bc) perf=$(echo "$bsize/1048576/$utime" | bc)
echo "*** Decoding with $perf MiB/s user time ***" echo "*** Decoding with $perf MiB/s user time ***"
cmp bench.dat dec.dat cmp bench.dat dec.dat
...@@ -5,7 +5,7 @@ AEC=../src/aec ...@@ -5,7 +5,7 @@ AEC=../src/aec
if [ ! -f typical.dat ]; then if [ ! -f typical.dat ]; then
rm -f typical.rz rm -f typical.rz
wget https://www.dkrz.de/redmine/attachments/download/442/typical.rz wget https://www.dkrz.de/redmine/attachments/download/442/typical.rz
$AEC -d -n16 -j64 -r256 -m -c typical.rz > typical.dat $AEC -d -n16 -j64 -r256 -m typical.rz typical.dat
rm -f bench.dat rm -f bench.dat
fi fi
if [ ! -f bench.dat ]; then if [ ! -f bench.dat ]; then
...@@ -15,7 +15,7 @@ if [ ! -f bench.dat ]; then ...@@ -15,7 +15,7 @@ if [ ! -f bench.dat ]; then
done done
fi fi
rm -f bench.rz rm -f bench.rz
utime=$(../src/utime $AEC -n16 -j64 -r256 -m -c bench.dat 2>&1 >bench.rz) utime=$(../src/utime $AEC -n16 -j64 -r256 -m bench.dat bench.rz 2>&1)
bsize=$(stat -c "%s" bench.dat) bsize=$(stat -c "%s" bench.dat)
perf=$(echo "$bsize/1048576/$utime" | bc) perf=$(echo "$bsize/1048576/$utime" | bc)
echo "*** Encoding with $perf MiB/s user time ***" echo "*** Encoding with $perf MiB/s user time ***"
...@@ -13,17 +13,17 @@ fi ...@@ -13,17 +13,17 @@ fi
unzip -oq $archive unzip -oq $archive
decode () { decode () {
$AEC -c -d $3 $1 > test.dat $AEC -d $3 $1 test.dat
cmp -n $(stat -c "%s" $2) $2 test.dat cmp -n $(stat -c "%s" $2) $2 test.dat
} }
code () { code () {
$AEC -c $3 $2 > test.rz $AEC $3 $2 test.rz
cmp $1 test.rz cmp $1 test.rz
} }
code_size () { code_size () {
$AEC -c $3 $2 > test.rz $AEC $3 $2 test.rz
if [ ! $(stat -c "%s" test.rz) -eq $(stat -c "%s" $1) ]; then if [ ! $(stat -c "%s" test.rz) -eq $(stat -c "%s" $1) ]; then
echo "$1 size mismatch" echo "$1 size mismatch"
exit 1 exit 1
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment