/* Try to load an icon for the specified CLASS_NAME in the directory DIR. Returns 0 if the icon could not be loaded, or returns a pointer to a new bitmap if it was successful. */ static struct grub_video_bitmap * try_loading_icon (grub_gfxmenu_icon_manager_t mgr, const char *dir, const char *class_name) { char *path; int l; path = grub_malloc (grub_strlen (dir) + grub_strlen (class_name) + grub_strlen (icon_extension) + 3); if (! path) return 0; grub_strcpy (path, dir); l = grub_strlen (path); if (path[l-1] != '/') { path[l] = '/'; path[l+1] = 0; } grub_strcat (path, class_name); grub_strcat (path, icon_extension); struct grub_video_bitmap *raw_bitmap; grub_video_bitmap_load (&raw_bitmap, path); grub_free (path); grub_errno = GRUB_ERR_NONE; /* Critical to clear the error!! */ if (! raw_bitmap) return 0; struct grub_video_bitmap *scaled_bitmap; grub_video_bitmap_create_scaled (&scaled_bitmap, mgr->icon_width, mgr->icon_height, raw_bitmap, GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); grub_video_bitmap_destroy (raw_bitmap); if (! scaled_bitmap) return 0; return scaled_bitmap; }
static grub_err_t scale_pixmap (grub_gfxmenu_box_t self, int i, int w, int h) { struct grub_video_bitmap **scaled = &self->scaled_pixmaps[i]; struct grub_video_bitmap *raw = self->raw_pixmaps[i]; if (raw == 0) return grub_errno; if (w == -1) w = grub_video_bitmap_get_width (raw); if (h == -1) h = grub_video_bitmap_get_height (raw); if (*scaled == 0 || ((int) grub_video_bitmap_get_width (*scaled) != w) || ((int) grub_video_bitmap_get_height (*scaled) != h)) { if (*scaled) { grub_video_bitmap_destroy (*scaled); *scaled = 0; } /* Don't try to create a bitmap with a zero dimension. */ if (w != 0 && h != 0) grub_video_bitmap_create_scaled (scaled, w, h, raw, GRUB_VIDEO_BITMAP_SCALE_METHOD_BEST); if (grub_errno != GRUB_ERR_NONE) { grub_error_push (); grub_error (grub_errno, "failed to scale bitmap for styled box pixmap #%d", i); } } return grub_errno; }