-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQtAxodoxInteropCommon.hpp
42 lines (31 loc) · 1.34 KB
/
QtAxodoxInteropCommon.hpp
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
#pragma once
#include "Include/Axodox.Graphics.h"
#include "Include/Axodox.Collections.h"
#include "Include/Axodox.Infrastructure.h"
#include "Include/Axodox.MachineLearning.h"
#include <QImage>
namespace QtAxInterop {
class InterOpHelper
{
InterOpHelper() {};
public:
static void QImageToTextureData(QImage& ReadyImage, Axodox::Graphics::TextureData& TexDat)
{
ReadyImage = ReadyImage.convertToFormat(QImage::Format_RGBA8888);
TexDat.Width = ReadyImage.width(); TexDat.Height = ReadyImage.height();
TexDat.Stride = ReadyImage.bytesPerLine();
TexDat.Format = DXGI_FORMAT_R8G8B8A8_UNORM_SRGB;
const uint8_t* data = reinterpret_cast<const uint8_t*>(ReadyImage.bits());
size_t dataSize = static_cast<size_t>(ReadyImage.sizeInBytes());
TexDat.Buffer.assign(data, data + dataSize);
}
static void TextureDataToQImage(Axodox::Graphics::TextureData& TexDat, QImage& OutImg)
{
int bytesPerPixel = 4;
QImage::Format format = QImage::Format_RGBA8888;
auto ImageBuffer = TexDat.ToFormat(DXGI_FORMAT_R8G8B8A8_UNORM_SRGB).Buffer;
QImage image(ImageBuffer.data(), TexDat.Width, TexDat.Height, TexDat.Width * bytesPerPixel, format);
OutImg = image.copy();
}
};
}