Explorar el Código

arraynd: adding constructors and operators for vec_t<int, N> and vec_t<ptrdiff_t, N> types.

undefined
Guillaume Bittoun Sam Hocevar <sam@hocevar.net> hace 10 años
padre
commit
2511de1f90
Se han modificado 6 ficheros con 43 adiciones y 15 borrados
  1. +1
    -1
      src/image/dither/ediff.cpp
  2. +1
    -1
      src/image/dither/ordered.cpp
  3. +3
    -3
      src/image/filter/convolution.cpp
  4. +1
    -1
      src/image/filter/median.cpp
  5. +1
    -1
      src/image/kernel.cpp
  6. +36
    -8
      src/lol/math/arraynd.h

+ 1
- 1
src/image/dither/ediff.cpp Ver fichero

@@ -32,7 +32,7 @@ Image Image::DitherEdiff(array2d<float> const &kernel, ScanMode scan) const
Image dst = *this; Image dst = *this;


ivec2 size = dst.GetSize(); ivec2 size = dst.GetSize();
ivec2 ksize = kernel.GetSize();
ivec2 ksize = (ivec2)kernel.GetSize();


int kx; int kx;
for (kx = 0; kx < ksize.x; kx++) for (kx = 0; kx < ksize.x; kx++)


+ 1
- 1
src/image/dither/ordered.cpp Ver fichero

@@ -45,7 +45,7 @@ static Image DitherHelper(Image const &image, array2d<float> const &kernel,
float scale, float angle) float scale, float angle)
{ {
ivec2 size = image.GetSize(); ivec2 size = image.GetSize();
ivec2 ksize = kernel.GetSize();
ivec2 ksize = (ivec2)kernel.GetSize();


float cost = lol::cos(angle); float cost = lol::cos(angle);
float sint = lol::sin(angle); float sint = lol::sin(angle);


+ 3
- 3
src/image/filter/convolution.cpp Ver fichero

@@ -28,7 +28,7 @@ static Image NonSepConv(Image &src, array2d<float> const &kernel);
Image Image::Convolution(array2d<float> const &kernel) Image Image::Convolution(array2d<float> const &kernel)
{ {
/* Find the cell with the largest value */ /* Find the cell with the largest value */
ivec2 ksize = kernel.GetSize();
ivec2 ksize = (ivec2)kernel.GetSize();
int bestx = -1, besty = -1; int bestx = -1, besty = -1;
float tmp = 0.f; float tmp = 0.f;
for (int dy = 0; dy < ksize.y; ++dy) for (int dy = 0; dy < ksize.y; ++dy)
@@ -85,7 +85,7 @@ Image Image::Convolution(array2d<float> const &kernel)


Image Image::Sharpen(array2d<float> const &kernel) Image Image::Sharpen(array2d<float> const &kernel)
{ {
ivec2 ksize = kernel.GetSize();
ivec2 ksize = (ivec2)kernel.GetSize();
array2d<float> newkernel(ksize); array2d<float> newkernel(ksize);


for (int dy = 0; dy < ksize.y; ++dy) for (int dy = 0; dy < ksize.y; ++dy)
@@ -105,7 +105,7 @@ static Image NonSepConv(Image &src, array2d<float> const &kernel)
typedef typename PixelType<FORMAT>::type pixel_t; typedef typename PixelType<FORMAT>::type pixel_t;


ivec2 const size = src.GetSize(); ivec2 const size = src.GetSize();
ivec2 const ksize = kernel.GetSize();
ivec2 const ksize = (ivec2)kernel.GetSize();
Image dst(size); Image dst(size);


array2d<pixel_t> const &srcp = src.Lock2D<FORMAT>(); array2d<pixel_t> const &srcp = src.Lock2D<FORMAT>();


+ 1
- 1
src/image/filter/median.cpp Ver fichero

@@ -168,7 +168,7 @@ Image Image::Median(array2d<float> const &kernel) const
else else
#endif #endif
{ {
ivec2 const ksize = kernel.GetSize();
ivec2 const ksize = (ivec2)kernel.GetSize();
array2d<vec3> list(ksize); array2d<vec3> list(ksize);


vec4 *srcp = tmp.Lock<PixelFormat::RGBA_F32>(); vec4 *srcp = tmp.Lock<PixelFormat::RGBA_F32>();


+ 1
- 1
src/image/kernel.cpp Ver fichero

@@ -186,7 +186,7 @@ static int cmpdot(const void *p1, const void *p2)


array2d<float> Image::NormalizeKernel(array2d<float> const &kernel) array2d<float> Image::NormalizeKernel(array2d<float> const &kernel)
{ {
ivec2 size = kernel.GetSize();
ivec2 size = (ivec2)kernel.GetSize();


array<Dot> tmp; array<Dot> tmp;
tmp.Resize(size.x * size.y); tmp.Resize(size.x * size.y);


+ 36
- 8
src/lol/math/arraynd.h Ver fichero

@@ -43,7 +43,7 @@ public:
{ {
} }


void FillSizes(int * sizes)
void FillSizes(ptrdiff_t * sizes)
{ {
*sizes = std::max((ptrdiff_t)*sizes, (ptrdiff_t)(m_initializers.size())); *sizes = std::max((ptrdiff_t)*sizes, (ptrdiff_t)(m_initializers.size()));


@@ -51,7 +51,7 @@ public:
subinitializer.FillSizes(sizes - 1); subinitializer.FillSizes(sizes - 1);
} }


void FillValues(T * origin, ptrdiff_t prev, int * sizes)
void FillValues(T * origin, ptrdiff_t prev, ptrdiff_t * sizes)
{ {
ptrdiff_t pos = 0; ptrdiff_t pos = 0;


@@ -75,12 +75,12 @@ public:
{ {
} }


void FillSizes(int * sizes)
void FillSizes(ptrdiff_t * sizes)
{ {
*sizes = std::max((ptrdiff_t)*sizes, (ptrdiff_t)(m_initializers.size())); *sizes = std::max((ptrdiff_t)*sizes, (ptrdiff_t)(m_initializers.size()));
} }


void FillValues(T * origin, ptrdiff_t prev, int * sizes)
void FillValues(T * origin, ptrdiff_t prev, ptrdiff_t * sizes)
{ {
UNUSED(sizes); UNUSED(sizes);


@@ -107,12 +107,19 @@ public:
{ {
} }


inline arraynd(vec_t<int, N> sizes, element_t e = element_t())
inline arraynd(vec_t<ptrdiff_t, N> sizes, element_t e = element_t())
: m_sizes(sizes) : m_sizes(sizes)
{ {
FixSizes(e); FixSizes(e);
} }


inline arraynd(vec_t<int, N> sizes, element_t e = element_t())
{
m_sizes = vec_t<ptrdiff_t, N>(sizes);
FixSizes(e);
}


inline arraynd(std::initializer_list<arraynd_initializer<element_t, N - 1> > initializer) inline arraynd(std::initializer_list<arraynd_initializer<element_t, N - 1> > initializer)
{ {
m_sizes[N - 1] = initializer.size(); m_sizes[N - 1] = initializer.size();
@@ -128,6 +135,21 @@ public:
inner_initializer.FillValues(&super::operator[](0), pos++, &m_sizes[N - 2]); inner_initializer.FillValues(&super::operator[](0), pos++, &m_sizes[N - 2]);
} }


/* Access elements directly using an vec_t<ptrdiff_t, N> index */
inline element_t const & operator[](vec_t<ptrdiff_t, N> const &pos) const
{
ptrdiff_t n = pos[N - 1];
for (ptrdiff_t i = N - 2; i >= 0; --i)
n = pos[i] + m_sizes[i + 1] * n;
return super::operator[](n);
}

inline element_t & operator[](vec_t<ptrdiff_t, N> const &pos)
{
return const_cast<element_t &>(
const_cast<arraynd<N, T...> const&>(*this)[pos]);
}

/* Access elements directly using an ivec2, ivec3 etc. index */ /* Access elements directly using an ivec2, ivec3 etc. index */
inline element_t const & operator[](vec_t<int, N> const &pos) const inline element_t const & operator[](vec_t<int, N> const &pos) const
{ {
@@ -207,13 +229,19 @@ public:


/* Resize the array. /* Resize the array.
* FIXME: data gets scrambled; should we care? */ * FIXME: data gets scrambled; should we care? */
inline void SetSize(vec_t<int, N> sizes, element_t e = element_t())
inline void SetSize(vec_t<ptrdiff_t, N> sizes, element_t e = element_t())
{ {
m_sizes = sizes; m_sizes = sizes;
FixSizes(e); FixSizes(e);
} }


inline vec_t<int, N> GetSize() const
inline void SetSize(vec_t<int, N> sizes, element_t e = element_t())
{
m_sizes = vec_t<ptrdiff_t, N>(sizes);
FixSizes(e);
}

inline vec_t<ptrdiff_t, N> GetSize() const
{ {
return this->m_sizes; return this->m_sizes;
} }
@@ -235,7 +263,7 @@ private:
this->Resize(total_size, e); this->Resize(total_size, e);
} }


vec_t<int, N> m_sizes;
vec_t<ptrdiff_t, N> m_sizes;
}; };


template<typename... T> using array2d = arraynd<2, T...>; template<typename... T> using array2d = arraynd<2, T...>;


Cargando…
Cancelar
Guardar