找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 4377|回复: 4
收起左侧

STM32+ILI9486 TFT JPEG图片解码例程下载

[复制链接]
ID:316073 发表于 2018-11-26 21:21 | 显示全部楼层 |阅读模式
ILI9486TFT驱动程序STM32  这个用来移植

1、该例程为JPEG图片解码例程。

2、使用说明
   (1)工程文件路径:SY-STM32F407 V2程序\SY-STM32F407 V2例程:JPEG图片解码例程\Project\Project.uvproj。
   (2)请使用MDK 4.0以上版本打开,MDK版本过低会导致无法识别工程。
   (3)下载调试工具为JLINK。
   (4)请将串口线(直连串口线)插在板子COM1口上,并打开超级终端或串口助手,配置波特率115200,8位,一个停止位,无校验位。
   (5)HEX文件下载到板子后,使用超级终端或串口调试助手可以看到调试信息,插上TFT模块显示一个小MM,表明例程运行正确。
3、注意事项
   请务必在下载、调试、运行过程中,保持板子上电、JLINK连接并插在电脑上。

单片机源程序如下:
  1. #include "jpegdecoder.h"


  2. static int MaskT, MaskL, MaskR, MaskB;        /* Active drawing area */

  3. /****************************************************************************************************************************
  4. *函数名称:JpgDecoderRead()
  5. *参数    :
  6. *返回值  :
  7. *功能描述:用于JPG解码读取内存卡JPG文件数据,内部调用
  8. ******************************************************************************************************************************/
  9. static UINT JpgDecoderRead(JDEC* jd,                /* Decoder object */BYTE* buff,                /* Pointer to the read buffer (NULL:skip) */UINT nd                        /* Number of bytes to read/skip from input stream */)
  10. {
  11.         UINT rb;
  12.         FIL *fil = (FIL*)jd->device;        /* Input stream of this session */


  13.         if (buff) {        /* Read nd bytes from the input strem */
  14.                 f_read(fil, buff, nd, &rb);
  15.                 return rb;        /* Returns number of bytes could be read */

  16.         } else {        /* Skip nd bytes on the input stream */
  17.                 return (f_lseek(fil, f_tell(fil) + nd) == FR_OK) ? nd : 0;
  18.         }
  19. }
  20. void SetJPGDisplayAera(uint16_t xs,uint16_t ys,uint16_t xe,uint16_t ye)
  21. {
  22.                 MaskL = xs;
  23.                 MaskR = xe;
  24.                 MaskT = ys;
  25.                 MaskB = ye;
  26. }
  27. /****************************************************************************************************************************
  28. *函数名称:Jpg_Display()
  29. *参数    :
  30. *返回值  :
  31. *功能描述:用于JPG解码后将RGB数据显示到TFT液晶屏,内部调用
  32. ******************************************************************************************************************************/
  33. static UINT Jpg_Display (
  34.         JDEC* jd,                /* Decoder object */
  35.         void* bitmap,        /* Bitmap data to be output */
  36.         JRECT* rect                /* Rectangular region to output */
  37. )
  38. {
  39.                 int yc, xc, xl, xs;
  40.          uint16_t *pData=(uint16_t*)bitmap;
  41.         jd = jd;        /* Suppress warning (device identifier is not needed) */

  42.         /*将解码数据显示到液晶屏区域*/
  43.         //disp_blt(rect->left, rect->right, rect->top, rect->bottom, (uint16_t*)bitmap);
  44.        


  45.         if (rect->left > rect->right || rect->top > rect->bottom) return 0;         /* Check varidity */
  46.         if (rect->left > MaskR || rect->right < MaskL  || rect->top > MaskB || rect->bottom < MaskT) return 0;        /* Check if in active area */

  47.         yc = rect->bottom - rect->top + 1;                        /* Vertical size */
  48.         xc = rect->right - rect->left + 1; xs = 0;        /* Horizontal size and skip */

  49.         if (rect->top < MaskT) {                /* Clip top of source image if it is out of active area */
  50.                 pData += xc * (MaskT - rect->top);
  51.                 yc -= MaskT - rect->top;
  52.                 rect->top = MaskT;
  53.         }
  54.         if (rect->bottom > MaskB) {        /* Clip bottom of source image if it is out of active area */
  55.                 yc -= rect->bottom - MaskB;
  56.                 rect->bottom = MaskB;
  57.         }
  58.         if (rect->left < MaskL) {                /* Clip left of source image if it is out of active area */
  59.                 pData += MaskL - rect->left;
  60.                 xc -= MaskL - rect->left;
  61.                 xs += MaskL - rect->left;
  62.                 rect->left = MaskL;
  63.         }
  64.         if (rect->right > MaskR) {        /* Clip right of source image it is out of active area */
  65.                 xc -= rect->right - MaskR;
  66.                 xs += rect->right - MaskR;
  67.                 rect->right = MaskR;
  68.         }
  69.         /*设置水平方向X开始坐标*/

  70. //     LCD_WriteReg(0x50, rect->left);
  71. //   /*设置水平方向X结束坐标*/
  72. //   LCD_WriteReg(0x51, rect->right);
  73. //   /*设置竖直方向Y开始坐标*/
  74. //     LCD_WriteReg(0x52, rect->top);
  75. //   /*设置竖直方向Y结束坐标*/
  76. //   LCD_WriteReg(0x53, rect->bottom);
  77.   LCD_SetCursor(rect->left, rect->top);
  78.         LCD_WriteRAM_Start();
  79.         do {        /* Send image data */
  80.                 xl = xc;
  81.                 do {
  82.                         //pd = *pat++;
  83.                         LCD_WriteRAM(*pData++);                        //显示像素
  84.                 } while (--xl);
  85.                 pData += xs;
  86.         } while (--yc);
  87.         return 1;        /* Continue decompression */       
  88. }
  89. /****************************************************************************************************************************
  90. *函数名称:Load_Jpg()
  91. *参数    :
  92. *返回值  :
  93. *功能描述:用于JPG解码并显示到TFT液晶屏,外部调用即可进行解码显示
  94. ******************************************************************************************************************************/
  95. void Load_Jpg (
  96.         FIL *fp,                /* Pointer to the open file object to load */
  97.         void *work,                /* Pointer to the working buffer (must be 4-byte aligned) */
  98.         UINT sz_work        /* Size of the working buffer (must be power of 2) */
  99. )
  100. {
  101.         JDEC jd;                /* Decoder object (124 bytes) */
  102.         JRESULT rc;
  103.         BYTE scale;

  104.         /*载入需要解码的JPG数据 */
  105.         rc = jd_prepare(&jd, JpgDecoderRead, work, sz_work, fp);
  106.         if (rc == JDR_OK)
  107.         {

  108.                 /*判断JPG的缩放,以适应屏幕大小*/
  109.                 for (scale = 0; scale < 3; scale++)
  110.                 {
  111.                         if ((jd.width >> scale) <= LCD_XMAX && (jd.height >> scale) <= LCD_YMAX) break;
  112.                 }

  113.                 /* 开始解码JPG文件并显示到液晶屏 */
  114.                 rc = jd_decomp(&jd, Jpg_Display, scale);        /* Start to decompress */

  115.         } else {
  116.                 LCD_SetColors(RED,WHITE);
  117.     LCD_DrawString(30,140,"prepare ERR");
  118.         }
  119. }
复制代码
  1. /* ------------------------------------------包含的头文件-----------------------------------------------*/
  2. #include "stm32f4xx.h"
  3. #include "delay.h"
  4. #include "led.h"
  5. #include "usart.h"
  6. #include "lcd.h"
  7. #include "adc.h"


  8. extern unsigned  char JPGBUFF[];


  9. /*************************************************************************************
  10.   * 函数名称:main()
  11.   * 参数    :void
  12.   * 返回值  :void
  13.   * 描述    :程序主入口main函数
  14.   *************************************************************************************/
  15. int main(void)
  16. {
  17.           SystemInit();                                       //初始化系统时钟,设置时钟为168Mhz
  18.           LED_GPIO_Config();                                           //初始化LED的GPIO配置
  19.           SysTick_Init();                        //系统节拍初始化  
  20.           USART1_Conf();                         //串口1初始化
  21.           LCD_Init();                            //LCD初始化
  22.           printf("\r\n欢迎使用SY-STM32F407 V2开发板!\r\n");
  23.           printf("\r\n        山岩科技!\r\n");
  24.           printf("\r\n            -----专业,值得信赖!\r\n");
  25.           delay_nms(50);                          //延时
  26.           printf("\r\n 这是一个JPG解码例程 \r\n");

  27.           LoadJpegFile(JPGBUFF);

  28.         while(1)
  29.         {
  30.                   LED1(On);
  31.                 delay_nms(300);
  32.                 LED1(Off);
  33.                 delay_nms(300);               
  34.         }
  35. }


  36. #ifdef  USE_FULL_ASSERT

  37. /**
  38.   * @brief  Reports the name of the source file and the source line number
  39.   *   where the assert_param error has occurred.
  40.   * @param  file: pointer to the source file name
  41.   * @param  line: assert_param error line source number
  42.   * @retval None
  43.   */
  44. void assert_failed(uint8_t* file, uint32_t line)
  45. {
  46.   /* User can add his own implementation to report the file name and line number,
  47.      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

  48.   /* Infinite loop */
  49.   while (1)
  50.   {
  51.   }
  52. }
  53. #endif

复制代码


所有资料51hei提供下载:
ILI9486 JPEG图片解码例程.rar (491.05 KB, 下载次数: 92)
回复

使用道具 举报

ID:365013 发表于 2018-12-28 09:07 | 显示全部楼层
好东西
回复

使用道具 举报

ID:476086 发表于 2019-2-13 10:45 | 显示全部楼层
这里解码和压缩的原理是什么,能不能解释下?
回复

使用道具 举报

ID:647790 发表于 2019-11-23 13:02 | 显示全部楼层
参考一下代码,准备移植感谢楼主分享
回复

使用道具 举报

ID:503899 发表于 2022-8-28 01:47 | 显示全部楼层
图片文件是用什么工具产生的?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

手机版|小黑屋|51黑电子论坛 |51黑电子论坛6群 QQ 管理员QQ:125739409;技术交流QQ群281945664

Powered by 单片机教程网

快速回复 返回顶部 返回列表