adding important low-level code for image and matrix manipulations

This commit is contained in:
Hartmut Seichter 2019-01-16 11:13:12 +01:00
parent 99fdade003
commit 46eff44297
4 changed files with 96 additions and 11 deletions

View file

@ -33,22 +33,36 @@ public:
image() = default;
enum image_type {
enum pixel_layout {
RGB8,
RGBA8,
LUM
};
bool create(const sizei& size,);
image(const sizei& s, pixel_layout t, void *ptr = nullptr);
bool create(const sizei& s, pixel_layout t, void *ptr = nullptr);
void destroy(bool release_memory = false);
const uint8_t *data() const { return _data.data(); }
uint8_t *data() { return _data.data(); }
pixel_layout layout() const;
void set_layout(const pixel_layout &layout);
uint64_t change_count() const;
void set_change_count(const uint64_t &change_count);
static uint32_t bytes_per_pixel(pixel_layout t);
protected:
sizei _size;
pixel_layout _layout;
uint64_t _change_count;
std::vector<uint8_t> _data;
std::string _uri;
};

View file

@ -487,8 +487,6 @@ public:
};
//////////////////////////////////////////////////////////////////////////
//
// Specializations
//

View file

@ -36,6 +36,8 @@ struct size_ {
size_(T_ w,T_ h) : width(w), height(h) {}
T_ area() const { return std::abs(width * height); }
};
typedef size_<real_t> size;

View file

@ -0,0 +1,71 @@
#include "pw/core/image.hpp"
#include <limits>
namespace pw {
image::image(const sizei &s, image::pixel_layout t, void *ptr)
{
}
bool image::create(const sizei &s, image::pixel_layout t, void *ptr)
{
auto n = bytes_per_pixel(t) * s.area();
if (ptr != nullptr) {
auto a = reinterpret_cast<uint8_t*>(ptr);
_data.assign(a,a + n);
} else {
_data.resize(n,0);
}
return !_data.empty();
}
void image::destroy(bool release_memory)
{
_data.clear();
if (release_memory) _data.shrink_to_fit();
}
uint32_t image::bytes_per_pixel(image::pixel_layout t)
{
switch (t) {
case pw::image::RGB8:
return 3;
case pw::image::RGBA8:
return 4;
case pw::image::LUM:
return 1;
}
return std::numeric_limits<uint32_t>::max();
}
image::pixel_layout image::layout() const
{
return _layout;
}
void image::set_layout(const pixel_layout &layout)
{
_layout = layout;
}
uint64_t image::change_count() const
{
return _change_count;
}
void image::set_change_count(const uint64_t &change_count)
{
_change_count = change_count;
}
}