Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1PR2GS-0000LI-07 for mharc-grub-devel@gnu.org; Fri, 10 Dec 2010 07:39:56 -0500 Received: from [140.186.70.92] (port=51395 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PR2GO-0000L2-MP for grub-devel@gnu.org; Fri, 10 Dec 2010 07:39:54 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PR2GH-0007EU-Ot for grub-devel@gnu.org; Fri, 10 Dec 2010 07:39:46 -0500 Received: from smarthost03.mail.zen.net.uk ([212.23.3.142]:54384) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PR2GH-0007EN-GI for grub-devel@gnu.org; Fri, 10 Dec 2010 07:39:45 -0500 Received: from [82.69.40.219] (helo=riva.pelham.vpn.ucam.org) by smarthost03.mail.zen.net.uk with esmtp (Exim 4.63) (envelope-from ) id 1PR2GF-0005go-GT for grub-devel@gnu.org; Fri, 10 Dec 2010 12:39:43 +0000 Received: from cjwatson by riva.pelham.vpn.ucam.org with local (Exim 3.36 #1 (Debian)) for grub-devel@gnu.org id 1PR2GE-0006YB-00; Fri, 10 Dec 2010 12:39:42 +0000 Date: Fri, 10 Dec 2010 12:39:42 +0000 From: Colin Watson To: grub-devel@gnu.org Message-ID: <20101210123941.GX21862@riva.ucam.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.5.18 (2008-05-17) X-Originating-Smarthost03-IP: [82.69.40.219] X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) Subject: [PATCH] background_color command X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GNU GRUB List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 10 Dec 2010 12:39:54 -0000 This patch adds a background_color command to gfxterm, which is useful if you just want a simple background fill and don't want to have to worry about scaling a background image to the right size. 2010-12-10 Colin Watson * grub-core/term/gfxterm.c (grub_gfxterm_background_color_cmd): New function. (GRUB_MOD_INIT): Register background_color command. (GRUB_MOD_FINI): Unregister background_color command. === modified file 'grub-core/term/gfxterm.c' --- grub-core/term/gfxterm.c 2010-09-14 21:06:01 +0000 +++ grub-core/term/gfxterm.c 2010-12-10 11:22:37 +0000 @@ -1180,6 +1180,76 @@ grub_gfxterm_background_image_cmd (grub_ return grub_errno; } +static grub_err_t +grub_gfxterm_background_color_cmd (grub_command_t cmd __attribute__ ((unused)), + int argc, char **args) +{ + int i; + unsigned int j; + unsigned long raw_color; + grub_uint8_t red, green, blue; + grub_uint8_t *data; + + if (argc != 1) + return grub_error (GRUB_ERR_BAD_ARGUMENT, "missing operand"); + + /* Check that we have video adapter active. */ + if (grub_video_get_info(NULL) != GRUB_ERR_NONE) + return grub_errno; + + for (i = 0; i < 7 && args[0][i]; i++) + if ((args[0][i] < '0' || args[0][i] > '9') + && (args[0][i] < 'a' || args[0][i] > 'f') + && (args[0][i] < 'A' || args[0][i] > 'F')) + break; + + if (i != 6) + return grub_error (GRUB_ERR_BAD_ARGUMENT, + "color `%s' is not in RRGGBB form", args[0]); + + raw_color = grub_strtoul (args[0], 0, 16); + red = (raw_color >> 16) & 0xFF; + green = (raw_color >> 8) & 0xFF; + blue = raw_color & 0xFF; + + /* Destroy existing background bitmap if loaded. */ + if (bitmap) + { + grub_video_bitmap_destroy (bitmap); + bitmap = 0; + + /* Mark whole screen as dirty. */ + dirty_region_add (0, 0, window.width, window.height); + } + + /* Create a filled bitmap so that we get suitable text blending. */ + grub_video_bitmap_create (&bitmap, window.width, window.height, + GRUB_VIDEO_BLIT_FORMAT_RGB_888); + if (grub_errno != GRUB_ERR_NONE) + return grub_errno; + + data = bitmap->data; + for (j = 0; j < window.height * window.width; j++) + { + *data++ = red; + *data++ = green; + *data++ = blue; + } + + bitmap_width = window.width; + bitmap_height = window.height; + + /* Set the border color. */ + virtual_screen.bg_color_display = grub_video_map_rgb (red, green, blue); + + /* Mark whole screen as dirty. */ + dirty_region_add (0, 0, window.width, window.height); + + /* All was ok. */ + grub_errno = GRUB_ERR_NONE; + return grub_errno; +} + static struct grub_term_output grub_video_term = { .name = "gfxterm", @@ -1201,6 +1271,7 @@ static struct grub_term_output grub_vide }; static grub_extcmd_t background_image_cmd_handle; +static grub_command_t background_color_cmd_handle; GRUB_MOD_INIT(gfxterm) { @@ -1211,10 +1282,16 @@ GRUB_MOD_INIT(gfxterm) N_("[-m (stretch|normal)] FILE"), N_("Load background image for active terminal."), background_image_cmd_options); + background_color_cmd_handle = + grub_register_command ("background_color", + grub_gfxterm_background_color_cmd, + N_("RRGGBB"), + N_("Set background color for active terminal.")); } GRUB_MOD_FINI(gfxterm) { + grub_unregister_command (background_color_cmd_handle); grub_unregister_extcmd (background_image_cmd_handle); grub_term_unregister_output (&grub_video_term); } Thanks, -- Colin Watson [cjwatson@ubuntu.com]