diff --git a/apps/plugins/pictureflow.c b/apps/plugins/pictureflow.c index 5613ce8..8bb4cd5 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; @@ -1122,7 +1119,7 @@ int load_surface(const int slide_index) } } if (cache[oldest_slide].hid != empty_slide_hid) { - rb->bufclose(cache[oldest_slide].hid); + buf_free(cache[oldest_slide].hid); cache[oldest_slide].hid = -1; } 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 == 0) 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; } @@ -1654,10 +1649,10 @@ void cleanup(void *parameter) int i; for (i = 0; i < slide_cache_in_use; i++) { - rb->bufclose(cache[i].hid); + buf_free(cache[i].hid); } if ( empty_slide_hid != - 1) - rb->bufclose(empty_slide_hid); + buf_free(empty_slide_hid); #ifdef USEGSLIB grey_release(); #endif @@ -1687,9 +1682,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; } @@ -2053,6 +2045,7 @@ void draw_album_text(void) int main(void) { int ret; + long grey_buf_used; rb->lcd_setfont(FONT_UI); draw_splashscreen(); @@ -2095,6 +2088,23 @@ int main(void) return PLUGIN_ERROR; } +#ifdef USEGSLIB + 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); +#endif + plugin_buf_size -= grey_buf_used; + plugin_buf = (void*)(grey_buf_used + (char*)plugin_buf); + 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 */ @@ -2106,12 +2116,6 @@ int main(void) } 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;