7 #include <cvd/internal/convert_pixel_types.h> 8 #include <cvd/internal/pixel_traits.h> 29 template <
class S,
class T>
32 if(size.x == -1 && size.y == -1)
36 if(!(in.in_image(begin) && out.in_image(dst) && in.in_image(begin + size -
ImageRef(1, 1)) && out.in_image(dst + size -
ImageRef(1, 1))))
38 std::cerr <<
"bad copy: " << in.
size() <<
" " << out.
size() <<
" " << size <<
" " << begin <<
" " << dst << std::endl;
48 const S* from = &in[begin];
59 template <class T, bool pod = std::is_pod<T>::value>
62 static void zero(T& t)
64 for(
unsigned int c = 0; c < Pixel::Component<T>::count; c++)
72 static void zero(T& t) { memset(&t, 0,
sizeof(T)); }
75 template <class T, bool pod = std::is_pod<T>::value>
78 static void zero(T* pixels,
int count)
83 std::fill(pixels + 1, pixels + count, *pixels);
91 static void zero(T* pixels,
int count)
93 memset(pixels, 0,
sizeof(T) * count);
114 for(
int r = 0; r < I.
size().y - 1; r++)
128 for(
int n = 0; n < w; n++)
129 for(
int x = 0; x < im.
size().x; x++)
132 im[im.
size().y - 1 - n][x] = pix;
135 for(
int y = w; y < im.
size().y - w; y++)
136 for(
int n = 0; n < w; n++)
139 im[y][im.
size().x - 1 - n] = pix;
146 template <
class A,
class B>
147 inline void differences(
const A* a,
const A* b, B* diff,
size_t count)
150 *(diff++) = (B) * (a++) - (B) * (b++);
156 template <
class A,
class B,
class C>
160 *(out++) += (*(a++) + *(b++)) * c;
166 template <
class A,
class B,
class C>
170 *(out++) = static_cast<C>(*(a++) * c);
181 dot += *(a++) * *(b++);
185 template <
class R,
class D,
class T>
200 template <
class T1,
class T2>
201 inline void square(
const T1* in, T2* out,
size_t count)
205 *(out++) = static_cast<T2>(*in * *in);
210 template <
class T1,
class T2>
211 inline void subtract_square(
const T1* in, T2* out,
size_t count)
215 *(out++) -= static_cast<T2>(*in * *in);
233 inline bool is_aligned<8>(
const void* ptr) {
return ((reinterpret_cast<size_t>(ptr)) & 0x7) == 0; }
235 inline bool is_aligned<16>(
const void* ptr) {
return ((reinterpret_cast<size_t>(ptr)) & 0xF) == 0; }
238 template <
int A,
class T>
241 return is_aligned<A>(ptr) ? 0 : (A - ((reinterpret_cast<size_t>(ptr)) & (A - 1))) /
sizeof(T);
245 void differences(
const short* a,
const short* b,
short* diff,
unsigned int size);
247 void differences(
const float* a,
const float* b,
float* diff,
size_t size);
248 void add_multiple_of_sum(
const float* a,
const float* b,
const float& c,
float* out,
size_t count);
249 void assign_multiple(
const float* a,
const float& c,
float* out,
size_t count);
250 double inner_product(
const float* a,
const float* b,
size_t count);
252 void square(
const float* in,
float* out,
size_t count);
253 void subtract_square(
const float* in,
float* out,
size_t count);
255 void differences(
const int32_t* a,
const int32_t* b, int32_t* diff,
size_t size);
256 void differences(
const double* a,
const double* b,
double* diff,
size_t size);
257 void add_multiple_of_sum(
const double* a,
const double* b,
const double& c,
double* out,
size_t count);
258 void assign_multiple(
const double* a,
const double& c,
double* out,
size_t count);
259 double inner_product(
const double* a,
const double* b,
size_t count);
All classes and functions are within the CVD namespace.
Definition: argb.h:6
double sum_squared_differences(const T *a, const T *b, size_t count)
Compute sum of (a_i - b_i)^2 (the SSD) This is accelerated using SIMD for some platforms and data typ...
Definition: utility.h:224
ImageRef size() const
What is the size of this image?
Definition: image.h:557
Definition: utility.h:186
void add_multiple_of_sum(const A *a, const A *b, const C &c, B *out, size_t count)
Compute pointwise (a_i + b_i) * c and add to out_i This is accelerated using SIMD for some platforms ...
Definition: utility.h:157
void fillBorders(BasicImage< T > &im, const T pix, int w=1)
Fill image borders.
Definition: utility.h:125
void copy(const BasicImage< S > &in, BasicImage< T > &out, ImageRef size=ImageRef(-1, -1), ImageRef begin=ImageRef(), ImageRef dst=ImageRef())
Generic image copy function for copying sub rectangles of images into other images.
Definition: utility.h:30
size_t steps_to_align(const T *ptr)
Compute the number of pointer increments necessary to yield alignment of A bytes. ...
Definition: utility.h:239
int x
The x co-ordinate.
Definition: image_ref.h:172
double inner_product(const T *a, const T *b, size_t count)
Compute sum(a_i*b_i) This is accelerated using SIMD for some platforms and data types (alignment is c...
Definition: utility.h:177
Definition: image_ref.h:29
void zeroBorders(BasicImage< T > &I)
Set the one-pixel border (top, bottom, sides) of an image to zero values.
Definition: utility.h:109
unsigned char byte
An 8-bit datatype.
Definition: byte.h:8
A generic image class to manage a block of arbitrarily padded data as an image.
Definition: image.h:273
void convert_image(const BasicImage< bayer_bggr > &from, BasicImage< byte > &to)
Convert Bayer pattern of various forms to greyscale data.
void zeroPixel(T &pixel)
Set a pixel to the default value (typically 0) For multi-component pixels, this zeros all components ...
Definition: utility.h:100
Definition: convert_pixel_types.h:441
void assign_multiple(const A *a, const B &c, C *out, size_t count)
Compute pointwise a_i * c and store in out_i This is accelerated using SIMD for some platforms and da...
Definition: utility.h:167
Definition: builtin_components.h:38
void differences(const A *a, const A *b, B *diff, size_t count)
Compute pointwise differences (a_i - b_i) and store in diff_i This is accelerated using SIMD for some...
Definition: utility.h:147
bool is_aligned(const void *ptr)
Check if the pointer is aligned to the specified byte granularity.
void zeroPixels(T *pixels, int count)
Set many pixels to the default value (typically 0) For multi-component pixels, this zeros all compone...
Definition: utility.h:105