Boost logo

Boost Users :

Subject: Re: [Boost-users] Boost-users Digest, Vol 2650, Issue 4
From: Robert Lupton the Good (rhl_at_[hidden])
Date: 2011-03-07 09:44:11


> 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


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