YourGameLib
Loading...
Searching...
No Matches
image.h
Go to the documentation of this file.
1/*
2Copyright (c) 2019-2024 Alexander Scholz
3
4This software is provided 'as-is', without any express or implied
5warranty. In no event will the authors be held liable for any damages
6arising from the use of this software.
7
8Permission is granted to anyone to use this software for any purpose,
9including commercial applications, and to alter it and redistribute it
10freely, subject to the following restrictions:
11
121. The origin of this software must not be misrepresented; you must not
13 claim that you wrote the original software. If you use this software
14 in a product, an acknowledgment in the product documentation would be
15 appreciated but is not required.
162. Altered source versions must be plainly marked as such, and must not be
17 misrepresented as being the original software.
183. This notice may not be removed or altered from any source distribution.
19*/
20#ifndef YOURGAME_IMAGE_H
21#define YOURGAME_IMAGE_H
22
23#include <cstdint>
24#include <array>
25#include <vector>
26
27namespace yourgame
28{
29 namespace util
30 {
31 class Image
32 {
33 public:
34 enum class Layout
35 {
36 RGBA
37 };
38
39 /* deleting the copy constructor and the copy assignment operator
40 prevents copying (and moving) of the object. */
41 Image(Image const &) = delete;
42 Image &operator=(Image const &) = delete;
43
44 static Image *fromMemoryEncoded(const uint8_t *data,
45 size_t numBytes,
46 bool flipVertically = false,
47 Layout layoutDst = Layout::RGBA);
48
49 static Image *fromMemoryRaw(const uint8_t *data,
50 int width,
51 int height,
52 Layout layout = Layout::RGBA);
53
54 static Image *fromEmpty(int width,
55 int height,
56 Layout layout = Layout::RGBA);
57
58 static std::array<int, 3> decodeImageInfo(const uint8_t *data,
59 size_t numBytes);
60
61 static int getNumChannelsFromLayout(Layout layout);
62
63 void premultiplyAlpha();
64
65 void updateRaw(const uint8_t *data,
66 int width,
67 int height,
68 Layout layout = Layout::RGBA);
69
70 const uint8_t *getData() const;
71
72 int getWidth() const;
73
74 int getHeight() const;
75
76 Layout getLayout() const;
77
78 int getNumChannels() const;
79
80 size_t getNumDemandedBytes() const;
81
82 private:
83 Image() {}
84 std::vector<uint8_t> m_data;
85 int m_width;
86 int m_height;
87 Layout m_layout;
88 };
89 } // namespace util
90} // namespace yourgame
91
92#endif
Definition image.h:32
int getNumChannels() const
Definition image.cpp:185
static Image * fromMemoryEncoded(const uint8_t *data, size_t numBytes, bool flipVertically=false, Layout layoutDst=Layout::RGBA)
Definition image.cpp:29
Layout getLayout() const
Definition image.cpp:180
void premultiplyAlpha()
Definition image.cpp:126
static Image * fromMemoryRaw(const uint8_t *data, int width, int height, Layout layout=Layout::RGBA)
Definition image.cpp:67
int getWidth() const
Definition image.cpp:170
size_t getNumDemandedBytes() const
Definition image.cpp:190
int getHeight() const
Definition image.cpp:175
Image(Image const &)=delete
static Image * fromEmpty(int width, int height, Layout layout=Layout::RGBA)
Definition image.cpp:88
const uint8_t * getData() const
Definition image.cpp:165
static int getNumChannelsFromLayout(Layout layout)
Definition image.cpp:120
Layout
Definition image.h:35
void updateRaw(const uint8_t *data, int width, int height, Layout layout=Layout::RGBA)
Definition image.cpp:147
static std::array< int, 3 > decodeImageInfo(const uint8_t *data, size_t numBytes)
Definition image.cpp:108
Image & operator=(Image const &)=delete
Definition audio.h:27