splash.c revision 2f8d336478536af789d654599f9523d02e0ca693
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
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 * 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 * Copyright (C) 2012-2013 Kay Sievers <kay@vrfy.org>
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen * Copyright (C) 2012 Harald Hoyer <harald@redhat.com>
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen/* we require at least BITMAPINFOHEADER, later versions are
43b3a5ef61859f06cdbaf26765cab8e1adac4296Tom Gundersen accepted, but their features ignored */
97f2d76d4f4dfab8b0629c09926a05a1e5621125Tom GundersenEFI_STATUS bmp_parse_header(UINT8 *bmp, UINTN size, struct bmp_dib **ret_dib,
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek if (size < sizeof(struct bmp_file) + sizeof(struct bmp_dib))
2ad8416dd057e7e3185169609ca3006e7649f576Zbigniew Jędrzejewski-Szmek /* check file header */
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen if (file->signature[0] != 'B' || file->signature[1] != 'M')
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen /* check device-independent bitmap */
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen dib = (struct bmp_dib *)(bmp + sizeof(struct bmp_file));
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen if (dib->compression != 0 && dib->compression != 3)
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen row_size = (((dib->depth * dib->x) + 31) / 32) * 4;
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen if (file->size - file->offset < dib->y * row_size)
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 if (file->offset > sizeof(struct bmp_file) + dib->size) {
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen map_size = file->offset - (sizeof(struct bmp_file) + dib->size);
9a4b012e43f23516373bf398dd9a458439d19939Tom Gundersen if (map_size != sizeof(struct bmp_map) * map_count)
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;
187dc6e554f2d5b4b5a3bee72c73ff5df6418aa6Thomas Hindoe Paaboel Andersen /* convert src from RGBA to XRGB */
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen /* decompose into RB and G components */
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;
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,
5fde13d748749f0e06e2e6cdd15f0980a79ea82cTom Gundersen /* transform and copy pixels */
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 out = &buf[(dib->y - y - 1) * dib->x];
ecb08ec6a5c52f2d940f3b8147e2a480affd46e1Zbigniew Jędrzejewski-Szmek for (i = 0; i < 8 && x < dib->x; i++) {
af6f0d422c521374ee6a2dd92df5935a5a476ae5Tom Gundersen out->Green = map[((*in) >> (7 - i)) & 1].green;
b3e013148603aa670bc2c060ac63d48e54d76fc2Tom Gundersen /* add row padding; new lines always start at 32 bit boundary */
b3e013148603aa670bc2c060ac63d48e54d76fc2Tom GundersenEFI_STATUS graphics_splash(UINT8 *content, UINTN len, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL *background) {
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen EFI_GUID GraphicsOutputProtocolGuid = EFI_GRAPHICS_OUTPUT_PROTOCOL_GUID;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen EFI_GRAPHICS_OUTPUT_PROTOCOL *GraphicsOutput = NULL;
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen if (StriCmp(L"Apple", ST->FirmwareVendor) == 0) {
32bc8adcd836baff68e4d0f53b9a382f358cccf8Tom Gundersen err = LibLocateProtocol(&GraphicsOutputProtocolGuid, (VOID **)&GraphicsOutput);
ca6038b89645c0c1bd547d6a420bf95eb3d6f4ccTom Gundersen err = bmp_parse_header(content, len, &dib, &map, &pixmap);
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 uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen GraphicsOutput->Mode->Info->HorizontalResolution,
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen GraphicsOutput->Mode->Info->VerticalResolution, 0);
16b9b87aeee9353b5b8dae6089a69752422a5b09Tom Gundersen /* EFI buffer */
3c9b886068d99e5d3cbabcac32a4decf37244c54Tom Gundersen blt_size = dib->x * dib->y * sizeof(EFI_GRAPHICS_OUTPUT_BLT_PIXEL);
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen err = uefi_call_wrapper(GraphicsOutput->Blt, 10, GraphicsOutput,
f1ac700248f231b7bdac2aafe8c35650efddb89fTom Gundersen blt, EfiBltVideoToBltBuffer, x_pos, y_pos, 0, 0,