blob: 3ab11aca6fadbc79d154335700151804ab4e516b [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +02002
3#include <cbfs.h>
4#include <vbe.h>
5#include <console/console.h>
6#include <endian.h>
7#include <bootsplash.h>
Patrick Rudolph5ebe4312019-09-26 08:47:40 +02008#include <stdlib.h>
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +02009
10#include "jpeg.h"
11
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +020012
13void set_bootsplash(unsigned char *framebuffer, unsigned int x_resolution,
Nico Huber99eee162023-07-14 00:09:00 +020014 unsigned int y_resolution, unsigned int bytes_per_line,
15 unsigned int fb_resolution)
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +020016{
Johanna Schander7fc006f2019-07-28 08:48:36 +020017 printk(BIOS_INFO, "Setting up bootsplash in %dx%d@%d\n", x_resolution, y_resolution,
18 fb_resolution);
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +020019 struct jpeg_decdata *decdata;
Julius Werner834b3ec2020-03-04 16:52:08 -080020 unsigned char *jpeg = cbfs_map("bootsplash.jpg", NULL);
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +020021 if (!jpeg) {
22 printk(BIOS_ERR, "Could not find bootsplash.jpg\n");
23 return;
24 }
25
Johanna Schander7fc006f2019-07-28 08:48:36 +020026 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 Huber99eee162023-07-14 00:09:00 +020031 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 Schanderdb7a3ae2019-07-24 10:14:26 +020041 decdata = malloc(sizeof(*decdata));
Nico Huber99eee162023-07-14 00:09:00 +020042 int ret = jpeg_decode(jpeg, framebuffer, image_width, image_height,
43 bytes_per_line, fb_resolution, decdata);
44 free(decdata);
Julius Werner834b3ec2020-03-04 16:52:08 -080045 cbfs_unmap(jpeg);
Johanna Schanderdb7a3ae2019-07-24 10:14:26 +020046 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}