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> {
65 explicit pair2I(
int first,
int second) :
std::pair<int, int>(
first,
second) {}
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> {
131 bits32f_noscale operator()(bits32f_noscale
a, bits32f_noscale
b)
const {
return a *
b; }
137using bits64f_noscale = double;
139BOOST_GIL_DEFINE_BASE_TYPEDEFS(64f_noscale, bits64f_noscale, gray)
140BOOST_GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64f_noscale, bits64f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
145template <
typename DstChannelV>
146struct channel_converter<bits32f_noscale, DstChannelV> {
147 DstChannelV operator()(bits32f_noscale
x)
const {
return DstChannelV(
x + 0.5f); }
150template <
typename SrcChannelV>
151struct channel_converter<SrcChannelV, bits32f_noscale> {
152 bits32f_noscale operator()(SrcChannelV
x)
const {
return bits32f_noscale(
x); }
155template <
typename DstChannelV>
156struct channel_converter<bits64f_noscale, DstChannelV> {
157 DstChannelV operator()(bits64f_noscale
x)
const {
return DstChannelV(
x + 0.5f); }
160template <
typename SrcChannelV>
161struct channel_converter<SrcChannelV, bits64f_noscale> {
162 bits64f_noscale operator()(SrcChannelV
x)
const {
return bits64f_noscale(
x); }
168#define LSST_CONVERT_NOOP(T1, T2) \
170 struct channel_converter<T1, T2> { \
171 T2 operator()(T1 x) const { return static_cast<T2>(x); } \
175 struct channel_converter<T2, T1> { \
176 T1 operator()(T2 x) const { return static_cast<T1>(x); } \
179LSST_CONVERT_NOOP(bits32f_noscale, bits64f_noscale);
181LSST_CONVERT_NOOP(
unsigned char,
short);
182LSST_CONVERT_NOOP(
unsigned char,
unsigned short);
183LSST_CONVERT_NOOP(
unsigned char,
int);
184LSST_CONVERT_NOOP(
unsigned short,
short);
185LSST_CONVERT_NOOP(
unsigned short,
int);
186LSST_CONVERT_NOOP(
short,
int);
188#undef LSST_CONVERT_NOOP
194#define LSST_BOOST_GIL_OP_EQUALS(TYPE, OP) \
195 template <typename T2> \
196 TYPE##_pixel_t& operator OP##=(TYPE##_pixel_t& lhs, T2 rhs) { \
197 return (lhs = lhs OP rhs); \
200#define LSST_BOOST_GIL_OP_EQUALS_ALL(PIXTYPE) \
201 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, +) \
202 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, -) \
203 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, *) \
204 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, /) \
205 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, &) \
206 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, |)
208LSST_BOOST_GIL_OP_EQUALS_ALL(gray8)
209LSST_BOOST_GIL_OP_EQUALS_ALL(gray8s)
210LSST_BOOST_GIL_OP_EQUALS_ALL(gray16)
211LSST_BOOST_GIL_OP_EQUALS_ALL(gray16s)
212LSST_BOOST_GIL_OP_EQUALS_ALL(gray32)
213LSST_BOOST_GIL_OP_EQUALS_ALL(gray32s)
214LSST_BOOST_GIL_OP_EQUALS_ALL(gray32f_noscale)
215LSST_BOOST_GIL_OP_EQUALS_ALL(gray64)
216LSST_BOOST_GIL_OP_EQUALS_ALL(gray64s)
217LSST_BOOST_GIL_OP_EQUALS_ALL(gray64f_noscale)
219#undef LSST_BOOST_GIL_OP_EQUALS
220#undef LSST_BOOST_GIL_OP_EQUALS_ALL
232template <
typename T,
bool rescale = false>
234 BOOST_MPL_ASSERT_MSG(boost::mpl::bool_<false>::value, I_DO_NOT_KNOW_HOW_TO_MAP_THIS_TYPE_TO_A_GIL_TYPE,
239struct types_traits<unsigned char, false> {
240 using image_t = boost::gil::gray8_image_t;
241 using view_t = boost::gil::gray8_view_t;
242 using const_view_t = boost::gil::gray8c_view_t;
243 using reference = boost::gil::channel_traits<char>::reference;
244 using const_reference = boost::gil::channel_traits<char>::const_reference;
248struct types_traits<short, false> {
249 using image_t = boost::gil::gray16s_image_t;
250 using view_t = boost::gil::gray16s_view_t;
251 using const_view_t = boost::gil::gray16sc_view_t;
252 using reference = boost::gil::channel_traits<short>::reference;
253 using const_reference = boost::gil::channel_traits<short>::const_reference;
257struct types_traits<unsigned short, false> {
258 using image_t = boost::gil::gray16_image_t;
259 using view_t = boost::gil::gray16_view_t;
260 using const_view_t = boost::gil::gray16c_view_t;
261 using reference = boost::gil::channel_traits<unsigned short>::reference;
262 using const_reference = boost::gil::channel_traits<unsigned short>::const_reference;
266struct types_traits<int, false> {
267 using image_t = boost::gil::gray32s_image_t;
268 using view_t = boost::gil::gray32s_view_t;
269 using const_view_t = boost::gil::gray32sc_view_t;
270 using reference = boost::gil::channel_traits<int>::reference;
271 using const_reference = boost::gil::channel_traits<int>::const_reference;
275struct types_traits<unsigned int, false> {
276 using image_t = boost::gil::gray32_image_t;
277 using view_t = boost::gil::gray32_view_t;
278 using const_view_t = boost::gil::gray32c_view_t;
279 using reference = boost::gil::channel_traits<int>::reference;
280 using const_reference = boost::gil::channel_traits<int>::const_reference;
284struct types_traits<float, false> {
285 using image_t = boost::gil::gray32f_noscale_image_t;
286 using view_t = boost::gil::gray32f_noscale_view_t;
287 using const_view_t = boost::gil::gray32f_noscalec_view_t;
288 using reference = boost::gil::channel_traits<float>::reference;
289 using const_reference = boost::gil::channel_traits<float>::const_reference;
293struct types_traits<long, false> {
294 using image_t = boost::gil::gray64s_image_t;
295 using view_t = boost::gil::gray64s_view_t;
296 using const_view_t = boost::gil::gray64sc_view_t;
297 using reference = boost::gil::channel_traits<long>::reference;
298 using const_reference = boost::gil::channel_traits<long>::const_reference;
302struct types_traits<unsigned long, false> {
303 using image_t = boost::gil::gray64_image_t;
304 using view_t = boost::gil::gray64_view_t;
305 using const_view_t = boost::gil::gray64c_view_t;
306 using reference = boost::gil::channel_traits<long>::reference;
307 using const_reference = boost::gil::channel_traits<long>::const_reference;
318 using type = boost::mpl::if_<std::is_same<long long, std::int64_t>,
long long,
struct unknown>::
type;
319 using type_u = boost::mpl::if_<std::is_same<long long, std::int64_t>, unsigned long long, struct unknown_u>
::type;
324struct types_traits<CheckBoost64::type, false> {
325 using image_t = boost::gil::gray64s_image_t;
326 using view_t = boost::gil::gray64s_view_t;
327 using const_view_t = boost::gil::gray64sc_view_t;
328 using reference = boost::gil::channel_traits<long>::reference;
329 using const_reference = boost::gil::channel_traits<long>::const_reference;
333struct types_traits<CheckBoost64::type_u, false> {
334 using image_t = boost::gil::gray64_image_t;
335 using view_t = boost::gil::gray64_view_t;
336 using const_view_t = boost::gil::gray64c_view_t;
337 using reference = boost::gil::channel_traits<long>::reference;
338 using const_reference = boost::gil::channel_traits<long>::const_reference;
342struct types_traits<double, false> {
343 using image_t = boost::gil::gray64f_noscale_image_t;
344 using view_t = boost::gil::gray64f_noscale_view_t;
345 using const_view_t = boost::gil::gray64f_noscalec_view_t;
346 using reference = boost::gil::channel_traits<double>::reference;
347 using const_reference = boost::gil::channel_traits<double>::const_reference;
351struct const_iterator_type {
352 using type =
typename boost::gil::const_iterator_type<T>::type;
356struct const_locator_type {
357 using type =
typename T::const_t;
360using difference_type = boost::gil::point2<std::ptrdiff_t>;
370template <
typename View1,
typename View2,
typename View3,
typename ViewDest,
typename F>
371BOOST_FORCEINLINE F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
372 const ViewDest& dst, F fun) {
374 typename View1::x_iterator srcIt1 = src1.row_begin(
y);
375 typename View2::x_iterator srcIt2 = src2.row_begin(
y);
376 typename View3::x_iterator srcIt3 = src3.row_begin(
y);
377 typename ViewDest::x_iterator dstIt = dst.row_begin(
y);
384template <
typename View1,
typename View2,
typename View3,
typename View4,
typename ViewDest,
typename F>
385BOOST_FORCEINLINE F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
const View4& src4,
386 const ViewDest& dst, F fun) {
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);
394 dstIt[
x] = fun(srcIt1[
x], srcIt2[
x], srcIt3[
x], srcIt4[
x]);
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.