diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 2965454..73942ce 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -4,6 +4,8 @@ add_subdirectory(deps) add_subdirectory(core) add_subdirectory(scene) add_subdirectory(system) +add_subdirectory(io) + #add_subdirectory(ui) add_subdirectory(scripting) add_subdirectory(visual) diff --git a/src/core/CMakeLists.txt b/src/core/CMakeLists.txt index dccf5cc..1656a2c 100644 --- a/src/core/CMakeLists.txt +++ b/src/core/CMakeLists.txt @@ -16,6 +16,7 @@ set(hdrs include/pw/core/timer.hpp include/pw/core/mesh.hpp include/pw/core/globals.hpp + include/pw/core/image.hpp ) set(srcs @@ -26,6 +27,7 @@ set(srcs src/core.cpp src/serialize.cpp src/timer.cpp + src/image.cpp ${CMAKE_SOURCE_DIR}/README.md ${CMAKE_SOURCE_DIR}/LICENSE ) diff --git a/src/core/include/pw/core/image.hpp b/src/core/include/pw/core/image.hpp index 1fc9107..4c50ea6 100644 --- a/src/core/include/pw/core/image.hpp +++ b/src/core/include/pw/core/image.hpp @@ -24,6 +24,7 @@ #define PW_CORE_IMAGE_HPP #include +#include namespace pw { @@ -32,12 +33,36 @@ public: image() = default; + enum pixel_layout { + RGB8, + RGBA8, + LUM + }; + 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: - std::vector _data; - std::string _uri; + sizei _size; + pixel_layout _layout; + uint64_t _change_count; + + std::vector _data; }; diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index a2de3b7..2f9a13f 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -487,8 +487,6 @@ public: }; -////////////////////////////////////////////////////////////////////////// - // // Specializations // diff --git a/src/core/include/pw/core/size.hpp b/src/core/include/pw/core/size.hpp index 6cf4e9e..69a9324 100644 --- a/src/core/include/pw/core/size.hpp +++ b/src/core/include/pw/core/size.hpp @@ -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_ size; diff --git a/src/core/src/image.cpp b/src/core/src/image.cpp index fdd0408..11c9e0e 100644 --- a/src/core/src/image.cpp +++ b/src/core/src/image.cpp @@ -1,7 +1,71 @@ #include "pw/core/image.hpp" +#include + 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(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::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; +} } diff --git a/src/deps/lua-5.3.5/CMakeLists.txt b/src/deps/lua-5.3.5/CMakeLists.txt index 8a5e67a..139832c 100644 --- a/src/deps/lua-5.3.5/CMakeLists.txt +++ b/src/deps/lua-5.3.5/CMakeLists.txt @@ -53,8 +53,7 @@ add_library (lualib STATIC ${libsrc} ) - - +target_compile_definitions(lualib PRIVATE LUA_USE_POSIX) if(UNIX) target_link_libraries( lualib m ) diff --git a/src/io/CMakeLists.txt b/src/io/CMakeLists.txt new file mode 100644 index 0000000..3b10b9d --- /dev/null +++ b/src/io/CMakeLists.txt @@ -0,0 +1,27 @@ + +set(hdrs + include/pw/io/image_io.hpp + ) + +set(srcs + src/image_io.cpp + ) + +add_library(pwio + STATIC + ${hdrs} + ${srcs} + ) + +target_include_directories( + pwio + PUBLIC + include + ) + +target_link_libraries(pwio pwcore) + + +#add_subdirectory(src) +#add_subdirectory(tests) + diff --git a/src/io/include/pw/io/image_io.hpp b/src/io/include/pw/io/image_io.hpp new file mode 100644 index 0000000..fce9c0e --- /dev/null +++ b/src/io/include/pw/io/image_io.hpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 1999-2019 Hartmut Seichter + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + * + */ + +#ifndef PW_IO_IMAGE_IO_HPP +#define PW_IO_IMAGE_IO_HPP + +#include + +namespace pw { + +class image_io { +public: + + static image_io& get(); + + image read(std::string const& uri,uint32_t flags = 0); + +protected: + + struct impl; + std::unique_ptr _impl; + + image_io() = default; + ~image_io() = default; + +}; + +} + +#endif diff --git a/src/io/src/image_io.cpp b/src/io/src/image_io.cpp new file mode 100644 index 0000000..2d42865 --- /dev/null +++ b/src/io/src/image_io.cpp @@ -0,0 +1,18 @@ +#include "pw/io/image_io.hpp" + +namespace pw { + + +struct image_io::impl +{ + +}; + + +image_io &image_io::get() +{ + static image_io instance; + return instance; +} + +} diff --git a/src/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index 34e06c1..38b6363 100644 --- a/src/scripting/src/script_system.cpp +++ b/src/scripting/src/script_system.cpp @@ -11,6 +11,7 @@ namespace pw { +#if defined(__clang) struct window_lua : public window { // overridable function sol::function lua_update; @@ -23,19 +24,21 @@ struct window_lua : public window { _on_update = [this](window&){this->lua_update();}; } }; +#endif void script_system::load(sol::table &ns) { + + ns.new_usertype("window", -// sol::constructors(), -// "on_update",&window_lua::lua_update, - "update",&window::update, - "title",sol::writeonly_property(&window::set_title), - "size",sol::property(&window::size,&window::set_size), - "position",sol::property(&window::position,&window::set_position), - "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen) - ); + "update",&window::update, + "title",sol::writeonly_property(&window::set_title), + "size",sol::property(&window::size,&window::set_size), + "position",sol::property(&window::position,&window::set_position), + "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen) + ); + ns.new_usertype("input", "new", sol::no_constructor,