Skip to content
Open
Show file tree
Hide file tree
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
5 changes: 3 additions & 2 deletions guetzli/guetzli.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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] != '-')
Expand All @@ -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;
Expand All @@ -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<float>(
guetzli::ButteraugliScoreForQuality(quality));

Expand Down
5 changes: 3 additions & 2 deletions guetzli/jpeg_data_reader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include <string.h>

#include "guetzli/jpeg_huffman_decode.h"
#include "guetzli/processor.h"

namespace guetzli {

Expand Down Expand Up @@ -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<uint64_t>(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;
Expand Down
1 change: 1 addition & 0 deletions guetzli/processor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down