Re: [Boost-bugs] [Boost C++ Libraries] #2211: Can not create image of Regular type

Subject: Re: [Boost-bugs] [Boost C++ Libraries] #2211: Can not create image of Regular type
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-08-18 10:42:35


#2211: Can not create image of Regular type
-----------------------------------+----------------------------------------
  Reporter: john.femiani_at_[hidden] | Owner: hljin
      Type: Bugs | Status: new
 Milestone: Boost 1.36.0 | Component: GIL
   Version: Boost 1.36.0 | Severity: Problem
Resolution: | Keywords:
-----------------------------------+----------------------------------------

Comment(by john.femiani_at_[hidden]):

 The issue is twofold:

  1. A regular type (like a single-chennel pixel) can be considered planer
 or interleaved. When the image type is planar, GIL tends to use the
 `num_channels` metafunction (valid only for !PixelBased), so it is easier
 just to say Regular types are '''not''' planar.

  2. The `is_planar` metafunction had no default value. I think it is safe
 to say that the `is_planar` metafunction is short for `is_planar_pixel`,
 and so if the type is not a pixel it should return `false_`. In fact, I
 think it is reasonable to let it have a default value of `false_`.

  3. Some of the code first checks if the image is planar and then uses
 !PixelBased operations if it is planar, but the code was laid out so that
 both branches of the `if (!IsPLanar)` condition had to compiles. I
 reorganized that code slightly.

 Since I have had bad luck attaching patches on this Trac site (Trac thinks
 they ar spam!), the patch that made my test compile is attached (no clue
 if I broke anything else, I just have the headers here).

 {{{
 #!patch
 Index: image.hpp
 ===================================================================
 --- image.hpp (revision 48190)
 +++ image.hpp (working copy)
 @@ -193,14 +193,25 @@
          if (_memory) _alloc.deallocate(_memory,
 total_allocated_size_in_bytes(dimensions));
      }

 + struct _channels_in_image :
 + mpl::eval_if<is_pixel<value_type>,
 + num_channels<view_t>,
 + mpl::int_<1>
 + >::type
 + {};
 +
      std::size_t total_allocated_size_in_bytes(const point_t& dimensions)
 const {
          std::size_t size_in_units =
 get_row_size_in_memunits(dimensions.x)*dimensions.y;
 - if (IsPlanar)
 - size_in_units =
 size_in_units*num_channels<view_t>::value;

 + typedef typename view_t::x_iterator x_iterator;
 +
 + if (IsPlanar)
 + size_in_units =
 size_in_units*_channels_in_image::value;
 +
          // return the size rounded up to the nearest byte
 - return (size_in_units + byte_to_memunit<typename
 view_t::x_iterator>::value - 1) / byte_to_memunit<typename
 view_t::x_iterator>::value
 - + (_align_in_bytes>0 ? _align_in_bytes-1:0); //
 add extra padding in case we need to align the first image pixel
 + return (size_in_units + byte_to_memunit<x_iterator>::value - 1) /
 byte_to_memunit<x_iterator>::value
 + + (_align_in_bytes>0 ? _align_in_bytes-1:0);
 + // add extra padding in case we need to align the first image
 pixel
      }

      std::size_t get_row_size_in_memunits(x_coord_t width) const { //
 number of units per row
 Index: pixel.hpp
 ===================================================================
 --- pixel.hpp (revision 48190)
 +++ pixel.hpp (working copy)
 @@ -42,7 +42,7 @@
  template <typename PixelBased> struct color_space_type;
  template <typename PixelBased> struct channel_mapping_type;
  template <typename PixelBased> struct channel_type;
 -template <typename PixelBased> struct is_planar;
 +template <typename PixelBased> struct is_planar : mpl::false_{}; //False
 by default

  template <typename PixelBased> struct color_space_type<const PixelBased>
 : public color_space_type<PixelBased> {};
  template <typename PixelBased> struct channel_mapping_type<const
 PixelBased> : public channel_mapping_type<PixelBased> {};
 }}}

-- 
Ticket URL: <http://svn.boost.org/trac/boost/ticket/2211#comment:1>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:58 UTC