diff --git a/apps/plugins/pictureflow.c b/apps/plugins/pictureflow.c index 5613ce8..e695e8a 100644 --- a/apps/plugins/pictureflow.c +++ b/apps/plugins/pictureflow.c @@ -32,6 +32,7 @@ #include "pluginbitmaps/pictureflow_logo.h" #include "lib/grey.h" #include "lib/feature_wrappers.h" +#include "lib/buffer_alloc.h" PLUGIN_HEADER @@ -1046,17 +1047,13 @@ int read_pfraw(char* filename) int size = sizeof(struct bitmap) + sizeof( pix_t ) * bmph.width * bmph.height; - int hid = rb->bufalloc(NULL, size, TYPE_BITMAP); - if (hid < 0) { + int hid = buf_alloc(size); + if (!hid) { rb->close( fh ); - return -1; + return 0; } - struct bitmap *bm; - if (rb->bufgetdata(hid, 0, (void *)&bm) < size) { - rb->close( fh ); - return -1; - } + struct bitmap *bm = buf_get_data(hid); bm->width = bmph.width; bm->height = bmph.height; @@ -1087,7 +1084,7 @@ static inline bool load_and_prepare_surface(const int slide_index, slide_index); int hid = read_pfraw(tmp_path_name); - if (hid < 0) + if (!hid) return false; cache[cache_index].hid = hid; @@ -1121,9 +1118,9 @@ int load_surface(const int slide_index) oldest_tick = cache[i].touched; } } - if (cache[oldest_slide].hid != empty_slide_hid) { - rb->bufclose(cache[oldest_slide].hid); - cache[oldest_slide].hid = -1; + if (cache[oldest_slide].hid && cache[oldest_slide].hid != empty_slide_hid) { + buf_free(cache[oldest_slide].hid); + cache[oldest_slide].hid = 0; } load_and_prepare_surface(slide_index, oldest_slide); } @@ -1136,14 +1133,12 @@ int load_surface(const int slide_index) */ static inline struct bitmap *get_slide(const int hid) { - if (hid < 0) + if (!hid) return NULL; struct bitmap *bmp; - ssize_t ret = rb->bufgetdata(hid, 0, (void *)&bmp); - if (ret < 0) - return NULL; + bmp = buf_get_data(hid); return bmp; } @@ -1652,12 +1647,6 @@ void cleanup(void *parameter) /* Turn on backlight timeout (revert to settings) */ backlight_use_settings(); /* backlight control in lib/helper.c */ - int i; - for (i = 0; i < slide_cache_in_use; i++) { - rb->bufclose(cache[i].hid); - } - if ( empty_slide_hid != - 1) - rb->bufclose(empty_slide_hid); #ifdef USEGSLIB grey_release(); #endif @@ -1687,9 +1676,6 @@ int create_empty_slide(bool force) return false; } - empty_slide_hid = read_pfraw( EMPTY_SLIDE ); - if (empty_slide_hid == -1 ) return false; - return true; } @@ -2095,23 +2081,35 @@ int main(void) return PLUGIN_ERROR; } +#ifdef USEGSLIB + long grey_buf_used; + if (!grey_init(plugin_buf, plugin_buf_size, GREY_BUFFERED|GREY_ON_COP, + LCD_WIDTH, LCD_HEIGHT, &grey_buf_used)) + rb->splash(HZ, "Greylib init failed!"); + grey_setfont(FONT_UI); + plugin_buf_size -= grey_buf_used; + plugin_buf = (void*)(grey_buf_used + (char*)plugin_buf); +#endif + buf_init(plugin_buf, plugin_buf_size); + + empty_slide_hid = read_pfraw( EMPTY_SLIDE ); + if (!(empty_slide_hid = read_pfraw( EMPTY_SLIDE ) )) + { + rb->splash(HZ, "Unable to load empty slide image"); + return PLUGIN_ERROR; + } + int i; /* initialize */ int min_slide_cache = fmin(number_of_slides, SLIDE_CACHE_SIZE); for (i = 0; i < min_slide_cache; i++) { - cache[i].hid = -1; + cache[i].hid = 0; cache[i].touched = 0; slide_cache_stack[i] = SLIDE_CACHE_SIZE-i-1; } slide_cache_stack_index = min_slide_cache-1; slide_cache_in_use = 0; -#ifdef USEGSLIB - if (!grey_init(plugin_buf, plugin_buf_size, GREY_BUFFERED|GREY_ON_COP, - LCD_WIDTH, LCD_HEIGHT, NULL)) - rb->splash(HZ, "Greylib init failed!"); - grey_setfont(FONT_UI); -#endif buffer = LCD_BUF; pf_state = pf_idle;