EHS
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 {
12 NONE,
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
47 Img(Str_8 id, UInt_8 byteDepth, UInt_8 channels, const Vec2_u64& resolution, const Byte* data);
48
49 Img(Str_8 id, UInt_8 byteDepth, UInt_8 channels, const Vec2_u64& resolution);
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
Definition: BaseObj.h:9
Definition: ImgCodec.h:16
Definition: Img.h:17
Byte * data
Definition: Img.h:28
Str_8 id
Definition: Img.h:23
Vec2_u64 resolution
Definition: Img.h:26
UInt_8 byteDepth
Definition: Img.h:24
UInt_64 hashId
Definition: Img.h:22
UInt_8 channels
Definition: Img.h:25
UInt_64 size
Definition: Img.h:27
Definition: Serializer.h:25
Definition: Anchor.h:6
unsigned char UInt_8
Definition: Types.h:43
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
Resampling
Definition: Img.h:11
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