|  | 
| 4 | 4 | #include <span> | 
| 5 | 5 | #include <vector> | 
| 6 | 6 | 
 | 
|  | 7 | +#include <sourcepp/math/Float.h> | 
|  | 8 | + | 
| 7 | 9 | #include "ImageFormats.h" | 
| 8 | 10 | 
 | 
| 9 |  | -namespace vtfpp::ImageConversion { | 
|  | 11 | +namespace vtfpp { | 
|  | 12 | + | 
|  | 13 | +namespace ImagePixel { | 
|  | 14 | + | 
|  | 15 | +struct RGBA8888 { | 
|  | 16 | +	static constexpr auto FORMAT = ImageFormat::RGBA8888; | 
|  | 17 | +	uint8_t r; | 
|  | 18 | +	uint8_t g; | 
|  | 19 | +	uint8_t b; | 
|  | 20 | +	uint8_t a; | 
|  | 21 | +}; | 
|  | 22 | + | 
|  | 23 | +struct ABGR8888 { | 
|  | 24 | +	static constexpr auto FORMAT = ImageFormat::ABGR8888; | 
|  | 25 | +	uint8_t a; | 
|  | 26 | +	uint8_t b; | 
|  | 27 | +	uint8_t g; | 
|  | 28 | +	uint8_t r; | 
|  | 29 | +}; | 
|  | 30 | + | 
|  | 31 | +struct RGB888 { | 
|  | 32 | +	static constexpr auto FORMAT = ImageFormat::RGB888; | 
|  | 33 | +	uint8_t r; | 
|  | 34 | +	uint8_t g; | 
|  | 35 | +	uint8_t b; | 
|  | 36 | +}; | 
|  | 37 | + | 
|  | 38 | +struct RGB888_BLUESCREEN : public RGB888 { | 
|  | 39 | +	static constexpr auto FORMAT = ImageFormat::RGB888_BLUESCREEN; | 
|  | 40 | +}; | 
|  | 41 | + | 
|  | 42 | +struct BGR888 { | 
|  | 43 | +	static constexpr auto FORMAT = ImageFormat::BGR888; | 
|  | 44 | +	uint8_t b; | 
|  | 45 | +	uint8_t g; | 
|  | 46 | +	uint8_t r; | 
|  | 47 | +}; | 
|  | 48 | + | 
|  | 49 | +struct BGR888_BLUESCREEN : public BGR888 { | 
|  | 50 | +	static constexpr auto FORMAT = ImageFormat::BGR888_BLUESCREEN; | 
|  | 51 | +}; | 
|  | 52 | + | 
|  | 53 | +struct RGB565 { | 
|  | 54 | +	static constexpr auto FORMAT = ImageFormat::RGB565; | 
|  | 55 | +	uint16_t r : 5; | 
|  | 56 | +	uint16_t g : 6; | 
|  | 57 | +	uint16_t b : 5; | 
|  | 58 | +}; | 
|  | 59 | + | 
|  | 60 | +struct I8 { | 
|  | 61 | +	static constexpr auto FORMAT = ImageFormat::I8; | 
|  | 62 | +	uint8_t i; | 
|  | 63 | +}; | 
|  | 64 | + | 
|  | 65 | +struct IA88 { | 
|  | 66 | +	static constexpr auto FORMAT = ImageFormat::IA88; | 
|  | 67 | +	uint8_t i; | 
|  | 68 | +	uint8_t a; | 
|  | 69 | +}; | 
|  | 70 | + | 
|  | 71 | +struct P8 { | 
|  | 72 | +	static constexpr auto FORMAT = ImageFormat::P8; | 
|  | 73 | +	uint8_t p; | 
|  | 74 | +}; | 
|  | 75 | + | 
|  | 76 | +struct A8 { | 
|  | 77 | +	static constexpr auto FORMAT = ImageFormat::A8; | 
|  | 78 | +	uint8_t a; | 
|  | 79 | +}; | 
|  | 80 | + | 
|  | 81 | +struct ARGB8888 { | 
|  | 82 | +	static constexpr auto FORMAT = ImageFormat::ARGB8888; | 
|  | 83 | +	uint8_t a; | 
|  | 84 | +	uint8_t r; | 
|  | 85 | +	uint8_t g; | 
|  | 86 | +	uint8_t b; | 
|  | 87 | +}; | 
|  | 88 | + | 
|  | 89 | +struct BGRA8888 { | 
|  | 90 | +	static constexpr auto FORMAT = ImageFormat::BGRA8888; | 
|  | 91 | +	uint8_t b; | 
|  | 92 | +	uint8_t g; | 
|  | 93 | +	uint8_t r; | 
|  | 94 | +	uint8_t a; | 
|  | 95 | +}; | 
|  | 96 | + | 
|  | 97 | +struct BGRX8888 { | 
|  | 98 | +	static constexpr auto FORMAT = ImageFormat::BGRX8888; | 
|  | 99 | +	uint8_t b; | 
|  | 100 | +	uint8_t g; | 
|  | 101 | +	uint8_t r; | 
|  | 102 | +	uint8_t x; | 
|  | 103 | +}; | 
|  | 104 | + | 
|  | 105 | +struct BGR565 { | 
|  | 106 | +	static constexpr auto FORMAT = ImageFormat::BGR565; | 
|  | 107 | +	uint16_t b : 5; | 
|  | 108 | +	uint16_t g : 6; | 
|  | 109 | +	uint16_t r : 5; | 
|  | 110 | +}; | 
|  | 111 | + | 
|  | 112 | +struct BGRX5551 { | 
|  | 113 | +	static constexpr auto FORMAT = ImageFormat::BGRX5551; | 
|  | 114 | +	uint16_t b : 5; | 
|  | 115 | +	uint16_t g : 5; | 
|  | 116 | +	uint16_t r : 5; | 
|  | 117 | +	uint16_t x : 1; | 
|  | 118 | +}; | 
|  | 119 | + | 
|  | 120 | +struct BGRA4444 { | 
|  | 121 | +	static constexpr auto FORMAT = ImageFormat::BGRA4444; | 
|  | 122 | +	uint16_t b : 4; | 
|  | 123 | +	uint16_t g : 4; | 
|  | 124 | +	uint16_t r : 4; | 
|  | 125 | +	uint16_t a : 4; | 
|  | 126 | +}; | 
|  | 127 | + | 
|  | 128 | +struct BGRA5551 { | 
|  | 129 | +	static constexpr auto FORMAT = ImageFormat::BGRA5551; | 
|  | 130 | +	uint16_t b : 5; | 
|  | 131 | +	uint16_t g : 5; | 
|  | 132 | +	uint16_t r : 5; | 
|  | 133 | +	uint16_t a : 1; | 
|  | 134 | +}; | 
|  | 135 | + | 
|  | 136 | +struct UV88 { | 
|  | 137 | +	static constexpr auto FORMAT = ImageFormat::UV88; | 
|  | 138 | +	uint8_t u; | 
|  | 139 | +	uint8_t v; | 
|  | 140 | +}; | 
|  | 141 | + | 
|  | 142 | +struct UVWQ8888 { | 
|  | 143 | +	static constexpr auto FORMAT = ImageFormat::UVWQ8888; | 
|  | 144 | +	uint8_t u; | 
|  | 145 | +	uint8_t v; | 
|  | 146 | +	uint8_t w; | 
|  | 147 | +	uint8_t q; | 
|  | 148 | +}; | 
|  | 149 | + | 
|  | 150 | +struct RGBA16161616F { | 
|  | 151 | +	static constexpr auto FORMAT = ImageFormat::RGBA16161616F; | 
|  | 152 | +	sourcepp::math::FloatCompressed16 r; | 
|  | 153 | +	sourcepp::math::FloatCompressed16 g; | 
|  | 154 | +	sourcepp::math::FloatCompressed16 b; | 
|  | 155 | +	sourcepp::math::FloatCompressed16 a; | 
|  | 156 | +}; | 
|  | 157 | + | 
|  | 158 | +struct RGBA16161616 { | 
|  | 159 | +	static constexpr auto FORMAT = ImageFormat::RGBA16161616; | 
|  | 160 | +	uint16_t r; | 
|  | 161 | +	uint16_t g; | 
|  | 162 | +	uint16_t b; | 
|  | 163 | +	uint16_t a; | 
|  | 164 | +}; | 
|  | 165 | + | 
|  | 166 | +struct UVLX8888 { | 
|  | 167 | +	static constexpr auto FORMAT = ImageFormat::UVLX8888; | 
|  | 168 | +	uint8_t u; | 
|  | 169 | +	uint8_t v; | 
|  | 170 | +	uint8_t l; | 
|  | 171 | +	uint8_t x; | 
|  | 172 | +}; | 
|  | 173 | + | 
|  | 174 | +struct R32F { | 
|  | 175 | +	static constexpr auto FORMAT = ImageFormat::R32F; | 
|  | 176 | +	float r; | 
|  | 177 | +}; | 
|  | 178 | + | 
|  | 179 | +struct RGB323232F { | 
|  | 180 | +	static constexpr auto FORMAT = ImageFormat::R32F; | 
|  | 181 | +	float r; | 
|  | 182 | +	float g; | 
|  | 183 | +	float b; | 
|  | 184 | +}; | 
|  | 185 | + | 
|  | 186 | +struct RGBA32323232F { | 
|  | 187 | +	static constexpr auto FORMAT = ImageFormat::RGBA32323232F; | 
|  | 188 | +	float r; | 
|  | 189 | +	float g; | 
|  | 190 | +	float b; | 
|  | 191 | +	float a; | 
|  | 192 | +}; | 
|  | 193 | + | 
|  | 194 | +} // namespace ImagePixel | 
|  | 195 | + | 
|  | 196 | +namespace ImageConversion { | 
| 10 | 197 | 
 | 
| 11 | 198 | /// Converts an image from one format to another. | 
| 12 | 199 | [[nodiscard]] std::vector<std::byte> convertImageDataToFormat(std::span<const std::byte> imageData, ImageFormat oldFormat, ImageFormat newFormat, uint16_t width, uint16_t height); | 
| @@ -56,4 +243,6 @@ void setResizedDims(uint16_t& width, ResizeMethod widthResize, uint16_t& height, | 
| 56 | 243 | /// Resize given image data to the new dimensions, where the new width and height are governed by the resize methods | 
| 57 | 244 | [[nodiscard]] std::vector<std::byte> resizeImageDataStrict(std::span<const std::byte> imageData, ImageFormat format, uint16_t width, uint16_t newWidth, uint16_t& widthOut, ResizeMethod widthResize, uint16_t height, uint16_t newHeight, uint16_t& heightOut, ResizeMethod heightResize, bool srgb, ResizeFilter filter, ResizeEdge edge = ResizeEdge::CLAMP); | 
| 58 | 245 | 
 | 
| 59 |  | -} // namespace vtfpp::ImageConversion | 
|  | 246 | +} // namespace ImageConversion | 
|  | 247 | + | 
|  | 248 | +} // namespace vtfpp | 
0 commit comments