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" 72 struct pair2I :
public std::pair<int, int> {
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));
92 boost::gil::memory_based_2d_locator<T>&
operator-=(boost::gil::memory_based_2d_locator<T>& loc, pair2I off) {
93 return (loc -= boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
105 template <
typename T>
107 return (loc += point2<std::ptrdiff_t>(off.first, off.second));
113 template <
typename T>
115 return (loc -= point2<std::ptrdiff_t>(off.first, off.second));
121 typedef uint64_t bits64;
122 typedef int64_t bits64s;
124 GIL_DEFINE_BASE_TYPEDEFS(64, bits64, gray)
125 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64, bits64, dev2n, devicen_t<2>, devicen_layout_t<2>)
126 GIL_DEFINE_BASE_TYPEDEFS(64
s, bits64s, gray)
127 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64
s, bits64s, dev2n, devicen_t<2>, devicen_layout_t<2>)
132 typedef float bits32f_noscale;
134 GIL_DEFINE_BASE_TYPEDEFS(32f_noscale, bits32f_noscale, gray)
135 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f_noscale, bits32f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
138 struct channel_multiplier<bits32f_noscale>
140 bits32f_noscale operator()(bits32f_noscale
a, bits32f_noscale
b)
const {
return a *
b; }
146 typedef double bits64f_noscale;
148 GIL_DEFINE_BASE_TYPEDEFS(64f_noscale, bits64f_noscale, gray)
149 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64f_noscale, bits64f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
154 template <
typename DstChannelV>
155 struct channel_converter<bits32f_noscale, DstChannelV>
157 DstChannelV operator()(bits32f_noscale
x)
const {
return DstChannelV(x + 0.5f); }
160 template <
typename SrcChannelV>
161 struct channel_converter<SrcChannelV, bits32f_noscale>
163 bits32f_noscale operator()(SrcChannelV
x)
const {
return bits32f_noscale(x); }
166 template <
typename DstChannelV>
167 struct channel_converter<bits64f_noscale, DstChannelV>
169 DstChannelV operator()(bits64f_noscale
x)
const {
return DstChannelV(x + 0.5f); }
172 template <
typename SrcChannelV>
173 struct channel_converter<SrcChannelV, bits64f_noscale>
175 bits64f_noscale operator()(SrcChannelV
x)
const {
return bits64f_noscale(x); }
181 #define LSST_CONVERT_NOOP(T1, T2) \ 183 struct channel_converter<T1, T2> : public std::unary_function<T1, T2> { \ 184 T2 operator()(T1 x) const { return static_cast<T2>(x); } \ 188 struct channel_converter<T2, T1> : public std::unary_function<T2, T1> { \ 189 T1 operator()(T2 x) const { return static_cast<T1>(x); } \ 192 LSST_CONVERT_NOOP(bits32f_noscale, bits64f_noscale);
194 LSST_CONVERT_NOOP(
unsigned char,
short);
195 LSST_CONVERT_NOOP(
unsigned char,
unsigned short);
196 LSST_CONVERT_NOOP(
unsigned char,
int);
197 LSST_CONVERT_NOOP(
unsigned short,
short);
198 LSST_CONVERT_NOOP(
unsigned short,
int);
199 LSST_CONVERT_NOOP(
short,
int);
201 #undef LSST_CONVERT_NOOP 207 #define LSST_BOOST_GIL_OP_EQUALS(TYPE, OP) \ 208 template <typename T2> \ 209 TYPE##_pixel_t& operator OP##=(TYPE##_pixel_t& lhs, T2 rhs) { \ 210 return (lhs = lhs OP rhs); \ 213 #define LSST_BOOST_GIL_OP_EQUALS_ALL(PIXTYPE) \ 214 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, +) \ 215 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, -) \ 216 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, *) \ 217 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, /) \ 218 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, &) \ 219 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, |) 221 LSST_BOOST_GIL_OP_EQUALS_ALL(gray8)
222 LSST_BOOST_GIL_OP_EQUALS_ALL(gray8s)
223 LSST_BOOST_GIL_OP_EQUALS_ALL(gray16)
224 LSST_BOOST_GIL_OP_EQUALS_ALL(gray16s)
225 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32)
226 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32s)
227 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32f_noscale)
228 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64)
229 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64s)
230 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64f_noscale)
232 #undef LSST_BOOST_GIL_OP_EQUALS 233 #undef LSST_BOOST_GIL_OP_EQUALS_ALL 245 #pragma warning(push) 246 #pragma warning(disable : 304) 249 template <
typename T,
bool rescale = false>
250 struct types_traits {
251 BOOST_MPL_ASSERT_MSG(boost::mpl::bool_<false>::value, I_DO_NOT_KNOW_HOW_TO_MAP_THIS_TYPE_TO_A_GIL_TYPE,
259 struct types_traits<unsigned char, false> {
260 typedef boost::gil::gray8_image_t image_t;
261 typedef boost::gil::gray8_view_t view_t;
262 typedef boost::gil::gray8c_view_t const_view_t;
263 typedef boost::gil::channel_traits<char>::reference reference;
264 typedef boost::gil::channel_traits<char>::const_reference const_reference;
268 struct types_traits<short, false> {
269 typedef boost::gil::gray16s_image_t image_t;
270 typedef boost::gil::gray16s_view_t view_t;
271 typedef boost::gil::gray16sc_view_t const_view_t;
272 typedef boost::gil::channel_traits<short>::reference reference;
273 typedef boost::gil::channel_traits<short>::const_reference const_reference;
277 struct types_traits<unsigned short, false> {
278 typedef boost::gil::gray16_image_t image_t;
279 typedef boost::gil::gray16_view_t view_t;
280 typedef boost::gil::gray16c_view_t const_view_t;
281 typedef boost::gil::channel_traits<unsigned short>::reference reference;
282 typedef boost::gil::channel_traits<unsigned short>::const_reference const_reference;
286 struct types_traits<
int, false> {
287 typedef boost::gil::gray32s_image_t image_t;
288 typedef boost::gil::gray32s_view_t view_t;
289 typedef boost::gil::gray32sc_view_t const_view_t;
290 typedef boost::gil::channel_traits<int>::reference reference;
291 typedef boost::gil::channel_traits<int>::const_reference const_reference;
295 struct types_traits<unsigned
int, false> {
296 typedef boost::gil::gray32_image_t image_t;
297 typedef boost::gil::gray32_view_t view_t;
298 typedef boost::gil::gray32c_view_t const_view_t;
299 typedef boost::gil::channel_traits<int>::reference reference;
300 typedef boost::gil::channel_traits<int>::const_reference const_reference;
304 struct types_traits<
float, false> {
305 typedef boost::gil::gray32f_noscale_image_t image_t;
306 typedef boost::gil::gray32f_noscale_view_t view_t;
307 typedef boost::gil::gray32f_noscalec_view_t const_view_t;
308 typedef boost::gil::channel_traits<float>::reference reference;
309 typedef boost::gil::channel_traits<float>::const_reference const_reference;
313 struct types_traits<long, false> {
314 typedef boost::gil::gray64s_image_t image_t;
315 typedef boost::gil::gray64s_view_t view_t;
316 typedef boost::gil::gray64sc_view_t const_view_t;
317 typedef boost::gil::channel_traits<long>::reference reference;
318 typedef boost::gil::channel_traits<long>::const_reference const_reference;
322 struct types_traits<unsigned long, false> {
323 typedef boost::gil::gray64_image_t image_t;
324 typedef boost::gil::gray64_view_t view_t;
325 typedef boost::gil::gray64c_view_t const_view_t;
326 typedef boost::gil::channel_traits<long>::reference reference;
327 typedef boost::gil::channel_traits<long>::const_reference const_reference;
337 struct CheckBoost64 {
338 typedef boost::mpl::if_<std::is_same<long long, std::int64_t>,
long long,
struct unknown>::
type type;
339 typedef boost::mpl::if_<std::is_same<long long, std::int64_t>, unsigned long long, struct unknown_u>
::type 345 struct types_traits<CheckBoost64::type, false> {
346 typedef boost::gil::gray64s_image_t image_t;
347 typedef boost::gil::gray64s_view_t view_t;
348 typedef boost::gil::gray64sc_view_t const_view_t;
349 typedef boost::gil::channel_traits<long>::reference reference;
350 typedef boost::gil::channel_traits<long>::const_reference const_reference;
354 struct types_traits<CheckBoost64::type_u, false> {
355 typedef boost::gil::gray64_image_t image_t;
356 typedef boost::gil::gray64_view_t view_t;
357 typedef boost::gil::gray64c_view_t const_view_t;
358 typedef boost::gil::channel_traits<long>::reference reference;
359 typedef boost::gil::channel_traits<long>::const_reference const_reference;
363 struct types_traits<double, false> {
364 typedef boost::gil::gray64f_noscale_image_t image_t;
365 typedef boost::gil::gray64f_noscale_view_t view_t;
366 typedef boost::gil::gray64f_noscalec_view_t const_view_t;
367 typedef boost::gil::channel_traits<double>::reference reference;
368 typedef boost::gil::channel_traits<double>::const_reference const_reference;
371 template <
typename T>
372 struct const_iterator_type {
376 template <
typename T>
377 struct const_locator_type {
378 typedef typename T::const_t
type;
381 typedef boost::gil::point2<std::ptrdiff_t> difference_type;
391 template <
typename View1,
typename View2,
typename View3,
typename ViewDest,
typename F>
392 BOOST_FORCEINLINE F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
393 const ViewDest& dst, F fun) {
395 typename View1::x_iterator srcIt1 = src1.row_begin(
y);
396 typename View2::x_iterator srcIt2 = src2.row_begin(
y);
397 typename View3::x_iterator srcIt3 = src3.row_begin(
y);
398 typename ViewDest::x_iterator dstIt = dst.row_begin(
y);
399 for (
std::ptrdiff_t x = 0;
x < dst.width(); ++
x) dstIt[
x] = fun(srcIt1[
x], srcIt2[x], srcIt3[x]);
405 template <
typename View1,
typename View2,
typename View3,
typename View4,
typename ViewDest,
typename F>
406 BOOST_FORCEINLINE F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
const View4& src4,
407 const ViewDest& dst, F fun) {
409 typename View1::x_iterator srcIt1 = src1.row_begin(
y);
410 typename View2::x_iterator srcIt2 = src2.row_begin(
y);
411 typename View3::x_iterator srcIt3 = src3.row_begin(
y);
412 typename View4::x_iterator srcIt4 = src4.row_begin(
y);
413 typename ViewDest::x_iterator dstIt = dst.row_begin(
y);
415 dstIt[
x] = fun(srcIt1[
x], srcIt2[x], srcIt3[x], srcIt4[x]);
422
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.
A base class for image defects.
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.
Backwards-compatibility support for depersisting the old Calib (FluxMag0/FluxMag0Err) objects...