soc/intel: Remove blank lines before '}' and after '{'
[coreboot2.git] / src / lib / bootsplash.c
blob0512770668d8eda121efa0ee7fd4f70cc42d42eb
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <cbfs.h>
4 #include <vbe.h>
5 #include <console/console.h>
6 #include <endian.h>
7 #include <bootsplash.h>
8 #include <stdlib.h>
10 #include "jpeg.h"
13 void set_bootsplash(unsigned char *framebuffer, unsigned int x_resolution,
14 unsigned int y_resolution, unsigned int bytes_per_line,
15 unsigned int fb_resolution)
17 if ((x_resolution > INT_MAX) || (y_resolution) > INT_MAX) {
18 printk(BIOS_ERR, "Display resolution way too large.\n");
19 return;
21 int xres = x_resolution, yres = y_resolution;
22 printk(BIOS_INFO, "Setting up bootsplash in %dx%d@%d\n", x_resolution, y_resolution,
23 fb_resolution);
24 size_t filesize;
25 unsigned char *jpeg = cbfs_map("bootsplash.jpg", &filesize);
26 if (!jpeg) {
27 printk(BIOS_ERR, "Could not find bootsplash.jpg\n");
28 return;
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;
37 printk(BIOS_DEBUG, "Bootsplash image resolution: %dx%d\n", image_width, image_height);
39 if (image_width > xres || image_height > yres) {
40 printk(BIOS_NOTICE, "Bootsplash image can't fit framebuffer.\n");
41 cbfs_unmap(jpeg);
42 return;
45 /* center image: */
46 framebuffer += (yres - image_height) / 2 * bytes_per_line
47 + (xres - image_width) / 2 * (fb_resolution / 8);
49 int ret = jpeg_decode(jpeg, filesize, framebuffer, image_width, image_height,
50 bytes_per_line, fb_resolution);
51 cbfs_unmap(jpeg);
52 if (ret != 0) {
53 printk(BIOS_ERR, "Bootsplash could not be decoded. jpeg_decode returned %d.\n",
54 ret);
55 return;
57 printk(BIOS_INFO, "Bootsplash loaded\n");