To quote its repo[0]: Wuffs is a memory-safe programming language (and a standard library written in that language) for Wrangling Untrusted File Formats Safely. Wrangling includes parsing, decoding and encoding. It compiles its library, written in its own language, to a C/C++ source file that can then be used independently without needing support for the language. That library is now imported to src/vendorcode/wuffs/. This change modifies our linters to ignore that directory because it's supposed to contain the wuffs compiler's result verbatim. Nigel Tao provided an initial wrapper around wuffs' jpeg decoder that implements our JPEG API. I further changed it a bit regarding data placement, dropped stuff from our API that wasn't ever used, or isn't used anymore, and generally made it fit coreboot a bit better. Features are Nigel's, bugs are mine. This commit also adapts our jpeg fuzz test to work with the modified API. After limiting it to deal only with approximately screen sized inputs, it fuzzed for 25 hours CPU time without a single hang or crash. This is a notable improvement over running the test with our old decoder which crashes within a minute. Finally, I tried the new parser with a pretty-much-random JPEG file I got from the internet, and it just showed it (once the resolution matched), which is also a notable improvement over the old decoder which is very particular about the subset of JPEG it supports. In terms of code size, a QEmu build's ramstage increases from 128060 bytes decompressed (64121 bytes after LZMA) to 172304 bytes decompressed (82734 bytes after LZMA). [0] https://github.com/google/wuffs Change-Id: If8fa7da69da1ad412f27c2c5e882393c7739bc82 Signed-off-by: Patrick Georgi <patrick@coreboot.org> Based-on-work-by: Nigel Tao <nigeltao@golang.org> Reviewed-on: https://review.coreboot.org/c/coreboot/+/78271 Reviewed-by: Paul Menzel <paulepanter@mailbox.org> Reviewed-by: Martin L Roth <gaumless@gmail.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
58 lines
1.7 KiB
C
58 lines
1.7 KiB
C
/* SPDX-License-Identifier: GPL-2.0-only */
|
|
|
|
#include <cbfs.h>
|
|
#include <vbe.h>
|
|
#include <console/console.h>
|
|
#include <endian.h>
|
|
#include <bootsplash.h>
|
|
#include <stdlib.h>
|
|
|
|
#include "jpeg.h"
|
|
|
|
|
|
void set_bootsplash(unsigned char *framebuffer, unsigned int x_resolution,
|
|
unsigned int y_resolution, unsigned int bytes_per_line,
|
|
unsigned int fb_resolution)
|
|
{
|
|
if ((x_resolution > INT_MAX) || (y_resolution) > INT_MAX) {
|
|
printk(BIOS_ERR, "Display resolution way too large.\n");
|
|
return;
|
|
}
|
|
int xres = x_resolution, yres = y_resolution;
|
|
printk(BIOS_INFO, "Setting up bootsplash in %dx%d@%d\n", x_resolution, y_resolution,
|
|
fb_resolution);
|
|
size_t filesize;
|
|
unsigned char *jpeg = cbfs_map("bootsplash.jpg", &filesize);
|
|
if (!jpeg) {
|
|
printk(BIOS_ERR, "Could not find bootsplash.jpg\n");
|
|
return;
|
|
}
|
|
|
|
unsigned int image_width, image_height;
|
|
if (jpeg_fetch_size(jpeg, filesize, &image_width, &image_height) != 0) {
|
|
printk(BIOS_ERR, "Could not parse bootsplash.jpg\n");
|
|
return;
|
|
}
|
|
|
|
printk(BIOS_DEBUG, "Bootsplash image resolution: %dx%d\n", image_width, image_height);
|
|
|
|
if (image_width > xres || image_height > yres) {
|
|
printk(BIOS_NOTICE, "Bootsplash image can't fit framebuffer.\n");
|
|
cbfs_unmap(jpeg);
|
|
return;
|
|
}
|
|
|
|
/* center image: */
|
|
framebuffer += (yres - image_height) / 2 * bytes_per_line
|
|
+ (xres - image_width) / 2 * (fb_resolution / 8);
|
|
|
|
int ret = jpeg_decode(jpeg, filesize, framebuffer, image_width, image_height,
|
|
bytes_per_line, fb_resolution);
|
|
cbfs_unmap(jpeg);
|
|
if (ret != 0) {
|
|
printk(BIOS_ERR, "Bootsplash could not be decoded. jpeg_decode returned %d.\n",
|
|
ret);
|
|
return;
|
|
}
|
|
printk(BIOS_INFO, "Bootsplash loaded\n");
|
|
}
|