Skip to content

Commit e21d768

Browse files
wip(vtfpp): accelerate conversion functions
1 parent 88092ea commit e21d768

File tree

8 files changed

+328
-230
lines changed

8 files changed

+328
-230
lines changed

cmake/AddPrettyParser.cmake

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ function(add_pretty_parser TARGET)
2323
# Define DEBUG macro
2424
target_compile_definitions(${TARGET} PRIVATE "$<$<CONFIG:Debug>:DEBUG>")
2525

26+
# MSVC on its bullshit again
27+
if(MSVC)
28+
target_compile_options(${TARGET} PRIVATE "/Zc:preprocessor")
29+
endif()
30+
2631
# Set optimization flags
2732
if(CMAKE_BUILD_TYPE MATCHES "Debug")
2833
# Build with debug friendly optimizations and debug symbols (MSVC defaults are fine)

include/vtfpp/ImageConversion.h

Lines changed: 163 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,168 @@
44
#include <span>
55
#include <vector>
66

7+
#include <sourcepp/math/Float.h>
8+
79
#include "ImageFormats.h"
810

9-
namespace vtfpp::ImageConversion {
11+
namespace vtfpp {
12+
13+
namespace ImagePixel {
14+
15+
struct RGBA8888 {
16+
uint8_t r;
17+
uint8_t g;
18+
uint8_t b;
19+
uint8_t a;
20+
};
21+
22+
struct ABGR8888 {
23+
uint8_t a;
24+
uint8_t b;
25+
uint8_t g;
26+
uint8_t r;
27+
};
28+
29+
struct RGB888 {
30+
uint8_t r;
31+
uint8_t g;
32+
uint8_t b;
33+
};
34+
35+
struct RGB888_BLUESCREEN : public RGB888 {};
36+
37+
struct BGR888 {
38+
uint8_t b;
39+
uint8_t g;
40+
uint8_t r;
41+
};
42+
43+
struct BGR888_BLUESCREEN : public BGR888 {};
44+
45+
struct RGB565 {
46+
uint16_t r : 5;
47+
uint16_t g : 6;
48+
uint16_t b : 5;
49+
};
50+
51+
struct I8 {
52+
uint8_t i;
53+
};
54+
55+
struct IA88 {
56+
uint8_t i;
57+
uint8_t a;
58+
};
59+
60+
struct P8 {
61+
uint8_t p;
62+
};
63+
64+
struct A8 {
65+
uint8_t a;
66+
};
67+
68+
struct ARGB8888 {
69+
uint8_t a;
70+
uint8_t r;
71+
uint8_t g;
72+
uint8_t b;
73+
};
74+
75+
struct BGRA8888 {
76+
uint8_t b;
77+
uint8_t g;
78+
uint8_t r;
79+
uint8_t a;
80+
};
81+
82+
struct BGRX8888 {
83+
uint8_t b;
84+
uint8_t g;
85+
uint8_t r;
86+
uint8_t x;
87+
};
88+
89+
struct BGR565 {
90+
uint16_t b : 5;
91+
uint16_t g : 6;
92+
uint16_t r : 5;
93+
};
94+
95+
struct BGRX5551 {
96+
uint16_t b : 5;
97+
uint16_t g : 5;
98+
uint16_t r : 5;
99+
uint16_t x : 1;
100+
};
101+
102+
struct BGRA4444 {
103+
uint16_t b : 4;
104+
uint16_t g : 4;
105+
uint16_t r : 4;
106+
uint16_t a : 4;
107+
};
108+
109+
struct BGRA5551 {
110+
uint16_t b : 5;
111+
uint16_t g : 5;
112+
uint16_t r : 5;
113+
uint16_t a : 1;
114+
};
115+
116+
struct UV88 {
117+
uint8_t u;
118+
uint8_t v;
119+
};
120+
121+
struct UVWQ8888 {
122+
uint8_t u;
123+
uint8_t v;
124+
uint8_t w;
125+
uint8_t q;
126+
};
127+
128+
struct RGBA16161616F {
129+
sourcepp::math::FloatCompressed16 r;
130+
sourcepp::math::FloatCompressed16 g;
131+
sourcepp::math::FloatCompressed16 b;
132+
sourcepp::math::FloatCompressed16 a;
133+
};
134+
135+
struct RGBA16161616 {
136+
uint16_t r;
137+
uint16_t g;
138+
uint16_t b;
139+
uint16_t a;
140+
};
141+
142+
struct UVLX8888 {
143+
uint8_t u;
144+
uint8_t v;
145+
uint8_t l;
146+
uint8_t x;
147+
};
148+
149+
struct R32F {
150+
float r;
151+
};
152+
153+
struct RGB323232F {
154+
float r;
155+
float g;
156+
float b;
157+
};
158+
159+
struct RGBA32323232F {
160+
float r;
161+
float g;
162+
float b;
163+
float a;
164+
};
165+
166+
} // namespace Pixel
167+
168+
namespace ImageConversion {
10169

11170
/// Converts an image from one format to another.
12171
[[nodiscard]] std::vector<std::byte> convertImageDataToFormat(std::span<const std::byte> imageData, ImageFormat oldFormat, ImageFormat newFormat, uint16_t width, uint16_t height);
@@ -56,4 +215,6 @@ void setResizedDims(uint16_t& width, ResizeMethod widthResize, uint16_t& height,
56215
/// Resize given image data to the new dimensions, where the new width and height are governed by the resize methods
57216
[[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);
58217

59-
} // namespace vtfpp::ImageConversion
218+
} // namespace ImageConversion
219+
220+
} // namespace vtfpp

0 commit comments

Comments
 (0)