CCS+C6678LE开发记录05:编译并使用开源JPEG图像(解)压缩库libjpeg

本文详细介绍了如何将libjpeg库移植到TI的TMS320C6678处理器上,并提供了一个读取JPEG图片的示例程序。从准备libjpeg源码开始,一步步指导如何在CCS环境中配置和编译,最终生成静态库文件。同时,文章还分享了如何在项目中使用该库进行JPEG图片的解码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

憋了这么久终于要爆发了。

上次解决了BMP图片读取的问题,这一次想解决读取JPEG图片的问题,本来打算自己新造一个轮子的,

但是既然已经有了libjpeg为何不尝试移植呢?话说这次真的移植成功了!

废话不多说,就列出具体步骤吧。

首先是准备libjpeg的源码(删除所有不必要的文件),我这里有一份整理好的源码压缩包,下载链接

http://download.youkuaiyun.com/detail/von_ryan_hack/8317245

然后打开CCS新建项目





设置目标平台为TMS320C6678

项目名称libjpeg

点击[ Next > ] 弹出对话框,展开[ Advanced Settings ]

选择Output type为Static Library


项目模板为Empty Project



在项目上右键菜单选择添加文件



浏览libjpeg源码文件夹,[Add Files...]添加文件(全选)



提示,选择【复制文件】即可



编译类型默认为Debug,如需调整,可在项目右键设置

或者打开设置对话框,选择 [Manage Configurations...]



选择Release并【Set Active】



接下来执行[Project]-->[Build All]即可

编译完成后请将输出文件夹(Debug或Release文件夹)下的libjpeg.lib

和jconfig.h   jmorecfg.h   jpeglib.h这写文件拷贝出来以供其他项目使用。


下面给出一个应用示例

新建项目(可参考这篇文章http://blog.youkuaiyun.com/fengyhack/article/details/41945029)

设置的时候注意添加libjpeg.lib以及jconfig.h; jmorecfg.h; jpeglib.h这几个文件

添加文件后,打开项目属性设置对话框



浏览Workspace选择刚才添加的libjpeg.lib文件


然后确定



接下来贴上示例的源代码main.c

(参考http://blog.youkuaiyun.com/fengyhack/article/details/42239807)

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "jpeglib.h"
  4. typedef unsigned char BYTE;
  5. int main(void)
  6. {
  7. char* szFileName = "F:\\Images\\Snapshot\\000.jpg";
  8. struct jpeg_decompress_struct cinfo;
  9. struct jpeg_error_mgr jerr;
  10. // STEP 1: StdError
  11. printf("\n-----------------------------------\n");
  12. cinfo.err = jpeg_std_error(&jerr);
  13. // STEP 2: Create
  14. printf("Create decompress information.\n");
  15. jpeg_create_decompress(&cinfo);
  16. FILE* pf = fopen(szFileName, "rb");
  17. if (pf != NULL)
  18. {
  19. // STEP 3: IO
  20. printf("Attach input file.\n");
  21. jpeg_stdio_src(&cinfo, pf);
  22. // STEP 4: Header
  23. printf("Read header information.\n");
  24. jpeg_read_header(&cinfo, TRUE);
  25. long width=cinfo.image_width;
  26. long height=cinfo.image_height;
  27. long channels=cinfo.num_components;
  28. printf("Image size information:\n%d*%d*%d(width*height*channel)\n",width,height,channels);
  29. long bytes = width*height*channels;
  30. printf("Allocate %d bytes memory:",bytes);
  31. BYTE* data = (BYTE*)malloc(bytes);
  32. int line=0;
  33. if (data != NULL)
  34. {
  35. printf("OK.\nPrepare to decompress the image...\n");
  36. // STEP 5: Start
  37. jpeg_start_decompress(&cinfo);
  38. JSAMPROW row_pointer[1];
  39. // STEP 6: ReadScan
  40. printf("Scan lines...\n");
  41. while (cinfo.output_scanline < cinfo.output_height)
  42. {
  43. row_pointer[0] = &data[(cinfo.output_height - cinfo.output_scanline - 1)*cinfo.image_width*cinfo.num_components];
  44. jpeg_read_scanlines(&cinfo, row_pointer, 1);
  45. ++line;
  46. if(line%100==0)
  47. {
  48. printf("Current line: %03d\n",line);
  49. }
  50. }
  51. // STEP 7: Finish
  52. jpeg_finish_decompress(&cinfo);
  53. printf("Decompression finished.\n");
  54. // Do something with
  55. // BYTE data[] here
  56. // and then release it
  57. free(data);
  58. }
  59. else
  60. {
  61. printf("FAILED.\n");
  62. }
  63. // STEP 8: Destroy
  64. jpeg_destroy_decompress(&cinfo);
  65. fclose(pf);
  66. }
  67. else
  68. {
  69. printf("Failed to open \'%s\'\n", szFileName);
  70. }
  71. printf("Test PASSED.\n");
  72. return 0;
  73. }

运行时输出截图如下



最后附上适用于C6678的libjpeg库及相应头文件的下载链接

http://download.youkuaiyun.com/detail/von_ryan_hack/8317241


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值