00001 #ifndef __IMAGE_SAMPLER_H__ 00002 #define __IMAGE_SAMPLER_H__ 00003 #include <stdint.h> 00004 #include "stm_export.h" 00005 00006 namespace spectral 00007 { 00008 00009 class Image; 00010 00012 class STM_EXPORT ImageSampler 00013 { 00014 public: 00015 enum EdgeMode 00016 { 00017 BACKGROUND, 00018 CLAMP, 00019 REFLECT, 00020 WRAP 00021 }; 00022 00023 ImageSampler(EdgeMode h, EdgeMode v) 00024 : m_horizontalWrap(h) 00025 , m_verticalWrap(v) 00026 { 00027 } 00028 00029 virtual ~ImageSampler() 00030 { 00031 } 00032 00033 virtual void SampleImage(const Image *image, 00034 float x, float y, 00035 const float *bg, 00036 float *result) const = 0; 00037 00038 void GetEdgeMode(EdgeMode &h, EdgeMode &v) const; 00039 00040 protected: 00041 const float *GetPixel(const Image *image, float x, float y) const; 00042 const float *GetPixel(const Image *image, int32_t x, int32_t y) const; 00043 private: 00044 const EdgeMode m_horizontalWrap, m_verticalWrap; 00045 }; 00046 00048 class STM_EXPORT NearestNeighbourSampler : public ImageSampler 00049 { 00050 public: 00051 NearestNeighbourSampler(EdgeMode h, EdgeMode v) 00052 : ImageSampler(h, v) 00053 { 00054 } 00055 00056 virtual ~NearestNeighbourSampler() 00057 { 00058 } 00059 00060 virtual void SampleImage(const Image *image, 00061 float x, float y, 00062 const float *bg, 00063 float *result) const; 00064 }; 00065 00067 class STM_EXPORT LanczosSampler : public ImageSampler 00068 { 00069 public: 00070 LanczosSampler(EdgeMode h, EdgeMode v, float a) 00071 : ImageSampler(h, v) 00072 , m_a(a) 00073 { 00074 } 00075 00076 virtual ~LanczosSampler() 00077 { 00078 } 00079 00080 virtual void SampleImage(const Image *image, 00081 float x, float y, 00082 const float *bg, 00083 float *result) const; 00084 private: 00085 const float m_a; 00086 }; 00087 00088 } 00089 00090 #endif 00091