⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 splash.c

📁 Windows CE 6.0 BSP for VOIP sample phone. Intel PXA270 platform.
💻 C
字号:
//
// Copyright (c) Microsoft Corporation.  All rights reserved.
//
//
// Use of this sample source code is subject to the terms of the Microsoft
// license agreement under which you licensed this sample source code. If
// you did not accept the terms of the license agreement, you are not
// authorized to use this sample source code. For the terms of the license,
// please see the license agreement between you and Microsoft or, if applicable,
// see the LICENSE.RTF on your install media or the root of your tools installation.
// THE SAMPLE SOURCE CODE IS PROVIDED "AS IS", WITH NO WARRANTIES OR INDEMNITIES.
//
//------------------------------------------------------------------------------
//
//  File:  splash.c
//
//  Bootloader splash screen routines.

#include <bsp.h>
#include <cecompress.h>
#include <oal_memory.h>
#include "splash.h"

// Bincompress constants
// max block size
#define BINCOMPRESS_MAX_BLOCK           CECOMPRESS_MAX_BLOCK
// signature lets us recognize compressed files
#define BINCOMPRESS_SIGNATURE_SIZE      4
// For storing compressed/uncompressed block lengths
typedef DWORD BLOCKLENGTH;
// Indicates noncompressed blocks (XPRESS only)
#define NO_COMPRESSION_BIT              (1L << 31)
// Indicates the last encoded block if it's original size 
// is smaller than CECOMPRESS_MAX_BLOCK (XPRESS only)
#define PARTIAL_BLOCK_BIT               (1L << 30)

// Since we don't have malloc and friends, use some large static buffers in SDRAM 
#define SDRAM_END (0xAC000000)
#define TEMP_BUFFER_SIZE (0x00200000)

// Utility macros
#define READ32(p) (*(p) | (*((p)+1) << 8) | (*((p)+2) << 16) | (*((p)+3) << 24))
#define RGBU16(r,g,b) ((UINT16)((b>>3)<<11 | (g>>2)<<5 | (r>>3)))

//------------------------------------------------------------------------------
// Global variables
//

static CeCompressDecodeStream g_DecodeStream;
static UINT8 *g_SplashBuffer, *g_MallocBuffer, *g_MallocBufferEnd;

static void * CompressAlloc (void * Context, DWORD dwAllocSize) {
    void * pAllocation = (void *) g_MallocBuffer;
    g_MallocBuffer += dwAllocSize;
    if (g_MallocBuffer >= g_MallocBufferEnd)
        return NULL;
    else
        return pAllocation;
}

static void CompressFree (void * Context, void * pAddress) {
}

static DWORD BinCompressOpenFile(const UINT8 * buf) {
    DWORD sig, size; 
    sig = READ32(buf);
    size = READ32(buf + 4);

    if (sig != 0x53525058) { // "XPRS" 
        KITLOutputDebugString("Splash bitmap file header mismatch! \r\n");
        return 0;
    } else {
        g_DecodeStream = CeCompressDecodeCreate(NULL, CompressAlloc);
        return size;
    }
}

static BOOL BinCompressReadFile(UINT8 * outBuf, const UINT8 * inBuf, DWORD dwOutLength) {
    DWORD dwBytesLeft = dwOutLength;
    DWORD dwBlockLength, dwDecompressedLength, dwDecodedCount;
    DWORD storedBlock, partialBlock;
    inBuf += BINCOMPRESS_SIGNATURE_SIZE + sizeof(BLOCKLENGTH);

    while (dwBytesLeft > 0) {
        dwBlockLength = READ32(inBuf);
        inBuf += 4;

        storedBlock = dwBlockLength & NO_COMPRESSION_BIT;
        partialBlock = dwBlockLength & PARTIAL_BLOCK_BIT;
        dwBlockLength &= ~(NO_COMPRESSION_BIT | PARTIAL_BLOCK_BIT);

        if (partialBlock) {
            dwDecompressedLength = READ32(inBuf);
            inBuf += 4;
        } else {
            dwDecompressedLength = CECOMPRESS_MAX_BLOCK;
        }

        if (storedBlock) {
            memcpy(outBuf, inBuf, dwBlockLength);
        } else {
            dwDecodedCount = CeCompressDecode(g_DecodeStream, outBuf, CECOMPRESS_MAX_BLOCK, dwDecompressedLength, inBuf, dwBlockLength);
            if (dwDecodedCount == -1) {
                KITLOutputDebugString("Splash Decompression Error...\r\n");
                return FALSE;
            }
        }

        inBuf += dwBlockLength;
        outBuf += dwDecompressedLength;
        dwBytesLeft -= dwDecompressedLength;
    }

    return TRUE;
}

static void BinCompressCloseFile(const UINT8 * ignored) {
    CeCompressDecodeClose(g_DecodeStream, NULL, CompressFree);
}

BOOL DisplaySplashScreen(UINT16 * fb) {
    UINT8 * in = g_SplashBuffer;
    UINT16 * fbp;
    DWORD dwSplashFileLength;
    int row, col;

    // Setup memory allocation stub routines
    g_SplashBuffer = (UINT8*) OALPAtoVA(SDRAM_END - (2 * TEMP_BUFFER_SIZE), FALSE);
    g_MallocBuffer = (UINT8 *) OALPAtoVA(SDRAM_END - TEMP_BUFFER_SIZE, FALSE);
    g_MallocBufferEnd = g_MallocBuffer + TEMP_BUFFER_SIZE;

    // Uncompress bitmap
    dwSplashFileLength = BinCompressOpenFile(splash);
    if (dwSplashFileLength > TEMP_BUFFER_SIZE) {
        KITLOutputDebugString("Splash bitmap file size too big! \r\n");
        dwSplashFileLength = 0;
        return FALSE;
    }
    
    // Display bitmap
    if (BinCompressReadFile(g_SplashBuffer, splash, dwSplashFileLength)) {
        // Skip BMP Header
        in = g_SplashBuffer + 54;

        // Display BMP Data
        fbp = fb + (240 * 319);
        for (row = 319; row >= 0; row--) {
            for (col = 0; col < 240; col++) {
             *fbp++ = RGBU16(in[0], in[1], in[2]);
             in += 3;
            }
            fbp -= (240 * 2);
        }
        BinCompressCloseFile(splash);
    } else {
        KITLOutputDebugString("Splash bitmap decompression error! \r\n");
        return FALSE;
    }
    return TRUE;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -