/usr/include/vigra/impexbase.hxx is in libvigraimpex-dev 1.10.0+dfsg-11ubuntu2.
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 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | /************************************************************************/
/* */
/* Copyright 2012 Christoph Spiel */
/* */
/* This file is part of the VIGRA computer vision library. */
/* The VIGRA Website is */
/* http://hci.iwr.uni-heidelberg.de/vigra/ */
/* Please direct questions, bug reports, and contributions to */
/* ullrich.koethe@iwr.uni-heidelberg.de or */
/* vigra@informatik.uni-hamburg.de */
/* */
/* Permission is hereby granted, free of charge, to any person */
/* obtaining a copy of this software and associated documentation */
/* files (the "Software"), to deal in the Software without */
/* restriction, including without limitation the rights to use, */
/* copy, modify, merge, publish, distribute, sublicense, and/or */
/* sell copies of the Software, and to permit persons to whom the */
/* Software is furnished to do so, subject to the following */
/* conditions: */
/* */
/* The above copyright notice and this permission notice shall be */
/* included in all copies or substantial portions of the */
/* Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND */
/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES */
/* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND */
/* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT */
/* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, */
/* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING */
/* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR */
/* OTHER DEALINGS IN THE SOFTWARE. */
/* */
/************************************************************************/
#ifndef VIGRA_IMPEXBASE_HXX
#define VIGRA_IMPEXBASE_HXX
#include <string>
#include "inspectimage.hxx"
#include "sized_int.hxx"
#include "utilities.hxx"
namespace vigra
{
typedef enum
{
UNSIGNED_INT_8,
UNSIGNED_INT_16,
UNSIGNED_INT_32,
SIGNED_INT_16,
SIGNED_INT_32,
IEEE_FLOAT_32,
IEEE_FLOAT_64
} pixel_t;
namespace detail
{
inline static pixel_t
pixel_t_of_string(const std::string& pixel_type)
{
if (pixel_type == "UINT8")
{
return UNSIGNED_INT_8;
}
else if (pixel_type == "UINT16")
{
return UNSIGNED_INT_16;
}
else if (pixel_type == "UINT32")
{
return UNSIGNED_INT_32;
}
else if (pixel_type == "INT16")
{
return SIGNED_INT_16;
}
else if (pixel_type == "INT32")
{
return SIGNED_INT_32;
}
else if (pixel_type == "FLOAT")
{
return IEEE_FLOAT_32;
}
else if (pixel_type == "DOUBLE")
{
return IEEE_FLOAT_64;
}
else
{
vigra_fail("vigra_ext::detail::pixel_t_of_string: unknown pixel type");
return UNSIGNED_INT_8; // NOT REACHED
}
}
struct identity
{
template <typename T>
T operator()(T x) const
{
return x;
}
};
typedef pair<double, double> range_t;
class linear_transform
{
public:
linear_transform(const range_t& source, const range_t& destination) :
scale_((destination.second - destination.first) / (source.second - source.first)),
offset_(destination.first / scale_ - source.first)
{}
template <typename T>
double operator()(T x) const
{
return scale_ * (static_cast<double>(x) + offset_);
}
private:
const double scale_;
const double offset_;
};
template <class Iterator, class Accessor>
inline static range_t
find_value_range(Iterator upper_left, Iterator lower_right, Accessor accessor,
/* is_scalar? */ VigraTrueType)
{
typedef typename Accessor::value_type value_type;
FindMinMax<value_type> extrema;
inspectImage(upper_left, lower_right, accessor, extrema);
return range_t(static_cast<double>(extrema.min), static_cast<double>(extrema.max));
}
template <class Iterator, class Accessor>
inline static range_t
find_value_range(Iterator upper_left, Iterator lower_right, Accessor accessor,
/* is_scalar? */ VigraFalseType)
{
typedef typename Accessor::ElementAccessor element_accessor;
typedef typename element_accessor::value_type value_type;
const int number_of_bands(static_cast<int>(accessor.size(upper_left)));
FindMinMax<value_type> extrema;
for (int i = 0; i != number_of_bands; ++i)
{
element_accessor band(i, accessor);
inspectImage(upper_left, lower_right, band, extrema);
}
return range_t(static_cast<double>(extrema.min), static_cast<double>(extrema.max));
}
template <class SourceIterator, class SourceAccessor>
inline static range_t
find_source_value_range(const ImageExportInfo& export_info,
SourceIterator upper_left, SourceIterator lower_right, SourceAccessor accessor)
{
if (export_info.getFromMin() < export_info.getFromMax())
{
return range_t(export_info.getFromMin(), export_info.getFromMax());
}
else
{
typedef typename SourceAccessor::value_type SourceValueType;
typedef typename NumericTraits<SourceValueType>::isScalar is_scalar;
const range_t range(find_value_range(upper_left, lower_right, accessor, is_scalar()));
if (range.first < range.second)
{
return range_t(range.first, range.second);
}
else
{
return range_t(range.first, range.first + 1.0);
}
}
}
template <typename T>
inline static range_t
find_destination_value_range(const ImageExportInfo& export_info)
{
if (export_info.getToMin() < export_info.getToMax())
{
return range_t(export_info.getToMin(), export_info.getToMax());
}
else
{
return range_t(static_cast<double>(NumericTraits<T>::min()),
static_cast<double>(NumericTraits<T>::max()));
}
}
inline static range_t
find_destination_value_range(const ImageExportInfo& export_info, pixel_t pixel_type)
{
switch (pixel_type)
{
case UNSIGNED_INT_8: return find_destination_value_range<UInt8>(export_info);
case UNSIGNED_INT_16: return find_destination_value_range<UInt16>(export_info);
case UNSIGNED_INT_32: return find_destination_value_range<UInt32>(export_info);
case SIGNED_INT_16: return find_destination_value_range<Int16>(export_info);
case SIGNED_INT_32: return find_destination_value_range<Int32>(export_info);
case IEEE_FLOAT_32: return find_destination_value_range<float>(export_info);
case IEEE_FLOAT_64: return find_destination_value_range<double>(export_info);
default:
vigra_fail("vigra_ext::detail::find_destination_value_range: not reached");
return range_t(0.0, 0.0); // NOT REACHED
}
}
} // end namespace detail
} // end namespace vigra
#endif // VIGRA_IMPEXBASE_HXX
|