refactor: we no longer need a concept for bitstream reader/writer

This commit is contained in:
Marcus Holland-Moritz 2024-02-03 19:02:45 +01:00
parent 27f0fd8d46
commit afe34ed8cf
5 changed files with 11 additions and 16 deletions

View File

@ -155,8 +155,4 @@ class bitstream_reader final {
iterator_type beg_, end_; iterator_type beg_, end_;
}; };
template <typename T>
concept bitstream_reader_type =
std::same_as<T, bitstream_reader<typename T::iterator_type>>;
} // namespace ricepp } // namespace ricepp

View File

@ -134,8 +134,4 @@ class bitstream_writer final {
iterator_type out_; iterator_type out_;
}; };
template <typename T>
concept bitstream_writer_type =
std::same_as<T, bitstream_writer<typename T::iterator_type>>;
} // namespace ricepp } // namespace ricepp

View File

@ -52,8 +52,9 @@ class codec final {
: block_size_{block_size} : block_size_{block_size}
, traits_{traits} {} , traits_{traits} {}
template <bitstream_writer_type W> template <typename BitstreamWriter>
void encode(std::span<pixel_value_type const> input, W& writer) const { void encode(std::span<pixel_value_type const> input,
BitstreamWriter& writer) const {
assert(input.size() % kComponentStreamCount == 0); assert(input.size() % kComponentStreamCount == 0);
std::array<pixel_value_type, kComponentStreamCount> last_value; std::array<pixel_value_type, kComponentStreamCount> last_value;
@ -77,8 +78,9 @@ class codec final {
writer.flush(); writer.flush();
} }
template <bitstream_reader_type R> template <typename BitstreamReader>
void decode(std::span<pixel_value_type> output, R& reader) const { void
decode(std::span<pixel_value_type> output, BitstreamReader& reader) const {
assert(output.size() % kComponentStreamCount == 0); assert(output.size() % kComponentStreamCount == 0);
std::array<pixel_value_type, kComponentStreamCount> last_value; std::array<pixel_value_type, kComponentStreamCount> last_value;

View File

@ -32,11 +32,11 @@
namespace ricepp::detail { namespace ricepp::detail {
template <size_t MaxBlockSize, typename PixelTraits, ranges::viewable_range V, template <size_t MaxBlockSize, typename PixelTraits, ranges::viewable_range V,
bitstream_reader_type R> typename BitstreamReader>
requires std::unsigned_integral<typename PixelTraits::value_type> && requires std::unsigned_integral<typename PixelTraits::value_type> &&
std::same_as<ranges::range_value_t<std::decay_t<V>>, std::same_as<ranges::range_value_t<std::decay_t<V>>,
typename PixelTraits::value_type> typename PixelTraits::value_type>
void decode_block(V block, R& reader, PixelTraits const& traits, void decode_block(V block, BitstreamReader& reader, PixelTraits const& traits,
typename PixelTraits::value_type& last_value) { typename PixelTraits::value_type& last_value) {
using pixel_value_type = typename PixelTraits::value_type; using pixel_value_type = typename PixelTraits::value_type;
static constexpr unsigned kPixelBits{PixelTraits::kBitCount}; static constexpr unsigned kPixelBits{PixelTraits::kBitCount};

View File

@ -80,11 +80,11 @@ compute_best_split(T const& delta, size_t size, uint64_t sum) noexcept {
} }
template <size_t MaxBlockSize, typename PixelTraits, ranges::viewable_range V, template <size_t MaxBlockSize, typename PixelTraits, ranges::viewable_range V,
bitstream_writer_type W> typename BitstreamWriter>
requires std::unsigned_integral<typename PixelTraits::value_type> && requires std::unsigned_integral<typename PixelTraits::value_type> &&
std::same_as<ranges::range_value_t<std::decay_t<V>>, std::same_as<ranges::range_value_t<std::decay_t<V>>,
typename PixelTraits::value_type> typename PixelTraits::value_type>
void encode_block(V block, W& writer, PixelTraits const& traits, void encode_block(V block, BitstreamWriter& writer, PixelTraits const& traits,
typename PixelTraits::value_type& last_value) { typename PixelTraits::value_type& last_value) {
using pixel_value_type = typename PixelTraits::value_type; using pixel_value_type = typename PixelTraits::value_type;
static constexpr unsigned kPixelBits{PixelTraits::kBitCount}; static constexpr unsigned kPixelBits{PixelTraits::kBitCount};
@ -99,6 +99,7 @@ void encode_block(V block, W& writer, PixelTraits const& traits,
assert(block.size() <= MaxBlockSize); assert(block.size() <= MaxBlockSize);
uint64_t sum{0}; uint64_t sum{0};
for (size_t i = 0; i < block.size(); ++i) { for (size_t i = 0; i < block.size(); ++i) {
auto const pixel = traits.read(block[i]); auto const pixel = traits.read(block[i]);
auto const diff = static_cast<pixel_value_type>(pixel - last); auto const diff = static_cast<pixel_value_type>(pixel - last);