Beispiel #1
0
EFI_STATUS
EFIAPI
LzmaCompress (
    CONST UINT8  *Source,
    UINT32       SourceSize,
    UINT8        *Destination,
    UINT32       *DestinationSize,
    UINT32       DictionarySize
)
{
    SRes              LzmaResult;
    CLzmaEncProps     props;
    SizeT propsSize = LZMA_PROPS_SIZE;
    SizeT destLen = SourceSize + SourceSize / 3 + 128;

    if (*DestinationSize < (UINT32)destLen)
    {
        *DestinationSize = (UINT32)destLen;
        return EFI_BUFFER_TOO_SMALL;
    }

    LzmaEncProps_Init(&props);
    props.dictSize = DictionarySize;
    props.level = 9;
    props.fb = 273;

    LzmaResult = LzmaEncode(
        (Byte*)((UINT8*)Destination + LZMA_HEADER_SIZE),
        &destLen,
        Source,
        (SizeT)SourceSize,
        &props,
        (UINT8*)Destination,
        &propsSize,
        props.writeEndMark,
        &g_ProgressCallback,
        &SzAllocForLzma,
        &SzAllocForLzma);

    *DestinationSize = (UINT32)(destLen + LZMA_HEADER_SIZE);

    SetEncodedSizeOfBuf(SourceSize, Destination);

    if (LzmaResult == SZ_OK) {
        return EFI_SUCCESS;
    }
    else {
        return EFI_INVALID_PARAMETER;
    }
}
EFI_STATUS
    LzmaCompress (
    IN     UINT8   *Source,
    IN     UINT32  SourceSize,
    IN     UINT8   *Destination,
    IN OUT UINT32  *DestinationSize
    )
{
    SRes              LzmaResult;
    CLzmaEncProps     props;
    SizeT propsSize = LZMA_PROPS_SIZE;
    SizeT destLen = SourceSize + SourceSize / 3 + 128;

    if (*DestinationSize < destLen)
    {
        *DestinationSize = destLen;
        return EFI_BUFFER_TOO_SMALL;
    }

    LzmaEncProps_Init(&props);
    props.dictSize = LZMA_DICTIONARY_SIZE;
    props.level = 9;
    props.fb = 273;

    LzmaResult = LzmaEncode(
        (Byte*)((UINT8*)Destination + LZMA_HEADER_SIZE), 
        &destLen,
        (VOID*)Source, 
        SourceSize,
        &props, 
        (UINT8*)Destination, 
        &propsSize, 
        props.writeEndMark,
        &g_ProgressCallback, 
        &SzAllocForLzma, 
        &SzAllocForLzma);

    *DestinationSize = destLen + LZMA_HEADER_SIZE;

    SetEncodedSizeOfBuf((UINT64)SourceSize, Destination);

    if (LzmaResult == SZ_OK) {
        return EFI_SUCCESS;
    } else {
        return EFI_INVALID_PARAMETER;
    }
}