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"
44 #include "boost/gil.hpp"
46 #ifndef BOOST_GIL_DEFINE_BASE_TYPEDEFS
49 #define BOOST_GIL_DEFINE_BASE_TYPEDEFS GIL_DEFINE_BASE_TYPEDEFS
50 #define BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL GIL_DEFINE_ALL_TYPEDEFS_INTERNAL
64 struct pair2I :
public std::pair<int, int> {
76 boost::gil::memory_based_2d_locator<T>&
operator+=(boost::gil::memory_based_2d_locator<T>& loc, pair2I off) {
77 return (loc += boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
84 boost::gil::memory_based_2d_locator<T>&
operator-=(boost::gil::memory_based_2d_locator<T>& loc, pair2I off) {
85 return (loc -= boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
99 return (loc += point2<std::ptrdiff_t>(off.first, off.second));
105 template <
typename T>
107 return (loc -= point2<std::ptrdiff_t>(off.first, off.second));
113 using bits64 = uint64_t;
114 using bits64s = int64_t;
116 BOOST_GIL_DEFINE_BASE_TYPEDEFS(64, bits64, gray)
117 BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64, bits64, dev2n, devicen_t<2>, devicen_layout_t<2>)
118 BOOST_GIL_DEFINE_BASE_TYPEDEFS(64s, bits64s, gray)
119 BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64s, bits64s, dev2n, devicen_t<2>, devicen_layout_t<2>)
124 using bits32f_noscale = float;
126 BOOST_GIL_DEFINE_BASE_TYPEDEFS(32f_noscale, bits32f_noscale, gray)
127 BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f_noscale, bits32f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
130 struct channel_multiplier<bits32f_noscale>
132 bits32f_noscale operator()(bits32f_noscale
a, bits32f_noscale
b)
const {
return a *
b; }
138 using bits64f_noscale = double;
140 BOOST_GIL_DEFINE_BASE_TYPEDEFS(64f_noscale, bits64f_noscale, gray)
141 BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64f_noscale, bits64f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
146 template <
typename DstChannelV>
147 struct channel_converter<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>
155 bits32f_noscale operator()(SrcChannelV
x)
const {
return bits32f_noscale(
x); }
158 template <
typename DstChannelV>
159 struct channel_converter<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>
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
199 #define LSST_BOOST_GIL_OP_EQUALS(TYPE, OP) \
200 template <typename T2> \
201 TYPE##_pixel_t& operator OP##=(TYPE##_pixel_t& lhs, T2 rhs) { \
202 return (lhs = lhs OP rhs); \
205 #define LSST_BOOST_GIL_OP_EQUALS_ALL(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, &) \
211 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, |)
213 LSST_BOOST_GIL_OP_EQUALS_ALL(gray8)
214 LSST_BOOST_GIL_OP_EQUALS_ALL(gray8s)
215 LSST_BOOST_GIL_OP_EQUALS_ALL(gray16)
216 LSST_BOOST_GIL_OP_EQUALS_ALL(gray16s)
217 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32)
218 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32s)
219 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32f_noscale)
220 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64)
221 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64s)
222 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64f_noscale)
224 #undef LSST_BOOST_GIL_OP_EQUALS
225 #undef LSST_BOOST_GIL_OP_EQUALS_ALL
237 template <
typename T,
bool rescale = false>
238 struct types_traits {
239 BOOST_MPL_ASSERT_MSG(boost::mpl::bool_<false>::value, I_DO_NOT_KNOW_HOW_TO_MAP_THIS_TYPE_TO_A_GIL_TYPE,
244 struct types_traits<unsigned char, false> {
245 using image_t = boost::gil::gray8_image_t;
246 using view_t = boost::gil::gray8_view_t;
247 using const_view_t = boost::gil::gray8c_view_t;
248 using reference = boost::gil::channel_traits<char>::reference;
249 using const_reference = boost::gil::channel_traits<char>::const_reference;
253 struct types_traits<short, false> {
254 using image_t = boost::gil::gray16s_image_t;
255 using view_t = boost::gil::gray16s_view_t;
256 using const_view_t = boost::gil::gray16sc_view_t;
257 using reference = boost::gil::channel_traits<short>::reference;
258 using const_reference = boost::gil::channel_traits<short>::const_reference;
262 struct types_traits<unsigned short, false> {
263 using image_t = boost::gil::gray16_image_t;
264 using view_t = boost::gil::gray16_view_t;
265 using const_view_t = boost::gil::gray16c_view_t;
266 using reference = boost::gil::channel_traits<unsigned short>::reference;
267 using const_reference = boost::gil::channel_traits<unsigned short>::const_reference;
271 struct types_traits<int, false> {
272 using image_t = boost::gil::gray32s_image_t;
273 using view_t = boost::gil::gray32s_view_t;
274 using const_view_t = boost::gil::gray32sc_view_t;
275 using reference = boost::gil::channel_traits<int>::reference;
276 using const_reference = boost::gil::channel_traits<int>::const_reference;
280 struct types_traits<unsigned int, false> {
281 using image_t = boost::gil::gray32_image_t;
282 using view_t = boost::gil::gray32_view_t;
283 using const_view_t = boost::gil::gray32c_view_t;
284 using reference = boost::gil::channel_traits<int>::reference;
285 using const_reference = boost::gil::channel_traits<int>::const_reference;
289 struct types_traits<float, false> {
290 using image_t = boost::gil::gray32f_noscale_image_t;
291 using view_t = boost::gil::gray32f_noscale_view_t;
292 using const_view_t = boost::gil::gray32f_noscalec_view_t;
293 using reference = boost::gil::channel_traits<float>::reference;
294 using const_reference = boost::gil::channel_traits<float>::const_reference;
298 struct types_traits<long, false> {
299 using image_t = boost::gil::gray64s_image_t;
300 using view_t = boost::gil::gray64s_view_t;
301 using const_view_t = boost::gil::gray64sc_view_t;
302 using reference = boost::gil::channel_traits<long>::reference;
303 using const_reference = boost::gil::channel_traits<long>::const_reference;
307 struct types_traits<unsigned long, false> {
308 using image_t = boost::gil::gray64_image_t;
309 using view_t = boost::gil::gray64_view_t;
310 using const_view_t = boost::gil::gray64c_view_t;
311 using reference = boost::gil::channel_traits<long>::reference;
312 using const_reference = boost::gil::channel_traits<long>::const_reference;
322 struct CheckBoost64 {
323 using type = boost::mpl::if_<std::is_same<long long, std::int64_t>,
long long,
struct unknown>::
type;
324 using type_u = boost::mpl::if_<std::is_same<long long, std::int64_t>, unsigned long long, struct unknown_u>
::type;
329 struct types_traits<CheckBoost64::type, false> {
330 using image_t = boost::gil::gray64s_image_t;
331 using view_t = boost::gil::gray64s_view_t;
332 using const_view_t = boost::gil::gray64sc_view_t;
333 using reference = boost::gil::channel_traits<long>::reference;
334 using const_reference = boost::gil::channel_traits<long>::const_reference;
338 struct types_traits<CheckBoost64::type_u, false> {
339 using image_t = boost::gil::gray64_image_t;
340 using view_t = boost::gil::gray64_view_t;
341 using const_view_t = boost::gil::gray64c_view_t;
342 using reference = boost::gil::channel_traits<long>::reference;
343 using const_reference = boost::gil::channel_traits<long>::const_reference;
347 struct types_traits<double, false> {
348 using image_t = boost::gil::gray64f_noscale_image_t;
349 using view_t = boost::gil::gray64f_noscale_view_t;
350 using const_view_t = boost::gil::gray64f_noscalec_view_t;
351 using reference = boost::gil::channel_traits<double>::reference;
352 using const_reference = boost::gil::channel_traits<double>::const_reference;
355 template <
typename T>
356 struct const_iterator_type {
360 template <
typename T>
361 struct const_locator_type {
362 using type =
typename T::const_t;
365 using difference_type = boost::gil::point2<std::ptrdiff_t>;
375 template <
typename View1,
typename View2,
typename View3,
typename ViewDest,
typename F>
376 BOOST_FORCEINLINE F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
377 const ViewDest& dst, F fun) {
379 typename View1::x_iterator srcIt1 = src1.row_begin(
y);
380 typename View2::x_iterator srcIt2 = src2.row_begin(
y);
381 typename View3::x_iterator srcIt3 = src3.row_begin(
y);
382 typename ViewDest::x_iterator dstIt = dst.row_begin(
y);
389 template <
typename View1,
typename View2,
typename View3,
typename View4,
typename ViewDest,
typename F>
390 BOOST_FORCEINLINE F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
const View4& src4,
391 const ViewDest& dst, F fun) {
393 typename View1::x_iterator srcIt1 = src1.row_begin(
y);
394 typename View2::x_iterator srcIt2 = src2.row_begin(
y);
395 typename View3::x_iterator srcIt3 = src3.row_begin(
y);
396 typename View4::x_iterator srcIt4 = src4.row_begin(
y);
397 typename ViewDest::x_iterator dstIt = dst.row_begin(
y);
399 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.