载入中...
搜索中...
未找到
ImageData.h
浏览该文件的文档.
1
2#pragma once
3
4#include "common/Data.h"
5#include "common/Resource.h"
6
7#include "medialoader/image/pixelformat.h"
8#include "medialoader/image/floattypes.h"
9#include "medialoader/image/Color.h"
10#include "medialoader/image/FormatHandler.h"
11
12#include <cstdint>
13
14namespace eve
15{
16namespace filesystem {
17class FileData;
18}
19namespace image
20{
21
25class ImageData : public Resource
26{
27public:
28 using float16 = medialoader::float16;
29 using Colorf = medialoader::Colorf;
30 using FormatHandler = medialoader::FormatHandler;
31
32 union Pixel
33 {
34 uint8_t rgba8[4];
35 uint16_t rgba16[4];
37 float rgba32f[4];
38 uint16_t packed16;
39 uint32_t packed32;
40 };
41
42 typedef void (*PixelSetFunction)(const Colorf &c, Pixel *p);
43 typedef void (*PixelGetFunction)(const Pixel *p, Colorf &c);
44
45 ImageData(Data *data);
46 ImageData(int width, int height, std::string format = "RGBA8");
47 ImageData(int width, int height, std::string format, void *data, bool own);
48 ImageData(const ImageData &c);
49 virtual ~ImageData();
50
61 void paste(ImageData *src, int dx, int dy, int sx, int sy, int sw, int sh);
62
81 ImageData *rotate(float radians, std::string filter = "nearest", bool expand = true) const;
82
88 bool inside(int x, int y) const;
89
96 void setPixel(int x, int y, const Colorf &p);
97
104 void getPixel(int x, int y, Colorf &c) const;
105 Colorf getPixel(int x, int y) const;
106
112 filesystem::FileData *encode(FormatHandler::EncodedFormat format, const char *filename, bool writefile) const;
113
114 // Implements ImageDataBase.
115 ImageData *clone() const;
116 void *getData() const;
117 size_t getSize() const;
118 bool isSRGB() const;
119
124 void adopt(eve::Resource &replacement) override;
125
126 int getWidth() const;
127 int getHeight() const;
128 std::string getFormat() const;
129
130 size_t getPixelSize() const;
131
132 PixelSetFunction getPixelSetFunction() const { return pixelSetFunction; }
133 PixelGetFunction getPixelGetFunction() const { return pixelGetFunction; }
134
135 static bool validPixelFormat(std::string format);
136 static bool canPaste(std::string src, std::string dst);
137
138 static PixelSetFunction getPixelSetFunction(std::string format);
139 static PixelGetFunction getPixelGetFunction(std::string format);
140
141 static bool getConstant(const char *in, FormatHandler::EncodedFormat &out);
142 static bool getConstant(FormatHandler::EncodedFormat in, const char *&out);
143 static std::vector<std::string> getConstants(FormatHandler::EncodedFormat);
144
145private:
146
147 // Create imagedata. Initialize with data if not null.
148 void create(int width, int height, std::string format, void *data = nullptr);
149
150 // Decode and load an encoded format.
151 void decode(Data *data);
152
153 // The actual data.
154 unsigned char *data = nullptr;
155
156 int width, height;
157 std::string format;
158
159 // The format handler that was used to decode the ImageData. We need to know
160 // this so we can properly delete memory allocated by the decoder.
161 FormatHandler* decodeHandler;
162
163 PixelSetFunction pixelSetFunction;
164 PixelGetFunction pixelGetFunction;
165
166}; // ImageData
167
168} // image
169} // eve
int y
Definition Grass.cpp:135
int x
Definition Grass.cpp:135
uint32_t c
glm::vec4 p[6]
std::string filter
std::string image
Resource is a game object that is managed by the ResourceManager. It can be loaded from a file or gen...
Definition Resource.h:35
Data buffer paired with a filename (used for type identification).
Definition FileData.h:12
Represents raw pixel data.
Definition ImageData.h:26
medialoader::float16 float16
Definition ImageData.h:28
ImageData * clone() const
Definition ImageData.cpp:72
void(* PixelGetFunction)(const Pixel *p, Colorf &c)
Definition ImageData.h:43
bool inside(int x, int y) const
Checks whether a position is inside this ImageData. Useful for checking bounds.
filesystem::FileData * encode(FormatHandler::EncodedFormat format, const char *filename, bool writefile) const
Encodes raw pixel data into a given format.
void getPixel(int x, int y, Colorf &c) const
Gets the pixel at location (x,y).
static bool getConstant(const char *in, FormatHandler::EncodedFormat &out)
void setPixel(int x, int y, const Colorf &p)
Sets the pixel at location (x,y).
medialoader::Colorf Colorf
Definition ImageData.h:29
void paste(ImageData *src, int dx, int dy, int sx, int sy, int sw, int sh)
Paste part of one ImageData onto another. The subregion defined by the top-left corner (sx,...
static bool canPaste(std::string src, std::string dst)
size_t getSize() const
static bool getConstant(FormatHandler::EncodedFormat in, const char *&out)
static std::vector< std::string > getConstants(FormatHandler::EncodedFormat)
PixelSetFunction getPixelSetFunction() const
Definition ImageData.h:132
static bool validPixelFormat(std::string format)
ImageData * rotate(float radians, std::string filter="nearest", bool expand=true) const
Rotate pixels around the image center and return a new ImageData.
void * getData() const
void(* PixelSetFunction)(const Colorf &c, Pixel *p)
Definition ImageData.h:42
PixelGetFunction getPixelGetFunction() const
Definition ImageData.h:133
size_t getPixelSize() const
void adopt(eve::Resource &replacement) override
Replace this instance's pixels with replacement's (cache reload). The replacement is drained; its des...
Definition ImageData.cpp:61
medialoader::FormatHandler FormatHandler
Definition ImageData.h:30
std::string getFormat() const
Definition Build.cpp:11