10#ifndef MVE_IMAGEDRAWING_HEADER
11#define MVE_IMAGEDRAWING_HEADER
29draw_line (Image<T>& image, int64_t x1, int64_t y1, int64_t x2, int64_t y2,
39draw_circle (Image<T>& image, int64_t x, int64_t y, int64_t radius,
48draw_rectangle (Image<T>& image, int64_t x1, int64_t y1, int64_t x2, int64_t y2,
65 int64_t
const chans = image.
channels();
66 int64_t
const row_stride = image.
width() * chans;
68 int64_t
const dx = std::abs(x1 - x0);
69 int64_t
const dy = std::abs(y1 - y0) ;
70 int64_t
const sx = x0 < x1 ? 1 : -1;
71 int64_t
const sy = y0 < y1 ? 1 : -1;
72 int64_t err = dx - dy;
74 T* ptr = &image.
at(x0, y0, 0);
77 std::copy(color, color + chans, ptr);
78 if (x0 == x1 && y0 == y1)
80 int64_t
const e2 = 2 * err;
91 ptr += sy * row_stride;
103 int64_t
const chans = image.
channels();
104 int64_t
const row_stride = image.
width() * chans;
105 T*
const ptr = &image.
at(x, y, 0);
106 std::copy(color, color + chans, ptr - radius * row_stride);
107 std::copy(color, color + chans, ptr - radius * chans);
108 std::copy(color, color + chans, ptr + radius * chans);
109 std::copy(color, color + chans, ptr + radius * row_stride);
111 int64_t f = 1 - radius;
113 int64_t ddf_y = -2 * radius;
128 std::copy(color, color + chans, ptr + xi * chans + yi * row_stride);
129 std::copy(color, color + chans, ptr - xi * chans + yi * row_stride);
130 std::copy(color, color + chans, ptr + xi * chans - yi * row_stride);
131 std::copy(color, color + chans, ptr - xi * chans - yi * row_stride);
132 std::copy(color, color + chans, ptr + xi * row_stride + yi * chans);
133 std::copy(color, color + chans, ptr - xi * row_stride + yi * chans);
134 std::copy(color, color + chans, ptr + xi * row_stride - yi * chans);
135 std::copy(color, color + chans, ptr - xi * row_stride - yi * chans);
148 x1 = std::max<int64_t>(0, x1);
149 x2 = std::max<int64_t>(0, x2);
150 x1 = std::min<int64_t>(image.
width() - 1, x1);
151 x2 = std::min<int64_t>(image.
width() - 1, x2);
152 y1 = std::max<int64_t>(0, y1);
153 y2 = std::max<int64_t>(0, y2);
154 y1 = std::min<int64_t>(image.
height() - 1, y1);
155 y2 = std::min<int64_t>(image.
height() - 1, y2);
158 T* ptr = image.
begin();
159 for (int64_t y = y1; y <= y2; ++y)
160 for (int64_t x = x1; x <= x2; ++x)
161 std::copy(color, color + image.
channels(),
162 ptr + x * image.
channels() + y * row_stride);
int64_t height(void) const
Returns the height of the image.
int64_t channels(void) const
Returns the amount of channels in the image.
int64_t width(void) const
Returns the width of the image.
Multi-channel image class of arbitrary but homogenous data type.
T const & at(int64_t index) const
Linear indexing of image data.
T * begin(void)
Returns data pointer to beginning.
#define MVE_IMAGE_NAMESPACE_END
#define MVE_NAMESPACE_BEGIN
#define MVE_IMAGE_NAMESPACE_BEGIN
#define MVE_NAMESPACE_END
void draw_line(Image< T > &image, int64_t x1, int64_t y1, int64_t x2, int64_t y2, T const *color)
Draws a line from (x0,y0) to (x1,y1) with given color on the image.
void draw_rectangle(Image< T > &image, int64_t x1, int64_t y1, int64_t x2, int64_t y2, T const *color)
Draws a rectangle from (x1,y1) to (x2,y2) on the image.
void draw_circle(Image< T > &image, int64_t x, int64_t y, int64_t radius, T const *color)
Draws a circle with midpoint (x,y) and given 'radius' on the image.
void swap(mve::Image< T > &a, mve::Image< T > &b)
Specialization of std::swap for efficient image swapping.