-
Notifications
You must be signed in to change notification settings - Fork 0
/
VTFCubeConverter.cpp
78 lines (66 loc) · 1.95 KB
/
VTFCubeConverter.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#define _USE_MATH_DEFINES
#include <math.h>
#include "VTFCubeConverter.h"
using namespace std;
VTFCubeConverter::VTFCubeConverter(std::string path, ConvertOptions* options) : CubeConverter(path, options)
{
}
bool VTFCubeConverter::Convert(std::string* faces)
{
int maxSize = 0;
for (int i = 0; i < 6; i++)
{
printf("Loading vtf '%s'...\n", faces[i].c_str());
auto success = faceVTFs[i].Load(faces[i].c_str());
if (!success)
{
printf("Error: Unable to load image '%s'\n", faces[i]);
return false;
}
else
{
int width = (int)faceVTFs[i].GetWidth();
int height = (int)faceVTFs[i].GetHeight();
maxSize = max(maxSize, width);
maxSize = max(maxSize, height);
//Decode vtf data from encodeded hdr bgra
float* decodedData = new float[width * height * 3];
decodedFaces[i] = decodedData;
auto vtfData = faceVTFs[i].GetData(0, 0, 0, 0);
int32_t t = 0;
for (int32_t s = 0; s < width * height * 4; s+= 4, t += 3)
{
bgra2float(&vtfData[s], &decodedData[t]);
}
}
}
DoConvertion(maxSize);
}
float* VTFCubeConverter::GetSourcePixel(int x, int y, int cubeFace)
{
auto* faceVTF = &faceVTFs[cubeFace];
int width = faceVTF->GetWidth();
int height = faceVTF->GetHeight();
x = min(width - 1, x);
y = min(height - 1, y);
int start = ((width * y) + x) * 3;
return &decodedFaces[cubeFace][start];
}
void VTFCubeConverter::GetCubeFaceSize(int cubeFace, int* width, int* height)
{
auto face = &faceVTFs[cubeFace];
*width = face->GetWidth();
*height = face->GetHeight();
//Pretend half height cube faces are square
if (*height * 2 == *width)
{
*height = *width;
}
}
VTFCubeConverter::~VTFCubeConverter()
{
for (int i = 0; i < 6; i++)
{
delete[] decodedFaces[i];
}
}