这是indexloc提供的服务,不要输入任何密码
Skip to content
Merged
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
11 changes: 7 additions & 4 deletions lib/jxl/enc_modular.cc
Original file line number Diff line number Diff line change
Expand Up @@ -391,8 +391,8 @@ ModularFrameEncoder::ModularFrameEncoder(const FrameHeader& frame_header,
// TODO(veluca): allow all predictors that don't break residual
// multipliers in lossy mode.
cparams.options.predictor = Predictor::Variable;
} else if (cparams.responsive) {
// zero predictor for Squeeze residues
} else if (cparams.responsive || cparams.lossy_palette) {
// zero predictor for Squeeze residues and lossy palette
cparams.options.predictor = Predictor::Zero;
} else if (quality < 100) {
// If not responsive and lossy. TODO(veluca): use near_lossless instead?
Expand All @@ -407,6 +407,9 @@ ModularFrameEncoder::ModularFrameEncoder(const FrameHeader& frame_header,
// just gradient predictor in thunder mode
cparams.options.predictor = Predictor::Gradient;
}
} else {
delta_pred = cparams.options.predictor;
if (cparams.lossy_palette) cparams.options.predictor = Predictor::Zero;
}
tree_splits.push_back(0);
if (cparams.modular_mode == false) {
Expand Down Expand Up @@ -639,7 +642,7 @@ Status ModularFrameEncoder::ComputeEncodingData(
maybe_palette.lossy_palette =
(cparams.lossy_palette && maybe_palette.num_c == 3);
if (maybe_palette.lossy_palette) {
maybe_palette.predictor = Predictor::Average4;
maybe_palette.predictor = delta_pred;
}
// TODO(veluca): use a custom weighted header if using the weighted
// predictor.
Expand All @@ -656,7 +659,7 @@ Status ModularFrameEncoder::ComputeEncodingData(
maybe_palette_3.ordered_palette = cparams.palette_colors >= 0;
maybe_palette_3.lossy_palette = cparams.lossy_palette;
if (maybe_palette_3.lossy_palette) {
maybe_palette_3.predictor = Predictor::Average4;
maybe_palette_3.predictor = delta_pred;
}
do_transform(gi, maybe_palette_3, weighted::Header(), pool);
}
Expand Down
1 change: 1 addition & 0 deletions lib/jxl/enc_modular.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ class ModularFrameEncoder {
std::vector<ModularMultiplierInfo> multiplier_info;
std::vector<std::vector<uint32_t>> gi_channel;
std::vector<size_t> image_widths;
Predictor delta_pred = Predictor::Average4;
};

} // namespace jxl
Expand Down
34 changes: 0 additions & 34 deletions lib/jxl/modular/transform/palette.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,40 +215,6 @@ static Status InvPalette(Image &input, uint32_t begin_c, uint32_t nb_colors,
}
},
"UndoDeltaPaletteWP");
} else if (predictor == Predictor::Gradient) {
// Gradient is the most common predictor for now. This special case gives
// about 20% extra speed.
RunOnPool(
pool, 0, nb, ThreadPool::SkipInit(),
[&](size_t c, size_t _) {
Channel &channel = input.channel[c0 + c];
for (size_t y = 0; y < channel.h; y++) {
pixel_type *JXL_RESTRICT p = channel.Row(y);
const pixel_type *JXL_RESTRICT idx = indices.Row(y);
for (size_t x = 0; x < channel.w; x++) {
int index = idx[x];
pixel_type val = 0;
const pixel_type palette_entry =
palette_internal::GetPaletteValue(
p_palette, index, /*c=*/c,
/*palette_size=*/palette.w,
/*onerow=*/onerow, /*bit_depth=*/bit_depth);
if (index < static_cast<int32_t>(nb_deltas)) {
pixel_type left =
x ? p[x - 1] : (y ? *(p + x - onerow_image) : 0);
pixel_type top = y ? *(p + x - onerow_image) : left;
pixel_type topleft =
x && y ? *(p + x - 1 - onerow_image) : left;
val = PixelAdd(ClampedGradient(left, top, topleft),
palette_entry);
} else {
val = palette_entry;
}
p[x] = val;
}
}
},
"UndoDeltaPaletteGradient");
} else {
RunOnPool(
pool, 0, nb, ThreadPool::SkipInit(),
Expand Down
27 changes: 27 additions & 0 deletions lib/jxl/modular_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,33 @@ TEST(ModularTest, RoundtripLossyDeltaPalette) {
/*distmap=*/nullptr, pool),
1.5);
}
TEST(ModularTest, RoundtripLossyDeltaPaletteWP) {
ThreadPool* pool = nullptr;
const PaddedBytes orig =
ReadTestData("wesaturate/500px/u76c0g_bliznaca_srgb8.png");
CompressParams cparams;
cparams.modular_mode = true;
cparams.color_transform = jxl::ColorTransform::kNone;
cparams.lossy_palette = true;
cparams.palette_colors = 0;
cparams.options.predictor = jxl::Predictor::Weighted;

DecompressParams dparams;

CodecInOut io_out;
size_t compressed_size;

CodecInOut io;
ASSERT_TRUE(SetFromBytes(Span<const uint8_t>(orig), &io, pool));
io.ShrinkTo(300, 100);

compressed_size = Roundtrip(&io, cparams, dparams, pool, &io_out);
EXPECT_LE(compressed_size, 7000u);
cparams.ba_params.intensity_target = 80.0f;
EXPECT_LE(ButteraugliDistance(io, io_out, cparams.ba_params,
/*distmap=*/nullptr, pool),
10.0);
}

TEST(ModularTest, RoundtripLossy) {
ThreadPool* pool = nullptr;
Expand Down