vil_clamp.cxx
Go to the documentation of this file.
1 // This is core/vil/vil_clamp.cxx
2 //:
3 // \file
4 // \author Ian Scott.
5 //
6 // \verbatim
7 // Modifications
8 // 23 Oct.2003 - Peter Vanroose - Added support for 64-bit int pixels
9 // \endverbatim
10 //
11 //-----------------------------------------------------------------------------
12 
13 #include <cstring>
14 #include "vil_clamp.h"
15 #ifdef _MSC_VER
16 # include <vcl_msvc_warnings.h>
17 #endif
18 #include <cassert>
19 #include <vil/vil_property.h>
20 #include <vil/vil_exception.h>
21 
22 
23 vil_image_resource_sptr vil_clamp(const vil_image_resource_sptr &src, double lo, double hi)
24 {
25  return new vil_clamp_image_resource(src, lo, hi);
26 }
27 
28 
30  src_(src),
31  lo_(lo),
32  hi_(hi)
33 {
34  assert (lo <= hi);
35 }
36 
37  //: Extra property information
38 bool vil_clamp_image_resource::get_property(char const* tag, void* property_value) const
39 {
40  if (0==std::strcmp(tag, vil_property_read_only))
41  return property_value ? (*static_cast<bool*>(property_value)) = true : true;
42 
43  return src_->get_property(tag, property_value);
44 }
45 
47  unsigned j0, unsigned nj) const
48 {
49  vil_image_view_base_sptr vs = src_->get_copy_view(i0, ni, j0, nj);
50  if (!vs) return nullptr;
51 
52  switch (vs->pixel_format())
53  {
54 #define macro( F , T ) \
55  case F : \
56  vil_clamp(static_cast<vil_image_view<T >&>(*vs), static_cast<vil_image_view<T >&>(*vs), \
57  T (lo_), T (hi_)); \
58  break;
59 
60  macro(VIL_PIXEL_FORMAT_BYTE , vxl_byte )
61  macro(VIL_PIXEL_FORMAT_SBYTE , vxl_sbyte )
62 #if VXL_HAS_INT_64
63  macro(VIL_PIXEL_FORMAT_UINT_64 , vxl_uint_64 )
64  macro(VIL_PIXEL_FORMAT_INT_64 , vxl_int_64 )
65 #endif
66  macro(VIL_PIXEL_FORMAT_UINT_32 , vxl_uint_32 )
67  macro(VIL_PIXEL_FORMAT_INT_32 , vxl_int_32 )
68  macro(VIL_PIXEL_FORMAT_UINT_16 , vxl_uint_16 )
69  macro(VIL_PIXEL_FORMAT_INT_16 , vxl_int_16 )
72 // How might you clamp a std::complex image ?
73 #undef macro
74  default:
76  vs->pixel_format(), "vil_clamp_image_resource::get_copy_view") );
77  return nullptr;
78  }
79  return vs;
80 }
Indicates that a function call failed because a pixel format could not be handled.
Definition: vil_exception.h:62
void vil_clamp(const vil_image_view< T > &src, vil_image_view< T > &dest, T lo, T hi)
Clamp an image view between two values.
Definition: vil_clamp.h:23
unsigned ni() const override
Dimensions: Planes x ni x nj.
Definition: vil_clamp.h:53
Exceptions thrown by vil, and a mechanism for turning them off.
A generic_image adaptor that behaves like a clamped version of its input.
Definition: vil_clamp.h:46
unsigned nj() const override
Dimensions: Planes x ni x nj.
Definition: vil_clamp.h:54
#define macro(F, T)
vil_image_view_base_sptr get_copy_view() const
Create a read/write view of a copy of all the data.
There is no class or function called vil_property.
vil_image_resource_sptr src_
Reference to underlying image source.
Definition: vil_clamp.h:75
void vil_exception_warning(T exception)
Throw an exception indicating a potential problem.
Definition: vil_exception.h:37
#define vil_property_read_only
Indicate that you can't call put_view on this image.
Definition: vil_property.h:47
vil_clamp_image_resource(vil_image_resource_sptr const &, double low, double high)
Definition: vil_clamp.cxx:28
bool get_property(char const *tag, void *property_value=nullptr) const override
Extra property information.
Definition: vil_clamp.cxx:37