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"
47 #pragma warning(disable : 68)
48 #pragma warning(disable : 304)
51 #include "boost/version.hpp"
52 #if BOOST_VERSION < 106900
53 #include "boost/gil/gil_all.hpp"
55 #include "boost/gil.hpp"
58 #ifndef BOOST_GIL_DEFINE_BASE_TYPEDEFS
61 #define BOOST_GIL_DEFINE_BASE_TYPEDEFS GIL_DEFINE_BASE_TYPEDEFS
62 #define BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL GIL_DEFINE_ALL_TYPEDEFS_INTERNAL
79 struct pair2I :
public std::pair<int, int> {
91 boost::gil::memory_based_2d_locator<T>&
operator+=(boost::gil::memory_based_2d_locator<T>& loc, pair2I off) {
92 return (loc += boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
99 boost::gil::memory_based_2d_locator<T>&
operator-=(boost::gil::memory_based_2d_locator<T>& loc, pair2I off) {
100 return (loc -= boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
112 template <
typename T>
114 return (loc += point2<std::ptrdiff_t>(off.first, off.second));
120 template <
typename T>
122 return (loc -= point2<std::ptrdiff_t>(off.first, off.second));
128 typedef uint64_t bits64;
129 typedef int64_t bits64s;
131 BOOST_GIL_DEFINE_BASE_TYPEDEFS(64, bits64, gray)
132 BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64, bits64, dev2n, devicen_t<2>, devicen_layout_t<2>)
133 BOOST_GIL_DEFINE_BASE_TYPEDEFS(64s, bits64s, gray)
134 BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64s, bits64s, dev2n, devicen_t<2>, devicen_layout_t<2>)
139 typedef float bits32f_noscale;
141 BOOST_GIL_DEFINE_BASE_TYPEDEFS(32f_noscale, bits32f_noscale, gray)
142 BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f_noscale, bits32f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
145 struct channel_multiplier<bits32f_noscale>
147 bits32f_noscale operator()(bits32f_noscale
a, bits32f_noscale
b)
const {
return a *
b; }
153 typedef double bits64f_noscale;
155 BOOST_GIL_DEFINE_BASE_TYPEDEFS(64f_noscale, bits64f_noscale, gray)
156 BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64f_noscale, bits64f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
161 template <
typename DstChannelV>
162 struct channel_converter<bits32f_noscale, DstChannelV>
164 DstChannelV operator()(bits32f_noscale
x)
const {
return DstChannelV(
x + 0.5f); }
167 template <
typename SrcChannelV>
168 struct channel_converter<SrcChannelV, bits32f_noscale>
170 bits32f_noscale operator()(SrcChannelV
x)
const {
return bits32f_noscale(
x); }
173 template <
typename DstChannelV>
174 struct channel_converter<bits64f_noscale, DstChannelV>
176 DstChannelV operator()(bits64f_noscale
x)
const {
return DstChannelV(
x + 0.5f); }
179 template <
typename SrcChannelV>
180 struct channel_converter<SrcChannelV, bits64f_noscale>
182 bits64f_noscale operator()(SrcChannelV
x)
const {
return bits64f_noscale(
x); }
188 #define LSST_CONVERT_NOOP(T1, T2) \
190 struct channel_converter<T1, T2> : public std::unary_function<T1, T2> { \
191 T2 operator()(T1 x) const { return static_cast<T2>(x); } \
195 struct channel_converter<T2, T1> : public std::unary_function<T2, T1> { \
196 T1 operator()(T2 x) const { return static_cast<T1>(x); } \
199 LSST_CONVERT_NOOP(bits32f_noscale, bits64f_noscale);
201 LSST_CONVERT_NOOP(
unsigned char,
short);
202 LSST_CONVERT_NOOP(
unsigned char,
unsigned short);
203 LSST_CONVERT_NOOP(
unsigned char,
int);
204 LSST_CONVERT_NOOP(
unsigned short,
short);
205 LSST_CONVERT_NOOP(
unsigned short,
int);
206 LSST_CONVERT_NOOP(
short,
int);
208 #undef LSST_CONVERT_NOOP
214 #define LSST_BOOST_GIL_OP_EQUALS(TYPE, OP) \
215 template <typename T2> \
216 TYPE##_pixel_t& operator OP##=(TYPE##_pixel_t& lhs, T2 rhs) { \
217 return (lhs = lhs OP rhs); \
220 #define LSST_BOOST_GIL_OP_EQUALS_ALL(PIXTYPE) \
221 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, +) \
222 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, -) \
223 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, *) \
224 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, /) \
225 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, &) \
226 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, |)
228 LSST_BOOST_GIL_OP_EQUALS_ALL(gray8)
229 LSST_BOOST_GIL_OP_EQUALS_ALL(gray8s)
230 LSST_BOOST_GIL_OP_EQUALS_ALL(gray16)
231 LSST_BOOST_GIL_OP_EQUALS_ALL(gray16s)
232 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32)
233 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32s)
234 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32f_noscale)
235 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64)
236 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64s)
237 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64f_noscale)
239 #undef LSST_BOOST_GIL_OP_EQUALS
240 #undef LSST_BOOST_GIL_OP_EQUALS_ALL
252 #pragma warning(push)
253 #pragma warning(disable : 304)
256 template <
typename T,
bool rescale = false>
257 struct types_traits {
258 BOOST_MPL_ASSERT_MSG(boost::mpl::bool_<false>::value, I_DO_NOT_KNOW_HOW_TO_MAP_THIS_TYPE_TO_A_GIL_TYPE,
266 struct types_traits<unsigned char, false> {
267 typedef boost::gil::gray8_image_t image_t;
268 typedef boost::gil::gray8_view_t view_t;
269 typedef boost::gil::gray8c_view_t const_view_t;
270 typedef boost::gil::channel_traits<char>::reference reference;
271 typedef boost::gil::channel_traits<char>::const_reference const_reference;
275 struct types_traits<short, false> {
276 typedef boost::gil::gray16s_image_t image_t;
277 typedef boost::gil::gray16s_view_t view_t;
278 typedef boost::gil::gray16sc_view_t const_view_t;
279 typedef boost::gil::channel_traits<short>::reference reference;
280 typedef boost::gil::channel_traits<short>::const_reference const_reference;
284 struct types_traits<unsigned short, false> {
285 typedef boost::gil::gray16_image_t image_t;
286 typedef boost::gil::gray16_view_t view_t;
287 typedef boost::gil::gray16c_view_t const_view_t;
288 typedef boost::gil::channel_traits<unsigned short>::reference reference;
289 typedef boost::gil::channel_traits<unsigned short>::const_reference const_reference;
293 struct types_traits<int, false> {
294 typedef boost::gil::gray32s_image_t image_t;
295 typedef boost::gil::gray32s_view_t view_t;
296 typedef boost::gil::gray32sc_view_t const_view_t;
297 typedef boost::gil::channel_traits<int>::reference reference;
298 typedef boost::gil::channel_traits<int>::const_reference const_reference;
302 struct types_traits<unsigned int, false> {
303 typedef boost::gil::gray32_image_t image_t;
304 typedef boost::gil::gray32_view_t view_t;
305 typedef boost::gil::gray32c_view_t const_view_t;
306 typedef boost::gil::channel_traits<int>::reference reference;
307 typedef boost::gil::channel_traits<int>::const_reference const_reference;
311 struct types_traits<float, false> {
312 typedef boost::gil::gray32f_noscale_image_t image_t;
313 typedef boost::gil::gray32f_noscale_view_t view_t;
314 typedef boost::gil::gray32f_noscalec_view_t const_view_t;
315 typedef boost::gil::channel_traits<float>::reference reference;
316 typedef boost::gil::channel_traits<float>::const_reference const_reference;
320 struct types_traits<long, false> {
321 typedef boost::gil::gray64s_image_t image_t;
322 typedef boost::gil::gray64s_view_t view_t;
323 typedef boost::gil::gray64sc_view_t const_view_t;
324 typedef boost::gil::channel_traits<long>::reference reference;
325 typedef boost::gil::channel_traits<long>::const_reference const_reference;
329 struct types_traits<unsigned long, false> {
330 typedef boost::gil::gray64_image_t image_t;
331 typedef boost::gil::gray64_view_t view_t;
332 typedef boost::gil::gray64c_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;
344 struct CheckBoost64 {
345 typedef boost::mpl::if_<std::is_same<long long, std::int64_t>,
long long,
struct unknown>::
type type;
346 typedef boost::mpl::if_<std::is_same<long long, std::int64_t>, unsigned long long, struct unknown_u>
::type
352 struct types_traits<CheckBoost64::type, false> {
353 typedef boost::gil::gray64s_image_t image_t;
354 typedef boost::gil::gray64s_view_t view_t;
355 typedef boost::gil::gray64sc_view_t const_view_t;
356 typedef boost::gil::channel_traits<long>::reference reference;
357 typedef boost::gil::channel_traits<long>::const_reference const_reference;
361 struct types_traits<CheckBoost64::type_u, false> {
362 typedef boost::gil::gray64_image_t image_t;
363 typedef boost::gil::gray64_view_t view_t;
364 typedef boost::gil::gray64c_view_t const_view_t;
365 typedef boost::gil::channel_traits<long>::reference reference;
366 typedef boost::gil::channel_traits<long>::const_reference const_reference;
370 struct types_traits<double, false> {
371 typedef boost::gil::gray64f_noscale_image_t image_t;
372 typedef boost::gil::gray64f_noscale_view_t view_t;
373 typedef boost::gil::gray64f_noscalec_view_t const_view_t;
374 typedef boost::gil::channel_traits<double>::reference reference;
375 typedef boost::gil::channel_traits<double>::const_reference const_reference;
378 template <
typename T>
379 struct const_iterator_type {
383 template <
typename T>
384 struct const_locator_type {
385 typedef typename T::const_t
type;
388 typedef boost::gil::point2<std::ptrdiff_t> difference_type;
398 template <
typename View1,
typename View2,
typename View3,
typename ViewDest,
typename F>
399 BOOST_FORCEINLINE F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
400 const ViewDest& dst, F fun) {
402 typename View1::x_iterator srcIt1 = src1.row_begin(
y);
403 typename View2::x_iterator srcIt2 = src2.row_begin(
y);
404 typename View3::x_iterator srcIt3 = src3.row_begin(
y);
405 typename ViewDest::x_iterator dstIt = dst.row_begin(
y);
412 template <
typename View1,
typename View2,
typename View3,
typename View4,
typename ViewDest,
typename F>
413 BOOST_FORCEINLINE F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
const View4& src4,
414 const ViewDest& dst, F fun) {
416 typename View1::x_iterator srcIt1 = src1.row_begin(
y);
417 typename View2::x_iterator srcIt2 = src2.row_begin(
y);
418 typename View3::x_iterator srcIt3 = src3.row_begin(
y);
419 typename View4::x_iterator srcIt4 = src4.row_begin(
y);
420 typename ViewDest::x_iterator dstIt = dst.row_begin(
y);
422 dstIt[
x] = fun(srcIt1[
x], srcIt2[
x], srcIt3[
x], srcIt4[
x]);
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects.
Image< LhsPixelT > & operator+=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Add lhs to Image rhs (i.e. pixel-by-pixel addition) where types are different.
Image< LhsPixelT > & operator-=(Image< LhsPixelT > &lhs, Image< RhsPixelT > const &rhs)
Subtract lhs from Image rhs (i.e. pixel-by-pixel subtraction) where types are different.
A base class for image defects.