Ticket #1999: patch_bootsplash_20080405.diff

File patch_bootsplash_20080405.diff, 7.2 KB (added by stpere, 16 years ago)

With RLE compression - removed duplications of image data..

  • src/tools/generate_boot_screen.cpp

     
    1212#include <iostream>
    1313#include <png.h>
    1414#include <string>
     15#include <stdarg.h>
    1516
    1617// TODO: Generate the single optimal palette for all three images,
    1718// store palette versions of these images as well, so that they are
     
    123124{
    124125    fprintf(sOutput, "static const uint16 %sWidth = %d;\n", baseName, width);
    125126    fprintf(sOutput, "static const uint16 %sHeight = %d;\n", baseName, height);
    126     fprintf(sOutput, "static const uint8 %sImage[] = {\n\t", baseName);
     127    fprintf(sOutput, "#ifndef __BOOTSPLASH_KERNEL__\n");
     128    fprintf(sOutput, "static const RLE_element %sCompressedImage[] = {\n\t", baseName);
    127129
    128130    int offset = 0;
     131    int lastColor = -1;
     132    int counter = 0;
    129133    for (int y = 0; y < height; y++) {
    130134        png_byte* row = rowPtrs[y];
    131135        for (int x = 0; x < width * 3; x++) {
    132             offset++;
    133             if (x == width * 3 - 1 && y == height - 1) {
    134                 fprintf(sOutput, "0x%02x\n};\n\n", row[x]);
    135                 break;
    136             } else if ((offset % 12) == 0)
    137                 fprintf(sOutput, "0x%02x,\n\t", row[x]);
    138             else
    139                 fprintf(sOutput, "0x%02x, ", row[x]);
     136            // if the currentColor is already being counted...
     137            if (lastColor == row[x]) {
     138                counter++;
     139            } else { // otherwise display what we had in memory, record that color and reset the counter...
     140                if (lastColor != -1) {
     141                    offset++;
     142                                    fprintf(sOutput, "{%d, 0x%02x}, ", counter, lastColor);
     143                    if (offset % 6 == 0) {
     144                        fprintf(sOutput, "\n\t");
     145                    }
     146                }
     147                lastColor = row[x];
     148                counter = 1;
     149            }
     150
     151            if (x == width * 3 - 1 && y == height - 1) { // if we reach the end...
     152                fprintf(sOutput, "{%d, 0x%02x}\n};\n\n", counter, row[x]);
     153                offset++;
     154                                break;
     155            }
    140156        }
    141157    }
     158    fprintf(sOutput, "static const uint16 %sSize = %d;\n", baseName, offset);
     159    fprintf(sOutput, "#endif\n\n");
    142160}
    143161
    144162
     
    210228    fprintf(sOutput, "static const int32 kSplashIconsPlacementY = %d;\n\n",
    211229        iconPlacementY);
    212230
     231    fprintf(sOutput, "struct RLE_element \n{\n\tuint16 count; \n\tuint8 colorComponent;\n};\n\n");
     232   
    213233    parseImage(argv[1], "kSplashLogo");
    214234    parseImage(argv[4], "kSplashIcons");
    215235
  • src/system/kernel/boot_splash.cpp

     
    77 */
    88
    99
    10 #include <boot_splash.h>
    11 
    1210#include <stdio.h>
    1311#include <stdlib.h>
    1412#include <string.h>
     
    1614
    1715#include <KernelExport.h>
    1816
     17#define __BOOTSPLASH_KERNEL__
    1918#include <boot/images.h>
     19
     20
    2021#include <boot_item.h>
    2122#include <debug.h>
    2223#include <frame_buffer_console.h>
    2324
     25#include <boot_splash.h>
    2426
     27
    2528//#define TRACE_BOOT_SPLASH 1
    2629#ifdef TRACE_BOOT_SPLASH
    2730#   define TRACE(x...) dprintf(x);
     
    3134
    3235
    3336static struct frame_buffer_boot_info *sInfo;
     37static uint8 *uncompressedIcons;
    3438
    35 
    3639static void
    3740blit15_cropped(const uint8 *data, uint16 imageLeft, uint16 imageTop,
    3841    uint16 imageRight, uint16 imageBottom, uint16 imageWidth,
     
    168171
    169172
    170173void
    171 boot_splash_init(void)
     174boot_splash_init(uint8 *boot_splash)
    172175{
    173176    TRACE("boot_splash_init: enter\n");
    174177
     
    177180
    178181    sInfo = (frame_buffer_boot_info *)get_boot_item(FRAME_BUFFER_BOOT_INFO,
    179182        NULL);
     183
     184    uncompressedIcons = boot_splash;
    180185}
    181186
    182187
     
    201206    int stageRightEdge = width * (stage + 1) / BOOT_SPLASH_STAGE_MAX;
    202207
    203208    height = min_c(iconsHalfHeight, sInfo->height);
    204     blit_cropped(kSplashIconsImage, NULL, stageLeftEdge, 0, stageRightEdge,
     209    blit_cropped(uncompressedIcons, NULL, stageLeftEdge, 0, stageRightEdge,
    205210        height, kSplashIconsWidth, NULL, x, y);
    206211}
    207212
  • src/system/kernel/main.c

     
    224224
    225225    TRACE("start of main2: initializing devices\n");
    226226
    227     boot_splash_init();
     227    boot_splash_init(sKernelArgs.boot_splash);
    228228
    229229    TRACE("Init modules\n");
    230230    boot_splash_set_stage(BOOT_SPLASH_STAGE_1_INIT_MODULES);
  • src/system/boot/platform/bios_ia32/video.cpp

     
    794794    }
    795795}
    796796
     797
     798static void
     799uncompressRLE(const RLE_element *compressed, uint8 *uncompressed, uint16 size)
     800{
     801    uint32 cursor = 0;
     802    for (uint16 i=0; i < size; i++) {
     803        memset(uncompressed+cursor, compressed[i].colorComponent, compressed[i].count);
     804        cursor += compressed[i].count;
     805    }
     806}
     807
    797808//  #pragma mark -
    798809
    799810extern "C" void
     
    868879    memset((void *)sFrameBuffer, 0,
    869880        gKernelArgs.frame_buffer.physical_buffer.size);
    870881
     882    uint8 * uncompressedLogo = (uint8*)kernel_args_malloc(kSplashLogoWidth*kSplashLogoHeight*3);
     883    uncompressRLE(kSplashLogoCompressedImage, uncompressedLogo, kSplashLogoSize);
     884
    871885    // TODO: support indexed versions of the images!
    872     // TODO: support compressed RGB image data (simple RLE?)
    873886
    874887    // render splash logo
    875888    uint16 iconsHalfHeight = kSplashIconsHeight / 2;
     
    884897    int y = (gKernelArgs.frame_buffer.height - height) * placementY / 100;
    885898   
    886899    height = min_c(kSplashLogoHeight, gKernelArgs.frame_buffer.height);
    887     blit_image(kSplashLogoImage, NULL, width, height, kSplashLogoWidth,
     900    blit_image(uncompressedLogo, NULL, width, height, kSplashLogoWidth,
    888901        NULL, x, y);
    889902
     903    kernel_args_free(uncompressedLogo);
     904
     905    gKernelArgs.boot_splash = (uint8*)kernel_args_malloc(kSplashIconsWidth*kSplashIconsHeight*3);
     906    uncompressRLE(kSplashIconsCompressedImage, gKernelArgs.boot_splash, kSplashIconsSize);
     907
    890908    // render initial (grayed out) icons
    891909    // the grayed out version is the lower half of the icons image
    892910
     
    901919        * placementY / 100;
    902920
    903921    // pointer into the lower half of the icons image data
    904     const uint8* lowerHalfIconImage = kSplashIconsImage
     922    const uint8* lowerHalfIconImage = gKernelArgs.boot_splash
    905923        + (kSplashIconsWidth * iconsHalfHeight) * 3;
    906924    height = min_c(iconsHalfHeight, gKernelArgs.frame_buffer.height);
    907925    blit_image(lowerHalfIconImage, NULL, width, height,
  • headers/private/kernel/boot/kernel_args.h

     
    7979
    8080    platform_kernel_args platform_args;
    8181    arch_kernel_args arch_args;
     82
     83    // bootsplash data
     84    uint8       *boot_splash;
     85
    8286} kernel_args;
    8387
    8488#endif  /* KERNEL_BOOT_KERNEL_ARGS_H */
  • headers/private/kernel/boot_splash.h

     
    1111
    1212#include <sys/types.h>
    1313
    14 
    1514enum {
    1615    BOOT_SPLASH_STAGE_1_INIT_MODULES = 0,
    1716    BOOT_SPLASH_STAGE_2_BOOTSTRAP_FS,
     
    2928extern "C" {
    3029#endif
    3130
    32 void boot_splash_init(void);
     31void boot_splash_init(uint8 * boot_splash);
    3332void boot_splash_set_stage(int stage);
    3433
    3534#ifdef __cplusplus