Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable extended baseline mode in clustering by default. #106

Merged
merged 1 commit into from
Feb 11, 2025
Merged
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
12 changes: 11 additions & 1 deletion lib/jpegli/entropy_coding.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <cstddef>
#include <cstdint>
#include <cstring>
#include <limits>
#include <vector>

#include "lib/base/bits.h"
Expand Down Expand Up @@ -585,13 +586,22 @@ void ClusterJpegHistograms(j_compress_ptr cinfo, const Histogram* histograms,
clusters->histogram_indexes.resize(num);
std::vector<uint32_t> slot_histograms;
std::vector<float> slot_costs;
// Since not all jpeg decoders support the extended sequential mode, i.e. the
// 0xff 0xc1 SOF marker, we will limit the number of clusters to 2 in
// sequential mode, unless the quantization tables already require the
// extended sequential mode.
const bool force_baseline =
!cinfo->progressive_mode && cinfo->master->force_baseline;

for (size_t i = 0; i < num; ++i) {
const Histogram& cur = histograms[i];
if (IsEmptyHistogram(cur)) {
continue;
}
float best_cost = HistogramCost(cur);
size_t best_slot = slot_histograms.size();
float best_cost = force_baseline && best_slot > 1
? std::numeric_limits<float>::max()
: HistogramCost(cur);
for (size_t j = 0; j < slot_histograms.size(); ++j) {
size_t prev_idx = slot_histograms[j];
const Histogram& prev = clusters->histograms[prev_idx];
Expand Down
Loading