32 #if !defined(GIL_LSST_H)
37 #include <type_traits>
39 #include "boost/mpl/assert.hpp"
40 #include "boost/mpl/bool.hpp"
41 #include "boost/mpl/if.hpp"
46 #pragma warning (push)
47 #pragma warning (disable: 68)
48 #pragma warning (disable: 304)
51 #include "boost/gil/gil_all.hpp"
57 namespace lsst {
namespace afw {
namespace image {
65 struct pair2I :
public std::pair<int, int> {
66 explicit pair2I(
int first,
int second) : std::pair<int, int>(first, second) {}
67 pair2I(std::pair<int, int> pair) : std::pair<int, int>(pair) {}
77 boost::gil::memory_based_2d_locator<T>&
operator+=(boost::gil::memory_based_2d_locator<T> &loc, pair2I off) {
78 return (loc += boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
85 boost::gil::memory_based_2d_locator<T>&
operator-=(boost::gil::memory_based_2d_locator<T> &loc, pair2I off) {
86 return (loc -= boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
96 boost::gil::memory_based_2d_locator<T>&
operator+=(boost::gil::memory_based_2d_locator<T> &loc,
97 std::pair<int, int> off) {
98 return (loc += boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
104 template <
typename T>
105 boost::gil::memory_based_2d_locator<T>&
operator-=(boost::gil::memory_based_2d_locator<T> &loc,
106 std::pair<int, int> off) {
107 return (loc -= boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
110 namespace boost {
namespace gil {
114 typedef uint64_t bits64;
115 typedef int64_t bits64s;
117 GIL_DEFINE_BASE_TYPEDEFS(64, gray)
118 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64, dev2n, devicen_t<2>, devicen_layout_t<2>)
119 GIL_DEFINE_BASE_TYPEDEFS(64s, gray)
120 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64s, dev2n, devicen_t<2>, devicen_layout_t<2>)
125 typedef
float bits32f_noscale;
127 GIL_DEFINE_BASE_TYPEDEFS(32f_noscale, gray)
128 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
130 template<> struct channel_multiplier<bits32f_noscale> : public std::binary_function<bits32f_noscale,bits32f_noscale,bits32f_noscale> {
131 bits32f_noscale operator()(bits32f_noscale a, bits32f_noscale
b)
const {
return a*
b; }
137 typedef double bits64f_noscale;
139 GIL_DEFINE_BASE_TYPEDEFS(64f_noscale, gray)
140 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
146 template <typename DstChannelV>
147 struct channel_converter<bits32f_noscale, DstChannelV> :
148 public std::unary_function<bits32f_noscale,DstChannelV> {
149 DstChannelV operator()(bits32f_noscale
x)
const {
return DstChannelV(x + 0.5f); }
152 template <
typename SrcChannelV>
153 struct channel_converter<SrcChannelV,bits32f_noscale> :
154 public std::unary_function<SrcChannelV,bits32f_noscale> {
155 bits32f_noscale operator()(SrcChannelV
x)
const {
return bits32f_noscale(x); }
158 template <
typename DstChannelV>
159 struct channel_converter<bits64f_noscale, DstChannelV> :
160 public std::unary_function<bits64f_noscale,DstChannelV> {
161 DstChannelV operator()(bits64f_noscale
x)
const {
return DstChannelV(x + 0.5f); }
164 template <
typename SrcChannelV>
165 struct channel_converter<SrcChannelV,bits64f_noscale> :
166 public std::unary_function<SrcChannelV,bits64f_noscale> {
167 bits64f_noscale operator()(SrcChannelV
x)
const {
return bits64f_noscale(x); }
173 #define LSST_CONVERT_NOOP(T1, T2) \
175 struct channel_converter<T1, T2> : public std::unary_function<T1, T2> { \
176 T2 operator()(T1 x) const { return static_cast<T2>(x); } \
180 struct channel_converter<T2, T1> : public std::unary_function<T2, T1> { \
181 T1 operator()(T2 x) const { return static_cast<T1>(x); } \
184 LSST_CONVERT_NOOP(bits32f_noscale, bits64f_noscale);
186 LSST_CONVERT_NOOP(
unsigned char,
short);
187 LSST_CONVERT_NOOP(
unsigned char,
unsigned short);
188 LSST_CONVERT_NOOP(
unsigned char,
int);
189 LSST_CONVERT_NOOP(
unsigned short,
short);
190 LSST_CONVERT_NOOP(
unsigned short,
int);
191 LSST_CONVERT_NOOP(
short,
int);
193 #undef LSST_CONVERT_NOOP
200 #define LSST_BOOST_GIL_OP_EQUALS(TYPE, OP) \
201 template<typename T2> \
202 TYPE##_pixel_t& operator OP##=(TYPE##_pixel_t& lhs, T2 rhs) { return (lhs = lhs OP rhs); }
204 #define LSST_BOOST_GIL_OP_EQUALS_ALL(PIXTYPE) \
205 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, +) \
206 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, -) \
207 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, *) \
208 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, /) \
209 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, &) \
210 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, |)
212 LSST_BOOST_GIL_OP_EQUALS_ALL(gray8)
213 LSST_BOOST_GIL_OP_EQUALS_ALL(gray8s)
214 LSST_BOOST_GIL_OP_EQUALS_ALL(gray16)
215 LSST_BOOST_GIL_OP_EQUALS_ALL(gray16s)
216 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32)
217 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32s)
218 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32f_noscale)
219 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64)
220 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64s)
221 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64f_noscale)
223 #undef LSST_BOOST_GIL_OP_EQUALS
224 #undef LSST_BOOST_GIL_OP_EQUALS_ALL
231 namespace lsst {
namespace afw {
namespace image {
namespace detail {
236 #pragma warning (push)
237 #pragma warning (disable: 304)
240 template<
typename T,
bool rescale=false>
struct types_traits {
241 BOOST_MPL_ASSERT_MSG(boost::mpl::bool_<false>::value,
242 I_DO_NOT_KNOW_HOW_TO_MAP_THIS_TYPE_TO_A_GIL_TYPE,
247 #pragma warning (pop)
250 template<>
struct types_traits<unsigned char, false> {
251 typedef boost::gil::gray8_image_t image_t;
252 typedef boost::gil::gray8_view_t view_t;
253 typedef boost::gil::gray8c_view_t const_view_t;
254 typedef boost::gil::channel_traits<char>::reference reference;
255 typedef boost::gil::channel_traits<char>::const_reference const_reference;
258 template<>
struct types_traits<short, false> {
259 typedef boost::gil::gray16s_image_t image_t;
260 typedef boost::gil::gray16s_view_t view_t;
261 typedef boost::gil::gray16sc_view_t const_view_t;
262 typedef boost::gil::channel_traits<short>::reference reference;
263 typedef boost::gil::channel_traits<short>::const_reference const_reference;
266 template<>
struct types_traits<unsigned short, false> {
267 typedef boost::gil::gray16_image_t image_t;
268 typedef boost::gil::gray16_view_t view_t;
269 typedef boost::gil::gray16c_view_t const_view_t;
270 typedef boost::gil::channel_traits<unsigned short>::reference reference;
271 typedef boost::gil::channel_traits<unsigned short>::const_reference const_reference;
274 template<>
struct types_traits<int, false> {
275 typedef boost::gil::gray32s_image_t image_t;
276 typedef boost::gil::gray32s_view_t view_t;
277 typedef boost::gil::gray32sc_view_t const_view_t;
278 typedef boost::gil::channel_traits<int>::reference reference;
279 typedef boost::gil::channel_traits<int>::const_reference const_reference;
282 template<>
struct types_traits<unsigned int, false> {
283 typedef boost::gil::gray32_image_t image_t;
284 typedef boost::gil::gray32_view_t view_t;
285 typedef boost::gil::gray32c_view_t const_view_t;
286 typedef boost::gil::channel_traits<int>::reference reference;
287 typedef boost::gil::channel_traits<int>::const_reference const_reference;
290 template<>
struct types_traits<float, false> {
291 typedef boost::gil::gray32f_noscale_image_t image_t;
292 typedef boost::gil::gray32f_noscale_view_t view_t;
293 typedef boost::gil::gray32f_noscalec_view_t const_view_t;
294 typedef boost::gil::channel_traits<float>::reference reference;
295 typedef boost::gil::channel_traits<float>::const_reference const_reference;
298 template<>
struct types_traits<long, false> {
299 typedef boost::gil::gray64s_image_t image_t;
300 typedef boost::gil::gray64s_view_t view_t;
301 typedef boost::gil::gray64sc_view_t const_view_t;
302 typedef boost::gil::channel_traits<long>::reference reference;
303 typedef boost::gil::channel_traits<long>::const_reference const_reference;
306 template<>
struct types_traits<unsigned long, false> {
307 typedef boost::gil::gray64_image_t image_t;
308 typedef boost::gil::gray64_view_t view_t;
309 typedef boost::gil::gray64c_view_t const_view_t;
310 typedef boost::gil::channel_traits<long>::reference reference;
311 typedef boost::gil::channel_traits<long>::const_reference const_reference;
321 struct CheckBoost64 {
322 typedef boost::mpl::if_<std::is_same<long long, std::int64_t>,
323 long long,
struct unknown>::type type;
324 typedef boost::mpl::if_<std::is_same<long long, std::int64_t>,
325 unsigned long long, struct unknown_u>::type type_u;
329 template<> struct types_traits<CheckBoost64::type, false> {
330 typedef boost::gil::gray64s_image_t image_t;
331 typedef boost::gil::gray64s_view_t view_t;
332 typedef boost::gil::gray64sc_view_t const_view_t;
333 typedef boost::gil::channel_traits<long>::reference reference;
334 typedef boost::gil::channel_traits<long>::const_reference const_reference;
337 template<>
struct types_traits<CheckBoost64::type_u, false> {
338 typedef boost::gil::gray64_image_t image_t;
339 typedef boost::gil::gray64_view_t view_t;
340 typedef boost::gil::gray64c_view_t const_view_t;
341 typedef boost::gil::channel_traits<long>::reference reference;
342 typedef boost::gil::channel_traits<long>::const_reference const_reference;
345 template<>
struct types_traits<double, false> {
346 typedef boost::gil::gray64f_noscale_image_t image_t;
347 typedef boost::gil::gray64f_noscale_view_t view_t;
348 typedef boost::gil::gray64f_noscalec_view_t const_view_t;
349 typedef boost::gil::channel_traits<double>::reference reference;
350 typedef boost::gil::channel_traits<double>::const_reference const_reference;
354 struct const_iterator_type {
355 typedef typename boost::gil::const_iterator_type<T>::type type;
359 struct const_locator_type {
360 typedef typename T::const_t type;
363 typedef boost::gil::point2<std::ptrdiff_t> difference_type;
366 namespace boost {
namespace gil {
370 template <
typename View1,
typename View2,
typename View3,
typename ViewDest,
typename F> GIL_FORCEINLINE
371 F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
const ViewDest& dst, F fun) {
372 for (std::ptrdiff_t
y=0;
y<dst.height(); ++
y) {
373 typename View1::x_iterator srcIt1=src1.row_begin(
y);
374 typename View2::x_iterator srcIt2=src2.row_begin(
y);
375 typename View3::x_iterator srcIt3=src3.row_begin(
y);
376 typename ViewDest::x_iterator dstIt=dst.row_begin(
y);
377 for (std::ptrdiff_t
x=0;
x<dst.width(); ++
x)
378 dstIt[
x]=fun(srcIt1[
x],srcIt2[x],srcIt3[x]);
385 template <
typename View1,
typename View2,
typename View3,
typename View4,
typename ViewDest,
typename F> GIL_FORCEINLINE
386 F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
const View4& src4,
const ViewDest& dst, F fun) {
387 for (std::ptrdiff_t
y=0;
y<dst.height(); ++
y) {
388 typename View1::x_iterator srcIt1=src1.row_begin(
y);
389 typename View2::x_iterator srcIt2=src2.row_begin(
y);
390 typename View3::x_iterator srcIt3=src3.row_begin(
y);
391 typename View4::x_iterator srcIt4=src4.row_begin(
y);
392 typename ViewDest::x_iterator dstIt=dst.row_begin(
y);
393 for (std::ptrdiff_t
x=0;
x<dst.width(); ++
x)
394 dstIt[
x]=fun(srcIt1[
x],srcIt2[x],srcIt3[x],srcIt4[x]);
Extent< double, N > & operator+=(Extent< double, N > &lhs, Extent< int, N > const &rhs)
Extent< double, N > & operator-=(Extent< double, N > &lhs, Extent< int, N > const &rhs)
table::Key< table::Array< Kernel::Pixel > > image
afw::table::Key< double > b
void operator-=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
void operator+=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)