diff --git a/guetzli/guetzli.cc b/guetzli/guetzli.cc index fb6cd0a9..f169fe1e 100644 --- a/guetzli/guetzli.cc +++ b/guetzli/guetzli.cc @@ -235,7 +235,7 @@ int main(int argc, char** argv) { int verbose = 0; int quality = kDefaultJPEGQuality; int memlimit_mb = kDefaultMemlimitMB; - + guetzli::Params params; int opt_idx = 1; for(;opt_idx < argc;opt_idx++) { if (strnlen(argv[opt_idx], 2) < 2 || argv[opt_idx][0] != '-' || argv[opt_idx][1] != '-') @@ -254,6 +254,7 @@ int main(int argc, char** argv) { memlimit_mb = atoi(argv[opt_idx]); } else if (!strcmp(argv[opt_idx], "--nomemlimit")) { memlimit_mb = -1; + params.nomemlimit = true; } else if (!strcmp(argv[opt_idx], "--")) { opt_idx++; break; @@ -270,7 +271,7 @@ int main(int argc, char** argv) { std::string in_data = ReadFileOrDie(argv[opt_idx]); std::string out_data; - guetzli::Params params; + params.butteraugli_target = static_cast( guetzli::ButteraugliScoreForQuality(quality)); diff --git a/guetzli/jpeg_data_reader.cc b/guetzli/jpeg_data_reader.cc index 513e1a25..8186317d 100644 --- a/guetzli/jpeg_data_reader.cc +++ b/guetzli/jpeg_data_reader.cc @@ -21,6 +21,7 @@ #include #include "guetzli/jpeg_huffman_decode.h" +#include "guetzli/processor.h" namespace guetzli { @@ -144,14 +145,14 @@ bool ProcessSOF(const uint8_t* data, const size_t len, jpg->error = JPEG_INVALID_SAMPLING_FACTORS; return false; } + guetzli::Params params; c->width_in_blocks = jpg->MCU_cols * c->h_samp_factor; c->height_in_blocks = jpg->MCU_rows * c->v_samp_factor; const uint64_t num_blocks = static_cast(c->width_in_blocks) * c->height_in_blocks; - if (num_blocks > (1ull << 21)) { + if (num_blocks > (1ull << 21) && !params.nomemlimit) { // Refuse to allocate more than 1 GB of memory for the coefficients, // that is 2M blocks x 64 coeffs x 2 bytes per coeff x max 4 components. - // TODO(user) Add this limit to a GuetzliParams struct. fprintf(stderr, "Image too large.\n"); jpg->error = JPEG_IMAGE_TOO_LARGE; return false; diff --git a/guetzli/processor.h b/guetzli/processor.h index 2c543a25..2a4614f7 100644 --- a/guetzli/processor.h +++ b/guetzli/processor.h @@ -34,6 +34,7 @@ struct Params { bool use_silver_screen = false; int zeroing_greedy_lookahead = 3; bool new_zeroing_model = true; + bool nomemlimit = false; }; bool Process(const Params& params, ProcessStats* stats,