Alien-FreeImage

 view release on metacpan or  search on metacpan

src/Source/LibJXR/jxrgluelib/JXRMeta.c  view on Meta::CPAN

    Call(pWS->Write(pWS, &cVal, sizeof(cVal)));
    cVal = (U8) (uValue >> 8);
    Call(pWS->Write(pWS, &cVal, sizeof(cVal)));

Cleanup:
    return err;
}

ERR GetULong(
    __in_ecount(1) struct WMPStream* pWS,
    size_t offPos,
    __out_ecount(1) U32* puValue)
{
    ERR err = WMP_errSuccess;
    U8  cVal;

    Call(pWS->SetPos(pWS, offPos));
    Call(pWS->Read(pWS, &cVal, sizeof(cVal)));
    puValue[0] = (U32) cVal;
    Call(pWS->Read(pWS, &cVal, sizeof(cVal)));
    puValue[0] += ((U32) cVal) << 8;
    Call(pWS->Read(pWS, &cVal, sizeof(cVal)));
    puValue[0] += ((U32) cVal) << 16;
    Call(pWS->Read(pWS, &cVal, sizeof(cVal)));
    puValue[0] += ((U32) cVal) << 24;
 
Cleanup:
    return err;
}

ERR PutULong(
    __in_ecount(1) struct WMPStream* pWS,
    size_t offPos,
    U32 uValue)
{
    ERR err = WMP_errSuccess;
    U8  cVal = (U8) uValue;

    Call(pWS->SetPos(pWS, offPos));
    Call(pWS->Write(pWS, &cVal, sizeof(cVal)));
    cVal = (U8) (uValue >> 8);
    Call(pWS->Write(pWS, &cVal, sizeof(cVal)));
    cVal = (U8) (uValue >> 16);
    Call(pWS->Write(pWS, &cVal, sizeof(cVal)));
    cVal = (U8) (uValue >> 24);
    Call(pWS->Write(pWS, &cVal, sizeof(cVal)));

Cleanup:
    return err;
}


ERR ReadBinaryData(__in_ecount(1) struct WMPStream* pWS,
                   const __in_win U32 uCount,
                   const __in_win U32 uValue,
                   U8 **ppbData)
{
    ERR err = WMP_errSuccess;
    U8 *pbData = NULL;

    Call(PKAlloc((void **) &pbData, uCount + 2)); // Allocate buffer to store data with space for an added ascii or unicode null
    if (uCount <= 4)
    {
        unsigned int i;
        for (i = 0; i < uCount; i++)
            pbData[i] = ((U8*)&uValue)[i]; // Copy least sig bytes - we assume 'II' type TIFF files
    }
    else
    {
        size_t offPosPrev;

        Call(pWS->GetPos(pWS, &offPosPrev));
        Call(pWS->SetPos(pWS, uValue));
        Call(pWS->Read(pWS, pbData, uCount));
        Call(pWS->SetPos(pWS, offPosPrev));
    }

    *ppbData = pbData;

Cleanup:
    if (Failed(err))
    {
        if (pbData)
            PKFree((void **) &pbData);
    }
    return err;
}


ERR ReadPropvar(__in_ecount(1) struct WMPStream* pWS,
                const __in_win U16 uType,
                const __in_win U32 uCount,
                const __in_win U32 uValue,
                __out_win DPKPROPVARIANT *pvar)
{
    ERR err = WMP_errSuccess;
    // U8 *pbData = NULL;

    memset(pvar, 0, sizeof(*pvar));
    if (uCount == 0)
        goto Cleanup; // Nothing to read in here

    switch (uType)
    {
        case WMP_typASCII:
            pvar->vt = DPKVT_LPSTR;
            Call(ReadBinaryData(pWS, uCount, uValue, (U8 **) &pvar->VT.pszVal));
            assert(0 == pvar->VT.pszVal[uCount - 1]); // Check that it's null-terminated
            // make sure (ReadBinaryData allocated uCount + 2 so this and unicode can have forced nulls)
            pvar->VT.pszVal[uCount] = 0;
            break;

        case WMP_typBYTE:
        case WMP_typUNDEFINED:
            // Return as regular C array rather than safearray, as this type is sometimes
            // used to convey unicode (which does not require a count field). Caller knows
            // uCount and can convert to safearray if necessary.
            pvar->vt = (DPKVT_BYREF | DPKVT_UI1);
            Call(ReadBinaryData(pWS, uCount, uValue, &pvar->VT.pbVal));
            break;

        case WMP_typSHORT:
            if (1 == uCount)
            {
                pvar->vt = DPKVT_UI2;
                pvar->VT.uiVal = (U16)(uValue & 0x0000FFFF);
            }
            else if (2 == uCount)
            {
                pvar->vt = DPKVT_UI4;
                pvar->VT.ulVal = uValue;
            }
            else
            {
                assert(FALSE); // NYI
                FailIf(TRUE, WMP_errNotYetImplemented);
            }
            break;

        default:
            assert(FALSE); // Unhandled type
            FailIf(TRUE, WMP_errNotYetImplemented);
            break;
    }

Cleanup:
    return err;
}


ERR WriteWmpDE(
    __in_ecount(1) struct WMPStream* pWS,
    size_t *pOffPos,
    const __in_ecount(1) WmpDE* pDE,
    const U8 *pbData,
    U32 *pcbDataWrittenToOffset)
{
    ERR err = WMP_errSuccess;
    size_t offPos = *pOffPos;

    assert(-1 != pDE->uCount);
    assert(-1 != pDE->uValueOrOffset);

    if (pcbDataWrittenToOffset)
    {
        assert(pbData); // Makes no sense to provide this arg without pbData
        *pcbDataWrittenToOffset = 0;
    }

    Call(PutUShort(pWS, offPos, pDE->uTag)); offPos += 2;
    Call(PutUShort(pWS, offPos, pDE->uType)); offPos += 2;
    Call(PutULong(pWS, offPos, pDE->uCount)); offPos += 4;

    switch (pDE->uType)
    {



( run in 0.840 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )