The small3d library
Tiny C++ 3D game development library for Win/MacOS/Linux/FreeBSD
Loading...
Searching...
No Matches
Image.hpp
Go to the documentation of this file.
1
10#pragma once
11
12#include <string>
13#include <memory>
14#include <vector>
15#include "Logger.hpp"
16#include <png.h>
17#include "Math.hpp"
18
19namespace small3d {
20
29 class Image {
30 private:
31
32 struct memoryDataAndPos_ {
33 std::vector<char> data;
34 uint64_t pos = 0;
35 template <class Archive>
36 void serialize(Archive& archive) {
37 archive(data, pos);
38 }
39 };
40
41 memoryDataAndPos_ memoryDataAndPos;
42
43 unsigned long width = 0, height = 0;
44 std::vector<uint8_t> imageData;
45 unsigned long imageDataSize = 0;
46 void load(const std::string& fileLocation, std::vector<char>& data);
47 static void readDataFromMemory(png_structp png_ptr, png_bytep outBytes,
48 png_size_t byteCountToRead);
49
50 public:
51
56 static const std::string NOTRGBA;
57
63 explicit Image(const std::string& fileLocation = "");
64
70 explicit Image(std::vector<char>& data);
71
75 ~Image() = default;
76
81 void toColour(Vec4 colour);
82
87 unsigned long getWidth() const;
88
93 unsigned long getHeight() const;
94
99 unsigned long getByteSize() const;
100
105 const uint8_t* getData() const;
106
107 template <class Archive>
108 void serialize(Archive& archive) {
109 archive(memoryDataAndPos, width, height, imageData, imageDataSize);
110 }
111
112 };
113
114}
Logger used in small3d.
Vectors, matrices and other math things.
An image, loaded from a .png file, which can be used for generating textures.
Definition Image.hpp:29
unsigned long getByteSize() const
Get the size of the image, in bytes.
Definition Image.cpp:283
unsigned long getWidth() const
Get the image width.
Definition Image.cpp:275
Image(const std::string &fileLocation="")
File-reading constructor.
Definition Image.cpp:18
const uint8_t * getData() const
Get the image data.
Definition Image.cpp:287
unsigned long getHeight() const
Get the image height.
Definition Image.cpp:279
static const std::string NOTRGBA
String saying that the colour encoding of the image being read is not RGB/RGBA.
Definition Image.hpp:56
void toColour(Vec4 colour)
Convert to a coloured 10 x 10 pixel image.
Definition Image.cpp:56
~Image()=default
Destructor.
Definition BinaryFile.hpp:15
4 component vector
Definition Math.hpp:68