banned raw void pointer from public API

This commit is contained in:
Hartmut Seichter 2022-06-07 17:13:02 +02:00
parent 2b312f3494
commit a5830ad9cd
5 changed files with 25 additions and 19 deletions

View file

@ -65,8 +65,8 @@ void register_core_function(sol::state& lua,sol::table& ns)
sol::call_constructor,sol::constructors<matrix4x4()>(), sol::call_constructor,sol::constructors<matrix4x4()>(),
"row",&matrix4x4::row, "row",&matrix4x4::row,
"column",&matrix4x4::column, "column",&matrix4x4::column,
"inverse",sol::readonly_property(&matrix4x4::inverse), "inverse", sol::readonly_property(&matrix4x4::inverse),
"identity",sol::readonly_property(matrix4x4::identity), "identity",sol::readonly_property(&matrix4x4::identity),
sol::meta_function::multiplication,[](const matrix4x4& a,const vector4& b) { return vector4(a * b); } sol::meta_function::multiplication,[](const matrix4x4& a,const vector4& b) { return vector4(a * b); }
); );
@ -229,13 +229,13 @@ void register_core_function(sol::state& lua,sol::table& ns)
auto image_type = ns.new_usertype<image>("image" auto image_type = ns.new_usertype<image>("image"
,sol::call_constructor,sol::constructors<image(),image(const size&,image::pixel_layout pl,const void*)>() ,sol::call_constructor,sol::constructors<image(),image(const size&,image::pixel_layout pl,const image::data_t*)>()
,"create",&image::create ,"create", &image::create
,"release",&image::release ,"release", &image::release
,"is_valid",sol::readonly_property(&image::is_valid) ,"is_valid", sol::readonly_property(&image::is_valid)
,"size",sol::readonly_property(&image::size) ,"size", sol::readonly_property(&image::size)
,"generate_noise",&image::generate_noise ,"generate_noise", &image::generate_noise
,"change_count",sol::property(&image::change_count,&image::set_change_count) ,"change_count", sol::property(&image::change_count,&image::set_change_count)
); );
ns.create_named("pixel_layout" ns.create_named("pixel_layout"

View file

@ -43,9 +43,10 @@ public:
HDR HDR
}; };
image(const size& s, pixel_layout t, const void *ptr = nullptr);
bool create(const size& s, pixel_layout t, const void *ptr = nullptr); image(const size& s, pixel_layout t, const data_t *ptr = nullptr);
bool create(const size& s, pixel_layout t, const data_t *ptr = nullptr);
void release(bool release_memory = false); void release(bool release_memory = false);
@ -72,9 +73,9 @@ public:
protected: protected:
::pw::size _size; ::pw::size _size { 0, 0 };
pixel_layout _layout; pixel_layout _layout { pixel_layout::RGB8 };
uint64_t _change_count; uint64_t _change_count { 0 };
std::vector<data_t> _data; std::vector<data_t> _data;

View file

@ -6,7 +6,9 @@
namespace pw { namespace pw {
image::image(const ::pw::size &s, image::pixel_layout t, const void *ptr) image::image(const ::pw::size &s,
image::pixel_layout t,
const data_t *ptr)
{ {
if (!this->create(s,t,ptr)) { if (!this->create(s,t,ptr)) {
debug::w() << __PRETTY_FUNCTION__ << " create failed"; debug::w() << __PRETTY_FUNCTION__ << " create failed";
@ -15,7 +17,7 @@ image::image(const ::pw::size &s, image::pixel_layout t, const void *ptr)
bool image::create(const ::pw::size &s, bool image::create(const ::pw::size &s,
image::pixel_layout t, image::pixel_layout t,
const void *ptr) const data_t *ptr)
{ {
size_t n = bytes_per_pixel(t) * s.area(); size_t n = bytes_per_pixel(t) * s.area();
_size = s; _size = s;

View file

@ -18,13 +18,13 @@ struct image_io::impl
image read_impl(const std::string& uri,uint32_t flags) image read_impl(const std::string& uri,uint32_t flags)
{ {
int x{ 0 }, y{ 0 }, n{ 0 }; int x{ 0 }, y{ 0 }, n{ 0 };
auto data = stbi_load(uri.c_str(), &x, &y, &n, 4); const auto data = stbi_load(uri.c_str(), &x, &y, &n, 4);
if (data) { if (data) {
image r; image r;
r.create(size(x,y),image::pixel_layout::RGBA8,data); r.create(size(x,y),image::pixel_layout::RGBA8,reinterpret_cast<image::data_t*>(data));
stbi_image_free(data); stbi_image_free(data);

View file

@ -13,8 +13,11 @@ for k,v in pairs(pw.path.get().resource_paths) do
end end
-- create image
local img = pw.image() local img = pw.image()
if not img:create(pw.size(512,512),pw.pixel_layout.rgb8) then
-- initialize with data
if not img:create(pw.size(512,512),pw.pixel_layout.rgb8,nil) then
print("image couldnt be created") print("image couldnt be created")
else else