Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Johanna Schander | db7a3ae | 2019-07-24 10:14:26 +0200 | [diff] [blame] | 2 | |
| 3 | #include <cbfs.h> |
| 4 | #include <vbe.h> |
| 5 | #include <console/console.h> |
| 6 | #include <endian.h> |
| 7 | #include <bootsplash.h> |
Patrick Rudolph | 5ebe431 | 2019-09-26 08:47:40 +0200 | [diff] [blame] | 8 | #include <stdlib.h> |
Johanna Schander | db7a3ae | 2019-07-24 10:14:26 +0200 | [diff] [blame] | 9 | |
| 10 | #include "jpeg.h" |
| 11 | |
Johanna Schander | db7a3ae | 2019-07-24 10:14:26 +0200 | [diff] [blame] | 12 | |
| 13 | void set_bootsplash(unsigned char *framebuffer, unsigned int x_resolution, |
Nico Huber | 99eee16 | 2023-07-14 00:09:00 +0200 | [diff] [blame] | 14 | unsigned int y_resolution, unsigned int bytes_per_line, |
| 15 | unsigned int fb_resolution) |
Johanna Schander | db7a3ae | 2019-07-24 10:14:26 +0200 | [diff] [blame] | 16 | { |
Johanna Schander | 7fc006f | 2019-07-28 08:48:36 +0200 | [diff] [blame] | 17 | printk(BIOS_INFO, "Setting up bootsplash in %dx%d@%d\n", x_resolution, y_resolution, |
| 18 | fb_resolution); |
Johanna Schander | db7a3ae | 2019-07-24 10:14:26 +0200 | [diff] [blame] | 19 | struct jpeg_decdata *decdata; |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 20 | unsigned char *jpeg = cbfs_map("bootsplash.jpg", NULL); |
Johanna Schander | db7a3ae | 2019-07-24 10:14:26 +0200 | [diff] [blame] | 21 | if (!jpeg) { |
| 22 | printk(BIOS_ERR, "Could not find bootsplash.jpg\n"); |
| 23 | return; |
| 24 | } |
| 25 | |
Johanna Schander | 7fc006f | 2019-07-28 08:48:36 +0200 | [diff] [blame] | 26 | int image_width, image_height; |
| 27 | jpeg_fetch_size(jpeg, &image_width, &image_height); |
| 28 | |
| 29 | printk(BIOS_DEBUG, "Bootsplash image resolution: %dx%d\n", image_width, image_height); |
| 30 | |
Nico Huber | 99eee16 | 2023-07-14 00:09:00 +0200 | [diff] [blame] | 31 | if (image_width > x_resolution || image_height > y_resolution) { |
| 32 | printk(BIOS_NOTICE, "Bootsplash image can't fit framebuffer.\n"); |
| 33 | cbfs_unmap(jpeg); |
| 34 | return; |
| 35 | } |
| 36 | |
| 37 | /* center image: */ |
| 38 | framebuffer += (y_resolution - image_height) / 2 * bytes_per_line + |
| 39 | (x_resolution - image_width) / 2 * (fb_resolution / 8); |
| 40 | |
Johanna Schander | db7a3ae | 2019-07-24 10:14:26 +0200 | [diff] [blame] | 41 | decdata = malloc(sizeof(*decdata)); |
Nico Huber | 99eee16 | 2023-07-14 00:09:00 +0200 | [diff] [blame] | 42 | int ret = jpeg_decode(jpeg, framebuffer, image_width, image_height, |
| 43 | bytes_per_line, fb_resolution, decdata); |
| 44 | free(decdata); |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 45 | cbfs_unmap(jpeg); |
Johanna Schander | db7a3ae | 2019-07-24 10:14:26 +0200 | [diff] [blame] | 46 | if (ret != 0) { |
| 47 | printk(BIOS_ERR, "Bootsplash could not be decoded. jpeg_decode returned %d.\n", |
| 48 | ret); |
| 49 | return; |
| 50 | } |
| 51 | printk(BIOS_INFO, "Bootsplash loaded\n"); |
| 52 | } |