@ -39,6 +39,7 @@
# include <values.h>
# include <unistd.h>
# include <wchar.h>
# include <dirent.h>
# include "ply-boot-splash-plugin.h"
# include "ply-buffer.h"
@ -112,6 +113,7 @@ typedef struct
ply_rectangle_t box_area , lock_area , watermark_area , dialog_area ;
ply_trigger_t * end_trigger ;
ply_pixel_buffer_t * background_buffer ;
ply_image_t * watermark_image ;
int animation_bottom ;
} view_t ;
@ -125,6 +127,10 @@ typedef struct
bool use_firmware_background ;
char * title ;
char * subtitle ;
uint32_t background_start_color ;
uint32_t background_end_color ;
uint32_t title_color ;
char * watermark_imagename ;
} mode_settings_t ;
struct _ply_boot_splash_plugin
@ -139,7 +145,6 @@ struct _ply_boot_splash_plugin
ply_image_t * header_image ;
ply_image_t * background_tile_image ;
ply_image_t * background_bgrt_image ;
ply_image_t * watermark_image ;
ply_list_t * views ;
ply_boot_splash_display_type_t state ;
@ -163,6 +168,7 @@ struct _ply_boot_splash_plugin
uint32_t background_start_color ;
uint32_t background_end_color ;
uint32_t title_color ;
int background_bgrt_raw_width ;
int background_bgrt_raw_height ;
@ -197,6 +203,78 @@ static void become_idle (ply_boot_splash_plugin_t *plugin,
ply_trigger_t * idle_trigger ) ;
static void view_show_message ( view_t * view , const char * message ) ;
bool is_dir ( const char * path ) {
struct stat path_stat ;
stat ( path , & path_stat ) ;
return S_ISDIR ( path_stat . st_mode ) ;
}
void image_get_res ( const char * basedir , int * xres , int * yres )
{
FILE * fp ;
char buf [ 512 ] ;
int oxres , oyres ;
oxres = * xres ;
oyres = * yres ;
snprintf ( buf , 512 , " %s/%dx%d.png " , basedir , oxres , oyres ) ;
fp = fopen ( buf , " r " ) ;
if ( ! fp ) {
* xres = 1024 ;
* yres = 768 ;
unsigned int t , tx , ty , mdist = 0xffffffff ;
struct dirent * dent ;
DIR * tdir ;
snprintf ( buf , 512 , " %s " , basedir ) ;
tdir = opendir ( buf ) ;
if ( ! tdir ) {
* xres = 0 ;
* yres = 0 ;
return ;
}
while ( ( dent = readdir ( tdir ) ) ) {
if ( sscanf ( dent - > d_name , " %dx%d.png " , & tx , & ty ) ! = 2 )
continue ;
/* We only want configs for resolutions smaller than the current one,
* so that we can actually fit the image on the screen . */
if ( tx > = oxres | | ty > = oyres )
continue ;
t = ( tx - oxres ) * ( tx - oxres ) + ( ty - oyres ) * ( ty - oyres ) ;
/* Penalize configs for resolutions with different aspect ratios. */
if ( oxres / oyres ! = tx / ty )
t * = 10 ;
if ( t < mdist ) {
* xres = tx ;
* yres = ty ;
mdist = t ;
}
}
closedir ( tdir ) ;
} else {
fclose ( fp ) ;
}
}
char * detect_image ( const char * logo_image , int xres , int yres ) {
char * buf ;
if ( logo_image ! = NULL ) {
if ( is_dir ( logo_image ) ) {
image_get_res ( logo_image , & xres , & yres ) ;
if ( asprintf ( & buf , " %s/%dx%d.png " , logo_image , xres , yres ) ! = - 1 )
return buf ;
} else {
return strdup ( logo_image ) ;
}
}
return NULL ;
}
static view_t *
view_new ( ply_boot_splash_plugin_t * plugin ,
ply_pixel_display_t * display )
@ -206,6 +284,7 @@ view_new (ply_boot_splash_plugin_t *plugin,
view = calloc ( 1 , sizeof ( view_t ) ) ;
view - > plugin = plugin ;
view - > display = display ;
view - > watermark_image = NULL ;
view - > entry = ply_entry_new ( plugin - > animation_dir ) ;
view - > keymap_icon = ply_keymap_icon_new ( display , plugin - > animation_dir ) ;
@ -254,6 +333,9 @@ view_free (view_t *view)
ply_label_free ( view - > title_label ) ;
ply_label_free ( view - > subtitle_label ) ;
if ( view - > watermark_image ! = NULL )
ply_image_free ( view - > watermark_image ) ;
if ( view - > background_buffer ! = NULL )
ply_pixel_buffer_free ( view - > background_buffer ) ;
@ -565,6 +647,7 @@ view_load (view_t *view)
{
unsigned long x , y , width , title_height = 0 , subtitle_height = 0 ;
unsigned long screen_width , screen_height , screen_scale ;
char * image_dir , * image_path ;
ply_boot_splash_plugin_t * plugin ;
ply_pixel_buffer_t * buffer ;
@ -600,11 +683,27 @@ view_load (view_t *view)
ply_pixel_buffer_free ( buffer ) ;
}
if ( plugin - > watermark_image ! = NULL ) {
view - > watermark_area . width = ply_image_get_width ( plugin - > watermark_image ) ;
view - > watermark_area . height = ply_image_get_height ( plugin - > watermark_image ) ;
view - > watermark_area . x = screen_width * plugin - > watermark_horizontal_alignment - ply_image_get_width ( plugin - > watermark_image ) * plugin - > watermark_horizontal_alignment ;
view - > watermark_area . y = screen_height * plugin - > watermark_vertical_alignment - ply_image_get_height ( plugin - > watermark_image ) * plugin - > watermark_vertical_alignment ;
if ( view - > watermark_image = = NULL & & plugin - > mode_settings [ plugin - > mode ] . watermark_imagename ) {
image_path = detect_image ( plugin - > mode_settings [ plugin - > mode ] . watermark_imagename ,
screen_width , screen_height ) ;
ply_trace ( " assing watermark %s " , image_path ) ;
view - > watermark_image = ply_image_new ( image_path ) ;
if ( image_path ! = NULL )
free ( image_path ) ;
}
if ( view - > watermark_image ! = NULL ) {
ply_trace ( " loading watermark image " ) ;
if ( ! ply_image_load ( view - > watermark_image ) ) {
ply_image_free ( view - > watermark_image ) ;
view - > watermark_image = NULL ;
}
}
if ( view - > watermark_image ! = NULL ) {
view - > watermark_area . width = ply_image_get_width ( view - > watermark_image ) ;
view - > watermark_area . height = ply_image_get_height ( view - > watermark_image ) ;
view - > watermark_area . x = screen_width * plugin - > watermark_horizontal_alignment - ply_image_get_width ( view - > watermark_image ) * plugin - > watermark_horizontal_alignment ;
view - > watermark_area . y = screen_height * plugin - > watermark_vertical_alignment - ply_image_get_height ( view - > watermark_image ) * plugin - > watermark_vertical_alignment ;
ply_trace ( " using %ldx%ld watermark centered at %ldx%ld for %ldx%ld screen " ,
view - > watermark_area . width , view - > watermark_area . height ,
view - > watermark_area . x , view - > watermark_area . y ,
@ -677,6 +776,21 @@ view_load (view_t *view)
width , subtitle_height , x , y , screen_width , screen_height ) ;
ply_label_show ( view - > subtitle_label , view - > display , x , y ) ;
}
uint32_t title_color = 0xff00ff ;
title_color = plugin - > mode_settings [ plugin - > mode ] . title_color ;
if ( view - > title_label ) {
ply_label_set_color ( view - > title_label ,
( ( title_color > > 16 ) & 0xff ) / 255.0f ,
( ( title_color > > 8 ) & 0xff ) / 255.0f ,
( title_color & 0xff ) / 255.0f ,
1.0f ) ;
ply_label_set_color ( view - > subtitle_label ,
( ( title_color > > 16 ) & 0xff ) / 255.0f ,
( ( title_color > > 8 ) & 0xff ) / 255.0f ,
( title_color & 0xff ) / 255.0f ,
1.0f ) ;
}
return true ;
}
@ -1009,8 +1123,21 @@ load_mode_settings (ply_boot_splash_plugin_t *plugin,
if ( settings - > use_firmware_background )
plugin - > use_firmware_background = true ;
settings - > watermark_imagename = ply_key_file_get_value ( key_file , group_name , " WatermarkImage " ) ;
settings - > title = ply_key_file_get_value ( key_file , group_name , " Title " ) ;
settings - > subtitle = ply_key_file_get_value ( key_file , group_name , " SubTitle " ) ;
settings - > title_color = ply_key_file_get_long ( key_file , group_name , " TitleColor " ,
plugin - > title_color ) ;
settings - > background_start_color =
ply_key_file_get_long ( key_file , group_name ,
" BackgroundStartColor " ,
plugin - > background_start_color ) ;
settings - > background_end_color =
ply_key_file_get_long ( key_file , group_name ,
" BackgroundEndColor " ,
plugin - > background_end_color ) ;
}
static ply_boot_splash_plugin_t *
@ -1048,10 +1175,6 @@ create_plugin (ply_key_file_t *key_file)
plugin - > background_tile_image = ply_image_new ( image_path ) ;
free ( image_path ) ;
asprintf ( & image_path , " %s/watermark.png " , image_dir ) ;
plugin - > watermark_image = ply_image_new ( image_path ) ;
free ( image_path ) ;
plugin - > animation_dir = image_dir ;
plugin - > font = ply_key_file_get_value ( key_file , " two-step " , " Font " ) ;
@ -1125,6 +1248,8 @@ create_plugin (ply_key_file_t *key_file)
ply_key_file_get_long ( key_file , " two-step " ,
" BackgroundEndColor " ,
PLYMOUTH_BACKGROUND_END_COLOR ) ;
plugin - > title_color = ply_key_file_get_long (
key_file , " two-step " , " TitleColor " , 0xffffff ) ;
plugin - > progress_bar_bg_color =
ply_key_file_get_long ( key_file , " two-step " ,
@ -1243,9 +1368,6 @@ destroy_plugin (ply_boot_splash_plugin_t *plugin)
if ( plugin - > background_bgrt_image ! = NULL )
ply_image_free ( plugin - > background_bgrt_image ) ;
if ( plugin - > watermark_image ! = NULL )
ply_image_free ( plugin - > watermark_image ) ;
for ( i = 0 ; i < PLY_BOOT_SPLASH_MODE_COUNT ; i + + ) {
free ( plugin - > mode_settings [ i ] . title ) ;
free ( plugin - > mode_settings [ i ] . subtitle ) ;
@ -1421,18 +1543,18 @@ draw_background (view_t *view,
ply_pixel_buffer_fill_with_hex_color ( pixel_buffer , & area , 0 ) ;
else if ( view - > background_buffer ! = NULL )
ply_pixel_buffer_fill_with_buffer ( pixel_buffer , view - > background_buffer , 0 , 0 ) ;
else if ( plugin - > background_start_color ! = plugin - > background_end_color )
else if ( plugin - > mode_settings[ plugin - > mode ] . background_start_color ! = plugin - > mode_settings [ plugin - > mode ] . background_end_color )
ply_pixel_buffer_fill_with_gradient ( pixel_buffer , & area ,
plugin - > background_start_color ,
plugin - > background_end_color ) ;
plugin - > mode_settings [ plugin - > mode ] . background_start_color ,
plugin - > mode_settings [ plugin - > mode ] . background_end_color ) ;
else
ply_pixel_buffer_fill_with_hex_color ( pixel_buffer , & area ,
plugin - > background_start_color ) ;
plugin - > mode_settings [ plugin - > mode ] . background_start_color ) ;
if ( plugin - > watermark_image ! = NULL ) {
if ( view - > watermark_image ! = NULL ) {
uint32_t * data ;
data = ply_image_get_data ( plugin - > watermark_image ) ;
data = ply_image_get_data ( view - > watermark_image ) ;
ply_pixel_buffer_fill_with_argb32_data ( pixel_buffer , & view - > watermark_area , data ) ;
}
}
@ -1663,14 +1785,6 @@ show_splash_screen (ply_boot_splash_plugin_t *plugin,
}
}
if ( plugin - > watermark_image ! = NULL ) {
ply_trace ( " loading watermark image " ) ;
if ( ! ply_image_load ( plugin - > watermark_image ) ) {
ply_image_free ( plugin - > watermark_image ) ;
plugin - > watermark_image = NULL ;
}
}
if ( ! load_views ( plugin ) ) {
ply_trace ( " couldn't load views " ) ;
return false ;