From 99fdade003c3e198cd576253d1d8008f4f2522c0 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 16 Jan 2019 10:38:37 +0100 Subject: [PATCH 1/4] added image basics --- src/core/CMakeLists.txt | 2 ++ src/core/include/pw/core/image.hpp | 13 ++++++++++++- src/core/src/image.cpp | 7 ------- 3 files changed, 14 insertions(+), 8 deletions(-) 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..73ff30d 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,11 +33,21 @@ public: image() = default; + enum image_type { + RGB8, + RGBA8, + LUM + }; + bool create(const sizei& size,); + + const uint8_t *data() const { return _data.data(); } + uint8_t *data() { return _data.data(); } protected: - std::vector _data; + sizei _size; + std::vector _data; std::string _uri; }; diff --git a/src/core/src/image.cpp b/src/core/src/image.cpp index fdd0408..e69de29 100644 --- a/src/core/src/image.cpp +++ b/src/core/src/image.cpp @@ -1,7 +0,0 @@ -#include "pw/core/image.hpp" - -namespace pw { - - - -} From 46eff4429781ecbb25258c419ba2153d6f357692 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 16 Jan 2019 11:13:12 +0100 Subject: [PATCH 2/4] adding important low-level code for image and matrix manipulations --- src/core/include/pw/core/image.hpp | 32 +++++++++---- src/core/include/pw/core/matrix.hpp | 2 - src/core/include/pw/core/size.hpp | 2 + src/core/src/image.cpp | 71 +++++++++++++++++++++++++++++ 4 files changed, 96 insertions(+), 11 deletions(-) diff --git a/src/core/include/pw/core/image.hpp b/src/core/include/pw/core/image.hpp index 73ff30d..4c50ea6 100644 --- a/src/core/include/pw/core/image.hpp +++ b/src/core/include/pw/core/image.hpp @@ -33,22 +33,36 @@ public: image() = default; - enum image_type { - RGB8, - RGBA8, - LUM - }; + 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; - 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 e69de29..11c9e0e 100644 --- a/src/core/src/image.cpp +++ b/src/core/src/image.cpp @@ -0,0 +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; +} + +} From e8be36243dd178b79ec793b4136660f8c27d7fca Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 16 Jan 2019 11:13:44 +0100 Subject: [PATCH 3/4] not dealing with SOL2 problem now --- src/deps/lua-5.3.5/CMakeLists.txt | 3 +-- src/scripting/src/script_system.cpp | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) 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/scripting/src/script_system.cpp b/src/scripting/src/script_system.cpp index b3a8c6d..5e1efc8 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,10 +24,13 @@ struct window_lua : public window { _on_update = [this](window&){this->lua_update();}; } }; +#endif void script_system::load(sol::table &ns) { + +#if defined(__clang) ns.new_usertype("window", sol::constructors(), "on_update",&window_lua::lua_update, @@ -36,6 +40,18 @@ void script_system::load(sol::table &ns) "position",sol::property(&window::position,&window::set_position), "fullscreen",sol::property(&window::fullscreen,&window::set_fullscreen) ); +#else + + + ns.new_usertype("window", + "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) + ); + +#endif ns.new_usertype("input", "new", sol::no_constructor, From 28905d301e1e6a1d4d1d02a864b20f4bf7bcb1e3 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Wed, 16 Jan 2019 11:37:36 +0100 Subject: [PATCH 4/4] skeletton for an io system --- src/CMakeLists.txt | 2 ++ src/io/CMakeLists.txt | 27 +++++++++++++++++ src/io/include/pw/io/image_io.hpp | 50 +++++++++++++++++++++++++++++++ src/io/src/image_io.cpp | 18 +++++++++++ 4 files changed, 97 insertions(+) create mode 100644 src/io/CMakeLists.txt create mode 100644 src/io/include/pw/io/image_io.hpp create mode 100644 src/io/src/image_io.cpp 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/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; +} + +}