picture flow: clean up code. no functional changes.

-use upper case for enum constants.
-rename variables to match it's use.
-remove tabs and fix indents.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28192 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Teruaki Kawashima 2010-10-02 14:28:46 +00:00
parent ad6c8c1a72
commit 23718ad646

View file

@ -237,6 +237,10 @@ typedef fb_data pix_t;
#define EMPTY_SLIDE_BMP PLUGIN_DEMOS_DIR "/pictureflow_emptyslide.bmp" #define EMPTY_SLIDE_BMP PLUGIN_DEMOS_DIR "/pictureflow_emptyslide.bmp"
#define SPLASH_BMP PLUGIN_DEMOS_DIR "/pictureflow_splash.bmp" #define SPLASH_BMP PLUGIN_DEMOS_DIR "/pictureflow_splash.bmp"
/* some magic numbers for cache_version. */
#define CACHE_REBUILD 0
#define CACHE_UPDATE 1
/* Error return values */ /* Error return values */
#define ERROR_NO_ALBUMS -1 #define ERROR_NO_ALBUMS -1
#define ERROR_BUFFER_FULL -2 #define ERROR_BUFFER_FULL -2
@ -296,8 +300,11 @@ struct pfraw_header {
int32_t height; /* bmap height in pixels */ int32_t height; /* bmap height in pixels */
}; };
enum show_album_name_values { album_name_hide = 0, album_name_bottom, enum show_album_name_values {
album_name_top }; ALBUM_NAME_HIDE = 0,
ALBUM_NAME_BOTTOM,
ALBUM_NAME_TOP
};
static char* show_album_name_conf[] = static char* show_album_name_conf[] =
{ {
"hide", "hide",
@ -320,7 +327,7 @@ static int backlight_mode = 0;
static bool resize = true; static bool resize = true;
static int cache_version = 0; static int cache_version = 0;
static int show_album_name = (LCD_HEIGHT > 100) static int show_album_name = (LCD_HEIGHT > 100)
? album_name_top : album_name_bottom; ? ALBUM_NAME_TOP : ALBUM_NAME_BOTTOM;
static struct configdata config[] = static struct configdata config[] =
{ {
@ -409,7 +416,7 @@ static int start_index_track_list = 0;
static int track_list_visible_entries = 0; static int track_list_visible_entries = 0;
static int track_list_y; static int track_list_y;
static int track_list_h; static int track_list_h;
static int track_scroll_index = 0; static int track_scroll_x = 0;
static int track_scroll_dir = 1; static int track_scroll_dir = 1;
/* /*
@ -441,7 +448,6 @@ static int pf_state;
/** code */ /** code */
static bool free_slide_prio(int prio); static bool free_slide_prio(int prio);
static inline unsigned fade_color(pix_t c, unsigned a); static inline unsigned fade_color(pix_t c, unsigned a);
bool save_pfraw(char* filename, struct bitmap *bm);
bool load_new_slide(void); bool load_new_slide(void);
int load_surface(int); int load_surface(int);
@ -734,15 +740,13 @@ int create_album_index(void)
rb->memset(&tcs, 0, sizeof(struct tagcache_search) ); rb->memset(&tcs, 0, sizeof(struct tagcache_search) );
album_count = 0; album_count = 0;
rb->tagcache_search(&tcs, tag_album); rb->tagcache_search(&tcs, tag_album);
unsigned int l, old_l = 0; unsigned int l, name_idx = 0;
album_names = buf; album_names = buf;
album[0].name_idx = 0;
while (rb->tagcache_get_next(&tcs)) while (rb->tagcache_get_next(&tcs))
{ {
buf_size -= sizeof(struct album_data); buf_size -= sizeof(struct album_data);
l = tcs.result_len; l = tcs.result_len;
if ( album_count > 0 ) album[-album_count].name_idx = name_idx;
album[-album_count].name_idx = album[1-album_count].name_idx + old_l;
if ( l > buf_size ) if ( l > buf_size )
/* not enough memory */ /* not enough memory */
@ -752,7 +756,7 @@ int create_album_index(void)
buf_size -= l; buf_size -= l;
buf = l + (char *)buf; buf = l + (char *)buf;
album[-album_count].seek = tcs.result_seek; album[-album_count].seek = tcs.result_seek;
old_l = l; name_idx += l;
album_count++; album_count++;
} }
rb->tagcache_search_finish(&tcs); rb->tagcache_search_finish(&tcs);
@ -799,9 +803,11 @@ int get_wps_current_index(void)
if(id3 && id3->album) { if(id3 && id3->album) {
int i; int i;
for( i=0; i < album_count; i++ ) for( i=0; i < album_count; i++ )
{
if(!rb->strcmp(album_names + album[i].name_idx, id3->album)) if(!rb->strcmp(album_names + album[i].name_idx, id3->album))
return i; return i;
} }
}
return last_album; return last_album;
} }
@ -980,7 +986,7 @@ void draw_splashscreen(void)
{ {
unsigned char * buf_tmp = buf; unsigned char * buf_tmp = buf;
size_t buf_tmp_size = buf_size; size_t buf_tmp_size = buf_size;
struct screen* display = rb->screens[0]; struct screen* display = rb->screens[SCREEN_MAIN];
#if FB_DATA_SZ > 1 #if FB_DATA_SZ > 1
ALIGN_BUFFER(buf_tmp, buf_tmp_size, sizeof(fb_data)); ALIGN_BUFFER(buf_tmp, buf_tmp_size, sizeof(fb_data));
#endif #endif
@ -994,8 +1000,8 @@ void draw_splashscreen(void)
#endif #endif
.data = buf_tmp .data = buf_tmp
}; };
int ret = rb->read_bmp_file(SPLASH_BMP, &logo, buf_tmp_size, FORMAT_NATIVE, int ret = rb->read_bmp_file(SPLASH_BMP, &logo, buf_tmp_size,
NULL); FORMAT_NATIVE, NULL);
#if LCD_DEPTH > 1 #if LCD_DEPTH > 1
rb->lcd_set_background(N_BRIGHT(0)); rb->lcd_set_background(N_BRIGHT(0));
rb->lcd_set_foreground(N_BRIGHT(255)); rb->lcd_set_foreground(N_BRIGHT(255));
@ -1071,8 +1077,30 @@ unsigned int mfnv(char *str)
return hash; return hash;
} }
/**
Save the given bitmap as filename in the pfraw format
*/
bool save_pfraw(char* filename, struct bitmap *bm)
{
struct pfraw_header bmph;
bmph.width = bm->width;
bmph.height = bm->height;
int fh = rb->creat( filename , 0666);
if( fh < 0 ) return false;
rb->write( fh, &bmph, sizeof( struct pfraw_header ) );
int y;
for( y = 0; y < bm->height; y++ )
{
pix_t *d = (pix_t*)( bm->data ) + (y*bm->width);
rb->write( fh, d, sizeof( pix_t ) * bm->width );
}
rb->close( fh );
return true;
}
/** /**
Precomupte the album art images and store them in CACHE_PREFIX. Precomupte the album art images and store them in CACHE_PREFIX.
Use the "?" bitmap if image is not found.
*/ */
bool create_albumart_cache(void) bool create_albumart_cache(void)
{ {
@ -1084,8 +1112,8 @@ bool create_albumart_cache(void)
char pfraw_file[MAX_PATH]; char pfraw_file[MAX_PATH];
char albumart_file[MAX_PATH]; char albumart_file[MAX_PATH];
unsigned int format = FORMAT_NATIVE; unsigned int format = FORMAT_NATIVE;
bool forced = cache_version == 0; bool update = (cache_version == CACHE_UPDATE);
cache_version = 0; cache_version = CACHE_REBUILD;
configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS, CONFIG_VERSION); configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS, CONFIG_VERSION);
if (resize) if (resize)
format |= FORMAT_RESIZE|FORMAT_KEEP_ASPECT; format |= FORMAT_RESIZE|FORMAT_KEEP_ASPECT;
@ -1095,7 +1123,7 @@ bool create_albumart_cache(void)
mfnv(get_album_name(i))); mfnv(get_album_name(i)));
/* delete existing cache, so it's a true rebuild */ /* delete existing cache, so it's a true rebuild */
if(rb->file_exists(pfraw_file)) { if(rb->file_exists(pfraw_file)) {
if(!forced) if(update)
continue; continue;
rb->remove(pfraw_file); rb->remove(pfraw_file);
} }
@ -1106,11 +1134,13 @@ bool create_albumart_cache(void)
input_bmp.data = buf; input_bmp.data = buf;
input_bmp.width = DISPLAY_WIDTH; input_bmp.width = DISPLAY_WIDTH;
input_bmp.height = DISPLAY_HEIGHT; input_bmp.height = DISPLAY_HEIGHT;
ret = read_image_file(albumart_file, &input_bmp, buf_size, format, &format_transposed); ret = read_image_file(albumart_file, &input_bmp, buf_size,
format, &format_transposed);
if (ret <= 0) { if (ret <= 0) {
rb->splashf(HZ, "Album art is bad: %s", get_album_name(i)); rb->splashf(HZ, "Album art is bad: %s", get_album_name(i));
rb->strcpy(albumart_file, EMPTY_SLIDE_BMP); rb->strcpy(albumart_file, EMPTY_SLIDE_BMP);
ret = read_image_file(albumart_file, &input_bmp, buf_size, format, &format_transposed); ret = read_image_file(albumart_file, &input_bmp, buf_size,
format, &format_transposed);
if(ret <= 0) if(ret <= 0)
continue; continue;
} }
@ -1129,6 +1159,32 @@ bool create_albumart_cache(void)
return true; return true;
} }
/**
Create the "?" slide, that is shown while loading
or when no cover was found.
*/
int create_empty_slide(bool force)
{
if ( force || ! rb->file_exists( EMPTY_SLIDE ) ) {
struct bitmap input_bmp;
int ret;
input_bmp.width = DISPLAY_WIDTH;
input_bmp.height = DISPLAY_HEIGHT;
#if LCD_DEPTH > 1
input_bmp.format = FORMAT_NATIVE;
#endif
input_bmp.data = (char*)buf;
ret = scaled_read_bmp_file(EMPTY_SLIDE_BMP, &input_bmp,
buf_size,
FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
&format_transposed);
if (!save_pfraw(EMPTY_SLIDE, &input_bmp))
return false;
}
return true;
}
/** /**
Thread used for loading and preparing bitmaps in the background Thread used for loading and preparing bitmaps in the background
*/ */
@ -1169,7 +1225,6 @@ void end_pf_thread(void)
rb->queue_delete(&thread_q); rb->queue_delete(&thread_q);
thread_is_running = false; thread_is_running = false;
} }
} }
@ -1198,27 +1253,6 @@ bool create_pf_thread(void)
return true; return true;
} }
/**
Safe the given bitmap as filename in the pfraw format
*/
bool save_pfraw(char* filename, struct bitmap *bm)
{
struct pfraw_header bmph;
bmph.width = bm->width;
bmph.height = bm->height;
int fh = rb->creat( filename , 0666);
if( fh < 0 ) return false;
rb->write( fh, &bmph, sizeof( struct pfraw_header ) );
int y;
for( y = 0; y < bm->height; y++ )
{
pix_t *d = (pix_t*)( bm->data ) + (y*bm->width);
rb->write( fh, d, sizeof( pix_t ) * bm->width );
}
rb->close( fh );
return true;
}
/* /*
* The following functions implement the linked-list-in-array used to manage * The following functions implement the linked-list-in-array used to manage
@ -1389,7 +1423,7 @@ int read_pfraw(char* filename, int prio)
struct pfraw_header bmph; struct pfraw_header bmph;
int fh = rb->open(filename, O_RDONLY); int fh = rb->open(filename, O_RDONLY);
if( fh < 0 ) { if( fh < 0 ) {
cache_version = 1; cache_version = CACHE_UPDATE;
return empty_slide_hid; return empty_slide_hid;
} }
else else
@ -1406,7 +1440,7 @@ int read_pfraw(char* filename, int prio)
return 0; return 0;
} }
rb->yield(); // allow audio to play when fast scrolling rb->yield(); /* allow audio to play when fast scrolling */
struct dim *bm = buflib_get_data(&buf_ctx, hid); struct dim *bm = buflib_get_data(&buf_ctx, hid);
bm->width = bmph.width; bm->width = bmph.width;
@ -1431,11 +1465,11 @@ static inline bool load_and_prepare_surface(const int slide_index,
const int cache_index, const int cache_index,
const int prio) const int prio)
{ {
char tmp_path_name[MAX_PATH+1]; char pfraw_file[MAX_PATH];
rb->snprintf(tmp_path_name, sizeof(tmp_path_name), CACHE_PREFIX "/%x.pfraw", rb->snprintf(pfraw_file, sizeof(pfraw_file), CACHE_PREFIX "/%x.pfraw",
mfnv(get_album_name(slide_index))); mfnv(get_album_name(slide_index)));
int hid = read_pfraw(tmp_path_name, prio); int hid = read_pfraw(pfraw_file, prio);
if (!hid) if (!hid)
return false; return false;
@ -1805,8 +1839,8 @@ void render_slide(struct slide_data *slide, const int alpha)
pixel -= PIXELSTEP_Y; pixel -= PIXELSTEP_Y;
} }
} }
rb->yield(); // allow audio to play when fast scrolling rb->yield(); /* allow audio to play when fast scrolling */
bmp = surface(slide->slide_index); // resync surface due to yield bmp = surface(slide->slide_index); /* resync surface due to yield */
ptr = &src[column * bmp->height]; ptr = &src[column * bmp->height];
p = (bmp->height-DISPLAY_OFFS) * PFREAL_ONE; p = (bmp->height-DISPLAY_OFFS) * PFREAL_ONE;
plim = MIN(sh * PFREAL_ONE, p + (LCD_HEIGHT/2) * dy); plim = MIN(sh * PFREAL_ONE, p + (LCD_HEIGHT/2) * dy);
@ -2086,32 +2120,6 @@ void cleanup(void)
rb->viewportmanager_theme_undo(i, false); rb->viewportmanager_theme_undo(i, false);
} }
/**
Create the "?" slide, that is shown while loading
or when no cover was found.
*/
int create_empty_slide(bool force)
{
if ( force || ! rb->file_exists( EMPTY_SLIDE ) ) {
struct bitmap input_bmp;
int ret;
input_bmp.width = DISPLAY_WIDTH;
input_bmp.height = DISPLAY_HEIGHT;
#if LCD_DEPTH > 1
input_bmp.format = FORMAT_NATIVE;
#endif
input_bmp.data = (char*)buf;
ret = scaled_read_bmp_file(EMPTY_SLIDE_BMP, &input_bmp,
buf_size,
FORMAT_NATIVE|FORMAT_RESIZE|FORMAT_KEEP_ASPECT,
&format_transposed);
if (!save_pfraw(EMPTY_SLIDE, &input_bmp))
return false;
}
return true;
}
/** /**
Shows the settings menu Shows the settings menu
*/ */
@ -2191,7 +2199,7 @@ int settings_menu(void)
break; break;
/* fallthrough if changed, since cache needs to be rebuilt */ /* fallthrough if changed, since cache needs to be rebuilt */
case 7: case 7:
cache_version = 0; cache_version = CACHE_REBUILD;
rb->remove(EMPTY_SLIDE); rb->remove(EMPTY_SLIDE);
rb->splash(HZ, "Cache will be rebuilt on next restart"); rb->splash(HZ, "Cache will be rebuilt on next restart");
break; break;
@ -2342,15 +2350,16 @@ static void track_list_yh(int char_height)
{ {
switch (show_album_name) switch (show_album_name)
{ {
case album_name_hide: case ALBUM_NAME_HIDE:
track_list_y = (show_fps ? char_height : 0); track_list_y = (show_fps ? char_height : 0);
track_list_h = LCD_HEIGHT - track_list_y; track_list_h = LCD_HEIGHT - track_list_y;
break; break;
case album_name_bottom: case ALBUM_NAME_BOTTOM:
track_list_y = (show_fps ? char_height : 0); track_list_y = (show_fps ? char_height : 0);
track_list_h = LCD_HEIGHT - track_list_y - char_height * 2; track_list_h = LCD_HEIGHT - track_list_y - char_height * 2;
break; break;
default: /* case album_name_top */ case ALBUM_NAME_TOP:
default:
track_list_y = char_height * 2; track_list_y = char_height * 2;
track_list_h = LCD_HEIGHT - track_list_y - track_list_h = LCD_HEIGHT - track_list_y -
(show_fps ? char_height : 0); (show_fps ? char_height : 0);
@ -2363,19 +2372,19 @@ static void track_list_yh(int char_height)
*/ */
void reset_track_list(void) void reset_track_list(void)
{ {
int albumtxt_h = rb->screens[SCREEN_MAIN]->getcharheight(); int char_height = rb->screens[SCREEN_MAIN]->getcharheight();
track_list_yh(albumtxt_h); track_list_yh(char_height);
track_list_visible_entries = fmin( track_list_h/albumtxt_h , track_count ); track_list_visible_entries = fmin( track_list_h/char_height , track_count );
start_index_track_list = 0; start_index_track_list = 0;
track_scroll_index = 0; track_scroll_x = 0;
track_scroll_dir = 1; track_scroll_dir = 1;
selected_track = 0; selected_track = 0;
/* let the tracklist start more centered /* let the tracklist start more centered
* if the screen isn't filled with tracks */ * if the screen isn't filled with tracks */
if (track_count*albumtxt_h < track_list_h) if (track_count*char_height < track_list_h)
{ {
track_list_h = track_count * albumtxt_h; track_list_h = track_count * char_height;
track_list_y = LCD_HEIGHT / 2 - (track_list_h / 2); track_list_y = LCD_HEIGHT / 2 - (track_list_h / 2);
} }
} }
@ -2405,11 +2414,11 @@ void show_track_list(void)
draw_gradient(titletxt_y, titletxt_h); draw_gradient(titletxt_y, titletxt_h);
mylcd_set_foreground(G_BRIGHT(255)); mylcd_set_foreground(G_BRIGHT(255));
if (titletxt_w > LCD_WIDTH ) { if (titletxt_w > LCD_WIDTH ) {
if ( titletxt_w + track_scroll_index <= LCD_WIDTH ) if ( titletxt_w + track_scroll_x <= LCD_WIDTH )
track_scroll_dir = 1; track_scroll_dir = 1;
else if ( track_scroll_index >= 0 ) track_scroll_dir = -1; else if ( track_scroll_x >= 0 ) track_scroll_dir = -1;
track_scroll_index += track_scroll_dir*2; track_scroll_x += track_scroll_dir*2;
titletxt_x = track_scroll_index; titletxt_x = track_scroll_x;
} }
mylcd_putsxy(titletxt_x,titletxt_y,get_track_name(track_i)); mylcd_putsxy(titletxt_x,titletxt_y,get_track_name(track_i));
} }
@ -2426,7 +2435,7 @@ void select_next_track(void)
{ {
if ( selected_track < track_count - 1 ) { if ( selected_track < track_count - 1 ) {
selected_track++; selected_track++;
track_scroll_index = 0; track_scroll_x = 0;
track_scroll_dir = 1; track_scroll_dir = 1;
if (selected_track==(track_list_visible_entries+start_index_track_list)) if (selected_track==(track_list_visible_entries+start_index_track_list))
start_index_track_list++; start_index_track_list++;
@ -2437,7 +2446,7 @@ void select_prev_track(void)
{ {
if (selected_track > 0 ) { if (selected_track > 0 ) {
if (selected_track==start_index_track_list) start_index_track_list--; if (selected_track==start_index_track_list) start_index_track_list--;
track_scroll_index = 0; track_scroll_x = 0;
track_scroll_dir = 1; track_scroll_dir = 1;
selected_track--; selected_track--;
} }
@ -2494,7 +2503,7 @@ play:
*/ */
void draw_album_text(void) void draw_album_text(void)
{ {
if (0 == show_album_name) if (show_album_name == ALBUM_NAME_HIDE)
return; return;
int albumtxt_w, albumtxt_h; int albumtxt_w, albumtxt_h;
@ -2528,7 +2537,7 @@ void draw_album_text(void)
prev_center_index = center_index; prev_center_index = center_index;
} }
if (show_album_name == album_name_top) if (show_album_name == ALBUM_NAME_TOP)
albumtxt_y = albumtxt_h / 2; albumtxt_y = albumtxt_h / 2;
else else
albumtxt_y = LCD_HEIGHT - albumtxt_h - albumtxt_h/2; albumtxt_y = LCD_HEIGHT - albumtxt_h - albumtxt_h/2;
@ -2544,8 +2553,6 @@ void draw_album_text(void)
else { else {
mylcd_putsxy((LCD_WIDTH - albumtxt_w) /2, albumtxt_y , albumtxt); mylcd_putsxy((LCD_WIDTH - albumtxt_w) /2, albumtxt_y , albumtxt);
} }
} }
/** /**
@ -2713,7 +2720,7 @@ int main(void)
mylcd_set_foreground(G_PIX(255,0,0)); mylcd_set_foreground(G_PIX(255,0,0));
#endif #endif
rb->snprintf(fpstxt, sizeof(fpstxt), "FPS: %d", fps); rb->snprintf(fpstxt, sizeof(fpstxt), "FPS: %d", fps);
if (show_album_name == album_name_top) if (show_album_name == ALBUM_NAME_TOP)
fpstxt_y = LCD_HEIGHT - fpstxt_y = LCD_HEIGHT -
rb->screens[SCREEN_MAIN]->getcharheight(); rb->screens[SCREEN_MAIN]->getcharheight();
else else
@ -2873,7 +2880,6 @@ enum plugin_status plugin_start(const void *parameter)
buf = (void*)(grey_buf_used + (char*)buf); buf = (void*)(grey_buf_used + (char*)buf);
#endif #endif
atexit(cleanup);
ret = main(); ret = main();
if ( ret == PLUGIN_OK || ret == PLUGIN_GOTO_WPS) { if ( ret == PLUGIN_OK || ret == PLUGIN_GOTO_WPS) {
if (configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS, if (configfile_save(CONFIG_FILE, config, CONFIG_NUM_ITEMS,