neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
image.hpp
Go to the documentation of this file.
1// image.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <vector>
24#include <unordered_map>
25#include <optional>
26#include <neogfx/core/event.hpp>
28
29namespace neogfx
30{
31 class image : public reference_counted<i_image>
32 {
33 public:
34 define_declared_event(Downloaded, downloaded)
35 define_declared_event(FailedToDownload, failed_to_download)
36 public:
42 public:
45 private:
46 struct error_parsing_image_pattern : std::logic_error { error_parsing_image_pattern() : std::logic_error("neogfx::image::error_parsing_image_pattern") {} };
47 struct no_resource : std::logic_error { no_resource() : std::logic_error("neogfx::image::no_resource") {} };
48 public:
50 image(const neogfx::size& aSize, const color& aColor = color::Black, dimension aDpiScaleFactor = 1.0, texture_sampling aSampling = texture_sampling::NormalMipmap, neogfx::color_space aColorSpace = neogfx::color_space::sRGB);
51 image(std::string const& aUri, dimension aDpiScaleFactor = 1.0, texture_sampling aSampling = texture_sampling::NormalMipmap, neogfx::color_space aColorSpace = neogfx::color_space::sRGB);
52 image(std::string const& aImagePattern, const std::unordered_map<std::string, color>& aColorMap, dimension aDpiScaleFactor = 1.0, texture_sampling aSampling = texture_sampling::NormalMipmap, neogfx::color_space aColorSpace = neogfx::color_space::sRGB);
53 image(std::string const& aUri, std::string const& aImagePattern, const std::unordered_map<std::string, color>& aColorMap, dimension aDpiScaleFactor = 1.0, texture_sampling aSampling = texture_sampling::NormalMipmap, neogfx::color_space aColorSpace = neogfx::color_space::sRGB);
54 image(image const& aOther);
55 image(image&& aOther);
56 image(image const& aOther, texture_sampling aSampling);
57 image(image&& aOther, texture_sampling aSampling);
59 public:
60 bool available() const override;
61 bool downloading() const override;
62 double downloading_progress() const override;
63 bool error() const override;
64 i_string const& error_string() const override;
65 public:
66 i_string const& uri() const override;
67 bool is_empty() const override;
68 const void* cdata() const override;
69 const void* data() const override;
70 void* data() override;
71 std::size_t size() const override;
72 hash_digest_type const& hash() const override;
73 public:
74 dimension dpi_scale_factor() const override;
77 texture_sampling sampling() const override;
79 const neogfx::size& extents() const override;
80 void resize(const neogfx::size& aNewSize) override;
81 const void* cpixels() const override;
82 const void* pixels() const override;
83 void* pixels() override;
84 color get_pixel(const point& aPoint) const override;
85 void set_pixel(const point& aPoint, const color& aColor) override;
86 private:
87 bool has_resource() const;
88 const i_resource& resource() const;
89 image_type_e recognize() const;
90 bool load();
91 bool load_png();
92 private:
93 ref_ptr<i_resource> iResource;
94 string iUri;
95 std::optional<string> iError;
96 dimension iDpiScaleFactor;
97 neogfx::color_space iColorSpace;
98 neogfx::color_format iColorFormat;
99 data_type iData;
100 mutable cache<data_type> iHash;
101 texture_sampling iSampling;
102 neogfx::size iSize;
103 };
104}
void set_pixel(const point &aPoint, const color &aColor) override
image(image &&aOther)
double downloading_progress() const override
texture_data_format data_format() const override
color get_pixel(const point &aPoint) const override
i_string const & error_string() const override
void resize(const neogfx::size &aNewSize) override
define_declared_event(Downloaded, downloaded) define_declared_event(FailedToDownload
const void * cpixels() const override
void * data() override
const void * data() const override
neogfx::color_format color_format() const override
void * pixels() override
image(std::string const &aUri, std::string const &aImagePattern, const std::unordered_map< std::string, color > &aColorMap, dimension aDpiScaleFactor=1.0, texture_sampling aSampling=texture_sampling::NormalMipmap, neogfx::color_space aColorSpace=neogfx::color_space::sRGB)
hash_digest_type const & hash() const override
data_type hash_digest_type
Definition image.hpp:44
neogfx::color_space color_space() const override
texture_sampling sampling() const override
const void * cdata() const override
image(image &&aOther, texture_sampling aSampling)
image(std::string const &aImagePattern, const std::unordered_map< std::string, color > &aColorMap, dimension aDpiScaleFactor=1.0, texture_sampling aSampling=texture_sampling::NormalMipmap, neogfx::color_space aColorSpace=neogfx::color_space::sRGB)
std::size_t size() const override
i_string const & uri() const override
bool is_empty() const override
image(image const &aOther, texture_sampling aSampling)
image(image const &aOther)
dimension dpi_scale_factor() const override
bool downloading() const override
bool available() const override
image(const neogfx::size &aSize, const color &aColor=color::Black, dimension aDpiScaleFactor=1.0, texture_sampling aSampling=texture_sampling::NormalMipmap, neogfx::color_space aColorSpace=neogfx::color_space::sRGB)
image(dimension aDpiScaleFactor=1.0, texture_sampling aSampling=texture_sampling::NormalMipmap, neogfx::color_space aColorSpace=neogfx::color_space::sRGB)
const void * pixels() const override
neolib::vector< uint8_t > data_type
Definition image.hpp:43
bool error() const override
const neogfx::size & extents() const override
image(std::string const &aUri, dimension aDpiScaleFactor=1.0, texture_sampling aSampling=texture_sampling::NormalMipmap, neogfx::color_space aColorSpace=neogfx::color_space::sRGB)
static const sRGB_color Black
Definition color.hpp:403
default_geometry_value_type dimension
color_format
Definition i_image.hpp:30
texture_data_format
Definition i_texture.hpp:56
texture_sampling
Definition i_texture.hpp:42
Definition plf_hive.h:79
#define define_declared_event(name, declName,...)
Definition event.hpp:195