More cleanups before CALIC Change-Id: Ib8356188fef8f8a074fcb785dd827cc248b4f547 Reviewed-on: https://chromium-review.googlesource.com/c/codecs/libwebp2/+/6658429 Reviewed-by: Yannis Guyon <yguyon@google.com> Tested-by: WebM Builds <builds@webmproject.org>
diff --git a/src/common/lossless/plane.h b/src/common/lossless/plane.h index 7b6c190..b2851f2 100644 --- a/src/common/lossless/plane.h +++ b/src/common/lossless/plane.h
@@ -70,7 +70,7 @@ virtual ~PlaneCodec() = default; - WP2Status Init(size_t width, size_t height) { + virtual WP2Status Init(uint32_t width, uint32_t height) { width_ = width; last_x_ = width - 1; height_ = height; @@ -80,7 +80,7 @@ return WP2_STATUS_OK; } - WP2Status Reset() { + virtual WP2Status Reset() { row_ = row_p_ = row_pp_ = nullptr; return WP2_STATUS_OK; } @@ -106,9 +106,9 @@ const int16_t *WP2_RESTRICT row_p_, *WP2_RESTRICT row_pp_; uint32_t y_; - size_t last_x_; // width - 1, for prediction borders + uint32_t last_x_; // width - 1, for prediction borders - size_t width_, height_; + uint32_t width_, height_; }; } // namespace WP2L
diff --git a/src/common/lossless/scp.cc b/src/common/lossless/scp.cc index 80335cd..fd5ba04 100644 --- a/src/common/lossless/scp.cc +++ b/src/common/lossless/scp.cc
@@ -52,7 +52,7 @@ //////////////////////////////////////////////////////////////////////////////// // ScpState. -WP2Status State::Init(size_t width, size_t height) { +WP2Status State::Init(uint32_t width, uint32_t height) { WP2_CHECK_STATUS(PlaneCodec::Init(width, height)); WP2_CHECK_STATUS(Reset()); @@ -137,7 +137,7 @@ //////////////////////////////////////////////////////////////////////////////// -WP2Status ClassicalState::Init(size_t width, size_t height) { +WP2Status ClassicalState::Init(uint32_t width, uint32_t height) { WP2_CHECK_STATUS(State::Init(width, height)); // Cache some constants.
diff --git a/src/common/lossless/scp.h b/src/common/lossless/scp.h index 95c76c5..87579c7 100644 --- a/src/common/lossless/scp.h +++ b/src/common/lossless/scp.h
@@ -139,9 +139,9 @@ // do predictions. class State : public PlaneCodec { public: - WP2Status Init(size_t width, size_t height); + WP2Status Init(uint32_t width, uint32_t height) override; - WP2Status Reset(); + WP2Status Reset() override; public: // Only for testing. // p = prediction, v = true pixel value, m = inclusive maximum true pixel @@ -244,7 +244,7 @@ class ClassicalState : public State { public: static int GetNumContexts(int maxerr_shift); - WP2Status Init(size_t width, size_t height); + WP2Status Init(uint32_t, uint32_t height) override; protected: int16_t PredictY0(size_t x, uint8_t* ctxt);
diff --git a/src/dec/lossless/plane_dec.cc b/src/dec/lossless/plane_dec.cc index 028daf7..34c9a4a 100644 --- a/src/dec/lossless/plane_dec.cc +++ b/src/dec/lossless/plane_dec.cc
@@ -252,9 +252,9 @@ break; } case PlaneCodec::Method::kNum: + default: assert(false); return WP2_STATUS_INVALID_PARAMETER; - break; } for (size_t y = 0; y < last_row; ++y) { WP2_CHECK_STATUS(ProcessRows(y));
diff --git a/src/enc/lossless/plane_enc.cc b/src/enc/lossless/plane_enc.cc index a158d76..2cf5622 100644 --- a/src/enc/lossless/plane_enc.cc +++ b/src/enc/lossless/plane_enc.cc
@@ -55,11 +55,7 @@ // What defines a plane encoding according to the SCP. struct Encoding { - void swap(Encoding& encoding) { - tokens.swap(encoding.tokens); - std::swap(mode, encoding.mode); - } - PredictionMode mode; // classical only + void swap(Encoding& encoding) { tokens.swap(encoding.tokens); } WP2::Vector<Token> tokens; };
diff --git a/tests/lossless/test_plane_codecs.cc b/tests/lossless/test_plane_codecs.cc index 4ef00d7..dc4fc69 100644 --- a/tests/lossless/test_plane_codecs.cc +++ b/tests/lossless/test_plane_codecs.cc
@@ -57,14 +57,15 @@ } // Limit makes it choose fewer values so per-channel palette will be used -void TestRoundTrip(const WP2::ArgbBuffer& image) { +void TestRoundTrip(const WP2::ArgbBuffer& image, + WP2L::EncodingAlgorithm algorithm) { WP2::Vector_u8 bytes; MemoryWriter memory_writer; EncoderConfig encoder_config; encoder_config.quality = 100; encoder_config.keep_unmultiplied = true; - encoder_config.lossless_algorithm = WP2L::EncodingAlgorithm::kSCP; + encoder_config.lossless_algorithm = algorithm; WP2_ASSERT_STATUS(Encode(image, &memory_writer, encoder_config)); DecoderConfig decoder_config; @@ -76,7 +77,8 @@ } class LosslessTestGen - : public testing::TestWithParam<std::tuple<int, bool, std::array<int, 2>>> { + : public testing::TestWithParam< + std::tuple<int, bool, std::array<int, 2>, WP2L::EncodingAlgorithm>> { }; TEST_P(LosslessTestGen, RoundTripData) { @@ -84,10 +86,11 @@ const bool has_alpha = std::get<1>(GetParam()); const size_t xsize = std::get<2>(GetParam())[0]; const size_t ysize = std::get<2>(GetParam())[1]; + const WP2L::EncodingAlgorithm algorithm = std::get<3>(GetParam()); bool limit[4] = {false}; for (int i = 0; i < 4; ++i) limit[i] = static_cast<bool>(val & (1 << i)); const auto image = GenerateImage(xsize, ysize, has_alpha, limit); - TestRoundTrip(image); + TestRoundTrip(image, algorithm); } INSTANTIATE_TEST_SUITE_P( @@ -100,23 +103,30 @@ std::array<int, 2>{256, 256}, std::array<int, 2>{555, 577}, std::array<int, 2>{577, 555}, - std::array<int, 2>{5, 800}))); + std::array<int, 2>{5, 800}), + testing::Values(WP2L::EncodingAlgorithm::kSCP))); -class LosslessTestFile : public testing::TestWithParam<std::string> {}; +class LosslessTestFile : public testing::TestWithParam< + std::tuple<std::string, WP2L::EncodingAlgorithm>> { +}; TEST_P(LosslessTestFile, RoundTripFile) { - const std::string file = GetParam(); + const std::string file = std::get<0>(GetParam()); + const WP2L::EncodingAlgorithm algorithm = std::get<1>(GetParam()); + WP2::ArgbBuffer image(WP2_ARGB_32); ASSERT_EQ(WP2::ReadImage(testutil::GetTestDataPath(file).c_str(), &image), WP2_STATUS_OK) << testutil::GetTestDataPath(file); - TestRoundTrip(image); + TestRoundTrip(image, algorithm); } -INSTANTIATE_TEST_SUITE_P(LosslessTestInstantiation, LosslessTestFile, - testing::Values("background.png", "logo.png", - "source1_64x48.png")); +INSTANTIATE_TEST_SUITE_P( + LosslessTestInstantiation, LosslessTestFile, + testing::Combine(testing::Values("background.png", "logo.png", + "source1_64x48.png"), + testing::Values(WP2L::EncodingAlgorithm::kSCP))); ////////////////////////////////////////////////////////////////////////////////