Skip to content

Commit

Permalink
. 修改图像背景色设置方法。(issues #90)
Browse files Browse the repository at this point in the history
  具体内容见ChangeLog_chenall.txt
  • Loading branch information
yaya committed Feb 21, 2016
1 parent b7af2b9 commit 93c7ee4
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 53 deletions.
30 changes: 16 additions & 14 deletions ChangeLog_chenall.txt
@@ -1,18 +1,20 @@
更新说明:
2016-02-15(yaya)
1.增加图像背景色设置方法。 splashimage --fill-color=[0xrrggbb]
作用之一,作为小图像的背景。
作用之二,直接作为菜单的背景(即不加载图像背景)。此时只设置字体的前景色即可。
2.增加动画菜单。 splashimage --animated=[type]=[delay]=[sequence_num]=[offset_x]=[offset_y]=[name]
类型[type]:bit0-3: 0/1/2=空/一次/循环
bit4-7: 0/1=普通/背景透明
一次:序列图像各显示一次,时间独占。可作为启动前导、序幕。
循环:序列图像无限循环,时间与菜单共享。可作为菜单里的动画。
提醒:请以16进制方式输入。否则易错。
延迟[delay]:序列图像之间的延迟。单位是滴答,即1/18.2秒。
序列数[sequence_num]:序列图像总数(从1开始计数)。
偏移[offset_x]、[offset_y]:图像偏移,单位像素。
名称[name]:图像名称,可包含路径。命名规则:xxxxx-01.xxx; xxxxx-02.xxx; ...; xxxxx-'sequence_num'.xxx 。
2016-02-21(yaya)
1.增加图像背景色设置方法。 splashimage --fill-color=[0xrrggbb]
作用之一,作为小图像的背景。
作用之二,直接作为菜单的背景(即不加载图像背景)。此时只设置字体的前景色即可。
2.增加动画菜单。 splashimage --animated=[type]=[delay]=[last_num]=[offset_x]=[offset_y]=[name]
类型[type]:bit 0-3: 播放次数 bit 4: 永远重复 bit 7: 透明背景
type=00:禁止播放
播放n次:序列图像各显示n次,时间独占。可作为启动前导、序幕。
永远重复:序列图像无限循环,时间与菜单共享。可作为菜单里的动画。
背景透明:即抠像。要求4角像素为背景色。
背景色最好为白色或黑色,这样可以去除一些灰色杂波。若是彩色背景,则应当非常干净。
提醒:请以16进制方式输入。否则易错。
延迟[delay]:序列图像之间的延迟。单位是滴答,即1/18.2秒。
序列数[last_num]:序列图像总数(2位数,从1开始计数)。
偏移[offset_x]、[offset_y]:图像偏移,单位像素。
名称[name]:图像名称,可包含路径。命名规则:xxxxx01.xxx; xxxxx02.xxx; ...; xxxxx'last_num'.xxx 。

2016-02-14(yaya)
setmenu 函数增加菜单项目背景短/满参数(默认短)
Expand Down
26 changes: 18 additions & 8 deletions stage2/builtins.c
Expand Up @@ -4119,9 +4119,9 @@ extern char splashimage[128];
int graphicsmode_func (char *arg, int flags);
unsigned long X_offset,Y_offset;
int vbe_fill_color (unsigned long color);
unsigned char animated_type=0; //bit0-3: 0/1/2=empty/one/loop bit4-7: 0/1=normal/background_transparent
unsigned char animated_type=0; //bit 0-3:times bit 4:repeat forever bit 7:transparent background type=00:disable
unsigned char animated_delay;
unsigned char animated_sequence_num;
unsigned char animated_last_num;
unsigned short animated_offset_x;
unsigned short animated_offset_y;
char animated_name[57];
Expand Down Expand Up @@ -4167,22 +4167,32 @@ splashimage_func(char *arg, int flags)
arg += 11;
if (safe_parse_maxint (&arg, &val))
animated_type = val;
if (!animated_type)
return 1;
arg++;
if (safe_parse_maxint (&arg, &val))
animated_delay = val;
arg++;
if (safe_parse_maxint (&arg, &val))
animated_sequence_num = val;
animated_last_num = val;
arg++;
if (safe_parse_maxint (&arg, &val))
animated_offset_x = val;
arg++;
if (safe_parse_maxint (&arg, &val))
animated_offset_y = val;
arg++;
if (! grub_open(arg))
{
animated_type = 0;
return 0;
}
else
grub_close();

strcpy(animated_name, arg);

if ((animated_type & 0x0f) == 2)
if (!(animated_type & 0x10) && (animated_type & 0x0f))
animated();
return 1;
}
Expand Down Expand Up @@ -4224,11 +4234,11 @@ static struct builtin builtin_splashimage =
BUILTIN_CMDLINE | BUILTIN_SCRIPT | BUILTIN_MENU | BUILTIN_HELP_LIST,
"splashimage --offset=[x]=[y] FILE",
"splashimage --fill-color=[0xrrggbb]\n"
"splashimage --animated=[type]=[delay]=[sequence_num]=[offset_x]=[offset_y]=[name]\n"
"type: bit0-3: 0/1/2=empty/one/loop\n"
" bit4-7: 0/1=normal/background_transparent\n"
"splashimage --animated=[type]=[delay]=[last_num]=[offset_x]=[offset_y]=[name]\n"
"type: bit 0-3:times bit 4:repeat forever bit 7:transparent background\n"
" type=00:disable\n"
"delay: ticks\n"
"naming rules for name: xxxxx-01.xxx; xxxxx-02.xxx; ...; xxxxx-'sequence_num'.xxx\n"
"naming rules for name: xxxxx01.xxx; xxxxx02.xxx; ...; xxxxx'last_num'.xxx\n"
"Load FILE as the background image when in graphics mode."
};

Expand Down
2 changes: 2 additions & 0 deletions stage2/char_io.c
Expand Up @@ -116,6 +116,8 @@ print_error (void)
{
if (errnum > ERR_NONE && errnum < MAX_ERR_NUM)
grub_printf ("\nError %u:(http://grub4dos.chenall.net/e/%u)\n\t %s\n", errnum, errnum, err_list[errnum]);
if (errnum == 15)
animated_type = 0;
}

char *
Expand Down
63 changes: 35 additions & 28 deletions stage2/graphics.c
Expand Up @@ -1037,20 +1037,27 @@ unsigned long delay0, old_tick, name_len;
int animated (void)
{
unsigned long cur_tick, delay1;
char tmp[128];
char num=0, tmp[128];
unsigned long long val;
char *p;

if (!animated_type)
return 0;

if (animated_delay)
{
delay0 = animated_delay;
animated_delay=0;
old_tick=currticks();
name_len=grub_strlen(animated_name);
if ((animated_type & 0x0f) == 2)
if (!(animated_type & 0x10) && (animated_type & 0x0f))
{
setcursor (2);
cls ();
num=animated_type & 0xf;
if (!(splashimage_loaded & 2) || !(cursor_state & 2))
{
setcursor (2);
cls ();
}
}
}

Expand All @@ -1067,9 +1074,14 @@ int animated (void)

if (delay0 <= delay1)
{
if (!(animated_type & 0x10) && (animated_type & 0x0f) && !num)
{
animated_type = 0;
return 1;
}
sprintf(tmp,"--offset=%d=%d %s",animated_offset_x,animated_offset_y,animated_name);
use_phys_base=1;
if ((animated_type & 0xf0) == 0x10)
if (animated_type & 0x80)
background_transparent=1;
splashimage_func(tmp,1);
use_phys_base=0;
Expand All @@ -1087,21 +1099,15 @@ int animated (void)
p=&animated_name[name_len-6];
safe_parse_maxint (&p, &val);

if (val>animated_sequence_num)
if (val>animated_last_num)
{
if ((animated_type & 0x0f) == 2)
{
animated_type = 0;
return 1;
}
else
{
animated_name[name_len-5]=0x31;
animated_name[name_len-6]=0x30;
}
if (!(animated_type & 0x10) && (animated_type & 0x0f))
num--;
animated_name[name_len-5]=0x31;
animated_name[name_len-6]=0x30;
}
}
if ((animated_type & 0x0f) == 1)
if (animated_type & 0x10)
return 1;
}
return 0;
Expand Down Expand Up @@ -1144,8 +1150,8 @@ static int read_image_bmp(int type)
bfbit = bmih.biBitCount>>3;
bftmp = 0;
//bftmp = (bmih.biWidth*(bmih.biBitCount>>3)+3)&~3;
SPLASH_W = bmih.biWidth;
SPLASH_H = bmih.biHeight;
// SPLASH_W = bmih.biWidth;
// SPLASH_H = bmih.biHeight;
// unsigned long *bmp = SPLASH_IMAGE;
unsigned char *bmp;
if (debug > 0)
Expand All @@ -1165,7 +1171,7 @@ static int read_image_bmp(int type)
else if (bftmp==0)
RGB=0;
}
if(y < SPLASH_H && x < SPLASH_W)
if(y < bmih.biHeight && x < bmih.biWidth)
if((y+Y_offset) < current_y_resolution && (x+X_offset) < current_x_resolution)
{
if (use_phys_base !=1)
Expand All @@ -1176,22 +1182,23 @@ static int read_image_bmp(int type)
if(current_bits_per_pixel == 24 || current_bits_per_pixel == 32)
{
// bmp[x] = bftmp; //
if((background_transparent == 1) && (bftmp & 0xff)==((bftmp & 0xff00)>>8) && (bftmp & 0xff)==((bftmp & 0xff0000)>>16)
&& ((RGB==0xff) ? ((bftmp & 0xff)>=0xf0) : ((RGB==0) ? ((bftmp & 0xff)<=0x1f) : (bftmp==bftmp0))))
if((background_transparent == 1) && (((bftmp & 0xff)==((bftmp & 0xff00)>>8) && (bftmp & 0xff)==((bftmp & 0xff0000)>>16) && RGB!=0xaa)?
((RGB==0xff) ? ((bftmp & 0xff)>=0xf0) : ((bftmp & 0xff)<=0x1f)) : (bftmp==bftmp0)))
*(unsigned long *)bmp = *(unsigned long *)((unsigned char *)SPLASH_IMAGE+(x+X_offset)*current_bytes_per_pixel+(y+Y_offset)*current_bytes_per_scanline);
else
*(unsigned long *)bmp = bftmp;
}
else
{
if((background_transparent == 1) && (bftmp & 0xff)==((bftmp & 0xff00)>>8) && (bftmp & 0xff)==((bftmp & 0xff0000)>>16)
&& ((RGB==0xff) ? ((bftmp & 0xff)>=0xf0) : ((RGB==0) ? ((bftmp & 0xff)<=0x1f) : (bftmp==bftmp0))))
if((background_transparent == 1) && (((bftmp & 0xff)==((bftmp & 0xff00)>>8) && (bftmp & 0xff)==((bftmp & 0xff0000)>>16) && RGB!=0xaa)?
((RGB==0xff) ? ((bftmp & 0xff)>=0xf0) : ((bftmp & 0xff)<=0x1f)) : (bftmp==bftmp0)))
*(unsigned short *)bmp = *(unsigned short *)((unsigned char *)SPLASH_IMAGE+(x+X_offset)*current_bytes_per_pixel+(y+Y_offset)*current_bytes_per_scanline);
else
*(unsigned short *)bmp = (unsigned short)pixel_shift(bftmp);
}
}
}
filepos += ((bmih.biWidth*bfbit&3)?(4-(bmih.biWidth*bfbit&3)):0);
}
return 2;
}
Expand Down Expand Up @@ -1349,8 +1356,8 @@ static void StoreBuffer()
lfb = (unsigned char *)current_phys_base + (sizei+i+Y_offset)*current_bytes_per_scanline + (sizej+j+X_offset)*current_bytes_per_pixel;
if(current_bits_per_pixel == 24 || current_bits_per_pixel == 32)
{
if((background_transparent == 1) && B==G && B==R
&& ((RGB==0xff) ? (B>=0xf0) : ((RGB==0) ? (B<=0x1f) : (B==B0 && G==G0 && R==R0))))
if((background_transparent == 1) && ((B==G && B==R && RGB!=0xaa)?
((RGB==0xff) ? (B>=0xf0) : (B<=0x1f)) : (B==B0 && G==G0 && R==R0)))
*(unsigned long *)lfb = *(unsigned long *)((unsigned char *)SPLASH_IMAGE + (sizei+i+Y_offset)*current_bytes_per_scanline + (sizej+j+X_offset)*current_bytes_per_pixel);
else
{
Expand All @@ -1361,8 +1368,8 @@ static void StoreBuffer()
}
else
{
if((background_transparent == 1) && B==G && B==R
&& ((RGB==0xff) ? (B>=0xf0) : ((RGB==0) ? (B<=0x1f) : (B==B0 && G==G0 && R==R0))))
if((background_transparent == 1) && ((B==G && B==R && RGB!=0xaa)?
((RGB==0xff) ? (B>=0xf0) : (B<=0x1f)) : (B==B0 && G==G0 && R==R0)))
*(unsigned short *)lfb = *(unsigned short *)((unsigned char *)SPLASH_IMAGE + (sizei+i+Y_offset)*current_bytes_per_scanline + (sizej+j+X_offset)*current_bytes_per_pixel);
else
{
Expand Down
2 changes: 1 addition & 1 deletion stage2/shared.h
Expand Up @@ -780,7 +780,7 @@ extern unsigned long current_phys_base;
extern unsigned long fill_color;
extern unsigned char animated_type;
extern unsigned char animated_delay;
extern unsigned char animated_sequence_num;
extern unsigned char animated_last_num;
extern unsigned short animated_offset_x;
extern unsigned short animated_offset_y;
extern char animated_name[57];
Expand Down
4 changes: 2 additions & 2 deletions stage2/stage2.c
Expand Up @@ -955,7 +955,7 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h
grub_timeout--;
}

if ((animated_type & 0x0f) == 1)
if ((animated_type & 0x10) && (grub_timeout >= 0))
animated();
/* Check for a keypress, however if TIMEOUT has been expired
(GRUB_TIMEOUT == -1) relax in GETKEY even if no key has been
Expand Down Expand Up @@ -989,7 +989,7 @@ run_menu (char *menu_entries, char *config_entries, /*int num_entries,*/ char *h
}
else
{
while (((animated_type & 0x0f) == 1) && (checkkey () == -1))
while ((animated_type & 0x10) && (checkkey () == -1))
animated();
c = /*ASCII_CHAR*/ (getkey ());
}
Expand Down

0 comments on commit 93c7ee4

Please sign in to comment.