Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rgb8_planar_image_t construction from rgb8_image_t is not supported #478

Closed
mloskot opened this issue Apr 8, 2020 · 0 comments · Fixed by #552
Closed

rgb8_planar_image_t construction from rgb8_image_t is not supported #478

mloskot opened this issue Apr 8, 2020 · 0 comments · Fixed by #552
Labels
cat/bug But reports and bug fixes
Milestone

Comments

@mloskot
Copy link
Member

mloskot commented Apr 8, 2020

This issue was reported by @sdebionne on Slack.

I don't know if this is a bug or an undocumented limitation (see below), but there may be not too complex ways to fix it (e.g. planar image copy-construction from interleaved image by zero-filling construction followed by copy_pixels with interleaved to planar pixel conversion; slower than uninitialized_copy though). See more details below.

/cc @stefanseefeld @chhenning in case you know more for background of this limitation (or bug).

Actual behavior

gil::rgb8_image_t            img1(gil::rgb8_planar_image_t{}); // OK
gil::rgb8_planar_image_t img2(gil::rgb8_image_t{});             // KO (fails to compile)

Expected behavior

Successful construction of planar images from interleaved images.

C++ Minimal Working Example

#include <boost/gil.hpp>
namespace gil = boost::gil;
int main()
{
    gil::rgb8_image_t img_i;
    gil::rgb8_planar_image_t img_p(img_i); // fails to compile

    // due to no overload of uninitialized_copy_aux supporting
    // input pair of interleaved iterators and output pair of planar iterators
    using both_planar = std::false_type;
    auto iv = gil::view(img_i);
    auto pv = gil::view(img_p);

    // fails to compile
    gil::detail::uninitialized_copy_aux(iv.begin().x(), iv.end().x(), pv.begin().x(), both_planar{});

    // compiles, becuase this direction is supported
    gil::detail::uninitialized_copy_aux(pv.begin().x(), pv.end().x(), iv.begin().x(), both_planar{});
}

Discussion

Apparently, this comment here is not entirely correct or complete:

/// std::uninitialized_copy for interleaved or mixed iterators
template <typename It1, typename It2>
BOOST_FORCEINLINE
void uninitialized_copy_aux(It1 first1, It1 last1, It2 first2, std::false_type)

and should rather read

/// std::uninitialized_copy for pairs of interleaved iterators or input pair of planar iterators and output pair of interleaved iterators

The gil::detail::uninitialized_copy_aux simply performs https://en.cppreference.com/w/cpp/memory/uninitialized_copy which requires

::new (static_cast<void*>(std::addressof(*current))) Value(*first);

that is not feasible for planar pixels.

References

Environment

  • Version (Git ref or <boost/version.hpp>): Boost 1.72, 1.73 (current master and develop)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cat/bug But reports and bug fixes
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant