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 | { |
Patrick Georgi | 1d029b4 | 2023-10-06 20:19:15 +0200 | [diff] [blame] | 17 | if ((x_resolution > INT_MAX) || (y_resolution) > INT_MAX) { |
| 18 | printk(BIOS_ERR, "Display resolution way too large.\n"); |
| 19 | return; |
| 20 | } |
| 21 | int xres = x_resolution, yres = y_resolution; |
Johanna Schander | 7fc006f | 2019-07-28 08:48:36 +0200 | [diff] [blame] | 22 | printk(BIOS_INFO, "Setting up bootsplash in %dx%d@%d\n", x_resolution, y_resolution, |
| 23 | fb_resolution); |
Patrick Georgi | 1d029b4 | 2023-10-06 20:19:15 +0200 | [diff] [blame] | 24 | size_t filesize; |
| 25 | unsigned char *jpeg = cbfs_map("bootsplash.jpg", &filesize); |
Johanna Schander | db7a3ae | 2019-07-24 10:14:26 +0200 | [diff] [blame] | 26 | if (!jpeg) { |
| 27 | printk(BIOS_ERR, "Could not find bootsplash.jpg\n"); |
| 28 | return; |
| 29 | } |
| 30 | |
Patrick Georgi | 1d029b4 | 2023-10-06 20:19:15 +0200 | [diff] [blame] | 31 | unsigned int image_width, image_height; |
| 32 | if (jpeg_fetch_size(jpeg, filesize, &image_width, &image_height) != 0) { |
| 33 | printk(BIOS_ERR, "Could not parse bootsplash.jpg\n"); |
| 34 | return; |
| 35 | } |
Johanna Schander | 7fc006f | 2019-07-28 08:48:36 +0200 | [diff] [blame] | 36 | |
| 37 | printk(BIOS_DEBUG, "Bootsplash image resolution: %dx%d\n", image_width, image_height); |
| 38 | |
Patrick Georgi | 1d029b4 | 2023-10-06 20:19:15 +0200 | [diff] [blame] | 39 | if (image_width > xres || image_height > yres) { |
Nico Huber | 99eee16 | 2023-07-14 00:09:00 +0200 | [diff] [blame] | 40 | printk(BIOS_NOTICE, "Bootsplash image can't fit framebuffer.\n"); |
| 41 | cbfs_unmap(jpeg); |
| 42 | return; |
| 43 | } |
| 44 | |
| 45 | /* center image: */ |
Patrick Georgi | 1d029b4 | 2023-10-06 20:19:15 +0200 | [diff] [blame] | 46 | framebuffer += (yres - image_height) / 2 * bytes_per_line |
| 47 | + (xres - image_width) / 2 * (fb_resolution / 8); |
Nico Huber | 99eee16 | 2023-07-14 00:09:00 +0200 | [diff] [blame] | 48 | |
Patrick Georgi | 1d029b4 | 2023-10-06 20:19:15 +0200 | [diff] [blame] | 49 | int ret = jpeg_decode(jpeg, filesize, framebuffer, image_width, image_height, |
| 50 | bytes_per_line, fb_resolution); |
Julius Werner | 834b3ec | 2020-03-04 16:52:08 -0800 | [diff] [blame] | 51 | cbfs_unmap(jpeg); |
Johanna Schander | db7a3ae | 2019-07-24 10:14:26 +0200 | [diff] [blame] | 52 | if (ret != 0) { |
| 53 | printk(BIOS_ERR, "Bootsplash could not be decoded. jpeg_decode returned %d.\n", |
| 54 | ret); |
| 55 | return; |
| 56 | } |
| 57 | printk(BIOS_INFO, "Bootsplash loaded\n"); |
| 58 | } |