Skip to content

Commit

Permalink
lvgl use native lv_png instead of library
Browse files Browse the repository at this point in the history
  • Loading branch information
s-hadinger committed Jan 12, 2022
1 parent 955d807 commit 636ac69
Show file tree
Hide file tree
Showing 9 changed files with 58 additions and 171 deletions.
50 changes: 0 additions & 50 deletions lib/libesp32_lvgl/lv_lib_png/README.md

This file was deleted.

21 changes: 0 additions & 21 deletions lib/libesp32_lvgl/lv_lib_png/library.json

This file was deleted.

2 changes: 1 addition & 1 deletion lib/libesp32_lvgl/lvgl/src/extra/libs/lv_libs.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ extern "C" {
// TODO Tasmota
// #include "bmp/lv_bmp.h"
// #include "fsdrv/lv_fsdrv.h"
// #include "png/lv_png.h"
#include "png/lv_png.h"
// #include "gif/lv_gif.h"
// #include "qrcode/lv_qrcode.h"
// #include "sjpg/lv_sjpg.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ Rename this file to lodepng.cpp to use it for C++, or to lodepng.c to use it for
*/

#include "lodepng.h"
#if LV_USE_PNG

#ifdef LODEPNG_COMPILE_DISK
#include <limits.h> /* LONG_MAX */
#include <stdio.h> /* file handling */
#endif /* LODEPNG_COMPILE_DISK */

#ifdef LODEPNG_COMPILE_ALLOCATORS
Expand Down Expand Up @@ -75,19 +75,19 @@ static void* lodepng_malloc(size_t size) {
#ifdef LODEPNG_MAX_ALLOC
if(size > LODEPNG_MAX_ALLOC) return 0;
#endif
return malloc(size);
return lv_mem_alloc(size);
}

/* NOTE: when realloc returns NULL, it leaves the original memory untouched */
static void* lodepng_realloc(void* ptr, size_t new_size) {
#ifdef LODEPNG_MAX_ALLOC
if(new_size > LODEPNG_MAX_ALLOC) return 0;
#endif
return realloc(ptr, new_size);
return lv_mem_realloc(ptr, new_size);
}

static void lodepng_free(void* ptr) {
free(ptr);
lv_mem_free(ptr);
}
#else /*LODEPNG_COMPILE_ALLOCATORS*/
/* TODO: support giving additional void* payload to the custom allocators */
Expand Down Expand Up @@ -343,42 +343,22 @@ static void lodepng_set32bitInt(unsigned char* buffer, unsigned value) {

/* returns negative value on error. This should be pure C compatible, so no fstat. */
static long lodepng_filesize(const char* filename) {
#if LV_PNG_USE_LV_FILESYSTEM
lv_fs_file_t f;
lv_fs_res_t res = lv_fs_open(&f, filename, LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) return -1;
uint32_t size = 0;
if(lv_fs_seek(&f, 0, SEEK_END) != 0) {
if(lv_fs_seek(&f, 0, LV_FS_SEEK_END) != 0) {
lv_fs_close(&f);
return -1;
}

lv_fs_tell(&f, &size);
lv_fs_close(&f);
return size;
#else
FILE* file;
long size;
file = fopen(filename, "rb");
if(!file) return -1;

if(fseek(file, 0, SEEK_END) != 0) {
fclose(file);
return -1;
}

size = ftell(file);
/* It may give LONG_MAX as directory size, this is invalid for us. */
if(size == LONG_MAX) size = -1;

fclose(file);
return size;
#endif
}

/* load file into buffer that already has the correct allocated size. Returns error code.*/
static unsigned lodepng_buffer_file(unsigned char* out, size_t size, const char* filename) {
#if LV_PNG_USE_LV_FILESYSTEM
lv_fs_file_t f;
lv_fs_res_t res = lv_fs_open(&f, filename, LV_FS_MODE_RD);
if(res != LV_FS_RES_OK) return 78;
Expand All @@ -389,18 +369,6 @@ static unsigned lodepng_buffer_file(unsigned char* out, size_t size, const char*
if (br != size) return 78;
lv_fs_close(&f);
return 0;
#else
FILE* file;
size_t readsize;
file = fopen(filename, "rb");
if(!file) return 78;

readsize = fread(out, 1, size, file);
fclose(file);

if(readsize != size) return 78;
return 0;
#endif
}

unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* filename) {
Expand All @@ -416,11 +384,13 @@ unsigned lodepng_load_file(unsigned char** out, size_t* outsize, const char* fil

/*write given buffer to the file, overwriting the file, it doesn't append to it.*/
unsigned lodepng_save_file(const unsigned char* buffer, size_t buffersize, const char* filename) {
FILE* file;
file = fopen(filename, "wb" );
if(!file) return 79;
fwrite(buffer, 1, buffersize, file);
fclose(file);
lv_fs_file_t f;
lv_fs_res_t res = lv_fs_open(&f, filename, LV_FS_MODE_WR);
if(res != LV_FS_RES_OK) return 79;

uint32_t bw;
res = lv_fs_write(&f, buffer, buffersize, &bw);
lv_fs_close(&f);
return 0;
}

Expand Down Expand Up @@ -611,6 +581,7 @@ static unsigned readBits(LodePNGBitReader* reader, size_t nbits) {
return result;
}

#if 0 /*Disable because tests fail due to unused declaration*/
/* Public for testing only. steps and result must have numsteps values. */
static unsigned lode_png_test_bitreader(const unsigned char* data, size_t size,
size_t numsteps, const size_t* steps, unsigned* result) {
Expand All @@ -630,6 +601,8 @@ static unsigned lode_png_test_bitreader(const unsigned char* data, size_t size,
}
return 1;
}
#endif

#endif /*LODEPNG_COMPILE_DECODER*/

static unsigned reverseBits(unsigned bits, unsigned num) {
Expand Down Expand Up @@ -2337,7 +2310,7 @@ static unsigned zlib_compress(unsigned char** out, size_t* outsize, const unsign
static unsigned zlib_decompress(unsigned char** out, size_t* outsize, size_t expected_size,
const unsigned char* in, size_t insize, const LodePNGDecompressSettings* settings) {
if(!settings->custom_zlib) return 87; /*no custom zlib function provided */
(void)expected_size;
LV_UNUSED(expected_size);
return settings->custom_zlib(out, outsize, in, insize, settings);
}
#endif /*LODEPNG_COMPILE_DECODER*/
Expand Down Expand Up @@ -2579,6 +2552,8 @@ unsigned char* lodepng_chunk_find(unsigned char* chunk, unsigned char* end, cons
if(lodepng_chunk_type_equals(chunk, type)) return chunk;
chunk = lodepng_chunk_next(chunk, end);
}

return 0; /*Shouldn't reach this*/
}

const unsigned char* lodepng_chunk_find_const(const unsigned char* chunk, const unsigned char* end, const char type[5]) {
Expand All @@ -2587,6 +2562,8 @@ const unsigned char* lodepng_chunk_find_const(const unsigned char* chunk, const
if(lodepng_chunk_type_equals(chunk, type)) return chunk;
chunk = lodepng_chunk_next_const(chunk, end);
}

return 0; /*Shouldn't reach this*/
}

unsigned lodepng_chunk_append(unsigned char** out, size_t* outsize, const unsigned char* chunk) {
Expand Down Expand Up @@ -6490,3 +6467,5 @@ unsigned encode(const std::string& filename,
#endif /* LODEPNG_COMPILE_PNG */
} /* namespace lodepng */
#endif /*LODEPNG_COMPILE_CPP*/

#endif /*LV_USE_PNG*/
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,8 @@ freely, subject to the following restrictions:

#include <string.h> /*for size_t*/

#ifndef LV_PNG_USE_LV_FILESYSTEM
#define LV_PNG_USE_LV_FILESYSTEM 0
#endif

#if LV_PNG_USE_LV_FILESYSTEM
#if defined(LV_LVGL_H_INCLUDE_SIMPLE)
#include "lvgl.h"
#else
#include "lvgl/lvgl.h"
#endif
#endif /* LV_PNG_USE_LV_FILESYSTEM */

#include "../../../lvgl.h"
#if LV_USE_PNG
extern const char* LODEPNG_VERSION_STRING;

/*
Expand Down Expand Up @@ -1095,6 +1085,8 @@ unsigned compress(std::vector<unsigned char>& out, const std::vector<unsigned ch
[X] provide alternatives for C library functions not present on some platforms (memcpy, ...)
*/

#endif /*LV_USE_PNG*/

#endif /*LODEPNG_H inclusion guard*/

/*
Expand Down
Loading

0 comments on commit 636ac69

Please sign in to comment.