Default background; skip background if VESA is uninitialized syslinux-3.30-pre7
authorH. Peter Anvin <hpa@zytor.com>
Thu, 14 Sep 2006 21:43:44 +0000 (14:43 -0700)
committerH. Peter Anvin <hpa@zytor.com>
Thu, 14 Sep 2006 21:43:44 +0000 (14:43 -0700)
com32/lib/sys/vesa/background.c
com32/lib/sys/vesa/initvesa.c

index 2e5b108..2dccfce 100644 (file)
@@ -239,29 +239,50 @@ static int read_jpeg_file(FILE *fp, uint8_t *header, int len)
   return rv;
 }
 
+/* Simple grey Gaussian hole, enough to look interesting */
+static void default_background(void)
+{
+  int x, y, dx, dy, dy2;
+  uint8_t *bgptr = (uint8_t *)&__vesacon_background;
+  uint8_t c;
+
+  for (y = 0, dy = -VIDEO_Y_SIZE/2; y < VIDEO_Y_SIZE; y++, dy++) {
+    dy2 = dy*dy;
+    for (x = 0, dx = -VIDEO_X_SIZE/2; x < VIDEO_X_SIZE; x++, dx++) {
+      c = ((dx*dx+dy2) >> 11) + 88;
+      *bgptr++ = c;
+      *bgptr++ = c;
+      *bgptr++ = c;
+      bgptr++;                 /* Dummy alpha */
+    }
+  }
+}
+
 int vesacon_load_background(const char *filename)
 {
-  FILE *fp;
+  FILE *fp = NULL;
   uint8_t header[8];
   int rv = 1;
 
-  if (!filename) {
-    draw_background();
-    return 0;
-  }
-
-  fp = fopen(filename, "r");
+  if (__vesacon_pixel_format == PXF_NONE)
+    return 0;                  /* Not in graphics mode */
 
-  if (!fp)
-    goto err;
-
-  if (fread(header, 1, 8, fp) != 8)
-    goto err;
-
-  if (!png_sig_cmp(header, 0, 8)) {
-    rv = read_png_file(fp);
-  } else if (!jpeg_sig_cmp(header, 8)) {
-    rv = read_jpeg_file(fp, header, 8);
+  if (!filename) {
+    default_background();
+  } else {
+    fp = fopen(filename, "r");
+    
+    if (!fp)
+      goto err;
+    
+    if (fread(header, 1, 8, fp) != 8)
+      goto err;
+    
+    if (!png_sig_cmp(header, 0, 8)) {
+      rv = read_png_file(fp);
+    } else if (!jpeg_sig_cmp(header, 8)) {
+      rv = read_jpeg_file(fp, header, 8);
+    }
   }
 
   /* This actually displays the stuff */
index 8acbe99..7394c9d 100644 (file)
@@ -47,7 +47,7 @@ struct vesa_info __vesa_info;
 struct vesa_char *__vesacon_text_display;
 
 int __vesacon_font_height, __vesacon_text_rows;
-enum vesa_pixel_format __vesacon_pixel_format;
+enum vesa_pixel_format __vesacon_pixel_format = PXF_NONE;
 unsigned int __vesacon_bytes_per_pixel;
 uint8_t __vesacon_graphics_font[FONT_MAX_CHARS][FONT_MAX_HEIGHT];
 
@@ -189,7 +189,6 @@ static int vesacon_set_mode(void)
 
   mi = &__vesa_info.mi;
   mode = bestmode;
-  __vesacon_pixel_format = bestpxf;
   __vesacon_bytes_per_pixel = mi->bpp >> 3;
 
   /* Download the SYSLINUX- or BIOS-provided font */
@@ -230,6 +229,8 @@ static int vesacon_set_mode(void)
   rm.edx.w[0] = VIDEO_Y_SIZE;
   __intcall(0x22, &rm, NULL);
 
+  __vesacon_pixel_format = bestpxf;
+
   return 0;
 }