Sfoglia il codice sorgente

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> 10 anni fa
parent
commit
2511de1f90
6 ha cambiato i file con 43 aggiunte e 15 eliminazioni
  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 Vedi File

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

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

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


+ 1
- 1
src/image/dither/ordered.cpp Vedi File

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

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


+ 3
- 3
src/image/filter/convolution.cpp Vedi File

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

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;

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

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


+ 1
- 1
src/image/filter/median.cpp Vedi File

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

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


+ 1
- 1
src/image/kernel.cpp Vedi File

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

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

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


+ 36
- 8
src/lol/math/arraynd.h Vedi File

@@ -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()));

@@ -51,7 +51,7 @@ public:
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;

@@ -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()));
}

void FillValues(T * origin, ptrdiff_t prev, int * sizes)
void FillValues(T * origin, ptrdiff_t prev, ptrdiff_t * 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)
{
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)
{
m_sizes[N - 1] = initializer.size();
@@ -128,6 +135,21 @@ public:
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 */
inline element_t const & operator[](vec_t<int, N> const &pos) const
{
@@ -207,13 +229,19 @@ public:

/* Resize the array.
* 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;
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;
}
@@ -235,7 +263,7 @@ private:
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...>;


Caricamento…
Annulla
Salva