TA的每日心情 | 奋斗 2023-7-6 08:48 |
---|
签到天数: 169 天 连续签到: 1 天 [LV.7]常住居民III
|
功能,从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库。
显示结果
|
|