载入中...
搜索中...
未找到
ImageData.h
浏览该文件的文档.
1
2#pragma once
3#include "common/Export.h"
4
5
6#include "common/Data.h"
7#include "common/Resource.h"
8#include "common/Result.h"
9
10#include "medialoader/image/pixelformat.h"
11#include "medialoader/image/floattypes.h"
12#include "medialoader/image/Color.h"
13#include "medialoader/image/FormatHandler.h"
14
15#include <cstdint>
16
17namespace eve
18{
19namespace filesystem {
20class FileData;
21}
22namespace image
23{
24
27
30 int centerX = 0;
31 int centerY = 0;
33};
34
39public:
40 using float16 = medialoader::float16;
41 using Colorf = medialoader::Colorf;
42 using FormatHandler = medialoader::FormatHandler;
43
45 union Pixel
46 {
47 uint8_t rgba8[4];
48 uint16_t rgba16[4];
49 float16 rgba16f[4];
50 float rgba32f[4];
51 uint16_t packed16;
52 uint32_t packed32;
53 };
54
55 typedef void (*PixelSetFunction)(const Colorf &c, Pixel *p);
56 typedef void (*PixelGetFunction)(const Pixel *p, Colorf &c);
57
58 ImageData(Data *data);
59 ImageData(int width, int height, std::string format = "RGBA8");
60 ImageData(int width, int height, std::string format, void *data, bool own);
61 ImageData(const ImageData &c);
62 virtual ~ImageData();
63
74 void paste(ImageData *src, int dx, int dy, int sx, int sy, int sw, int sh);
75
94 ImageData *rotate(float radians, std::string filter = "nearest", bool expand = true) const;
95
106 [[nodiscard]] eve::Result<int> scalePcg(int newWidth, int newHeight, ImageScaleFilter filter);
107
113 bool inside(int x, int y) const;
114
121 void setPixel(int x, int y, const Colorf &p);
122
135 [[nodiscard]] eve::Result<UvPaintReceipt> paintCircleUv(float u, float v, float radiusPixels,
136 const Colorf &color, bool wrapU = false,
137 bool wrapV = false);
138
145 void getPixel(int x, int y, Colorf &c) const;
146 Colorf getPixel(int x, int y) const;
147
153 filesystem::FileData *encode(FormatHandler::EncodedFormat format, const char *filename, bool writefile) const;
154
155 // Implements ImageDataBase.
156 ImageData *clone() const;
157 void *getData() const;
158 size_t getSize() const;
159 bool isSRGB() const;
160
165 void adopt(eve::Resource &replacement) override;
166
167 int getWidth() const;
168 int getHeight() const;
169 std::string getFormat() const;
170
171 size_t getPixelSize() const;
172
173 PixelSetFunction getPixelSetFunction() const { return pixelSetFunction; }
174 PixelGetFunction getPixelGetFunction() const { return pixelGetFunction; }
175
176 static bool validPixelFormat(std::string format);
177 static bool canPaste(std::string src, std::string dst);
178
179 static PixelSetFunction getPixelSetFunction(std::string format);
180 static PixelGetFunction getPixelGetFunction(std::string format);
181
182 static bool getConstant(const char *in, FormatHandler::EncodedFormat &out);
183 static bool getConstant(FormatHandler::EncodedFormat in, const char *&out);
184 static std::vector<std::string> getConstants(FormatHandler::EncodedFormat);
185
186private:
187
188 // Create imagedata. Initialize with data if not null.
189 void create(int width, int height, std::string format, void *data = nullptr);
190
191 // Decode and load an encoded format.
192 void decode(Data *data);
193
194 // The actual data.
195 unsigned char *data = nullptr;
196
197 int width, height;
198 std::string format;
199
200 // The format handler that was used to decode the ImageData. We need to know
201 // this so we can properly delete memory allocated by the decoder.
202 FormatHandler* decodeHandler;
203
204 PixelSetFunction pixelSetFunction;
205 PixelGetFunction pixelGetFunction;
206
207}; // ImageData
208
209} // image
210} // eve
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
glm::vec4 p[6]
#define EVENGINE_API_PLATFORM
Definition Export.h:107
vk::UniqueImage image
float u
Definition Grass.cpp:233
float v
std::int32_t c
std::uint32_t height
std::uint32_t width
Move-only, checked operation results for the common layer.
std::string filter
float dy
float dx
std::vector< char > inside
Data public API.
Definition Data.h:8
Resource is a game object that is managed by the ResourceManager. It can be loaded from a file or gen...
Definition Resource.h:51
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Data buffer paired with a filename (used for type identification).
Definition FileData.h:14
Represents raw pixel data.
Definition ImageData.h:38
medialoader::float16 float16
Definition ImageData.h:40
static bool getConstant(const char *in, FormatHandler::EncodedFormat &out)
medialoader::Colorf Colorf
Definition ImageData.h:41
static bool getConstant(FormatHandler::EncodedFormat in, const char *&out)
static std::vector< std::string > getConstants(FormatHandler::EncodedFormat)
PixelSetFunction getPixelSetFunction() const
Definition ImageData.h:173
PixelGetFunction getPixelGetFunction() const
Definition ImageData.h:174
medialoader::FormatHandler FormatHandler
Definition ImageData.h:42
ImageScaleFilter
Sampling modes used by Pcg-compatible in-place texture scaling.
Definition ImageData.h:26
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
Owning receipt for one UV-space raster paint operation.
Definition ImageData.h:29
Pixel public API.
Definition ImageData.h:46
glm::vec4 color