diff options
author | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-05-01 22:52:45 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@theqtcompany.com> | 2015-05-02 16:18:04 +0000 |
commit | a6abebf98ecfbadfeec252283feeea9e04715581 (patch) | |
tree | 1bda4a827305380e6453a1f39250de136c2d21f6 | |
parent | 749f98c8f28ffd06d5caccffe60edc94f280f6f7 (diff) |
Change-Id: I10ec7869659b69038811bd48b6beb7f43fbc5a8c
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
-rw-r--r-- | src/quickcl/qquickclcontext.cpp | 61 | ||||
-rw-r--r-- | src/quickcl/qquickclcontext.h | 4 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/quickcl/qquickclcontext.cpp b/src/quickcl/qquickclcontext.cpp index 7aae3fa..9d63fec 100644 --- a/src/quickcl/qquickclcontext.cpp +++ b/src/quickcl/qquickclcontext.cpp @@ -397,4 +397,65 @@ cl_program QQuickCLContext::buildProgramFromFile(const QString &filename) return buildProgram(f.readAll()); } +/*! + Returns a matching OpenCL image format for the given QImage \a format. + */ +cl_image_format QQuickCLContext::toCLImageFormat(QImage::Format format) +{ + cl_image_format fmt; + + switch (format) { + case QImage::Format_Indexed8: + fmt.image_channel_order = CL_A; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case QImage::Format_RGB32: + case QImage::Format_ARGB32: + case QImage::Format_ARGB32_Premultiplied: + if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) { + fmt.image_channel_order = CL_BGRA; + fmt.image_channel_data_type = CL_UNORM_INT8; + } else { + fmt.image_channel_order = CL_ARGB; + fmt.image_channel_data_type = CL_UNORM_INT8; + } + break; + + case QImage::Format_RGB16: + fmt.image_channel_order = CL_RGB; + fmt.image_channel_data_type = CL_UNORM_SHORT_565; + break; + + case QImage::Format_RGB555: + fmt.image_channel_order = CL_RGB; + fmt.image_channel_data_type = CL_UNORM_SHORT_555; + break; + + case QImage::Format_RGB888: + fmt.image_channel_order = CL_RGB; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case QImage::Format_RGBX8888: + fmt.image_channel_order = CL_RGBx; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + case QImage::Format_RGBA8888: + case QImage:: Format_RGBA8888_Premultiplied: + fmt.image_channel_order = CL_RGBA; + fmt.image_channel_data_type = CL_UNORM_INT8; + break; + + default: + qWarning("toCLImageFormat: Unrecognized QImage format %d", format); + fmt.image_channel_order = 0; + fmt.image_channel_data_type = 0; + break; + } + + return fmt; +} + QT_END_NAMESPACE diff --git a/src/quickcl/qquickclcontext.h b/src/quickcl/qquickclcontext.h index d780ad5..2072188 100644 --- a/src/quickcl/qquickclcontext.h +++ b/src/quickcl/qquickclcontext.h @@ -38,6 +38,7 @@ #define QQUICKCLCONTEXT_H #include <QtQuickCL/qtquickclglobal.h> +#include <QtGui/qimage.h> QT_BEGIN_NAMESPACE @@ -62,9 +63,12 @@ public: QByteArray platformName() const; QByteArray deviceExtensions() const; + cl_program buildProgram(const QByteArray &src); cl_program buildProgramFromFile(const QString &filename); + static cl_image_format toCLImageFormat(QImage::Format format); + private: QQuickCLContextPrivate *d_ptr; }; |