splash.c revision 2f8d336478536af789d654599f9523d02e0ca693
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen/*
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * This program is free software; you can redistribute it and/or modify it
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * under the terms of the GNU Lesser General Public License as published by
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * the Free Software Foundation; either version 2.1 of the License, or
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * (at your option) any later version.
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen *
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * This program is distributed in the hope that it will be useful, but
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * WITHOUT ANY WARRANTY; without even the implied warranty of
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * Lesser General Public License for more details.
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen *
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * Copyright (C) 2012-2013 Kay Sievers <kay@vrfy.org>
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * Copyright (C) 2012 Harald Hoyer <harald@redhat.com>
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen */
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen#include <efi.h>
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen#include <efilib.h>
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen#include "util.h"
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen#include "splash.h"
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersenstruct bmp_file {
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen CHAR8 signature[2];
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINT32 size;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen UINT16 reserved[2];
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen UINT32 offset;
a501033335ed402c8f7e86fe41a15531ba69abd7Tom Gundersen} __attribute__((packed));
a501033335ed402c8f7e86fe41a15531ba69abd7Tom Gundersen
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen/* we require at least BITMAPINFOHEADER, later versions are
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen accepted, but their features ignored */
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersenstruct bmp_dib {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINT32 size;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINT32 x;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINT32 y;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINT16 planes;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINT16 depth;
daeb71a36a98834664e4d95773a3629b746f4db8Tom Gundersen UINT32 compression;
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen UINT32 image_size;
3aeb37bc4f32b5edc334f2ac7c5d3c7b0a121328Tom Gundersen INT32 x_pixel_meter;
c6f7c917a1b494d4455800823472227463f87438Tom Gundersen INT32 y_pixel_meter;
9bf3b53533cdc9b95c921b71da755401f223f765Lennart Poettering UINT32 colors_used;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINT32 colors_important;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen} __attribute__((packed));
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersenstruct bmp_map {
a501033335ed402c8f7e86fe41a15531ba69abd7Tom Gundersen UINT8 blue;
a501033335ed402c8f7e86fe41a15531ba69abd7Tom Gundersen UINT8 green;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen UINT8 red;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen UINT8 reserved;
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen} __attribute__((packed));
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen
97f2d76d4f4dfab8b0629c09926a05a1e5621125Tom GundersenEFI_STATUS bmp_parse_header(UINT8 *bmp, UINTN size, struct bmp_dib **ret_dib,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen struct bmp_map **ret_map, UINT8 **pixmap) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen struct bmp_file *file;
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek struct bmp_dib *dib;
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek struct bmp_map *map;
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek UINTN row_size;
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek if (size < sizeof(struct bmp_file) + sizeof(struct bmp_dib))
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek return EFI_INVALID_PARAMETER;
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek /* check file header */
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek file = (struct bmp_file *)bmp;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen if (file->signature[0] != 'B' || file->signature[1] != 'M')
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen return EFI_INVALID_PARAMETER;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen if (file->size != size)
5b9d4dc05560ddda89e48b6b39365824b15e1300Tom Gundersen return EFI_INVALID_PARAMETER;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen if (file->size < file->offset)
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen return EFI_INVALID_PARAMETER;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen /* check device-independent bitmap */
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen dib = (struct bmp_dib *)(bmp + sizeof(struct bmp_file));
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen if (dib->size < sizeof(struct bmp_dib))
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen return EFI_UNSUPPORTED;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen switch (dib->depth) {
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen case 1:
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen case 4:
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen case 8:
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen case 24:
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen if (dib->compression != 0)
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen return EFI_UNSUPPORTED;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen break;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen case 16:
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen case 32:
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (dib->compression != 0 && dib->compression != 3)
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen return EFI_UNSUPPORTED;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen break;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen default:
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return EFI_UNSUPPORTED;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen }
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen row_size = (((dib->depth * dib->x) + 31) / 32) * 4;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen if (file->size - file->offset < dib->y * row_size)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return EFI_INVALID_PARAMETER;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (row_size * dib->y > 64 * 1024 * 1024)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen return EFI_INVALID_PARAMETER;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen /* check color table */
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen map = (struct bmp_map *)(bmp + sizeof(struct bmp_file) + dib->size);
03e334a1c7dc8c20c38902aa039440763acc9b17Lennart Poettering if (file->offset < sizeof(struct bmp_file) + dib->size)
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen return EFI_INVALID_PARAMETER;
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen if (file->offset > sizeof(struct bmp_file) + dib->size) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINT32 map_count;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINTN map_size;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (dib->colors_used)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen map_count = dib->colors_used;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen else {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen switch (dib->depth) {
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen case 1:
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen case 4:
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen case 8:
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen map_count = 1 << dib->depth;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen break;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen default:
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen map_count = 0;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen break;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen }
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen }
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen map_size = file->offset - (sizeof(struct bmp_file) + dib->size);
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen if (map_size != sizeof(struct bmp_map) * map_count)
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen return EFI_INVALID_PARAMETER;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen }
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen *ret_map = map;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen *ret_dib = dib;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen *pixmap = bmp + file->offset;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen return EFI_SUCCESS;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen}
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersenstatic VOID pixel_blend(UINT32 *dst, const UINT32 source) {
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen UINT32 alpha, src, src_rb, src_g, dst_rb, dst_g, rb, g;
6e37cd2f4af8928d905203108a4331e375d7127cThomas Hindoe Paaboel Andersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen alpha = (source & 0xff);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
187dc6e554f2d5b4b5a3bee72c73ff5df6418aa6Thomas Hindoe Paaboel Andersen /* convert src from RGBA to XRGB */
187dc6e554f2d5b4b5a3bee72c73ff5df6418aa6Thomas Hindoe Paaboel Andersen src = source >> 8;
187dc6e554f2d5b4b5a3bee72c73ff5df6418aa6Thomas Hindoe Paaboel Andersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen /* decompose into RB and G components */
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen src_rb = (src & 0xff00ff);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen src_g = (src & 0x00ff00);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen dst_rb = (*dst & 0xff00ff);
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek dst_g = (*dst & 0x00ff00);
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen /* blend */
ed88bcfb7c15029f9fc95ee2380759a9eb782d46Zbigniew Jędrzejewski-Szmek rb = ((((src_rb - dst_rb) * alpha + 0x800080) >> 8) + dst_rb) & 0xff00ff;
ed88bcfb7c15029f9fc95ee2380759a9eb782d46Zbigniew Jędrzejewski-Szmek g = ((((src_g - dst_g) * alpha + 0x008000) >> 8) + dst_g) & 0x00ff00;
ed88bcfb7c15029f9fc95ee2380759a9eb782d46Zbigniew Jędrzejewski-Szmek
ed88bcfb7c15029f9fc95ee2380759a9eb782d46Zbigniew Jędrzejewski-Szmek *dst = (rb | g);
ed88bcfb7c15029f9fc95ee2380759a9eb782d46Zbigniew Jędrzejewski-Szmek}
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-SzmekEFI_STATUS bmp_to_blt(EFI_GRAPHICS_OUTPUT_BLT_PIXEL *buf,
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek struct bmp_dib *dib, struct bmp_map *map,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINT8 *pixmap) {
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen UINT8 *in;
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen UINTN y;
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen /* transform and copy pixels */
e9f3d2d508bfd9fb5b54e82994bda365a71eb864Zbigniew Jędrzejewski-Szmek in = pixmap;
e9f3d2d508bfd9fb5b54e82994bda365a71eb864Zbigniew Jędrzejewski-Szmek for (y = 0; y < dib->y; y++) {
e9f3d2d508bfd9fb5b54e82994bda365a71eb864Zbigniew Jędrzejewski-Szmek EFI_GRAPHICS_OUTPUT_BLT_PIXEL *out;
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmek UINTN row_size;
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmek UINTN x;
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek
36f822c4bd077f9121757e24b6516e5c7ada63b5Zbigniew Jędrzejewski-Szmek out = &buf[(dib->y - y - 1) * dib->x];
98a375f6d5cac24eb80d6d4e00699851324afdecTom Gundersen for (x = 0; x < dib->x; x++, in++, out++) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen switch (dib->depth) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen case 1: {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINTN i;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek for (i = 0; i < 8 && x < dib->x; i++) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen out->Red = map[((*in) >> (7 - i)) & 1].red;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen out->Green = map[((*in) >> (7 - i)) & 1].green;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen out->Blue = map[((*in) >> (7 - i)) & 1].blue;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen out++;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen x++;
f8a0bb5285024b6ce372c3157e761e6543ebdcd2Andreas Henriksson }
a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8Zbigniew Jędrzejewski-Szmek out--;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen x--;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen break;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen }
74df0fca09b3c31ed19e14ba80f996fdff772417Lennart Poettering
b5884878a2874447b2a9f07f324a7cd909d96d48Lennart Poettering case 4: {
da927ba997d68401563b927f92e6e40e021a8e5cMichal Schmidt UINTN i;
74df0fca09b3c31ed19e14ba80f996fdff772417Lennart Poettering
b5884878a2874447b2a9f07f324a7cd909d96d48Lennart Poettering i = (*in) >> 4;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen out->Red = map[i].red;
a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8Zbigniew Jędrzejewski-Szmek out->Green = map[i].green;
a2a5291b3f5ab6ed4c92f51d0fd10a03047380d8Zbigniew Jędrzejewski-Szmek out->Blue = map[i].blue;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen if (x < (dib->x - 1)) {
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen out++;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen x++;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen i = (*in) & 0x0f;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen out->Red = map[i].red;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen out->Green = map[i].green;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen out->Blue = map[i].blue;
edf029b7fd9a5853a87d3ca99aac2922bb8a277eTom Gundersen }
edf029b7fd9a5853a87d3ca99aac2922bb8a277eTom Gundersen break;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen }
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen case 8:
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen out->Red = map[*in].red;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen out->Green = map[*in].green;
3f85ef0f05ffc51e19f86fb83a1c51e8e3cd6817Harald Hoyer out->Blue = map[*in].blue;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen break;
f61942250a43a123580d7bbe5d7873dc5118ed97Tom Gundersen
97f2d76d4f4dfab8b0629c09926a05a1e5621125Tom Gundersen case 16: {
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek UINT16 i = *(UINT16 *) in;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek out->Red = (i & 0x7c00) >> 7;
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt out->Green = (i & 0x3e0) >> 2;
f647962d64e844689f3e2acfce6102fc47e76df2Michal Schmidt out->Blue = (i & 0x1f) << 3;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen in += 1;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen break;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen }
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen case 24:
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen out->Red = in[2];
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen out->Green = in[1];
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen out->Blue = in[0];
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen in += 2;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen break;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek case 32: {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen UINT32 i = *(UINT32 *) in;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen pixel_blend((UINT32 *)out, i);
464cf22f17e0cf2d8bfa6d72b5e7a662d634f149Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen in += 3;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen break;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen }
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen }
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen }
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen
b3e013148603aa670bc2c060ac63d48e54d76fc2Tom Gundersen /* add row padding; new lines always start at 32 bit boundary */
edbb03e95a3c31bf719d5c6c46eec14d0bcb9c8fTom Gundersen row_size = in - pixmap;
7eb08da4b388b920c8a894b1500c9cc7dc1f31efTom Gundersen in += ((row_size + 3) & ~3) - row_size;
edbb03e95a3c31bf719d5c6c46eec14d0bcb9c8fTom Gundersen }
eb7040ec50fbfe5aad9eaf305bd442a4a235abaaTom Gundersen
b3e013148603aa670bc2c060ac63d48e54d76fc2Tom Gundersen return EFI_SUCCESS;
9b1c2626cef16722603bded9bb52033aba34dd74Tom Gundersen}
bf175aafd20c9ef974709ef12c5acf836121af33Tom Gundersen
b3e013148603aa670bc2c060ac63d48e54d76fc2Tom GundersenEFI_STATUS graphics_splash(UINT8 *content, UINTN len, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *background) {
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen EFI_GRAPHICS_OUTPUT_BLT_PIXEL pixel = {};
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen EFI_GUID GraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput = NULL;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen struct bmp_dib *dib;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen struct bmp_map *map;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen UINT8 *pixmap;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen UINT64 blt_size;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen VOID *blt = NULL;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen UINTN x_pos = 0;
ca6038b89645c0c1bd547d6a420bf95eb3d6f4ccTom Gundersen UINTN y_pos = 0;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen EFI_STATUS err;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen if (!background) {
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen if (StriCmp(L"Apple", ST->FirmwareVendor) == 0) {
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen pixel.Red = 0xc0;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen pixel.Green = 0xc0;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen pixel.Blue = 0xc0;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen }
ca6038b89645c0c1bd547d6a420bf95eb3d6f4ccTom Gundersen background = &pixel;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen }
ca6038b89645c0c1bd547d6a420bf95eb3d6f4ccTom Gundersen
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen err = LibLocateProtocol(&GraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
ca6038b89645c0c1bd547d6a420bf95eb3d6f4ccTom Gundersen if (EFI_ERROR(err))
ca6038b89645c0c1bd547d6a420bf95eb3d6f4ccTom Gundersen return err;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen
ca6038b89645c0c1bd547d6a420bf95eb3d6f4ccTom Gundersen err = bmp_parse_header(content, len, &dib, &map, &pixmap);
ca6038b89645c0c1bd547d6a420bf95eb3d6f4ccTom Gundersen if (EFI_ERROR(err))
ca6038b89645c0c1bd547d6a420bf95eb3d6f4ccTom Gundersen goto err;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if(dib->x < GraphicsOutput->Mode->Info->HorizontalResolution)
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen x_pos = (GraphicsOutput->Mode->Info->HorizontalResolution - dib->x) / 2;
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen if(dib->y < GraphicsOutput->Mode->Info->VerticalResolution)
be32eb9b7fbcb22e4b648086d644135e38279633Tom Gundersen y_pos = (GraphicsOutput->Mode->Info->VerticalResolution - dib->y) / 2;
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen (EFI_GRAPHICS_OUTPUT_BLT_PIXEL *)background,
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen EfiBltVideoFill, 0, 0, 0, 0,
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen GraphicsOutput->Mode->Info->HorizontalResolution,
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen GraphicsOutput->Mode->Info->VerticalResolution, 0);
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen /* EFI buffer */
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen blt_size = dib->x * dib->y * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen blt = AllocatePool(blt_size);
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen if (!blt)
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen return EFI_OUT_OF_RESOURCES;
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen err = uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen blt, EfiBltVideoToBltBuffer, x_pos, y_pos, 0, 0,
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen dib->x, dib->y, 0);
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen if (EFI_ERROR(err))
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen goto err;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen err = bmp_to_blt(blt, dib, map, pixmap);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen if (EFI_ERROR(err))
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen goto err;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen err = graphics_mode(TRUE);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen if (EFI_ERROR(err))
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen goto err;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen err = uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen blt, EfiBltBufferToVideo, 0, 0, x_pos, y_pos,
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen dib->x, dib->y, 0);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersenerr:
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen FreePool(blt);
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen return err;
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen}
04b67d49254d956d31bcfe80340fb9df7ed332d3Tom Gundersen