32#if !defined(GIL_LSST_H)
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
64struct pair2I :
public std::pair<int, int> {
76boost::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));
84boost::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));
107 return (loc -= point2<std::ptrdiff_t>(off.first, off.second));
113using bits64 = uint64_t;
114using bits64s = int64_t;
116BOOST_GIL_DEFINE_BASE_TYPEDEFS(64, bits64, gray)
117BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64, bits64, dev2n, devicen_t<2>, devicen_layout_t<2>)
118BOOST_GIL_DEFINE_BASE_TYPEDEFS(64s, bits64s, gray)
119BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64s, bits64s, dev2n, devicen_t<2>, devicen_layout_t<2>)
124using bits32f_noscale =
float;
126BOOST_GIL_DEFINE_BASE_TYPEDEFS(32f_noscale, bits32f_noscale, gray)
127BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f_noscale, bits32f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
130struct channel_multiplier<bits32f_noscale>
132 bits32f_noscale operator()(bits32f_noscale
a, bits32f_noscale
b)
const {
return a *
b; }
138using bits64f_noscale =
double;
140BOOST_GIL_DEFINE_BASE_TYPEDEFS(64f_noscale, bits64f_noscale, gray)
141BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64f_noscale, bits64f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
146template <
typename DstChannelV>
147struct channel_converter<bits32f_noscale, DstChannelV>
149 DstChannelV operator()(bits32f_noscale
x)
const {
return DstChannelV(
x + 0.5f); }
152template <
typename SrcChannelV>
153struct channel_converter<SrcChannelV, bits32f_noscale>
155 bits32f_noscale operator()(SrcChannelV
x)
const {
return bits32f_noscale(
x); }
158template <
typename DstChannelV>
159struct channel_converter<bits64f_noscale, DstChannelV>
161 DstChannelV operator()(bits64f_noscale
x)
const {
return DstChannelV(
x + 0.5f); }
164template <
typename SrcChannelV>
165struct 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); } \
184LSST_CONVERT_NOOP(bits32f_noscale, bits64f_noscale);
186LSST_CONVERT_NOOP(
unsigned char,
short);
187LSST_CONVERT_NOOP(
unsigned char,
unsigned short);
188LSST_CONVERT_NOOP(
unsigned char,
int);
189LSST_CONVERT_NOOP(
unsigned short,
short);
190LSST_CONVERT_NOOP(
unsigned short,
int);
191LSST_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, |)
213LSST_BOOST_GIL_OP_EQUALS_ALL(gray8)
214LSST_BOOST_GIL_OP_EQUALS_ALL(gray8s)
215LSST_BOOST_GIL_OP_EQUALS_ALL(gray16)
216LSST_BOOST_GIL_OP_EQUALS_ALL(gray16s)
217LSST_BOOST_GIL_OP_EQUALS_ALL(gray32)
218LSST_BOOST_GIL_OP_EQUALS_ALL(gray32s)
219LSST_BOOST_GIL_OP_EQUALS_ALL(gray32f_noscale)
220LSST_BOOST_GIL_OP_EQUALS_ALL(gray64)
221LSST_BOOST_GIL_OP_EQUALS_ALL(gray64s)
222LSST_BOOST_GIL_OP_EQUALS_ALL(gray64f_noscale)
224#undef LSST_BOOST_GIL_OP_EQUALS
225#undef LSST_BOOST_GIL_OP_EQUALS_ALL
237template <
typename T,
bool rescale = false>
239 BOOST_MPL_ASSERT_MSG(boost::mpl::bool_<false>::value, I_DO_NOT_KNOW_HOW_TO_MAP_THIS_TYPE_TO_A_GIL_TYPE,
244struct 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;
253struct 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;
262struct 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;
271struct 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;
280struct 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;
289struct 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;
298struct 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;
307struct 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;
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;
329struct 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;
338struct 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;
347struct 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;
356struct const_iterator_type {
361struct const_locator_type {
362 using type =
typename T::const_t;
365using difference_type = boost::gil::point2<std::ptrdiff_t>;
375template <
typename View1,
typename View2,
typename View3,
typename ViewDest,
typename F>
376BOOST_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);
389template <
typename View1,
typename View2,
typename View3,
typename View4,
typename ViewDest,
typename F>
390BOOST_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.