diff --git a/CHANGELOG.md b/CHANGELOG.md index f8ca6938..842a89b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,12 @@ All notable changes to this project are documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [2.3.1] - 2021-1-25 + +### Fixed + +- Fixed [#155](https://github.com/team-charls/charls/issues/155), charls::jpegls_decoder::decode: 2 overloads have similar conversions in v2.3.0 + ## [2.3.0] - 2022-1-24 ### Added diff --git a/SECURITY.md b/SECURITY.md index 1abcf339..eba3e547 100644 --- a/SECURITY.md +++ b/SECURITY.md @@ -4,7 +4,8 @@ | Version | Supported | | ------- | ------------------ | -| 2.3.0 | :white_check_mark: | +| 2.3.1 | :white_check_mark: | +| 2.3.0 | :x: | | 2.2.0 | :x: | | 2.1.0 | :x: | | 2.0.0 | :x: | diff --git a/include/charls/charls_jpegls_decoder.h b/include/charls/charls_jpegls_decoder.h index fd4205e0..bdac9902 100644 --- a/include/charls/charls_jpegls_decoder.h +++ b/include/charls/charls_jpegls_decoder.h @@ -271,7 +271,8 @@ class jpegls_decoder final /// An error occurred during the operation. /// Thrown when memory for the decoder could not be allocated. /// Frame info of the decoded image and the interleave mode. - template + template static std::pair decode(const SourceContainer& source, DestinationContainer& destination, const size_t maximum_size_in_bytes = 7680 * 4320 * 3) @@ -324,7 +325,7 @@ class jpegls_decoder final /// /// An error occurred during the operation. /// Thrown when memory for the decoder could not be allocated. - template + template jpegls_decoder(const Container& source_container, const bool parse_header) : jpegls_decoder(source_container.data(), source_container.size() * sizeof(typename Container::value_type), parse_header) @@ -354,7 +355,7 @@ class jpegls_decoder final /// A STL like container that provides the functions data() and size() and the type value_type. /// /// An error occurred during the operation. - template + template jpegls_decoder& source(const Container& source_container) { return source(source_container.data(), source_container.size() * sizeof(typename Container::value_type)); @@ -557,7 +558,7 @@ class jpegls_decoder final /// /// Number of bytes to the next line in the buffer, when zero, decoder will compute it. /// An error occurred during the operation. - template + template void decode(CHARLS_OUT Container& destination_container, const uint32_t stride = 0) const { decode(destination_container.data(), destination_container.size() * sizeof(typename Container::value_type), stride); @@ -569,7 +570,7 @@ class jpegls_decoder final /// Number of bytes to the next line in the buffer, when zero, decoder will compute it. /// An error occurred during the operation. /// Container with the decoded data. - template + template CHARLS_CHECK_RETURN Container decode(const uint32_t stride = 0) const { Container destination(destination_size() / sizeof(typename Container::value_type)); diff --git a/include/charls/charls_jpegls_encoder.h b/include/charls/charls_jpegls_encoder.h index 55ed756e..0b60d59f 100644 --- a/include/charls/charls_jpegls_encoder.h +++ b/include/charls/charls_jpegls_encoder.h @@ -285,7 +285,7 @@ class jpegls_encoder final /// An error occurred during the operation. /// Thrown when memory for the encoder could not be allocated. /// Container with the JPEG-LS encoded bytes. - template + template static Container encode(const Container& source, const charls::frame_info& frame, const charls::interleave_mode interleave_mode = charls::interleave_mode::none, const encoding_options encoding_options = charls::encoding_options::none) @@ -410,14 +410,14 @@ class jpegls_encoder final /// /// The STL like container, that supports the functions data() and size() and the typedef value_type. /// - template + template jpegls_encoder& destination(Container& destination_container) { return destination(destination_container.data(), destination_container.size() * sizeof(typename Container::value_type)); } - template + template jpegls_encoder& destination(const Container& destination_container) = delete; /// @@ -519,7 +519,7 @@ class jpegls_encoder final /// Stride is sometimes called pitch. If padding bytes are present, the stride is wider than the width of the image. /// /// The number of bytes written to the destination. - template + template size_t encode(const Container& source_container, const uint32_t stride = 0) const { return encode(source_container.data(), source_container.size() * sizeof(typename Container::value_type), stride); diff --git a/include/charls/version.h b/include/charls/version.h index f0613184..9889a56d 100644 --- a/include/charls/version.h +++ b/include/charls/version.h @@ -16,7 +16,7 @@ extern "C" { #define CHARLS_VERSION_MAJOR 2 #define CHARLS_VERSION_MINOR 3 -#define CHARLS_VERSION_PATCH 0 +#define CHARLS_VERSION_PATCH 1 /// /// Returns the version of CharLS in the semver format "major.minor.patch" or "major.minor.patch-pre_release" diff --git a/unittest/jpegls_decoder_test.cpp b/unittest/jpegls_decoder_test.cpp index 4a744afd..de9029e9 100644 --- a/unittest/jpegls_decoder_test.cpp +++ b/unittest/jpegls_decoder_test.cpp @@ -735,6 +735,28 @@ TEST_CLASS(jpegls_decoder_test) #endif } + TEST_METHOD(decode_to_buffer_with_uint16_size_works) // NOLINT + { + // These are compile time checks to detect issues with overloads that have similar conversions. + constexpr frame_info frame_info{100, 100, 8, 1}; + const vector source(static_cast(frame_info.width) * frame_info.height); + + const vector encoded_source{ + jpegls_encoder::encode(source, frame_info, interleave_mode::none, encoding_options::even_destination_size)}; + + jpegls_decoder decoder; + decoder.source(encoded_source); + decoder.read_header(); + + vector destination(decoder.destination_size()); + + void* data{destination.data()}; + const uint16_t size{static_cast(destination.size())}; + + // size is not a perfect match and needs a conversion. + decoder.decode(data, size); + } + private: static vector::iterator find_scan_header(const vector::iterator begin, const vector::iterator end) noexcept diff --git a/unittest/jpegls_encoder_test.cpp b/unittest/jpegls_encoder_test.cpp index 2e2da702..12f71e91 100644 --- a/unittest/jpegls_encoder_test.cpp +++ b/unittest/jpegls_encoder_test.cpp @@ -1324,6 +1324,32 @@ TEST_CLASS(jpegls_encoder_test) Assert::IsFalse(it == destination.cend()); } + TEST_METHOD(encode_to_buffer_with_uint16_size_works) // NOLINT + { + // These are compile time checks to detect issues with overloads that have similar conversions. + constexpr frame_info frame_info{100, 100, 8, 1}; + + jpegls_encoder encoder; + encoder.frame_info(frame_info); + + vector destination(encoder.estimated_destination_size()); + + void* data1 = destination.data(); + const uint16_t size1 = static_cast(destination.size()); + encoder.destination(data1, size1); + + vector source(static_cast(frame_info.width) * frame_info.height); + void* data2 = source.data(); + const uint16_t size2 = static_cast(source.size()); + + // Set 1 value to prevent complains about const. + uint8_t* p = static_cast(data2); + *p = 7; + + // size2 is not a perfect match and needs a conversion. + ignore = encoder.encode(data2, size2); + } + private: static void test_by_decoding(const vector& encoded_source, const frame_info& source_frame_info, const void* expected_destination, const size_t expected_destination_size,