diff --git a/apps/plugins/pictureflow.c b/apps/plugins/pictureflow.c index 5613ce8..e8fcb08 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 @@ -398,7 +399,7 @@ static inline int clz(uint32_t v) } #else static const char clz_lut[16] = { 4, 3, 2, 2, 1, 1, 1, 1, - 0, 0, 0, 0, 0, 0, 0, 0 }; + 0, 0, 0, 0, 0, 0, 0, 0 }; /* This clz is based on the log2(n) implementation at * http://graphics.stanford.edu/~seander/bithacks.html#IntegerLogLookup * It is not any faster than the one above, but trades 16B in the lookup table @@ -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; @@ -1116,14 +1113,14 @@ int load_surface(const int slide_index) } else { for (i = 0; i < SLIDE_CACHE_SIZE; i++) { /* look for oldest slide */ - if (cache[i].touched < oldest_tick) { + if (cache[i].touched < oldest_tick && cache[i].hid) { oldest_slide = i; 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,13 @@ 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); + bmp->data = sizeof(struct bitmap) + (char *)bmp; return bmp; } @@ -1329,7 +1325,7 @@ void render_slide(struct slide_data *slide, const int alpha) xsnum = CAM_DIST * (slide->cx - xp) - fmuln(xp, zo, PFREAL_SHIFT - 2, 0); xsden = fmuln(xp, sinr, PFREAL_SHIFT - 2, 0) - CAM_DIST * cosr; xs = fdiv(xsnum, xsden); - + xsnumi = -CAM_DIST_R - zo; xsdeni = sinr; int x; @@ -1411,7 +1407,7 @@ void render_slide(struct slide_data *slide, const int alpha) xs = fdiv(xsnum, xsden); } else xs += PFREAL_ONE; - + } /* let the music play... */ rb->yield(); @@ -1652,12 +1648,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 +1677,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,7 +2040,7 @@ void draw_album_text(void) int main(void) { int ret; - + rb->lcd_setfont(FONT_UI); draw_splashscreen(); @@ -2076,7 +2063,7 @@ int main(void) rb->splash(HZ, "No albums found. Please enable database"); return PLUGIN_ERROR; } - + number_of_slides = album_count; if ((cache_version != CACHE_VERSION) && !create_albumart_cache()) { rb->splash(HZ, "Could not create album art cache"); @@ -2095,23 +2082,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;