QT,使用硬件加速(GPU)将原始图像转换为jpg
我需要将 Raw 图像缓冲区转换为 jpg 图像缓冲区。
目前,我通过以下方式执行此操作:
QImage tmpImage
= QImage(rawImgBuffer, img_width, img_height, image.format ); //image.format=RGB888
QBuffer bufferJpeg(&ba);
bufferJpeg.open(QIODevice::WriteOnly);
tmpImage.save(&bufferJpeg, "JPG");
QByteArray finalJpgBuffer = bufferJpeg.data();
它工作正常,但 cpu 负载太高(我有很多线程每秒多次执行此操作)。 阅读 Qt 文档我发现这篇文章:硬件加速和嵌入式平台。 如果我理解,我可以使用 QPainter 类来执行 GPU 操作...... 是否可以使用此类进行此转换(从 raw 到 jpg)? (或另一个使用硬件加速(GPU)的类似Qt类)!
我的应用程序需要独立于平台。
非常感谢。
I need to convert an Raw image buffer into a jpg image buffer.
At the moment, I do this operation in the following way:
QImage tmpImage
= QImage(rawImgBuffer, img_width, img_height, image.format ); //image.format=RGB888
QBuffer bufferJpeg(&ba);
bufferJpeg.open(QIODevice::WriteOnly);
tmpImage.save(&bufferJpeg, "JPG");
QByteArray finalJpgBuffer = bufferJpeg.data();
It works fine but the cpu load is too high (I have a lot of threads that do this operation a lot of time each second).
Reading the Qt documentation I found this article: Hardware Acceleration & Embedded Platforms.
If i understood, I can use the QPainter class to execute gpu operations...
Is it possible to do this convertion (from raw to jpg) using this class? (or another similar Qt class that use hardware acceleration (gpu))!!
My application need to be platform indipendent.
Thanx at all.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为 QImage 使用 GPU 来生成 jpeg。
这可能没有帮助(除非在非常有限的 CPU 上),因为从 GPU 取回数据的传输时间通常占主导地位。使用硬件加速进行显示的原因是结果已经在 GPU 中准备好显示。
I don't think QImage uses the GPU to generate a jpeg.
This probably wouldn't help (except on very limited CPUs) since the transfer time of getting the data back out of the GPU would normally dominate. The reason for using hardware acceleration for display is that the result is then already in the GPU ready for display.
据我所知,QPainter 不处理图像格式(在本例中为 jpeg)的解码。它是由 Qt 使用 libjpeg 完成的,libjpeg 由 Qt 使用插件控制。您可以在 qt_source_tree/src/plugins/imageformats/jpeg 中找到该插件。这只是使用系统上可用的库(Linux 中的 libjpeg.so)。如果它是硬件加速或不加速,则取决于您的系统。
我遇到过硬件解码需要使用特定库的情况。在这种情况下,我必须创建一个特定的 Qt 插件来处理这个问题。
As far as I know decoding of image formats (jpeg in this case) is not handled by QPainter. It is done by Qt using libjpeg, which is controlled by Qt using a plugin. You can find the plugin in qt_source_tree/src/plugins/imageformats/jpeg. That is simply using the library you have available on your system (libjpeg.so in Linux). If it is hardware accelerated or not, it is up to your system.
I had a case in which hardware decoding required to use a specific library. In that case I had to create a specific Qt plugin to handle that.