banned raw void pointer from public API
This commit is contained in:
parent
2b312f3494
commit
a5830ad9cd
5 changed files with 25 additions and 19 deletions
|
@ -65,8 +65,8 @@ void register_core_function(sol::state& lua,sol::table& ns)
|
|||
sol::call_constructor,sol::constructors<matrix4x4()>(),
|
||||
"row",&matrix4x4::row,
|
||||
"column",&matrix4x4::column,
|
||||
"inverse",sol::readonly_property(&matrix4x4::inverse),
|
||||
"identity",sol::readonly_property(matrix4x4::identity),
|
||||
"inverse", sol::readonly_property(&matrix4x4::inverse),
|
||||
"identity",sol::readonly_property(&matrix4x4::identity),
|
||||
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"
|
||||
,sol::call_constructor,sol::constructors<image(),image(const size&,image::pixel_layout pl,const void*)>()
|
||||
,"create",&image::create
|
||||
,"release",&image::release
|
||||
,"is_valid",sol::readonly_property(&image::is_valid)
|
||||
,"size",sol::readonly_property(&image::size)
|
||||
,"generate_noise",&image::generate_noise
|
||||
,"change_count",sol::property(&image::change_count,&image::set_change_count)
|
||||
,sol::call_constructor,sol::constructors<image(),image(const size&,image::pixel_layout pl,const image::data_t*)>()
|
||||
,"create", &image::create
|
||||
,"release", &image::release
|
||||
,"is_valid", sol::readonly_property(&image::is_valid)
|
||||
,"size", sol::readonly_property(&image::size)
|
||||
,"generate_noise", &image::generate_noise
|
||||
,"change_count", sol::property(&image::change_count,&image::set_change_count)
|
||||
);
|
||||
|
||||
ns.create_named("pixel_layout"
|
||||
|
|
|
@ -43,9 +43,10 @@ public:
|
|||
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);
|
||||
|
||||
|
@ -72,9 +73,9 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
::pw::size _size;
|
||||
pixel_layout _layout;
|
||||
uint64_t _change_count;
|
||||
::pw::size _size { 0, 0 };
|
||||
pixel_layout _layout { pixel_layout::RGB8 };
|
||||
uint64_t _change_count { 0 };
|
||||
|
||||
std::vector<data_t> _data;
|
||||
|
||||
|
|
|
@ -6,7 +6,9 @@
|
|||
|
||||
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)) {
|
||||
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,
|
||||
image::pixel_layout t,
|
||||
const void *ptr)
|
||||
const data_t *ptr)
|
||||
{
|
||||
size_t n = bytes_per_pixel(t) * s.area();
|
||||
_size = s;
|
||||
|
|
|
@ -18,13 +18,13 @@ struct image_io::impl
|
|||
image read_impl(const std::string& uri,uint32_t flags)
|
||||
{
|
||||
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) {
|
||||
|
||||
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);
|
||||
|
||||
|
|
|
@ -13,8 +13,11 @@ for k,v in pairs(pw.path.get().resource_paths) do
|
|||
end
|
||||
|
||||
|
||||
-- create 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")
|
||||
else
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue