24 #ifndef _SEIMPLEMENTATION_IMAGE_WRITEABLEIMAGEINTERFACETRAITS_H_ 25 #define _SEIMPLEMENTATION_IMAGE_WRITEABLEIMAGEINTERFACETRAITS_H_ 43 class WriteableIterator;
45 class WriteableSetter {
50 friend class WriteableIterator;
56 m_image->setValue(m_x, m_y, v);
61 v += m_image->getValue(m_x, m_y);
62 m_image->setValue(m_x, m_y, v);
67 return m_image->getValue(m_x, m_y);
71 class WriteableIterator :
std::iterator<std::forward_iterator_tag, WriteableInterfaceType::PixelType> {
81 m_width{image->getWidth()},
82 m_height{image->getHeight()},
83 m_setter{image, 0, 0} {
91 return m_x != b.m_x || m_y != b.m_y || m_width != b.m_width || m_height != b.m_height || m_image != b.m_image;
100 if (m_y >= m_height) {
109 return m_image->getValue(m_x, m_y);
126 return image->getWidth();
130 return image->getHeight();
134 return WriteableSetter(image,
x,
y);
138 return image->getValue(
x,
y);
142 return WriteableIterator{image};
146 return WriteableIterator{image, 0};
150 double scale_factor,
double x,
double y);
159 double x_shift,
double y_shift) {
160 int window_width =
width(window);
161 int window_height =
height(window);
162 for (
int x_win = 0; x_win < window_width; x_win++) {
163 for (
int y_win = 0; y_win < window_height; y_win++) {
164 double x = (x_win - 0.5 - x_shift) / scale_factor;
165 double y = (y_win - 0.5 - y_shift) / scale_factor;
170 double x_delta =
x - xi;
171 double y_delta =
y - yi;
176 double v11 =
getClamped(source, xi + 1, yi + 1);
178 window->setValue(x_win, y_win, (1.0 - y_delta) * ((1.0 - x_delta) * v00 + x_delta * v10) +
179 y_delta * ((1.0 - x_delta) * v01 + x_delta * v11));
187 double x_shift,
double y_shift) {
188 int window_width =
width(window);
189 int window_height =
height(window);
190 for (
int x_win = 0; x_win < window_width; x_win++) {
191 for (
int y_win = 0; y_win < window_height; y_win++) {
192 float x = (x_win - x_shift) / scale_factor;
193 float y = (y_win - y_shift) / scale_factor;
205 if (source->isInside(src_x, src_y)) {
211 window->setValue(x_win, y_win,
237 double scale_factor,
double x,
double y) {
239 double scaled_width =
width(image2) * scale_factor;
240 double scaled_height =
height(image2) * scale_factor;
244 int window_width = x_max - x_min;
246 int y_max =
std::ceil(
y + scaled_height / 2.);
247 int window_height = y_max - y_min;
249 double x_shift =
x - scaled_width / 2. - x_min;
250 double y_shift =
y - scaled_height / 2. - y_min;
252 auto window =
factory(window_width, window_height);
259 double corr_factor = 1. / (scale_factor * scale_factor);
261 for (
int x_im =
std::max(x_min, 0); x_im < std::min<int>(x_max,
width(image1)); ++x_im) {
262 for (
int y_im =
std::max(y_min, 0); y_im < std::min<int>(y_max,
height(image1)); ++y_im) {
263 int x_win = x_im - x_min;
264 int y_win = y_im - y_min;
265 at(image1, x_im, y_im) += corr_factor *
at(window, x_win, y_win);
static ImageType factory(std::size_t width, std::size_t height)
#define INTERP_MAXKERNELWIDTH
static std::size_t height(const WriteableInterfaceTypePtr &image)
WriteableIterator iterator
SourceXtractor::WriteableImage< SourceXtractor::SeFloat > WriteableInterfaceType
static std::size_t height(ImageType &image)
static WriteableInterfaceTypePtr factory(std::size_t width, std::size_t height)
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > x
static double & at(ImageType &image, std::size_t x, std::size_t y)
auto operator*(T v, const ImageTraits< WriteableInterfaceTypePtr >::WriteableSetter &setter) -> decltype(v *WriteableInterfaceType::PixelType(0))
static void addImageToImage(ImageType &image1, const ImageType &image2, double scale, double x, double y)
WriteableInterfaceType::PixelType operator+=(WriteableInterfaceType::PixelType v)
static iterator end(const WriteableInterfaceTypePtr &image)
WriteableIterator(WriteableInterfaceTypePtr image, int)
std::shared_ptr< DependentParameter< std::shared_ptr< EngineParameter > > > y
WriteableSetter(WriteableInterfaceTypePtr &image, int x, int y)
WriteableSetter & operator*()
WriteableInterfaceType::PixelType operator=(WriteableInterfaceType::PixelType v)
static double getClamped(const WriteableInterfaceTypePtr &image, int x, int y)
WriteableInterfaceTypePtr m_image
static iterator begin(const WriteableInterfaceTypePtr &image)
WriteableIterator & operator++()
static WriteableSetter at(WriteableInterfaceTypePtr &image, std::size_t x, std::size_t y)
static std::size_t width(const WriteableInterfaceTypePtr &image)
static void shiftResize(const WriteableInterfaceTypePtr &source, WriteableInterfaceTypePtr &window, double scale_factor, double x_shift, double y_shift)
static void shiftResizeLancszos(const WriteableInterfaceTypePtr &source, WriteableInterfaceTypePtr &window, double scale_factor, double x_shift, double y_shift)
static ImageInterfaceType::PixelType at(const WriteableInterfaceTypePtr &image, std::size_t x, std::size_t y)
WriteableInterfaceTypePtr m_image
std::shared_ptr< WriteableInterfaceType > WriteableInterfaceTypePtr
WriteableInterfaceType::PixelType operator*() const
static std::size_t width(ImageType &image)
bool operator!=(const WriteableIterator &b) const
WriteableIterator(WriteableInterfaceTypePtr image)