Shifting the hue of a QImage / QPixmap

亡梦爱人 提交于 2019-12-04 08:30:54

A possible course of action:

  1. Load your image as a QImage
  2. Do a QImage QImage::convertToFormat(QImage::Format_Indexed8) to get a indexed image with a color table
  3. Get color table values with QRgb QImage::color ( int i ) const
  4. Manipulate the colors with QColor ( QRgb color ) and the other QColor methods
  5. Alter the color table with void QImage::setColor ( int index, QRgb colorValue )

You've got a few options, none of which are built-in Qt solutions, unfortunately.

  1. Use OpenMP or some other concurrency library to take advantage of SSE/SSE2.
  2. Use the GPU via OpenGL, DirectX or various GPGPU programming techniques.
  3. (the solution I chose) Use OpenCL to take advantage of both CPU and GPU concurency without all the "fun" of shader programming.
  4. Spawn off a pool of thread workers and have each of them handle a chunk of the image.

My application does lots of image filtering and I was honestly shocked at the performance gain that was to be had after I ported filters to OpenCL.

At 1936×2592 a brightness modification filter was running in 175ms in native C++ code iterating through each pixel within a QImage.

After porting to OpenCL that went down to 15ms. Of course, the data had to be pulled out of the QImage and reinserted but that overhead was nothing compared to the OpenCL performance gains.

Best of luck on your coding adventures!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!