查看: 1531|回复: 0

【STM32746G-Discovery】jpg图片解码显示

[复制链接]
  • TA的每日心情
    奋斗
    2023-7-6 08:48
  • 签到天数: 169 天

    连续签到: 1 天

    [LV.7]常住居民III

    发表于 2016-7-6 08:52:22 | 显示全部楼层 |阅读模式
    分享到:
    功能,从TF卡中读取文件名为image.jpg图片文件,显示在液晶屏上。所以TF卡上的文件名必须要一致。
    要从TF卡中读取文件,那么这里要使用到FatFs文件系统了,在前面已经介绍过了,不再赘述。
    这里要使用到LCD,所以要对LCD进行初始化。
    static void LCD_Config(void){  /* Initialize the LCD */    BSP_LCD_Init();    /* Background Layer Initialization */  BSP_LCD_LayerDefaultInit(0, LCD_FRAME_BUFFER);    /* Set Foreground Layer */  BSP_LCD_SelectLayer(0);    /* Enable the LCD */  BSP_LCD_DisplayOn();      /* Set Display window */  BSP_LCD_SetLayerWindow(0, 0, 0, IMAGE_WIDTH, IMAGE_HEIGHT);    /* Clear the LCD Background layer */  BSP_LCD_Clear(LCD_COLOR_WHITE); }挂载文件系统:
    f_mount(&SDFatFs, (TCHAR const*)SDPath, 0)打开图片文件
    f_open(&MyFile, "image.jpg", FA_READ)解码使用的函数。
    jpeg_decode(&MyFile, IMAGE_WIDTH, _aucLine, Jpeg_CallbackFunction);void jpeg_decode(FIL *file, uint32_t width, uint8_t * buff, uint8_t (*callback)(uint8_t*, uint32_t)){       /* Decode JPEG Image */  JSAMPROW buffer[2] = {0}; /* Output row buffer */  uint32_t row_stride = 0; /* physical row width in image buffer */    buffer[0] = buff;          /* Step 1: allocate and initialize JPEG decompression object */  cinfo.err = jpeg_std_error(&jerr);  /* Initialize the JPEG decompression object */    jpeg_create_decompress(&cinfo);    jpeg_stdio_src (&cinfo, file);  /* Step 3: read image parameters with jpeg_read_header() */  jpeg_read_header(&cinfo, TRUE);  /* TBC */  /* Step 4: set parameters for decompression */  cinfo.dct_method = JDCT_FLOAT;  /* Step 5: start decompressor */  jpeg_start_decompress(&cinfo);  row_stride = width * 3;  while (cinfo.output_scanline < cinfo.output_height)  {    (void) jpeg_read_scanlines(&cinfo, buffer, 1);        /* TBC */    if (callback(buffer[0], row_stride) != 0)    {      break;    }  }  /* Step 6: Finish decompression */  jpeg_finish_decompress(&cinfo);  /* Step 7: Release JPEG decompression object */  jpeg_destroy_decompress(&cinfo);    }这里的解码使用了Lib_FPEG库。

    显示结果
    回复

    使用道具 举报

    您需要登录后才可以回帖 注册/登录

    本版积分规则

    关闭

    站长推荐上一条 /2 下一条

    手机版|小黑屋|与非网

    GMT+8, 2024-4-26 04:54 , Processed in 0.109791 second(s), 18 queries , MemCache On.

    ICP经营许可证 苏B2-20140176  苏ICP备14012660号-2   苏州灵动帧格网络科技有限公司 版权所有.

    苏公网安备 32059002001037号

    Powered by Discuz! X3.4

    Copyright © 2001-2024, Tencent Cloud.