EHS
Loading...
Searching...
No Matches
Img.h
Go to the documentation of this file.
1#pragma once
2
3#include "ehs/Types.h"
4#include "ehs/BaseObj.h"
5#include "ehs/Str.h"
6#include "ImgCodec.h"
7
8namespace ehs
9{
10 enum class Resampling : UInt_8
11 {
14 };
15
16 class EHS_LIB_IO Img : public BaseObj
17 {
18 private:
19 static Array<ImgCodec> codecs;
20
21 protected:
22 UInt_64 hashId;
27 UInt_64 size;
29
30 public:
31 static bool HasCodec(UInt_64 hashExt);
32
33 static bool HasCodec(const Str_8& ext);
34
35 static bool AddCodec(ImgCodec codec);
36
37 static const ImgCodec* GetCodec(UInt_64 hashExt);
38
39 static const ImgCodec* GetCodec(const Str_8& ext);
40
41 ~Img() override;
42
43 Img();
44
45 Img(const Str_8& filePath);
46
48
50
51 Img(Img&& img) noexcept;
52
53 Img(const Img& img);
54
55 Img& operator=(Img&& img) noexcept;
56
57 Img& operator=(const Img& img);
58
59 operator const Byte* () const;
60
61 operator Byte* ();
62
63 void Release();
64
65 UInt_64 GetHashId() const;
66
67 void SetId(Str_8 newId);
68
69 Str_8 GetId() const;
70
71 UInt_8 GetByteDepth() const;
72
73 UInt_8 GetBitDepth() const;
74
75 UInt_8 GetChannels() const;
76
77 Vec2_u64 GetResolution() const;
78
79 UInt_64 GetSize() const;
80
81 void SetPixel(UInt_64 index, const Byte* pixel);
82
83 void GetPixel(UInt_64 index, Byte* pixel) const;
84
85 void SetPixel(UInt_64 x, UInt_64 y, const Byte* pixel);
86
87 void GetPixel(UInt_64 x, UInt_64 y, Byte* pixel) const;
88
89 void Resize(Resampling method, const Vec2_u64& newResolution);
90
91 Img GetResized(Resampling method, const Vec2_u64& newResolution) const;
92
93 void ToRGBA();
94
95 Img GetAsRGBA() const;
96
97 void ToRGB();
98
99 Img GetAsRGB() const;
100
101 void ToMonoA();
102
103 Img GetAsMonoA() const;
104
105 void ToMono();
106
107 Img GetAsMono() const;
108
109 void To32();
110
111 Img GetAs32() const;
112
113 void To24();
114
115 Img GetAs24() const;
116
117 void To16();
118
119 Img GetAs16() const;
120
121 void To8();
122
123 Img GetAs8() const;
124
125 bool IsValid() const;
126
127 bool Export(const Str_8& filePath) const;
128
129 private:
130 Img GetNearestNeighbor(const Vec2_u64& newResolution) const;
131
132 void NearestNeighbor(const Vec2_u64& newResolution);
133
134 void RGB_To_RGBA(UInt_64 newSize, Byte* buffer) const;
135
136 void MonoA_To_RGBA(UInt_64 newSize, Byte* buffer) const;
137
138 void Mono_To_RGBA(UInt_64 newSize, Byte* buffer) const;
139
140 void RGBA_To_RGB(UInt_64 newSize, Byte* buffer) const;
141
142 void MonoA_To_RGB(UInt_64 newSize, Byte* buffer) const;
143
144 void Mono_To_RGB(UInt_64 newSize, Byte* buffer) const;
145
146 void RGBA_To_MonoA(UInt_64 newSize, Byte* buffer) const;
147
148 void RGB_To_MonoA(UInt_64 newSize, Byte* buffer) const;
149
150 void Mono_To_MonoA(UInt_64 newSize, Byte* buffer) const;
151
152 void RGBA_To_Mono(UInt_64 newSize, Byte* buffer) const;
153
154 void RGB_To_Mono(UInt_64 newSize, Byte* buffer) const;
155
156 void MonoA_To_Mono(UInt_64 newSize, Byte* buffer) const;
157
158 void BD24_to_BD32(UInt_64 newSize, Byte* buffer) const;
159
160 void BD16_to_BD32(UInt_64 newSize, Byte* buffer) const;
161
162 void BD8_to_BD32(UInt_64 newSize, Byte* buffer) const;
163
164 void BD32_to_BD24(UInt_64 newSize, Byte* buffer) const;
165
166 void BD16_to_BD24(UInt_64 newSize, Byte* buffer) const;
167
168 void BD8_to_BD24(UInt_64 newSize, Byte* buffer) const;
169
170 void BD32_to_BD16(UInt_64 newSize, Byte* buffer) const;
171
172 void BD24_to_BD16(UInt_64 newSize, Byte* buffer) const;
173
174 void BD8_to_BD16(UInt_64 newSize, Byte* buffer) const;
175
176 void BD32_to_BD8(UInt_64 newSize, Byte* buffer) const;
177
178 void BD24_to_BD8(UInt_64 newSize, Byte* buffer) const;
179
180 void BD16_to_BD8(UInt_64 newSize, Byte* buffer) const;
181 };
182
183 bool EncodeQOI(const ehs::ImgCodec* codec, ehs::Serializer<ehs::UInt_64>& out, const ehs::Img* in);
184
186
188}
Definition Array.h:16
BaseObj()
Definition BaseObj.cpp:10
Definition ImgCodec.h:16
Definition Img.h:17
Img GetAs32() const
Definition Img.cpp:613
Byte * data
Definition Img.h:28
void To32()
Definition Img.cpp:572
void To16()
Definition Img.cpp:720
UInt_64 GetHashId() const
Definition Img.cpp:178
Img()
Definition Img.cpp:53
Img GetResized(Resampling method, const Vec2_u64 &newResolution) const
Definition Img.cpp:265
void To8()
Definition Img.cpp:794
void ToMono()
Definition Img.cpp:498
void ToRGB()
Definition Img.cpp:350
void Resize(Resampling method, const Vec2_u64 &newResolution)
Definition Img.cpp:251
void GetPixel(UInt_64 index, Byte *pixel) const
Definition Img.cpp:227
UInt_8 GetBitDepth() const
Definition Img.cpp:199
static bool HasCodec(UInt_64 hashExt)
Definition Img.cpp:10
void SetPixel(UInt_64 index, const Byte *pixel)
Definition Img.cpp:219
bool Export(const Str_8 &filePath) const
Definition Img.cpp:873
Vec2_u64 GetResolution() const
Definition Img.cpp:209
Str_8 id
Definition Img.h:23
Str_8 GetId() const
Definition Img.cpp:189
Img GetAsMonoA() const
Definition Img.cpp:465
UInt_8 GetByteDepth() const
Definition Img.cpp:194
UInt_8 GetChannels() const
Definition Img.cpp:204
void To24()
Definition Img.cpp:646
Vec2_u64 resolution
Definition Img.h:26
Img GetAs8() const
Definition Img.cpp:835
void Release()
Definition Img.cpp:168
UInt_8 byteDepth
Definition Img.h:24
Img GetAsRGB() const
Definition Img.cpp:391
Img GetAsMono() const
Definition Img.cpp:539
Img GetAs16() const
Definition Img.cpp:761
void ToRGBA()
Definition Img.cpp:276
UInt_64 hashId
Definition Img.h:22
UInt_64 GetSize() const
Definition Img.cpp:214
UInt_8 channels
Definition Img.h:25
void ToMonoA()
Definition Img.cpp:424
Img & operator=(Img &&img) noexcept
Definition Img.cpp:117
UInt_64 size
Definition Img.h:27
static bool AddCodec(ImgCodec codec)
Definition Img.cpp:24
bool IsValid() const
Definition Img.cpp:868
void SetId(Str_8 newId)
Definition Img.cpp:183
static const ImgCodec * GetCodec(UInt_64 hashExt)
Definition Img.cpp:34
Img GetAsRGBA() const
Definition Img.cpp:317
Img GetAs24() const
Definition Img.cpp:687
Definition Serializer.h:25
Definition Anchor.h:6
@ NONE
Definition Dock.h:7
unsigned char UInt_8
Definition Types.h:43
Vec2< UInt_64 > Vec2_u64
Definition Vec2.h:372
bool DecodePNG(const ehs::ImgCodec *codec, ehs::Serializer< ehs::UInt_64 > &in, ehs::Img *out)
Definition Img.cpp:1642
bool DecodeQOI(const ehs::ImgCodec *codec, ehs::Serializer< ehs::UInt_64 > &in, ehs::Img *out)
Definition Img.cpp:1558
Str< Char_8, UInt_64 > Str_8
Definition Str.h:1953
Resampling
Definition Img.h:11
@ NEAREST_NEIGHBOR
Definition Img.h:13
unsigned char Byte
Definition Types.h:39
bool EncodeQOI(const ehs::ImgCodec *codec, ehs::Serializer< ehs::UInt_64 > &out, const ehs::Img *in)
Definition Img.cpp:1440