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/gil/gil_all.hpp" 67 struct pair2I :
public std::pair<int, int> {
79 boost::gil::memory_based_2d_locator<T>&
operator+=(boost::gil::memory_based_2d_locator<T>& loc, pair2I off) {
80 return (loc += boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
87 boost::gil::memory_based_2d_locator<T>&
operator-=(boost::gil::memory_based_2d_locator<T>& loc, pair2I off) {
88 return (loc -= boost::gil::point2<std::ptrdiff_t>(off.first, off.second));
100 template <
typename T>
102 return (loc += point2<std::ptrdiff_t>(off.first, off.second));
108 template <
typename T>
110 return (loc -= point2<std::ptrdiff_t>(off.first, off.second));
116 typedef uint64_t bits64;
117 typedef int64_t bits64s;
119 GIL_DEFINE_BASE_TYPEDEFS(64, bits64, gray)
120 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64, bits64, dev2n, devicen_t<2>, devicen_layout_t<2>)
121 GIL_DEFINE_BASE_TYPEDEFS(64
s, bits64s, gray)
122 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64
s, bits64s, dev2n, devicen_t<2>, devicen_layout_t<2>)
127 typedef float bits32f_noscale;
129 GIL_DEFINE_BASE_TYPEDEFS(32f_noscale, bits32f_noscale, gray)
130 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(32f_noscale, bits32f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
133 struct channel_multiplier<bits32f_noscale>
135 bits32f_noscale operator()(bits32f_noscale
a, bits32f_noscale
b)
const {
return a *
b; }
141 typedef double bits64f_noscale;
143 GIL_DEFINE_BASE_TYPEDEFS(64f_noscale, bits64f_noscale, gray)
144 GIL_DEFINE_ALL_TYPEDEFS_INTERNAL(64f_noscale, bits64f_noscale, dev2n, devicen_t<2>, devicen_layout_t<2>)
149 template <
typename DstChannelV>
150 struct channel_converter<bits32f_noscale, DstChannelV>
152 DstChannelV operator()(bits32f_noscale
x)
const {
return DstChannelV(x + 0.5f); }
155 template <
typename SrcChannelV>
156 struct channel_converter<SrcChannelV, bits32f_noscale>
158 bits32f_noscale operator()(SrcChannelV
x)
const {
return bits32f_noscale(x); }
161 template <
typename DstChannelV>
162 struct channel_converter<bits64f_noscale, DstChannelV>
164 DstChannelV operator()(bits64f_noscale
x)
const {
return DstChannelV(x + 0.5f); }
167 template <
typename SrcChannelV>
168 struct channel_converter<SrcChannelV, bits64f_noscale>
170 bits64f_noscale operator()(SrcChannelV
x)
const {
return bits64f_noscale(x); }
176 #define LSST_CONVERT_NOOP(T1, T2) \ 178 struct channel_converter<T1, T2> : public std::unary_function<T1, T2> { \ 179 T2 operator()(T1 x) const { return static_cast<T2>(x); } \ 183 struct channel_converter<T2, T1> : public std::unary_function<T2, T1> { \ 184 T1 operator()(T2 x) const { return static_cast<T1>(x); } \ 187 LSST_CONVERT_NOOP(bits32f_noscale, bits64f_noscale);
189 LSST_CONVERT_NOOP(
unsigned char,
short);
190 LSST_CONVERT_NOOP(
unsigned char,
unsigned short);
191 LSST_CONVERT_NOOP(
unsigned char,
int);
192 LSST_CONVERT_NOOP(
unsigned short,
short);
193 LSST_CONVERT_NOOP(
unsigned short,
int);
194 LSST_CONVERT_NOOP(
short,
int);
196 #undef LSST_CONVERT_NOOP 202 #define LSST_BOOST_GIL_OP_EQUALS(TYPE, OP) \ 203 template <typename T2> \ 204 TYPE##_pixel_t& operator OP##=(TYPE##_pixel_t& lhs, T2 rhs) { \ 205 return (lhs = lhs OP rhs); \ 208 #define LSST_BOOST_GIL_OP_EQUALS_ALL(PIXTYPE) \ 209 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, +) \ 210 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, -) \ 211 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, *) \ 212 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, /) \ 213 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, &) \ 214 LSST_BOOST_GIL_OP_EQUALS(PIXTYPE, |) 216 LSST_BOOST_GIL_OP_EQUALS_ALL(gray8)
217 LSST_BOOST_GIL_OP_EQUALS_ALL(gray8s)
218 LSST_BOOST_GIL_OP_EQUALS_ALL(gray16)
219 LSST_BOOST_GIL_OP_EQUALS_ALL(gray16s)
220 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32)
221 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32s)
222 LSST_BOOST_GIL_OP_EQUALS_ALL(gray32f_noscale)
223 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64)
224 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64s)
225 LSST_BOOST_GIL_OP_EQUALS_ALL(gray64f_noscale)
227 #undef LSST_BOOST_GIL_OP_EQUALS 228 #undef LSST_BOOST_GIL_OP_EQUALS_ALL 240 #pragma warning(push) 241 #pragma warning(disable : 304) 244 template <
typename T,
bool rescale = false>
245 struct types_traits {
246 BOOST_MPL_ASSERT_MSG(boost::mpl::bool_<false>::value, I_DO_NOT_KNOW_HOW_TO_MAP_THIS_TYPE_TO_A_GIL_TYPE,
254 struct types_traits<unsigned char, false> {
255 typedef boost::gil::gray8_image_t image_t;
256 typedef boost::gil::gray8_view_t view_t;
257 typedef boost::gil::gray8c_view_t const_view_t;
258 typedef boost::gil::channel_traits<char>::reference reference;
259 typedef boost::gil::channel_traits<char>::const_reference const_reference;
263 struct types_traits<short, false> {
264 typedef boost::gil::gray16s_image_t image_t;
265 typedef boost::gil::gray16s_view_t view_t;
266 typedef boost::gil::gray16sc_view_t const_view_t;
267 typedef boost::gil::channel_traits<short>::reference reference;
268 typedef boost::gil::channel_traits<short>::const_reference const_reference;
272 struct types_traits<unsigned short, false> {
273 typedef boost::gil::gray16_image_t image_t;
274 typedef boost::gil::gray16_view_t view_t;
275 typedef boost::gil::gray16c_view_t const_view_t;
276 typedef boost::gil::channel_traits<unsigned short>::reference reference;
277 typedef boost::gil::channel_traits<unsigned short>::const_reference const_reference;
281 struct types_traits<
int, false> {
282 typedef boost::gil::gray32s_image_t image_t;
283 typedef boost::gil::gray32s_view_t view_t;
284 typedef boost::gil::gray32sc_view_t const_view_t;
285 typedef boost::gil::channel_traits<int>::reference reference;
286 typedef boost::gil::channel_traits<int>::const_reference const_reference;
290 struct types_traits<unsigned
int, false> {
291 typedef boost::gil::gray32_image_t image_t;
292 typedef boost::gil::gray32_view_t view_t;
293 typedef boost::gil::gray32c_view_t const_view_t;
294 typedef boost::gil::channel_traits<int>::reference reference;
295 typedef boost::gil::channel_traits<int>::const_reference const_reference;
299 struct types_traits<
float, false> {
300 typedef boost::gil::gray32f_noscale_image_t image_t;
301 typedef boost::gil::gray32f_noscale_view_t view_t;
302 typedef boost::gil::gray32f_noscalec_view_t const_view_t;
303 typedef boost::gil::channel_traits<float>::reference reference;
304 typedef boost::gil::channel_traits<float>::const_reference const_reference;
308 struct types_traits<long, false> {
309 typedef boost::gil::gray64s_image_t image_t;
310 typedef boost::gil::gray64s_view_t view_t;
311 typedef boost::gil::gray64sc_view_t const_view_t;
312 typedef boost::gil::channel_traits<long>::reference reference;
313 typedef boost::gil::channel_traits<long>::const_reference const_reference;
317 struct types_traits<unsigned long, false> {
318 typedef boost::gil::gray64_image_t image_t;
319 typedef boost::gil::gray64_view_t view_t;
320 typedef boost::gil::gray64c_view_t const_view_t;
321 typedef boost::gil::channel_traits<long>::reference reference;
322 typedef boost::gil::channel_traits<long>::const_reference const_reference;
332 struct CheckBoost64 {
333 typedef boost::mpl::if_<std::is_same<long long, std::int64_t>,
long long,
struct unknown>::
type type;
334 typedef boost::mpl::if_<std::is_same<long long, std::int64_t>, unsigned long long, struct unknown_u>
::type 340 struct types_traits<CheckBoost64::type, false> {
341 typedef boost::gil::gray64s_image_t image_t;
342 typedef boost::gil::gray64s_view_t view_t;
343 typedef boost::gil::gray64sc_view_t const_view_t;
344 typedef boost::gil::channel_traits<long>::reference reference;
345 typedef boost::gil::channel_traits<long>::const_reference const_reference;
349 struct types_traits<CheckBoost64::type_u, false> {
350 typedef boost::gil::gray64_image_t image_t;
351 typedef boost::gil::gray64_view_t view_t;
352 typedef boost::gil::gray64c_view_t const_view_t;
353 typedef boost::gil::channel_traits<long>::reference reference;
354 typedef boost::gil::channel_traits<long>::const_reference const_reference;
358 struct types_traits<double, false> {
359 typedef boost::gil::gray64f_noscale_image_t image_t;
360 typedef boost::gil::gray64f_noscale_view_t view_t;
361 typedef boost::gil::gray64f_noscalec_view_t const_view_t;
362 typedef boost::gil::channel_traits<double>::reference reference;
363 typedef boost::gil::channel_traits<double>::const_reference const_reference;
366 template <
typename T>
367 struct const_iterator_type {
371 template <
typename T>
372 struct const_locator_type {
373 typedef typename T::const_t
type;
376 typedef boost::gil::point2<std::ptrdiff_t> difference_type;
386 template <
typename View1,
typename View2,
typename View3,
typename ViewDest,
typename F>
387 BOOST_FORCEINLINE F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
388 const ViewDest& dst, F fun) {
390 typename View1::x_iterator srcIt1 = src1.row_begin(
y);
391 typename View2::x_iterator srcIt2 = src2.row_begin(
y);
392 typename View3::x_iterator srcIt3 = src3.row_begin(
y);
393 typename ViewDest::x_iterator dstIt = dst.row_begin(
y);
394 for (
std::ptrdiff_t x = 0;
x < dst.width(); ++
x) dstIt[
x] = fun(srcIt1[
x], srcIt2[x], srcIt3[x]);
400 template <
typename View1,
typename View2,
typename View3,
typename View4,
typename ViewDest,
typename F>
401 BOOST_FORCEINLINE F transform_pixels(
const View1& src1,
const View2& src2,
const View3& src3,
const View4& src4,
402 const ViewDest& dst, F fun) {
404 typename View1::x_iterator srcIt1 = src1.row_begin(
y);
405 typename View2::x_iterator srcIt2 = src2.row_begin(
y);
406 typename View3::x_iterator srcIt3 = src3.row_begin(
y);
407 typename View4::x_iterator srcIt4 = src4.row_begin(
y);
408 typename ViewDest::x_iterator dstIt = dst.row_begin(
y);
410 dstIt[
x] = fun(srcIt1[
x], srcIt2[x], srcIt3[x], srcIt4[x]);
417
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.