CARPLAY版本整理
This commit is contained in:
2
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/.gitignore
vendored
Normal file
2
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/.gitignore
vendored
Normal file
@ -0,0 +1,2 @@
|
||||
*.o
|
||||
*.d
|
21
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/LICENSE
Normal file
21
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/LICENSE
Normal file
@ -0,0 +1,21 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2019 LittlevGL
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
50
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/README.md
Normal file
50
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/README.md
Normal file
@ -0,0 +1,50 @@
|
||||
# PNG decoder for LVGL
|
||||
|
||||
Allow the use of PNG images in LVGL. This implementation uses [lodepng](https://github.com/lvandeve/lodepng) library.
|
||||
|
||||
## Get started
|
||||
- Download or clone this repository
|
||||
- [Download from GitHub](https://github.com/littlevgl/lv_lib_lodepng/archive/master.zip)
|
||||
- Clone: `git clone https://github.com/littlevgl/lv_lib_png.git`
|
||||
- Include the library: `#include "lv_lib_png/lv_png.h"`
|
||||
- Initalize the decocer with `lv_png_init()`
|
||||
- Test with the following code:
|
||||
```c
|
||||
LV_IMG_DECLARE(png_decoder_test);
|
||||
lv_obj_t * img = lv_img_create(lv_scr_act(), NULL);
|
||||
lv_img_set_src(img, &png_decoder_test);
|
||||
```
|
||||
|
||||
## Use PNG images from file
|
||||
By deafult `lodepng` uses C file IO API (e.g. `fopen`) and images can be opened like this:
|
||||
```c
|
||||
lv_img_set_src(img, "./lv_lib_lodepng/png_decoder_test.png");
|
||||
```
|
||||
|
||||
If you want to make `lodepng` to use LVGL's file system API add `#define LV_PNG_USE_LV_FILESYSTEM 1` to the end of your`lv_conf.h`.
|
||||
In this case you need to [register a driver](https://docs.lvgl.io/latest/en/html/overview/file-system.html) fo LVGL. The following functions are required:
|
||||
- `open_cb()`
|
||||
- `read_cb()`
|
||||
- `close_cb()`
|
||||
- `size_cb()`
|
||||
|
||||
After that fiels can be opened like this:
|
||||
```c
|
||||
lv_img_set_src(img, "P:lv_lib_lodepng/png_decoder_test.png");
|
||||
```
|
||||
|
||||
|
||||
Note that the path of the file might be different.
|
||||
|
||||
## Use PNG images from flash
|
||||
To store a PNG image in flash it needs to be converted to C array with [Online Image converter](https://lvgl.io/tools/imageconverter). Choose `Raw with alpha` Color format and `C array` Output format. Copy the result C array to your project and use it like this:
|
||||
```c
|
||||
LV_IMG_DECLARE(my_test_img);
|
||||
lv_obj_t * img = lv_img_create(lv_scr_act(), NULL);
|
||||
lv_img_set_src(img, &my_test_img);
|
||||
```
|
||||
|
||||
## Learn more
|
||||
To learn more about the PNG decoder itself read [this blog post](https://blog.littlevgl.com/2018-10-05/png_converter)
|
||||
|
||||
To learn more about the Image decoder interface of LittlevGL read the realevant part of the [documentation](https://docs.littlevgl.com/en/html/overview/image.html#image-decoder).
|
6237
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/lodepng.c
Normal file
6237
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/lodepng.c
Normal file
File diff suppressed because it is too large
Load Diff
1767
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/lodepng.h
Normal file
1767
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/lodepng.h
Normal file
File diff suppressed because it is too large
Load Diff
255
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/lv_png.c
Normal file
255
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/lv_png.c
Normal file
@ -0,0 +1,255 @@
|
||||
/**
|
||||
* @file lv_png.c
|
||||
*
|
||||
*/
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
#ifdef LV_LVGL_H_INCLUDE_SIMPLE
|
||||
#include <lvgl.h>
|
||||
#else
|
||||
#include <lvgl/lvgl.h>
|
||||
#endif
|
||||
|
||||
#include "lv_png.h"
|
||||
#include "lodepng.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* STATIC PROTOTYPES
|
||||
**********************/
|
||||
static lv_res_t decoder_info(struct _lv_img_decoder * decoder, const void * src, lv_img_header_t * header);
|
||||
static lv_res_t decoder_open(lv_img_decoder_t * dec, lv_img_decoder_dsc_t * dsc);
|
||||
static void decoder_close(lv_img_decoder_t * dec, lv_img_decoder_dsc_t * dsc);
|
||||
static void convert_color_depth(uint8_t * img, uint32_t px_cnt);
|
||||
|
||||
/**********************
|
||||
* STATIC VARIABLES
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Register the PNG decoder functions in LittlevGL
|
||||
*/
|
||||
void lv_png_init(void)
|
||||
{
|
||||
lv_img_decoder_t * dec = lv_img_decoder_create();
|
||||
lv_img_decoder_set_info_cb(dec, decoder_info);
|
||||
lv_img_decoder_set_open_cb(dec, decoder_open);
|
||||
lv_img_decoder_set_close_cb(dec, decoder_close);
|
||||
}
|
||||
|
||||
/**********************
|
||||
* STATIC FUNCTIONS
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Get info about a PNG image
|
||||
* @param src can be file name or pointer to a C array
|
||||
* @param header store the info here
|
||||
* @return LV_RES_OK: no error; LV_RES_INV: can't get the info
|
||||
*/
|
||||
static lv_res_t decoder_info(struct _lv_img_decoder * decoder, const void * src, lv_img_header_t * header)
|
||||
{
|
||||
(void) decoder; /*Unused*/
|
||||
lv_img_src_t src_type = lv_img_src_get_type(src); /*Get the source type*/
|
||||
|
||||
/*If it's a PNG file...*/
|
||||
if(src_type == LV_IMG_SRC_FILE) {
|
||||
const char * fn = src;
|
||||
if(!strcmp(&fn[strlen(fn) - 3], "png")) { /*Check the extension*/
|
||||
|
||||
/* Read the width and height from the file. They have a constant location:
|
||||
* [16..23]: width
|
||||
* [24..27]: height
|
||||
*/
|
||||
uint32_t size[2];
|
||||
#if LV_PNG_USE_LV_FILESYSTEM
|
||||
lv_fs_file_t f;
|
||||
lv_fs_res_t res = lv_fs_open(&f, fn, LV_FS_MODE_RD);
|
||||
if(res != LV_FS_RES_OK) return -1;
|
||||
lv_fs_seek(&f, 16);
|
||||
uint32_t rn;
|
||||
lv_fs_read(&f, &size, 8, &rn);
|
||||
if(rn != 8) return LV_RES_INV;
|
||||
lv_fs_close(&f);
|
||||
#else
|
||||
RomFile* file;
|
||||
file = RomFileOpen(fn);
|
||||
if(!file) return LV_RES_INV;
|
||||
RomFileSeek(file, 16, SEEK_SET);
|
||||
size_t rn = RomFileRead(file, size, 8);
|
||||
RomFileClose(file);
|
||||
if(rn != 8) return LV_RES_INV;
|
||||
#endif
|
||||
/*Save the data in the header*/
|
||||
header->always_zero = 0;
|
||||
header->cf = LV_IMG_CF_RAW_ALPHA;
|
||||
/*The width and height are stored in Big endian format so convert them to little endian*/
|
||||
header->w = (lv_coord_t) ((size[0] & 0xff000000) >> 24) + ((size[0] & 0x00ff0000) >> 8);
|
||||
header->h = (lv_coord_t) ((size[1] & 0xff000000) >> 24) + ((size[1] & 0x00ff0000) >> 8);
|
||||
|
||||
return LV_RES_OK;
|
||||
}
|
||||
}
|
||||
/*If it's a PNG file in a C array...*/
|
||||
else if(src_type == LV_IMG_SRC_VARIABLE) {
|
||||
const lv_img_dsc_t * img_dsc = src;
|
||||
header->always_zero = 0;
|
||||
header->cf = img_dsc->header.cf; /*Save the color format*/
|
||||
header->w = img_dsc->header.w; /*Save the color width*/
|
||||
header->h = img_dsc->header.h; /*Save the color height*/
|
||||
return LV_RES_OK;
|
||||
}
|
||||
|
||||
return LV_RES_INV; /*If didn't succeeded earlier then it's an error*/
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Open a PNG image and return the decided image
|
||||
* @param src can be file name or pointer to a C array
|
||||
* @param style style of the image object (unused now but certain formats might use it)
|
||||
* @return pointer to the decoded image or `LV_IMG_DECODER_OPEN_FAIL` if failed
|
||||
*/
|
||||
static lv_res_t decoder_open(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
|
||||
{
|
||||
|
||||
(void) decoder; /*Unused*/
|
||||
uint32_t error; /*For the return values of PNG decoder functions*/
|
||||
|
||||
uint8_t * img_data = NULL;
|
||||
|
||||
/*If it's a PNG file...*/
|
||||
if(dsc->src_type == LV_IMG_SRC_FILE) {
|
||||
const char * fn = dsc->src;
|
||||
|
||||
if(!strcmp(&fn[strlen(fn) - 3], "png")) { /*Check the extension*/
|
||||
|
||||
/*Load the PNG file into buffer. It's still compressed (not decoded)*/
|
||||
unsigned char * png_data; /*Pointer to the loaded data. Same as the original file just loaded into the RAM*/
|
||||
size_t png_data_size; /*Size of `png_data` in bytes*/
|
||||
|
||||
/*Load the file*/
|
||||
RomFile *file = RomFileOpen(fn);
|
||||
if (!file) {
|
||||
printf("open %s fail.\n", fn);
|
||||
}
|
||||
RomFileRead(file, NULL, file->size);
|
||||
png_data = file->buf;
|
||||
png_data_size = file->size;
|
||||
|
||||
/*Decode the PNG image*/
|
||||
uint32_t png_width; /*Will be the width of the decoded image*/
|
||||
uint32_t png_height; /*Will be the width of the decoded image*/
|
||||
|
||||
/*Decode the loaded image in ARGB8888 */
|
||||
/* unsigned int ts;
|
||||
ts = get_timer(0); */
|
||||
error = lodepng_decode32(&img_data, &png_width, &png_height, png_data, png_data_size);
|
||||
/* ts = get_timer(ts);
|
||||
printf("%s decode %d us.\n", fn, ts); */
|
||||
//free(png_data); /*Free the loaded file*/
|
||||
RomFileClose(file);
|
||||
|
||||
if(error) {
|
||||
printf("error %u: %s\n", error, lodepng_error_text(error));
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
/*Convert the image to the system's color depth*/
|
||||
convert_color_depth(img_data, png_width * png_height);
|
||||
dsc->img_data = img_data;
|
||||
return LV_RES_OK; /*The image is fully decoded. Return with its pointer*/
|
||||
}
|
||||
}
|
||||
/*If it's a PNG file in a C array...*/
|
||||
else if(dsc->src_type == LV_IMG_SRC_VARIABLE) {
|
||||
const lv_img_dsc_t * img_dsc = dsc->src;
|
||||
uint32_t png_width; /*No used, just required by he decoder*/
|
||||
uint32_t png_height; /*No used, just required by he decoder*/
|
||||
|
||||
/*Decode the image in ARGB8888 */
|
||||
error = lodepng_decode32(&img_data, &png_width, &png_height, img_dsc->data, img_dsc->data_size);
|
||||
|
||||
if(error) {
|
||||
return LV_RES_INV;
|
||||
}
|
||||
|
||||
/*Convert the image to the system's color depth*/
|
||||
convert_color_depth(img_data, png_width * png_height);
|
||||
|
||||
dsc->img_data = img_data;
|
||||
return LV_RES_OK; /*Return with its pointer*/
|
||||
}
|
||||
|
||||
return LV_RES_INV; /*If not returned earlier then it failed*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Free the allocated resources
|
||||
*/
|
||||
static void decoder_close(lv_img_decoder_t * decoder, lv_img_decoder_dsc_t * dsc)
|
||||
{
|
||||
(void) decoder; /*Unused*/
|
||||
if(dsc->img_data) free((uint8_t *)dsc->img_data);
|
||||
}
|
||||
|
||||
/**
|
||||
* If the display is not in 32 bit format (ARGB888) then covert the image to the current color depth
|
||||
* @param img the ARGB888 image
|
||||
* @param px_cnt number of pixels in `img`
|
||||
*/
|
||||
static void convert_color_depth(uint8_t * img, uint32_t px_cnt)
|
||||
{
|
||||
#if LV_COLOR_DEPTH == 32
|
||||
lv_color32_t * img_argb = (lv_color32_t*)img;
|
||||
lv_color_t c;
|
||||
lv_color_t * img_c = (lv_color_t *) img;
|
||||
uint32_t i;
|
||||
for(i = 0; i < px_cnt; i++) {
|
||||
c = LV_COLOR_MAKE(img_argb[i].ch.red, img_argb[i].ch.green, img_argb[i].ch.blue);
|
||||
img_c[i].ch.red = c.ch.blue;
|
||||
img_c[i].ch.blue = c.ch.red;
|
||||
}
|
||||
#elif LV_COLOR_DEPTH == 16
|
||||
lv_color32_t * img_argb = (lv_color32_t*)img;
|
||||
lv_color_t c;
|
||||
uint32_t i;
|
||||
for(i = 0; i < px_cnt; i++) {
|
||||
c = LV_COLOR_MAKE(img_argb[i].ch.blue, img_argb[i].ch.green, img_argb[i].ch.red);
|
||||
img[i*3 + 2] = img_argb[i].ch.alpha;
|
||||
img[i*3 + 1] = c.full >> 8;
|
||||
img[i*3 + 0] = c.full & 0xFF;
|
||||
}
|
||||
#elif LV_COLOR_DEPTH == 8
|
||||
lv_color32_t * img_argb = (lv_color32_t*)img;
|
||||
lv_color_t c;
|
||||
uint32_t i;
|
||||
for(i = 0; i < px_cnt; i++) {
|
||||
c = LV_COLOR_MAKE(img_argb[i].red, img_argb[i].green, img_argb[i].blue);
|
||||
img[i*3 + 1] = img_argb[i].alpha;
|
||||
img[i*3 + 0] = c.full
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
43
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/lv_png.h
Normal file
43
MXC_A27-PCB4.5-270S/lib/LittlevGL/lv_lib_png/lv_png.h
Normal file
@ -0,0 +1,43 @@
|
||||
/**
|
||||
* @file lv_png.h
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LV_PNG_H
|
||||
#define LV_PNG_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/*********************
|
||||
* INCLUDES
|
||||
*********************/
|
||||
|
||||
/*********************
|
||||
* DEFINES
|
||||
*********************/
|
||||
|
||||
/**********************
|
||||
* TYPEDEFS
|
||||
**********************/
|
||||
|
||||
/**********************
|
||||
* GLOBAL PROTOTYPES
|
||||
**********************/
|
||||
|
||||
/**
|
||||
* Register the PNG decoder functions in LittlevGL
|
||||
*/
|
||||
void lv_png_init(void);
|
||||
|
||||
/**********************
|
||||
* MACROS
|
||||
**********************/
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
} /* extern "C" */
|
||||
#endif
|
||||
|
||||
#endif /*LV_PNG_H*/
|
Binary file not shown.
After Width: | Height: | Size: 20 KiB |
Reference in New Issue
Block a user