Jpeg 库的解码OpenCL优化
来源:互联网 发布:php sae环境 编辑:程序博客网 时间:2024/06/06 15:36
libJpeg库解码OpenCL优化
这两周在闲暇时基于通用的libjpeg库重新做了一个opencl解码实现。重新熟悉下算法。
代码路径
https://github.com/jxt1234/platform_external_jpeg
OpenCL文件夹目录下面的就是所有的修改。
用Xcode开发的,没兴趣去整Makefile了,代码独立,移植集成也很方便。
主要特点
1.算法代码完全独立,不修改原来库中的代码。
2.支持各种YUV格式(411、422、444等等)。
3.霍夫曼解码仍然由CPU完成,采用OpenCL做idct和颜色转换,向量化实现,效率很高。(PS:当年移植那个坑爹的libjpeg-opencl时被坑死了)
4.只支持输出为rgb的格式,需要扩展的看下代码自己改,也不麻烦,这部分用simd实现比较好,因此没怎么写。
使用示例
extern "C"{#include "jpeglib.h"};int main() { const char* inputfile = "input.jpg"; const char* outputfile = "output.jpeg"; struct jpeg_decompress_struct cinfo; FILE* infile; int row_stride; auto sta = clock(); if ((infile = fopen(inputfile, "rb")) == NULL) { return NULL; } jpeg_create_decompress(&cinfo); struct jpeg_error_mgr jerr; cinfo.err = jpeg_std_error(&jerr); jpeg_stdio_src(&cinfo, infile); (void) jpeg_read_header(&cinfo, TRUE); /*必须设成float方式,若是cpu解码,这个会影响性能,但对于gpu来说没有关系,而且float方式精度最高,几乎不会造成图片失真*/ cinfo.dct_method = JDCT_FLOAT; (void) jpeg_start_decompress(&cinfo); auto width = cinfo.output_width; auto height = cinfo.output_height; /*rgb 三个分量*/ auto pixels = (JSAMPLE*)(malloc(width*height*3)); /*opencl 解码的 api*/ /*pixels 默认为rgb24位,事先分配好内存*/ jpeg_decode_by_opencl(&cinfo, pixels); //这里用abort而不是finish,直接中止掉 (void) jpeg_abort_decompress(&cinfo); jpeg_destroy_decompress(&cinfo); fclose(infile); auto fin = clock(); printf("Time cost for %d * %d, %lu / %ds\n", width, height, fin-sta, CLOCKS_PER_SEC); /*用得到的pixels做一些事情。。。。。。*/ /*释放掉pixels*/ free(pixels); return 0;}
性能数据
MACBook上数据,仅供参考
OpenCL优化后数据:
Time cost for 3200 * 2000, 177757 / 1000000s
MCU is 130001 / 1000000s
原CPU方式数据
Time cost for 3200 * 2000, 363453 / 1000000s
idct和颜色转换的时间压缩到可以忽略不计了。几乎只剩下解霍夫曼编码的时间,总体性能是提升了100%。
1 0
- Jpeg 库的解码OpenCL优化
- JPEG 编解码在 Cell 上的优化
- JPEG 编解码在 Cell 上的优化
- linux下的jpeg解码库使用
- S3C6410的JPEG解码
- S3C6410的JPEG解码
- 简单的JPEG解码程序
- 简单的JPEG解码程序
- 简单的JPEG解码程序
- 基于CUDA的JPEG解码
- 简单的JPEG解码程序
- jpeg解码库使用实例
- JPEG解码
- jpeg解码
- JPEG解码
- JPEG解码
- jpeg解码
- jpeg图像的压缩编码与解码
- ubuntu修改用户名、计算机名、主目录名
- linux 命令系列之 passwd(25)
- MFC 中ComboBox的 Data属性设置多行选项
- 开课第一天
- DFS深度优先搜索之lake counting
- Jpeg 库的解码OpenCL优化
- Android Studio安装时的注意点
- 【RFID第五次作业】第八章课后习题
- 结构体的巨大作用
- Bounded Recovery
- 物联网1122班刘佳 第八章作业
- 【狗狗40】Square Ice
- HDU1316 How Many Fibs? 【大数】
- (转载)Android Fragment 真正的完全解析(下)