Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [QOpenGLWidget] flashing image where I use OpenCL
Forum Update on Monday, May 27th 2025

[QOpenGLWidget] flashing image where I use OpenCL

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 375 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    debian
    wrote on 13 Nov 2015, 13:48 last edited by
    #1

    Hello!
    I have to output several network streams, now I use qt-5.5.1 and OpenGL.
    Because network streams in YUV420 I convert it to RGB (http://www.fourcc.org/fccyvrgb.php), it work, but not very quick.
    Now I try use OpenCL for convert streams, follow my code:
    QImage OCL::convert(const char *buf, quint16 width, quint16 height, ocl_queue queue)
    {
    QImage img;
    if (_ready && buf && width && height && queue < QUEUE_UNKNOWN) {
    const size_t stride = width * 4;
    const size_t sz = stride * height;
    const size_t dims[2] = {width, height};
    cl_mem in = NULL;
    cl_mem out = NULL;
    _rgb[queue].resize(sz);
    in = clCreateBuffer(_context, CL_MEM_READ_ONLY, width * height * 3 / 2, NULL, &_ret);
    if (IS_ERROR(_ret)) {
    qDebug() << "clCreateBuffer input, error" << _ret;
    goto EXIT;
    }
    out = clCreateBuffer(_context, CL_MEM_WRITE_ONLY, sz, NULL, &_ret);
    if (IS_ERROR(_ret)) {
    qDebug() << "clCreateBuffer out, error" << _ret;
    goto EXIT;
    }
    _ret = clSetKernelArg(_kernel, 0, sizeof(cl_mem), &in);
    if (IS_ERROR(_ret)) {
    qDebug() << "clSetKernelArg 0, error" << _ret;
    goto EXIT;
    }
    _ret = clSetKernelArg(_kernel, 1, sizeof(cl_mem), &out);
    if (IS_ERROR(_ret)) {
    qDebug() << "clSetKernelArg 1, error" << _ret;
    goto EXIT;
    }
    _ret = clEnqueueWriteBuffer(_command[queue], in, CL_TRUE, 0, width * height * 3 / 2, buf, 0, NULL, NULL);
    if (IS_ERROR(_ret)) {
    qDebug() << "clEnqueueWriteBuffer, error" << _ret;
    goto EXIT;
    }
    // FIXME: periodic clEnqueueNDRangeKernel, error -52
    _ret = clEnqueueNDRangeKernel(_command[queue], _kernel, 2, NULL, dims, NULL, 0, NULL, NULL);
    if (IS_ERROR(_ret)) {
    qDebug() << "clEnqueueNDRangeKernel, error" << _ret;
    goto EXIT;
    }
    _ret = clEnqueueReadBuffer(_command[queue], out, CL_TRUE, 0, sz, _rgb[queue].data(), 0, NULL, NULL);
    if (IS_ERROR(_ret)) {
    qDebug() << "clEnqueueReadBuffer, error" << _ret;
    goto EXIT;
    }
    img = QImage(reinterpret_cast<const uchar *>(_rgb[queue].constData()), width, height, stride, QImage::Format_ARGB32);
    EXIT:
    if (in != NULL)
    clReleaseMemObject(in);
    if (out != NULL)
    clReleaseMemObject(out);
    }
    return img;
    }
    This is work very quick, but I see flashing images.
    How can I solve this problem?
    Thank you and excuse my bad english.

    1 Reply Last reply
    0

    1/1

    13 Nov 2015, 13:48

    • Login

    • Login or register to search.
    1 out of 1
    • First post
      1/1
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved