29 Color( uint8_t{0U}, uint8_t{0U}, uint8_t{0U}, uint8_t{255U} )
37 Color( uint8_t iR, uint8_t iG, uint8_t iB )
39 Color( iR, iG, iB, uint8_t{255U} )
48 Color( uint8_t iR, uint8_t iG, uint8_t iB, uint8_t iA )
50 r(std::clamp(iR, uint8_t{0U}, uint8_t{255U})),
51 g(std::clamp(iG, uint8_t{0U}, uint8_t{255U})),
52 b(std::clamp(iB, uint8_t{0U}, uint8_t{255U})),
53 a(std::clamp(iA, uint8_t{0U}, uint8_t{255U}))
61 return (this->
r == rhs.
r) && (this->
g == rhs.
g) && (this->
b == rhs.
b) && (this->
a == rhs.
a);
72static_assert(
sizeof(
Color) == 4,
"Color must be exactly 4 bytes");
73static_assert(std::is_trivially_copyable_v<Color>,
"Color must be trivially copyable");
92 ImageData(
unsigned int width,
unsigned int height);
109 ImageData(std::vector<uint8_t>
const& fileBytes);
117 ImageData(
unsigned int width,
unsigned int height, std::vector<std::uint8_t>
const& pixelsRGBA);
154 void Fill(
Color color );
162 void SetPixel(
unsigned int x,
unsigned int y,
Color color );
170 const Color GetPixel(
unsigned int x,
unsigned int y )
const;
179 static void DrawImageOnImageAtPos(
unsigned int const x,
unsigned int const y,
ImageData& toImage,
ImageData& fromImage);
185 std::vector<uint8_t> GetImageDataRGBA()
const;
191 std::vector<uint8_t> GetImageDataRGB()
const;
199 return static_cast<size_t>(mWidth) *
static_cast<size_t>(mHeight) *
sizeof(
Color);
206 void WriteJpegFile(
char const* filename);
213 void WritePngFile(
char const* filename);
221 void AllocateMemory(
unsigned int width,
unsigned int height );
226 void CleanAllocatedMemory();
230 void LoadImageDataRGBA(std::vector<std::uint8_t>
const& pixels);
234 void LoadImageDataRGB(std::vector<std::uint8_t>
const& pixels);
239 bool LoadTexturePngFile(
char const* filename);
244 bool LoadTextureJpegFile(
char const* filename);
248 return static_cast<size_t>(y) *
static_cast<size_t>(mWidth) +
static_cast<size_t>(x);
253 return mData[GetLinearIndex(x, y)];
258 return mData[GetLinearIndex(x, y)];
263 unsigned int mHeight;
265 std::vector<Color> mData;
Represents raw 2D image data stored in memory.
const Color & PixelRef(unsigned int x, unsigned int y) const
size_t GetLinearIndex(unsigned int x, unsigned int y) const
unsigned int GetWidth() const
Returns the image width.
unsigned int GetHeight() const
Returns the image height.
Color & PixelRef(unsigned int x, unsigned int y)
size_t GetSizeInBytes() const
Gets the total size of the image in memory.
Represents a color with red, green, blue, and alpha channels.
Color()
Default constructor. Initializes to black with full opacity.
Color(uint8_t iR, uint8_t iG, uint8_t iB)
Constructs a fully opaque RGB color.
Color(uint8_t iR, uint8_t iG, uint8_t iB, uint8_t iA)
Constructs a color with specified RGBA channels.
bool operator==(Color const &rhs) const
Equality operator for comparing two colors.