Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions guetzli/guetzli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ void Usage() {
"\n"
"Flags:\n"
" --verbose - Print a verbose trace of all attempts to standard output.\n"
" --overwrite - Overwrite target file even if it exists.\n"
" --quality Q - Visual quality to aim for, expressed as a JPEG quality value.\n"
" Default value is %d.\n"
" --memlimit M - Memory limit in MB. Guetzli will fail if unable to stay under\n"
Expand All @@ -233,6 +234,7 @@ int main(int argc, char** argv) {
std::set_terminate(TerminateHandler);

int verbose = 0;
int overwrite = 0;
int quality = kDefaultJPEGQuality;
int memlimit_mb = kDefaultMemlimitMB;

Expand All @@ -254,6 +256,8 @@ int main(int argc, char** argv) {
memlimit_mb = atoi(argv[opt_idx]);
} else if (!strcmp(argv[opt_idx], "--nomemlimit")) {
memlimit_mb = -1;
} else if (!strcmp(argv[opt_idx], "--override")) {
overwrite = 1;
} else if (!strcmp(argv[opt_idx], "--")) {
opt_idx++;
break;
Expand All @@ -263,7 +267,7 @@ int main(int argc, char** argv) {
}
}

if (argc - opt_idx != 2) {
if (argc - opt_idx != 2 && !overwrite) {
Usage();
}

Expand All @@ -280,6 +284,12 @@ int main(int argc, char** argv) {
stats.debug_output_file = stderr;
}

char* out_file = argv[opt_idx + 1];

if (overwrite) {
out_file = argv[opt_idx];
}

static const unsigned char kPNGMagicBytes[] = {
0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n',
};
Expand Down Expand Up @@ -321,6 +331,6 @@ int main(int argc, char** argv) {
}
}

WriteFileOrDie(argv[opt_idx + 1], out_data);
WriteFileOrDie(out_file, out_data);
return 0;
}