Merge branch 'master' of gitlab.com:seichter/pixwerx
This commit is contained in:
commit
53b86a9608
11 changed files with 205 additions and 15 deletions
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#define PW_CORE_IMAGE_HPP
|
||||
|
||||
#include <pw/core/globals.hpp>
|
||||
#include <pw/core/size.hpp>
|
||||
|
||||
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<unsigned char> _data;
|
||||
std::string _uri;
|
||||
sizei _size;
|
||||
pixel_layout _layout;
|
||||
uint64_t _change_count;
|
||||
|
||||
std::vector<uint8_t> _data;
|
||||
|
||||
};
|
||||
|
||||
|
|
|
@ -487,8 +487,6 @@ public:
|
|||
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
//
|
||||
// Specializations
|
||||
//
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -1,7 +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;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -53,8 +53,7 @@ add_library (lualib STATIC
|
|||
${libsrc}
|
||||
)
|
||||
|
||||
|
||||
|
||||
target_compile_definitions(lualib PRIVATE LUA_USE_POSIX)
|
||||
|
||||
if(UNIX)
|
||||
target_link_libraries( lualib m )
|
||||
|
|
27
src/io/CMakeLists.txt
Normal file
27
src/io/CMakeLists.txt
Normal file
|
@ -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)
|
||||
|
50
src/io/include/pw/io/image_io.hpp
Normal file
50
src/io/include/pw/io/image_io.hpp
Normal file
|
@ -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 <pw/core/image.hpp>
|
||||
|
||||
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> _impl;
|
||||
|
||||
image_io() = default;
|
||||
~image_io() = default;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
18
src/io/src/image_io.cpp
Normal file
18
src/io/src/image_io.cpp
Normal file
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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>("window",
|
||||
// sol::constructors<window_lua(sol::this_state)>(),
|
||||
// "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>("input",
|
||||
"new", sol::no_constructor,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue