Skip to content

Commit

Permalink
use zip_view
Browse files Browse the repository at this point in the history
  • Loading branch information
igagis committed Nov 14, 2024
1 parent 7b6626f commit d319d99
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/rasterimage/image.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class image : public dimensioned
using image_span_type = image_span<channel_type, num_channels>;
using const_image_span_type = const_image_span<channel_type, num_channels>;
using pixel_type = r4::vector<channel_type, num_channels>;
using value_type = typename pixel_type::value_type;

static_assert(sizeof(pixel_type) == sizeof(channel_type) * number_of_channels, "pixel_type has padding");

Expand Down Expand Up @@ -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
)
{
Expand All @@ -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<value_type*>(row.data())
reinterpret_cast<typename pixel_type::value_type*>(row.data())
);
// NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-pointer-arithmetic)
src_row += stride_in_values;
Expand All @@ -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<value_type>(f);
return rasterimage::value<pixel_type::value_type>(f);
}
};

Expand Down
23 changes: 15 additions & 8 deletions src/rasterimage/image_span.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class image_span : public dimensioned
is_const_span, //
const r4::vector<channel_type, num_channels>,
r4::vector<channel_type, num_channels>>;
using value_type = typename pixel_type::value_type;

static_assert(sizeof(pixel_type) == sizeof(channel_type) * number_of_channels, "pixel_type has padding");

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -238,6 +238,7 @@ class image_span : public dimensioned
using const_iterator = iterator_internal<true>;
using reverse_iterator = std::reverse_iterator<iterator>;
using const_reverse_iterator = std::reverse_iterator<const_iterator>;
using value_type = typename iterator::value_type;

explicit image_span(
dimensions_type dimensions, //
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
);
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/rasterimage/image_variant.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<decltype(im)>::value_type;
using value_type = typename std::remove_reference_t<decltype(im)>::pixel_type::value_type;
if constexpr (!std::is_same_v<value_type, uint8_t> && !std::is_same_v<value_type, uint16_t>) {
throw std::invalid_argument("write_png(): PNG supports only 8 bit or 16 bit per channel images");
}
Expand Down

0 comments on commit d319d99

Please sign in to comment.