Use io::stream for png input
This commit is contained in:
parent
72a8734853
commit
eecc054870
5 changed files with 14 additions and 15 deletions
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
#include <psemek/util/array.hpp>
|
#include <psemek/util/array.hpp>
|
||||||
#include <psemek/gfx/color.hpp>
|
#include <psemek/gfx/color.hpp>
|
||||||
|
#include <psemek/io/stream.hpp>
|
||||||
|
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
|
|
@ -23,7 +24,7 @@ namespace psemek::gfx
|
||||||
void write_pgm(pixmap_monochrome const & p, std::ostream & os);
|
void write_pgm(pixmap_monochrome const & p, std::ostream & os);
|
||||||
void write_ppm(pixmap_rgb const & p, std::ostream & os);
|
void write_ppm(pixmap_rgb const & p, std::ostream & os);
|
||||||
|
|
||||||
pixmap_rgba read_png(std::istream & is);
|
pixmap_rgba read_png(io::istream && is);
|
||||||
pixmap_monochrome read_png_monochrome(std::istream & is);
|
pixmap_monochrome read_png_monochrome(io::istream && is);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,7 @@
|
||||||
#include <psemek/gfx/texture.hpp>
|
#include <psemek/gfx/texture.hpp>
|
||||||
#include <psemek/gfx/resource/font_9x12_png.hpp>
|
#include <psemek/gfx/resource/font_9x12_png.hpp>
|
||||||
#include <psemek/geom/constants.hpp>
|
#include <psemek/geom/constants.hpp>
|
||||||
#include <psemek/util/memory_stream.hpp>
|
#include <psemek/io/memory_stream.hpp>
|
||||||
#include <psemek/log/log.hpp>
|
#include <psemek/log/log.hpp>
|
||||||
|
|
||||||
static const char vertex_source[] =
|
static const char vertex_source[] =
|
||||||
|
|
@ -164,8 +164,7 @@ namespace psemek::gfx
|
||||||
text_mesh.setup<geom::point<float, 3>, gfx::normalized<color_rgba>, geom::point<std::uint16_t, 2>>();
|
text_mesh.setup<geom::point<float, 3>, gfx::normalized<color_rgba>, geom::point<std::uint16_t, 2>>();
|
||||||
texture_mesh.setup<geom::point<float, 3>, gfx::normalized<geom::point<std::uint16_t, 2>>>();
|
texture_mesh.setup<geom::point<float, 3>, gfx::normalized<geom::point<std::uint16_t, 2>>>();
|
||||||
|
|
||||||
util::memory_istream font_data(resource::font_9x12_png);
|
font_texture.load(gfx::read_png_monochrome(io::memory_istream{resource::font_9x12_png}));
|
||||||
font_texture.load(gfx::read_png_monochrome(font_data));
|
|
||||||
|
|
||||||
font_texture.bind();
|
font_texture.bind();
|
||||||
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_SWIZZLE_G, gl::RED);
|
gl::TexParameteri(gl::TEXTURE_2D, gl::TEXTURE_SWIZZLE_G, gl::RED);
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ namespace psemek::gfx
|
||||||
{
|
{
|
||||||
|
|
||||||
template <typename Pixel>
|
template <typename Pixel>
|
||||||
basic_pixmap<Pixel> read_png_impl(std::istream & is, png_byte expected_color_type)
|
basic_pixmap<Pixel> read_png_impl(io::istream & is, png_byte expected_color_type)
|
||||||
{
|
{
|
||||||
png_error_ptr error = [](png_structp, png_const_charp str)
|
png_error_ptr error = [](png_structp, png_const_charp str)
|
||||||
{
|
{
|
||||||
|
|
@ -40,7 +40,7 @@ namespace psemek::gfx
|
||||||
if (!end_info) throw std::runtime_error("png_create_info_struct returned null");
|
if (!end_info) throw std::runtime_error("png_create_info_struct returned null");
|
||||||
|
|
||||||
png_rw_ptr read = [](png_structp png, png_bytep ptr, size_t count){
|
png_rw_ptr read = [](png_structp png, png_bytep ptr, size_t count){
|
||||||
reinterpret_cast<std::istream *>(png_get_io_ptr(png))->read(reinterpret_cast<char *>(ptr), count);
|
reinterpret_cast<io::istream *>(png_get_io_ptr(png))->read(reinterpret_cast<char *>(ptr), count);
|
||||||
};
|
};
|
||||||
png_set_read_fn(png, &is, read);
|
png_set_read_fn(png, &is, read);
|
||||||
|
|
||||||
|
|
@ -74,12 +74,12 @@ namespace psemek::gfx
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
pixmap_rgba read_png(std::istream & is)
|
pixmap_rgba read_png(io::istream && is)
|
||||||
{
|
{
|
||||||
return read_png_impl<color_rgba>(is, PNG_COLOR_TYPE_RGBA);
|
return read_png_impl<color_rgba>(is, PNG_COLOR_TYPE_RGBA);
|
||||||
}
|
}
|
||||||
|
|
||||||
pixmap_monochrome read_png_monochrome(std::istream & is)
|
pixmap_monochrome read_png_monochrome(io::istream && is)
|
||||||
{
|
{
|
||||||
return read_png_impl<std::uint8_t>(is, PNG_COLOR_TYPE_GRAY);
|
return read_png_impl<std::uint8_t>(is, PNG_COLOR_TYPE_GRAY);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,8 @@
|
||||||
#include <psemek/ui/default_element_factory.hpp>
|
#include <psemek/ui/default_element_factory.hpp>
|
||||||
|
|
||||||
#include <psemek/ui/box_shape.hpp>
|
#include <psemek/ui/box_shape.hpp>
|
||||||
#include <psemek/util/memory_stream.hpp>
|
|
||||||
|
#include <psemek/io/memory_stream.hpp>
|
||||||
|
|
||||||
#include <psemek/ui/resources/cross_red_16x16_png.hpp>
|
#include <psemek/ui/resources/cross_red_16x16_png.hpp>
|
||||||
|
|
||||||
|
|
@ -548,8 +549,7 @@ namespace psemek::ui
|
||||||
|
|
||||||
default_element_factory::impl::impl()
|
default_element_factory::impl::impl()
|
||||||
{
|
{
|
||||||
util::memory_istream is{resources::cross_red_16x16_png};
|
cross_red_16x16 = std::make_shared<gfx::texture_2d>(gfx::texture_2d::from_pixmap(gfx::read_png(io::memory_istream{resources::cross_red_16x16_png})));
|
||||||
cross_red_16x16 = std::make_shared<gfx::texture_2d>(gfx::texture_2d::from_pixmap(gfx::read_png(is)));
|
|
||||||
cross_red_16x16->nearest_filter();
|
cross_red_16x16->nearest_filter();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
#include <psemek/gfx/resource/font_9x12_png.hpp>
|
#include <psemek/gfx/resource/font_9x12_png.hpp>
|
||||||
|
|
||||||
#include <psemek/util/memory_stream.hpp>
|
#include <psemek/io/memory_stream.hpp>
|
||||||
|
|
||||||
namespace psemek::ui
|
namespace psemek::ui
|
||||||
{
|
{
|
||||||
|
|
@ -14,8 +14,7 @@ namespace psemek::ui
|
||||||
std::string_view name = "default_9x12";
|
std::string_view name = "default_9x12";
|
||||||
geom::vector<int, 2> size{9, 12};
|
geom::vector<int, 2> size{9, 12};
|
||||||
|
|
||||||
util::memory_istream is{gfx::resource::font_9x12_png};
|
gfx::texture_2d atlas = gfx::texture_2d::from_pixmap(gfx::read_png_monochrome(io::memory_istream{gfx::resource::font_9x12_png}));
|
||||||
gfx::texture_2d atlas = gfx::texture_2d::from_pixmap(gfx::read_png_monochrome(is));
|
|
||||||
atlas.nearest_filter();
|
atlas.nearest_filter();
|
||||||
atlas.clamp();
|
atlas.clamp();
|
||||||
gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_G, gl::RED);
|
gl::TexParameteri(atlas.target, gl::TEXTURE_SWIZZLE_G, gl::RED);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue