Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost-users Digest, Vol 2650, Issue 4
From: Curtis Gehman (curtis2006_at_[hidden])
Date: 2011-04-22 15:06:50


On Mar 07, 2011, at 07:44 AM, Robert Lupton the Good <rhl_at_[hidden]> wrote:

> > Sorry for the slow response. I simply defined the following:
> >
> > typedef boost::gil::pixel<float, boost::gil::gray_layout_t> gray_float_pixel_t;
> > typedef boost::gil::image<gray_float_pixel_t, false> gray_float_image_t;
> > typedef gray_float_image_t::view_t gray_float_view_t;
> > typedef gray_float_image_t::const_view_t gray_float_const_view_t;
> >
> > As Dr. Bourdev advised, I do not use with these typedefs any of the color conversion operations offered by GIL. Apparently those rely on the scaling properties of the float wrapper type.
> >
> > So far, all I have done with these typedefs is ...
> >
> > 1. construct views using interleaved_view and pixel data pointed to by [const] float*, as illustrated near the beginning of the GIL tutorial
> > 2. create x- and y- iterators for the views to apply row- and column-oriented algorithms
>
> Sorry for _my_ slow response (I was in Japan). I don't care about colour conversions, but I think that these types will convert to integral types with scaling unless you add more boilerplate. I added the following -- but it may not all have been needed; this was quite a while ago and I was new to gil. I also have some remaining conversion problems where I have to rewrite expressions to make them compile, but this may be something else. Anyway, I'd really like to see native gil support for a complete set of NON-scaling types.
>
>
> namespace boost { namespace gil {
> /*
> * Define a type that's a pure float, without scaling into [0, 1]
> */
> typedef float bits32f_noscale;
>
> GIL_DEFINE_BASE_TYPEDEFS(32f_noscale, gray)
> GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
>
> template<> struct channel_multiplier<bits32f_noscale> : public std::binary_function<bits32f_noscale,bits32f_noscale,bits32f_noscale> {
> bits32f_noscale operator()(bits32f_noscale a, bits32f_noscale b) const { return a*b; }
> };
>
> template <typename DstChannelV>
> struct channel_converter<bits32f_noscale, DstChannelV> :
> public std::unary_function<bits32f_noscale,DstChannelV> {
> DstChannelV operator()(bits32f_noscale x) const { return DstChannelV(x + 0.5f); }
> };
>
> template <typename SrcChannelV>
> struct channel_converter<SrcChannelV,bits32f_noscale> :
> public std::unary_function<SrcChannelV,bits32f_noscale> {
> bits32f_noscale operator()(SrcChannelV x) const { return bits32f_noscale(x); }
> };
>
> //
> // Totally specialised templates to resolve ambiguities
> //
> #define CONVERT_NOOP(T1, T2) \
> template <> \
> struct channel_converter<T1, T2> : public std::unary_function<T1, T2> { \
> T2 operator()(T1 x) const { return static_cast<T2>(x); } \
> }; \
> \
> template <> \
> struct channel_converter<T2, T1> : public std::unary_function<T2, T1> { \
> T1 operator()(T2 x) const { return static_cast<T1>(x); } \
> }
>
> CONVERT_NOOP(unsigned char, short);
> CONVERT_NOOP(unsigned char, unsigned short);
> CONVERT_NOOP(unsigned char, int);
> CONVERT_NOOP(unsigned short, short);
> CONVERT_NOOP(unsigned short, int);
> CONVERT_NOOP(short, int);
>
> #undef CONVERT_NOOP
 
Using only the four typedefs that I provided earlier, I don't see any sign that the GIL classes that I'm using are scaling the floats behind the curtain. I haven't been able to follow the details of the metaprogramming inside GIL, but I have observed two key facts that suggest that no scaling is occuring:

   1. The end result has the scale I expect (without scaling).
   2. std::less<typename std::iterator_traits<InIter>::value_type> works with InIter = gray_float_const_view_t::x_iterator (or y_iterator).

Hopefully, Christian or Lubomir will provide a more authoritative response <nudge/>




Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net