Merge pull request #165 from kwagyeman/master

Fixed copy_to_fb for loading images.
This commit is contained in:
Ibrahim Abd Elkader 2017-01-03 19:29:33 +02:00 committed by GitHub
commit fc6bd9db5c
3 changed files with 14 additions and 8 deletions

View File

@ -277,7 +277,7 @@ static save_image_format_t imblib_parse_extension(image_t *img, const char *path
return FORMAT_DONT_CARE; return FORMAT_DONT_CARE;
} }
static bool imlib_read_geometry(FIL *fp, image_t *img, const char *path, img_read_settings_t *rs) bool imlib_read_geometry(FIL *fp, image_t *img, const char *path, img_read_settings_t *rs)
{ {
file_read_open(fp, path); file_read_open(fp, path);
char magic[2]; char magic[2];

View File

@ -925,6 +925,7 @@ void jpeg_read_geometry(FIL *fp, image_t *img, const char *path);
void jpeg_read_pixels(FIL *fp, image_t *img); void jpeg_read_pixels(FIL *fp, image_t *img);
void jpeg_read(image_t *img, const char *path); void jpeg_read(image_t *img, const char *path);
void jpeg_write(image_t *img, const char *path, int quality); void jpeg_write(image_t *img, const char *path, int quality);
bool imlib_read_geometry(FIL *fp, image_t *img, const char *path, img_read_settings_t *rs);
void imlib_image_operation(image_t *img, const char *path, image_t *other, line_op_t op); void imlib_image_operation(image_t *img, const char *path, image_t *other, line_op_t op);
void imlib_load_image(image_t *img, const char *path); void imlib_load_image(image_t *img, const char *path);
void imlib_save_image(image_t *img, const char *path, rectangle_t *roi, int quality); void imlib_save_image(image_t *img, const char *path, rectangle_t *roi, int quality);

View File

@ -11,7 +11,7 @@
#include "imlib.h" #include "imlib.h"
#include "array.h" #include "array.h"
#include "sensor.h" #include "sensor.h"
#include "ff.h" #include "ff_wrapper.h"
#include "xalloc.h" #include "xalloc.h"
#include "fb_alloc.h" #include "fb_alloc.h"
#include "framebuffer.h" #include "framebuffer.h"
@ -1889,16 +1889,21 @@ mp_obj_t py_image_load_image(uint n_args, const mp_obj_t *args, mp_map_t *kw_arg
int copy_to_fb = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_copy_to_fb), false); int copy_to_fb = py_helper_lookup_int(kw_args, MP_OBJ_NEW_QSTR(MP_QSTR_copy_to_fb), false);
if (copy_to_fb) { if (copy_to_fb) {
fb->w = 4; // non-zero init value
fb->h = 4; // non-zero init value
fb->bpp = 1; // non-zero init value
image.pixels = MAIN_FB()->pixels; image.pixels = MAIN_FB()->pixels;
FIL fp;
img_read_settings_t rs;
imlib_read_geometry(&fp, &image, path, &rs);
file_buffer_off(&fp);
file_close(&fp);
fb->w = image.w;
fb->h = image.h;
fb->bpp = image.bpp;
} }
imlib_load_image(&image, path); imlib_load_image(&image, path);
if (copy_to_fb) {
fb->w = image.w;
fb->h = image.h;
fb->bpp = image.bpp;
}
return py_image_from_struct(&image); return py_image_from_struct(&image);
} }