-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathjulia_imageprovider.cpp
More file actions
62 lines (51 loc) · 1.86 KB
/
julia_imageprovider.cpp
File metadata and controls
62 lines (51 loc) · 1.86 KB
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
#include "jlcxx/functions.hpp"
#include "julia_api.hpp"
#include "julia_imageprovider.hpp"
#include "foreign_thread_manager.hpp"
#include <QThread>
namespace qmlwrap
{
JuliaImageProvider::JuliaImageProvider(QQmlImageProviderBase::ImageType type) : QQuickImageProvider(type)
{
}
template<typename ImageT>
inline ImageT process_request(JuliaImageProvider::callback_t f, const QString &id, QSize *size, const QSize &requestedSize)
{
if(f == nullptr)
{
throw std::runtime_error("No callback function set for JuliaImageProvider");
}
GCGuard gc_guard;
ImageResult<ImageT> response = jlcxx::unbox<ImageResult<ImageT>>(f(id, requestedSize.width(), requestedSize.height()));
*size = response.m_size;
return std::move(response.m_image);
}
QImage JuliaImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
{
if(imageType() != QQmlImageProviderBase::Image)
{
throw std::runtime_error("JuliaImageProvider is not of type Image");
}
return process_request<QImage>(m_callback, id, size, requestedSize);
}
QPixmap JuliaImageProvider::requestPixmap(const QString &id, QSize *size, const QSize &requestedSize)
{
if(imageType() != QQmlImageProviderBase::Pixmap)
{
throw std::runtime_error("JuliaImageProvider is not of type Pixmap");
}
return process_request<QPixmap>(m_callback, id, size, requestedSize);
}
QQuickTextureFactory *JuliaImageProvider::requestTexture(const QString &id, QSize *size, const QSize &requestedSize)
{
if(imageType() != QQmlImageProviderBase::Texture)
{
throw std::runtime_error("JuliaImageProvider is not of type Texture");
}
return process_request<QQuickTextureFactory*>(m_callback, id, size, requestedSize);
}
void JuliaImageProvider::set_callback(jlcxx::SafeCFunction fdata)
{
m_callback = jlcxx::make_function_pointer<jl_value_t*(const QString&,int,int)>(fdata);
}
} // namespace qmlwrap