/usr/include/gamera/plugins/arithmetic.hpp is in python-gamera-dev 3.3.3-2+deb7u1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | /*
*
* Copyright (C) 2001-2005 Ichiro Fujinaga, Michael Droettboom,
* and Karl MacMillan
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#ifndef mgd_arithmetic
#define mgd_arithmetic
#include <functional>
#include "gamera.hpp"
template<class T, class U, class FUNCTOR>
inline
typename ImageFactory<T>::view_type*
arithmetic_combine(T& a, const U& b, const FUNCTOR& functor, bool in_place) {
if (a.nrows() != b.nrows() || a.ncols() != b.ncols())
throw std::runtime_error("Images must be the same size.");
typedef typename T::value_type TVALUE;
typedef typename ImageFactory<T>::view_type VIEW;
if (in_place) {
typename T::vec_iterator ia = a.vec_begin();
typename U::const_vec_iterator ib = b.vec_begin();
typename choose_accessor<T>::accessor ad = choose_accessor<T>::make_accessor(a);
for (; ia != a.vec_end(); ++ia, ++ib) {
ad.set(NumericTraits<TVALUE>::fromPromote
(functor(typename NumericTraits<TVALUE>::Promote(*ia),
typename NumericTraits<TVALUE>::Promote(*ib))),
ia);
}
// Returning NULL is converted to None by the wrapper mechanism
return NULL;
} else {
typename ImageFactory<T>::data_type* dest_data =
new typename ImageFactory<T>::data_type(a.size(), a.origin());
VIEW* dest = new VIEW(*dest_data, a);
typename T::vec_iterator ia = a.vec_begin();
typename U::const_vec_iterator ib = b.vec_begin();
typename VIEW::vec_iterator id = dest->vec_begin();
typename choose_accessor<VIEW>::accessor ad = choose_accessor<VIEW>::make_accessor(*dest);
// Vigra's combineTwoImages does not clip back to one of the standard
// Gamera image types, so we have to do this differently ourselves. MGD
try {
for (; ia != a.vec_end(); ++ia, ++ib, ++id) {
ad.set(NumericTraits<TVALUE>::fromPromote
(functor(typename NumericTraits<TVALUE>::Promote(*ia),
typename NumericTraits<TVALUE>::Promote(*ib))),
id);
}
} catch (std::exception e) {
delete dest;
delete dest_data;
throw;
}
return dest;
}
}
template<class T, class U>
typename ImageFactory<T>::view_type*
add_images(T& a, const U& b, bool in_place=true) {
typedef typename T::value_type TVALUE;
typedef typename NumericTraits<TVALUE>::Promote PROMOTE;
return arithmetic_combine(a, b, std::plus<PROMOTE>(), in_place);
}
template <class T>
struct my_minus : public std::binary_function<T,T,T>
{
T operator()(const T& x, const T& y) const {
typedef typename NumericTraits<T>::Promote PROMOTE;
return std::minus<T>()(x, y);
}
};
template<>
struct my_minus<OneBitPixel> : public std::binary_function<OneBitPixel, OneBitPixel, OneBitPixel>
{
OneBitPixel operator()(const OneBitPixel& x, const OneBitPixel& y) const {
// Note the result is inverted, because the default accessor performs an invert.
// GAAAH!
if (is_black(x) && !is_black(y))
return pixel_traits<OneBitPixel>::white();
else
return pixel_traits<OneBitPixel>::black();
}
};
template<class T, class U>
typename ImageFactory<T>::view_type*
subtract_images(T& a, const U& b, bool in_place=true) {
typedef typename T::value_type TVALUE;
return arithmetic_combine(a, b, my_minus<TVALUE>(), in_place);
}
template<class T, class U>
typename ImageFactory<T>::view_type*
multiply_images(T& a, const U& b, bool in_place=true) {
typedef typename T::value_type TVALUE;
typedef typename NumericTraits<TVALUE>::Promote PROMOTE;
return arithmetic_combine(a, b, std::multiplies<PROMOTE>(), in_place);
}
template<class T, class U>
typename ImageFactory<T>::view_type*
divide_images(T& a, const U& b, bool in_place=true) {
typedef typename T::value_type TVALUE;
typedef typename NumericTraits<TVALUE>::Promote PROMOTE;
return arithmetic_combine(a, b, std::divides<PROMOTE>(), in_place);
}
#endif
|