diff --git a/src/rasterimage/image.hpp b/src/rasterimage/image.hpp index c900dbd..a114ab4 100644 --- a/src/rasterimage/image.hpp +++ b/src/rasterimage/image.hpp @@ -46,7 +46,6 @@ class image : public dimensioned using image_span_type = image_span; using const_image_span_type = const_image_span; using pixel_type = r4::vector; - using value_type = typename pixel_type::value_type; static_assert(sizeof(pixel_type) == sizeof(channel_type) * number_of_channels, "pixel_type has padding"); @@ -130,7 +129,7 @@ class image : public dimensioned static image make( dimensions_type dims, // - const value_type* data, + const typename pixel_type::value_type* data, size_t stride_in_values = 0 ) { @@ -151,7 +150,7 @@ class image : public dimensioned // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) src_row + num_values_per_row, // NOLINTNEXTLINE(cppcoreguidelines-pro-type-reinterpret-cast) - reinterpret_cast(row.data()) + reinterpret_cast(row.data()) ); // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic) src_row += stride_in_values; @@ -162,9 +161,9 @@ class image : public dimensioned return im; } - constexpr static value_type value(float f) + constexpr static typename pixel_type::value_type value(float f) { - return rasterimage::value(f); + return rasterimage::value(f); } }; diff --git a/src/rasterimage/image_span.hpp b/src/rasterimage/image_span.hpp index 24e15fc..f2f115a 100644 --- a/src/rasterimage/image_span.hpp +++ b/src/rasterimage/image_span.hpp @@ -51,7 +51,6 @@ class image_span : public dimensioned is_const_span, // const r4::vector, r4::vector>; - using value_type = typename pixel_type::value_type; static_assert(sizeof(pixel_type) == sizeof(channel_type) * number_of_channels, "pixel_type has padding"); @@ -96,6 +95,7 @@ class image_span : public dimensioned using iterator_category = std::input_iterator_tag; using difference_type = std::ptrdiff_t; + using value_type = decltype(line); using reference = value_type; using pointer = void; @@ -238,6 +238,7 @@ class image_span : public dimensioned using const_iterator = iterator_internal; using reverse_iterator = std::reverse_iterator; using const_reverse_iterator = std::reverse_iterator; + using value_type = typename iterator::value_type; explicit image_span( dimensions_type dimensions, // @@ -299,6 +300,15 @@ class image_span : public dimensioned return this->buffer == nullptr; } + /** + * @brief Get number of lines. + * @return Number of lines in this image span. + */ + size_t size() const noexcept + { + return this->dims().y(); + } + iterator begin() noexcept { return iterator(utki::make_span(this->buffer, this->dims().x()), this->stride_px); @@ -426,14 +436,11 @@ class image_span : public dimensioned ASSERT(!src_span.empty()) ASSERT(src_span.dims() == dst_span.dims()) - // TODO: use zip_view - auto src_line = src_span.begin(); - auto dst_line = dst_span.begin(); - for (; src_line != src_span.end(); ++src_line, ++dst_line) { + for (auto [s, d] : utki::views::zip(src_span, dst_span)) { std::copy( - src_line->begin(), // - src_line->end(), - dst_line->begin() + s.begin(), // + s.end(), + d.begin() ); } } diff --git a/src/rasterimage/image_variant.cpp b/src/rasterimage/image_variant.cpp index 86bd491..7ce1b4d 100644 --- a/src/rasterimage/image_variant.cpp +++ b/src/rasterimage/image_variant.cpp @@ -203,7 +203,7 @@ void image_variant::write_png(const papki::file& fi) const // get bits per channel std::visit( [](const auto& im) { - using value_type = typename std::remove_reference_t::value_type; + using value_type = typename std::remove_reference_t::pixel_type::value_type; if constexpr (!std::is_same_v && !std::is_same_v) { throw std::invalid_argument("write_png(): PNG supports only 8 bit or 16 bit per channel images"); }