jxrlib: Add library sources

This commit is contained in:
Rémi Bernon 2020-09-11 20:56:27 +02:00 committed by Andrew Eikum
parent 9a746c257e
commit d9d777072a
63 changed files with 37177 additions and 0 deletions

930
jxrlib/jxrgluelib/JXRGlue.c Normal file
View file

@ -0,0 +1,930 @@
//*@@@+++@@@@******************************************************************
//
// Copyright © Microsoft Corp.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// • Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// • Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//*@@@---@@@@******************************************************************
#include <stdlib.h>
#include <ctype.h>
#define INITGUID
#include <JXRGlue.h>
//================================================================
const PKIID IID_PKImageScanEncode = 1;
const PKIID IID_PKImageFrameEncode = 2;
const PKIID IID_PKImageUnsupported = 100;
const PKIID IID_PKImageWmpEncode = 101;
const PKIID IID_PKImageWmpDecode = 201;
//================================================================
// Misc supporting functions
//================================================================
ERR PKAlloc(void** ppv, size_t cb)
{
*ppv = calloc(1, cb);
return *ppv ? WMP_errSuccess : WMP_errOutOfMemory;
}
ERR PKFree(void** ppv)
{
if (ppv)
{
free(*ppv);
*ppv = NULL;
}
return WMP_errSuccess;
}
ERR PKAllocAligned(void** ppv, size_t cb, size_t iAlign)
{
U8 *pOrigPtr;
U8 *pReturnedPtr;
size_t iAlignmentCorrection;
const size_t c_cbBlockSize = cb + sizeof(void*) + iAlign - 1;
*ppv = NULL;
pOrigPtr = calloc(1, c_cbBlockSize);
if (NULL == pOrigPtr)
return WMP_errOutOfMemory;
iAlignmentCorrection = iAlign - ((size_t)pOrigPtr % iAlign);
if (iAlignmentCorrection < sizeof(void*))
// Alignment correction won't leave us enough space to store pOrigPtr - advance to next block
iAlignmentCorrection += iAlign;
assert(iAlignmentCorrection >= sizeof(void*)); // Alignment correction must have space for pOrigPtr
assert(iAlignmentCorrection + cb <= c_cbBlockSize); // Don't exceed right edge of memory block
pReturnedPtr = pOrigPtr + iAlignmentCorrection;
*(void**)(pReturnedPtr - sizeof(void*)) = pOrigPtr;
assert(0 == ((size_t)pReturnedPtr % iAlign)); // Are we in fact aligned?
*ppv = pReturnedPtr;
return WMP_errSuccess;
}
ERR PKFreeAligned(void** ppv)
{
if (ppv && *ppv)
{
U8 **ppOrigPtr = (U8**)((U8*)(*ppv) - sizeof(void*));
assert(*ppOrigPtr <= (U8*)ppOrigPtr); // Something's wrong if pOrigPtr points forward
free(*ppOrigPtr);
*ppv = NULL;
}
return WMP_errSuccess;
}
int PKStrnicmp(const char* s1, const char* s2, size_t c)
{
for(; tolower(*s1) == tolower(*s2) && *s1 && *s2 && c; ++s1, ++s2, --c);
return c ? *s1 - *s2 : 0;
}
static const PKPixelInfo pixelInfo[] =
{
{&GUID_PKPixelFormatDontCare, 1, Y_ONLY, BD_8, 8, PK_pixfmtNul, 0, 0, 0, 0},
// Gray
//{&GUID_PKPixelFormat2bppGray, 1, Y_ONLY, BD_8, 2, PK_pixfmtNul},
//{&GUID_PKPixelFormat4bppGray, 1, Y_ONLY, BD_8, 4, PK_pixfmtNul},
{&GUID_PKPixelFormatBlackWhite, 1, Y_ONLY, BD_1, 1, PK_pixfmtNul, 1, 1, 1, 1},//BlackIsZero is default for GUID_PKPixelFormatBlackWhite
{&GUID_PKPixelFormatBlackWhite, 1, Y_ONLY, BD_1, 1, PK_pixfmtNul, 0, 1, 1, 1},//WhiteIsZero
{&GUID_PKPixelFormat8bppGray, 1, Y_ONLY, BD_8, 8, PK_pixfmtNul, 1, 1, 8, 1},
{&GUID_PKPixelFormat16bppGray, 1, Y_ONLY, BD_16, 16, PK_pixfmtNul, 1, 1, 16, 1},
{&GUID_PKPixelFormat16bppGrayFixedPoint, 1, Y_ONLY, BD_16S, 16, PK_pixfmtNul, 1, 1, 16, 2},
{&GUID_PKPixelFormat16bppGrayHalf, 1, Y_ONLY, BD_16F, 16, PK_pixfmtNul, 1, 1, 16, 3},
//{&GUID_PKPixelFormat32bppGray, 1, Y_ONLY, BD_32, 32, PK_pixfmtNul, 1, 1, 32, 1},
{&GUID_PKPixelFormat32bppGrayFixedPoint, 1, Y_ONLY, BD_32S, 32, PK_pixfmtNul, 1, 1, 32, 2},
{&GUID_PKPixelFormat32bppGrayFloat, 1, Y_ONLY, BD_32F, 32, PK_pixfmtNul, 1, 1, 32, 3},
// RGB
{&GUID_PKPixelFormat24bppRGB, 3, CF_RGB, BD_8, 24, PK_pixfmtNul, 2, 3, 8, 1},
{&GUID_PKPixelFormat24bppBGR, 3, CF_RGB, BD_8, 24, PK_pixfmtBGR, 2, 3, 8, 1},
{&GUID_PKPixelFormat32bppRGB, 3, CF_RGB, BD_8, 32, PK_pixfmtNul, 2, 3, 8, 1},
{&GUID_PKPixelFormat32bppBGR, 3, CF_RGB, BD_8, 32, PK_pixfmtBGR, 2, 3, 8, 1},
{&GUID_PKPixelFormat48bppRGB, 3, CF_RGB, BD_16, 48, PK_pixfmtNul, 2, 3, 16, 1},
{&GUID_PKPixelFormat48bppRGBFixedPoint, 3, CF_RGB, BD_16S, 48, PK_pixfmtNul, 2, 3, 16, 2},
{&GUID_PKPixelFormat48bppRGBHalf, 3, CF_RGB, BD_16F, 48, PK_pixfmtNul, 2, 3, 16, 3},
{&GUID_PKPixelFormat64bppRGBFixedPoint, 3, CF_RGB, BD_16S, 64, PK_pixfmtNul, 2, 3, 16, 2},
{&GUID_PKPixelFormat64bppRGBHalf, 3, CF_RGB, BD_16F, 64, PK_pixfmtNul, 2, 3, 16, 3},
//{&GUID_PKPixelFormat96bppRGB, 3, CF_RGB, BD_32, 96, PK_pixfmtNul, 2, 3, 32, 1},
{&GUID_PKPixelFormat96bppRGBFixedPoint, 3, CF_RGB, BD_32S, 96, PK_pixfmtNul, 2, 3, 32, 2},
{&GUID_PKPixelFormat96bppRGBFloat, 3, CF_RGB, BD_32F, 96, PK_pixfmtNul, 2, 3, 32, 3},
{&GUID_PKPixelFormat128bppRGBFixedPoint, 3, CF_RGB, BD_32S, 128, PK_pixfmtNul, 2, 3, 32, 2},
{&GUID_PKPixelFormat128bppRGBFloat, 3, CF_RGB, BD_32F, 128, PK_pixfmtNul, 2, 3, 32, 3},
// RGBA
{&GUID_PKPixelFormat32bppBGRA, 4, CF_RGB, BD_8, 32, PK_pixfmtHasAlpha | PK_pixfmtBGR, 2, 4, 8, 1},
{&GUID_PKPixelFormat32bppRGBA, 4, CF_RGB, BD_8, 32, PK_pixfmtHasAlpha, 2, 4, 8, 1},
{&GUID_PKPixelFormat64bppRGBA, 4, CF_RGB, BD_16, 64, PK_pixfmtHasAlpha, 2, 4, 16, 1},
{&GUID_PKPixelFormat64bppRGBAFixedPoint, 4, CF_RGB, BD_16S, 64, PK_pixfmtHasAlpha, 2, 4, 16, 2},
{&GUID_PKPixelFormat64bppRGBAHalf, 4, CF_RGB, BD_16F, 64, PK_pixfmtHasAlpha, 2, 4, 16, 3},
//{&GUID_PKPixelFormat128bppRGBA, 4, CF_RGB, BD_32, 128, PK_pixfmtHasAlpha, 2, 4, 32, 1},
{&GUID_PKPixelFormat128bppRGBAFixedPoint, 4, CF_RGB, BD_32S, 128, PK_pixfmtHasAlpha, 2, 4, 32, 2},
{&GUID_PKPixelFormat128bppRGBAFloat, 4, CF_RGB, BD_32F, 128, PK_pixfmtHasAlpha, 2, 4, 32, 3},
// PRGBA
{&GUID_PKPixelFormat32bppPBGRA, 4, CF_RGB, BD_8, 32, PK_pixfmtHasAlpha | PK_pixfmtPreMul | PK_pixfmtBGR, 2, 4, 8, 1},
{&GUID_PKPixelFormat32bppPRGBA, 4, CF_RGB, BD_8, 32, PK_pixfmtHasAlpha | PK_pixfmtPreMul, 2, 4, 8, 1},
{&GUID_PKPixelFormat64bppPRGBA, 4, CF_RGB, BD_16, 64, PK_pixfmtHasAlpha | PK_pixfmtPreMul, 2, 4, 16, 1},
//{&GUID_PKPixelFormat64bppPRGBAFixedPoint, 4, CF_RGB, BD_16S, 64, PK_pixfmtHasAlpha, 2, 4, 16, 2},
//{&GUID_PKPixelFormat64bppPRGBAHalf, 4, CF_RGB, BD_16F, 64, PK_pixfmtHasAlpha, 2, 4, 16, 3},
//{&GUID_PKPixelFormat128bppPRGBAFixedPoint, 4, CF_RGB, BD_32S, 128, PK_pixfmtHasAlpha, 2, 4, 32, 2},
{&GUID_PKPixelFormat128bppPRGBAFloat, 4, CF_RGB, BD_32F, 128, PK_pixfmtHasAlpha | PK_pixfmtPreMul, 2, 4, 32, 3},
// Packed formats
{&GUID_PKPixelFormat16bppRGB555, 3, CF_RGB, BD_5, 16, PK_pixfmtNul, 2, 3, 5, 1},
{&GUID_PKPixelFormat16bppRGB565, 3, CF_RGB, BD_565, 16, PK_pixfmtNul, 2, 3, 6, 1},
{&GUID_PKPixelFormat32bppRGB101010, 3, CF_RGB, BD_10, 32, PK_pixfmtNul, 2, 3, 10, 1},
// CMYK
{&GUID_PKPixelFormat32bppCMYK, 4, CMYK, BD_8, 32, PK_pixfmtNul, 5, 4, 8, 1},
{&GUID_PKPixelFormat40bppCMYKAlpha, 5, CMYK, BD_8, 40, PK_pixfmtHasAlpha, 5, 5, 8, 1},
{&GUID_PKPixelFormat64bppCMYK, 4, CMYK, BD_16, 64, PK_pixfmtNul, 5, 4, 16, 1},
{&GUID_PKPixelFormat80bppCMYKAlpha, 5, CMYK, BD_16, 80, PK_pixfmtHasAlpha, 5, 5, 16, 1},
// N_CHANNEL
{&GUID_PKPixelFormat24bpp3Channels, 3, NCOMPONENT, BD_8, 24, PK_pixfmtNul, PK_PI_NCH, 3, 8, 1},//the N channel TIF by PS has PhotometricInterpretation of PK_PI_RGB
{&GUID_PKPixelFormat32bpp4Channels, 4, NCOMPONENT, BD_8, 32, PK_pixfmtNul, PK_PI_NCH, 4, 8, 1},
{&GUID_PKPixelFormat40bpp5Channels, 5, NCOMPONENT, BD_8, 40, PK_pixfmtNul, PK_PI_NCH, 5, 8, 1},
{&GUID_PKPixelFormat48bpp6Channels, 6, NCOMPONENT, BD_8, 48, PK_pixfmtNul, PK_PI_NCH, 6, 8, 1},
{&GUID_PKPixelFormat56bpp7Channels, 7, NCOMPONENT, BD_8, 56, PK_pixfmtNul, PK_PI_NCH, 7, 8, 1},
{&GUID_PKPixelFormat64bpp8Channels, 8, NCOMPONENT, BD_8, 64, PK_pixfmtNul, PK_PI_NCH, 8, 8, 1},
{&GUID_PKPixelFormat32bpp3ChannelsAlpha, 4, NCOMPONENT, BD_8, 32, PK_pixfmtHasAlpha, PK_PI_NCH, 4, 8, 1},
{&GUID_PKPixelFormat40bpp4ChannelsAlpha, 5, NCOMPONENT, BD_8, 40, PK_pixfmtHasAlpha, PK_PI_NCH, 5, 8, 1},
{&GUID_PKPixelFormat48bpp5ChannelsAlpha, 6, NCOMPONENT, BD_8, 48, PK_pixfmtHasAlpha, PK_PI_NCH, 6, 8, 1},
{&GUID_PKPixelFormat56bpp6ChannelsAlpha, 7, NCOMPONENT, BD_8, 56, PK_pixfmtHasAlpha, PK_PI_NCH, 7, 8, 1},
{&GUID_PKPixelFormat64bpp7ChannelsAlpha, 8, NCOMPONENT, BD_8, 64, PK_pixfmtHasAlpha, PK_PI_NCH, 8, 8, 1},
{&GUID_PKPixelFormat72bpp8ChannelsAlpha, 9, NCOMPONENT, BD_8, 72, PK_pixfmtHasAlpha, PK_PI_NCH, 9, 8, 1},
{&GUID_PKPixelFormat48bpp3Channels, 3, NCOMPONENT, BD_16, 48, PK_pixfmtNul, PK_PI_NCH, 3, 16, 1},
{&GUID_PKPixelFormat64bpp4Channels, 4, NCOMPONENT, BD_16, 64, PK_pixfmtNul, PK_PI_NCH, 4, 16, 1},
{&GUID_PKPixelFormat80bpp5Channels, 5, NCOMPONENT, BD_16, 80, PK_pixfmtNul, PK_PI_NCH, 5, 16, 1},
{&GUID_PKPixelFormat96bpp6Channels, 6, NCOMPONENT, BD_16, 96, PK_pixfmtNul, PK_PI_NCH, 6, 16, 1},
{&GUID_PKPixelFormat112bpp7Channels, 7, NCOMPONENT, BD_16, 112, PK_pixfmtNul, PK_PI_NCH, 7, 16, 1},
{&GUID_PKPixelFormat128bpp8Channels, 8, NCOMPONENT, BD_16, 128, PK_pixfmtNul, PK_PI_NCH, 8, 16, 1},
{&GUID_PKPixelFormat64bpp3ChannelsAlpha, 4, NCOMPONENT, BD_16, 64, PK_pixfmtHasAlpha, PK_PI_NCH, 4, 16, 1},
{&GUID_PKPixelFormat80bpp4ChannelsAlpha, 5, NCOMPONENT, BD_16, 80, PK_pixfmtHasAlpha, PK_PI_NCH, 5, 16, 1},
{&GUID_PKPixelFormat96bpp5ChannelsAlpha, 6, NCOMPONENT, BD_16, 96, PK_pixfmtHasAlpha, PK_PI_NCH, 6, 16, 1},
{&GUID_PKPixelFormat112bpp6ChannelsAlpha, 7, NCOMPONENT, BD_16, 112, PK_pixfmtHasAlpha, PK_PI_NCH, 7, 16, 1},
{&GUID_PKPixelFormat128bpp7ChannelsAlpha, 8, NCOMPONENT, BD_16, 128, PK_pixfmtHasAlpha, PK_PI_NCH, 8, 16, 1},
{&GUID_PKPixelFormat144bpp8ChannelsAlpha, 9, NCOMPONENT, BD_16, 144, PK_pixfmtHasAlpha, PK_PI_NCH, 9, 16, 1},
//RGBE
{&GUID_PKPixelFormat32bppRGBE, 4, CF_RGBE, BD_8, 32, PK_pixfmtNul, PK_PI_RGBE, 4, 8, 1},
//YUV
{&GUID_PKPixelFormat12bppYUV420, 3, YUV_420, BD_8, 48, PK_pixfmtNul},
{&GUID_PKPixelFormat16bppYUV422, 3, YUV_422, BD_8, 32, PK_pixfmtNul},
{&GUID_PKPixelFormat24bppYUV444, 3, YUV_444, BD_8, 24, PK_pixfmtNul},
};
//----------------------------------------------------------------
//ERR GetPixelInfo(PKPixelFormatGUID enPixelFormat, const PKPixelInfo** ppPI)
ERR PixelFormatLookup(PKPixelInfo* pPI, U8 uLookupType)
{
ERR err = WMP_errSuccess;
size_t i;
for (i = 0; i < sizeof2(pixelInfo); ++i)
{
if (LOOKUP_FORWARD == uLookupType)
{
if (IsEqualGUID(pPI->pGUIDPixFmt, pixelInfo[i].pGUIDPixFmt))
{
*pPI = pixelInfo[i];
goto Cleanup;
}
}
else if (LOOKUP_BACKWARD_TIF == uLookupType)
{
if (pPI->uSamplePerPixel == pixelInfo[i].uSamplePerPixel &&
pPI->uBitsPerSample == pixelInfo[i].uBitsPerSample &&
pPI->uSampleFormat == pixelInfo[i].uSampleFormat &&
pPI->uInterpretation == pixelInfo[i].uInterpretation)
{
// match alpha & premult
if ((pPI->grBit & (PK_pixfmtHasAlpha | PK_pixfmtPreMul)) ==
(pixelInfo[i].grBit & (PK_pixfmtHasAlpha | PK_pixfmtPreMul)))
{
*pPI = pixelInfo[i];
goto Cleanup;
}
}
}
}
Call(WMP_errUnsupportedFormat);
Cleanup:
return err;
}
const PKPixelFormatGUID* GetPixelFormatFromHash(const U8 uPFHash)
{
int i;
for (i = 0; i < sizeof2(pixelInfo); i++)
{
if (pixelInfo[i].pGUIDPixFmt->Data4[7] == uPFHash)
return pixelInfo[i].pGUIDPixFmt;
}
// If we reached this point, we did not find anything which matched the hash
return NULL;
}
//----------------------------------------------------------------
typedef struct tagPKIIDInfo
{
const char* szExt;
const PKIID* pIIDEnc;
const PKIID* pIIDDec;
} PKIIDInfo;
static ERR GetIIDInfo(const char* szExt, const PKIIDInfo** ppInfo)
{
ERR err = WMP_errSuccess;
static PKIIDInfo iidInfo[] = {
{".jxr", &IID_PKImageWmpEncode, &IID_PKImageWmpDecode},
{".wdp", &IID_PKImageUnsupported, &IID_PKImageWmpDecode},
{".hdp", &IID_PKImageUnsupported, &IID_PKImageWmpDecode},
};
size_t i = 0;
*ppInfo = NULL;
for (i = 0; i < sizeof2(iidInfo); ++i)
{
if (0 == PKStrnicmp(szExt, iidInfo[i].szExt, strlen(iidInfo[i].szExt)))
{
*ppInfo = &iidInfo[i];
goto Cleanup;
}
}
Call(WMP_errUnsupportedFormat);
Cleanup:
return err;
}
ERR GetImageEncodeIID(const char* szExt, const PKIID** ppIID)
{
ERR err = WMP_errSuccess;
const PKIIDInfo* pInfo = NULL;
Call(GetIIDInfo(szExt, &pInfo));
*ppIID = pInfo->pIIDEnc;
Cleanup:
return err;
}
ERR GetImageDecodeIID(const char* szExt, const PKIID** ppIID)
{
ERR err = WMP_errSuccess;
const PKIIDInfo* pInfo = NULL;
Call(GetIIDInfo(szExt, &pInfo));
*ppIID = pInfo->pIIDDec;
Cleanup:
return err;
}
//================================================================
// PKFactory
//================================================================
ERR PKCreateFactory_CreateStream(PKStream** ppStream)
{
ERR err = WMP_errSuccess;
Call(PKAlloc((void **) ppStream, sizeof(**ppStream)));
Cleanup:
return err;
}
ERR PKCreateFactory_Release(PKFactory** ppFactory)
{
ERR err = WMP_errSuccess;
Call(PKFree((void **) ppFactory));
Cleanup:
return err;
}
//----------------------------------------------------------------
ERR PKCreateFactory(PKFactory** ppFactory, U32 uVersion)
{
ERR err = WMP_errSuccess;
PKFactory* pFactory = NULL;
UNREFERENCED_PARAMETER( uVersion );
Call(PKAlloc((void **) ppFactory, sizeof(**ppFactory)));
pFactory = *ppFactory;
pFactory->CreateStream = PKCreateFactory_CreateStream;
pFactory->CreateStreamFromFilename = CreateWS_File;
pFactory->CreateStreamFromMemory = CreateWS_Memory;
pFactory->Release = PKCreateFactory_Release;
Cleanup:
return err;
}
//================================================================
// PKCodecFactory
//================================================================
ERR PKCodecFactory_CreateCodec(const PKIID* iid, void** ppv)
{
ERR err = WMP_errSuccess;
if (IID_PKImageWmpEncode == *iid)
{
Call(PKImageEncode_Create_WMP((PKImageEncode**)ppv));
}
else if (IID_PKImageWmpDecode == *iid)
{
Call(PKImageDecode_Create_WMP((PKImageDecode**)ppv));
}
else
{
Call(WMP_errUnsupportedFormat);
}
Cleanup:
return err;
}
ERR PKCodecFactory_CreateDecoderFromFile(const char* szFilename, PKImageDecode** ppDecoder)
{
ERR err = WMP_errSuccess;
char *pExt = NULL;
const PKIID* pIID = NULL;
struct WMPStream* pStream = NULL;
PKImageDecode* pDecoder = NULL;
// get file extension
pExt = strrchr(szFilename, '.');
FailIf(NULL == pExt, WMP_errUnsupportedFormat);
// get decode PKIID
Call(GetImageDecodeIID(pExt, &pIID));
// create stream
Call(CreateWS_File(&pStream, szFilename, "rb"));
// Create decoder
Call(PKCodecFactory_CreateCodec(pIID, (void **) ppDecoder));
pDecoder = *ppDecoder;
// attach stream to decoder
Call(pDecoder->Initialize(pDecoder, pStream));
pDecoder->fStreamOwner = !0;
Cleanup:
return err;
}
ERR PKCodecFactory_CreateFormatConverter(PKFormatConverter** ppFConverter)
{
ERR err = WMP_errSuccess;
PKFormatConverter* pFC = NULL;
Call(PKAlloc((void **) ppFConverter, sizeof(**ppFConverter)));
pFC = *ppFConverter;
pFC->Initialize = PKFormatConverter_Initialize;
pFC->InitializeConvert = PKFormatConverter_InitializeConvert;
pFC->GetPixelFormat = PKFormatConverter_GetPixelFormat;
pFC->GetSourcePixelFormat = PKFormatConverter_GetSourcePixelFormat;
pFC->GetSize = PKFormatConverter_GetSize;
pFC->GetResolution = PKFormatConverter_GetResolution;
pFC->Copy = PKFormatConverter_Copy;
pFC->Convert = PKFormatConverter_Convert;
pFC->Release = PKFormatConverter_Release;
Cleanup:
return err;
}
ERR PKCreateCodecFactory_Release(PKCodecFactory** ppCFactory)
{
ERR err = WMP_errSuccess;
Call(PKFree((void **) ppCFactory));
Cleanup:
return err;
}
ERR PKCreateCodecFactory(PKCodecFactory** ppCFactory, U32 uVersion)
{
ERR err = WMP_errSuccess;
PKCodecFactory* pCFactory = NULL;
UNREFERENCED_PARAMETER( uVersion );
Call(PKAlloc((void **) ppCFactory, sizeof(**ppCFactory)));
pCFactory = *ppCFactory;
pCFactory->CreateCodec = PKCodecFactory_CreateCodec;
pCFactory->CreateDecoderFromFile = PKCodecFactory_CreateDecoderFromFile;
pCFactory->CreateFormatConverter = PKCodecFactory_CreateFormatConverter;
pCFactory->Release = PKCreateCodecFactory_Release;
Cleanup:
return err;
}
//================================================================
// PKImageEncode
//================================================================
ERR PKImageEncode_Initialize(
PKImageEncode* pIE,
struct WMPStream* pStream,
void* pvParam,
size_t cbParam)
{
ERR err = WMP_errSuccess;
UNREFERENCED_PARAMETER( pIE );
UNREFERENCED_PARAMETER( pvParam );
UNREFERENCED_PARAMETER( cbParam );
pIE->pStream = pStream;
pIE->guidPixFormat = GUID_PKPixelFormatDontCare;
pIE->fResX = 96;
pIE->fResY = 96;
pIE->cFrame = 1;
Call(pIE->pStream->GetPos(pIE->pStream, &pIE->offStart));
Cleanup:
return err;
}
ERR PKImageEncode_Terminate(
PKImageEncode* pIE)
{
UNREFERENCED_PARAMETER( pIE );
return WMP_errSuccess;
}
ERR PKImageEncode_SetPixelFormat(
PKImageEncode* pIE,
PKPixelFormatGUID enPixelFormat)
{
pIE->guidPixFormat = enPixelFormat;
return WMP_errSuccess;
}
ERR PKImageEncode_SetSize(
PKImageEncode* pIE,
I32 iWidth,
I32 iHeight)
{
ERR err = WMP_errSuccess;
pIE->uWidth = (U32)iWidth;
pIE->uHeight = (U32)iHeight;
return err;
}
ERR PKImageEncode_SetResolution(
PKImageEncode* pIE,
Float fResX,
Float fResY)
{
pIE->fResX = fResX;
pIE->fResY = fResY;
return WMP_errSuccess;
}
ERR PKImageEncode_SetColorContext(PKImageEncode *pIE,
const U8 *pbColorContext,
U32 cbColorContext)
{
UNREFERENCED_PARAMETER( pIE );
UNREFERENCED_PARAMETER( pbColorContext );
UNREFERENCED_PARAMETER( cbColorContext );
return WMP_errNotYetImplemented;
}
ERR PKImageEncode_SetDescriptiveMetadata(PKImageEncode *pIE, const DESCRIPTIVEMETADATA *pDescMetadata)
{
UNREFERENCED_PARAMETER( pIE );
UNREFERENCED_PARAMETER( pDescMetadata );
return WMP_errNotYetImplemented;
}
ERR PKImageEncode_WritePixels(
PKImageEncode* pIE,
U32 cLine,
U8* pbPixels,
U32 cbStride)
{
UNREFERENCED_PARAMETER( pIE );
UNREFERENCED_PARAMETER( cLine );
UNREFERENCED_PARAMETER( pbPixels );
UNREFERENCED_PARAMETER( cbStride );
return WMP_errAbstractMethod;
}
ERR PKImageEncode_WriteSource(
PKImageEncode* pIE,
PKFormatConverter* pFC,
PKRect* pRect)
{
ERR err = WMP_errSuccess;
PKPixelFormatGUID enPFFrom = GUID_PKPixelFormatDontCare;
PKPixelFormatGUID enPFTo = GUID_PKPixelFormatDontCare;
PKPixelInfo pPIFrom;
PKPixelInfo pPITo;
U32 cbStrideTo = 0;
U32 cbStrideFrom = 0;
U32 cbStride = 0;
U8* pb = NULL;
// CWMTranscodingParam* pParam = NULL;
// get pixel format
Call(pFC->GetSourcePixelFormat(pFC, &enPFFrom));
Call(pFC->GetPixelFormat(pFC, &enPFTo));
FailIf(!IsEqualGUID(&pIE->guidPixFormat, &enPFTo), WMP_errUnsupportedFormat);
// calc common stride
// Call(GetPixelInfo(enPFFrom, &pPIFrom));
pPIFrom.pGUIDPixFmt = &enPFFrom;
PixelFormatLookup(&pPIFrom, LOOKUP_FORWARD);
// Call(GetPixelInfo(enPFTo, &pPITo));
pPITo.pGUIDPixFmt = &enPFTo;
PixelFormatLookup(&pPITo, LOOKUP_FORWARD);
// cbStrideFrom = (pPIFrom->cbPixel * pRect->Width + pPIFrom->cbPixelDenom - 1) / pPIFrom->cbPixelDenom;
cbStrideFrom = (BD_1 == pPIFrom.bdBitDepth ? ((pPIFrom.cbitUnit * pRect->Width + 7) >> 3) : (((pPIFrom.cbitUnit + 7) >> 3) * pRect->Width));
if (&GUID_PKPixelFormat12bppYUV420 == pPIFrom.pGUIDPixFmt
|| &GUID_PKPixelFormat16bppYUV422 == pPIFrom.pGUIDPixFmt)
cbStrideFrom >>= 1;
// cbStrideTo = (pPITo->cbPixel * pIE->uWidth + pPITo->cbPixelDenom - 1) / pPITo->cbPixelDenom;
cbStrideTo = (BD_1 == pPITo.bdBitDepth ? ((pPITo.cbitUnit * pIE->uWidth + 7) >> 3) : (((pPITo.cbitUnit + 7) >> 3) * pIE->uWidth));
if (&GUID_PKPixelFormat12bppYUV420 == pPITo.pGUIDPixFmt
|| &GUID_PKPixelFormat16bppYUV422 == pPITo.pGUIDPixFmt)
cbStrideTo >>= 1;
cbStride = max(cbStrideFrom, cbStrideTo);
// actual dec/enc with local buffer
Call(PKAllocAligned((void **) &pb, cbStride * pRect->Height, 128));
Call(pFC->Copy(pFC, pRect, pb, cbStride));
Call(pIE->WritePixels(pIE, pRect->Height, pb, cbStride));
Cleanup:
PKFreeAligned((void **) &pb);
return err;
}
ERR PKImageEncode_WritePixelsBandedBegin(PKImageEncode* pEncoder, struct WMPStream *pPATempFile)
{
UNREFERENCED_PARAMETER( pEncoder );
UNREFERENCED_PARAMETER( pPATempFile );
return WMP_errAbstractMethod;
}
ERR PKImageEncode_WritePixelsBanded(PKImageEncode* pEncoder, U32 cLines, U8* pbPixels, U32 cbStride, Bool fLastCall)
{
UNREFERENCED_PARAMETER( pEncoder );
UNREFERENCED_PARAMETER( cLines );
UNREFERENCED_PARAMETER( pbPixels );
UNREFERENCED_PARAMETER( cbStride );
UNREFERENCED_PARAMETER( fLastCall );
return WMP_errAbstractMethod;
}
ERR PKImageEncode_WritePixelsBandedEnd(PKImageEncode* pEncoder)
{
UNREFERENCED_PARAMETER( pEncoder );
return WMP_errAbstractMethod;
}
ERR PKImageEncode_Transcode(
PKImageEncode* pIE,
PKFormatConverter* pFC,
PKRect* pRect)
{
ERR err = WMP_errSuccess;
PKPixelFormatGUID enPFFrom = GUID_PKPixelFormatDontCare;
PKPixelFormatGUID enPFTo = GUID_PKPixelFormatDontCare;
PKPixelInfo pPIFrom;
PKPixelInfo pPITo;
U32 cbStrideTo = 0;
U32 cbStrideFrom = 0;
U32 cbStride = 0;
U8* pb = NULL;
CWMTranscodingParam cParam = {0};
// get pixel format
Call(pFC->GetSourcePixelFormat(pFC, &enPFFrom));
Call(pFC->GetPixelFormat(pFC, &enPFTo));
FailIf(!IsEqualGUID(&pIE->guidPixFormat, &enPFTo), WMP_errUnsupportedFormat);
// calc common stride
// Call(GetPixelInfo(enPFFrom, &pPIFrom));
pPIFrom.pGUIDPixFmt = &enPFFrom;
PixelFormatLookup(&pPIFrom, LOOKUP_FORWARD);
// Call(GetPixelInfo(enPFTo, &pPITo));
pPITo.pGUIDPixFmt = &enPFTo;
PixelFormatLookup(&pPITo, LOOKUP_FORWARD);
// cbStrideFrom = (pPIFrom->cbPixel * pRect->Width + pPIFrom->cbPixelDenom - 1) / pPIFrom->cbPixelDenom;
cbStrideFrom = (BD_1 == pPIFrom.bdBitDepth ? ((pPIFrom.cbitUnit * pRect->Width + 7) >> 3) : (((pPIFrom.cbitUnit + 7) >> 3) * pRect->Width));
if (&GUID_PKPixelFormat12bppYUV420 == pPIFrom.pGUIDPixFmt
|| &GUID_PKPixelFormat16bppYUV422 == pPIFrom.pGUIDPixFmt)
cbStrideFrom >>= 1;
// cbStrideTo = (pPITo->cbPixel * pIE->uWidth + pPITo->cbPixelDenom - 1) / pPITo->cbPixelDenom;
cbStrideTo = (BD_1 == pPITo.bdBitDepth ? ((pPITo.cbitUnit * pIE->uWidth + 7) >> 3) : (((pPITo.cbitUnit + 7) >> 3) * pIE->uWidth));
if (&GUID_PKPixelFormat12bppYUV420 == pPITo.pGUIDPixFmt
|| &GUID_PKPixelFormat16bppYUV422 == pPITo.pGUIDPixFmt)
cbStrideTo >>= 1;
cbStride = max(cbStrideFrom, cbStrideTo);
if(pIE->bWMP){
cParam.cLeftX = pFC->pDecoder->WMP.wmiI.cROILeftX;
cParam.cTopY = pFC->pDecoder->WMP.wmiI.cROITopY;
cParam.cWidth = pFC->pDecoder->WMP.wmiI.cROIWidth;
cParam.cHeight = pFC->pDecoder->WMP.wmiI.cROIHeight;
cParam.oOrientation = pFC->pDecoder->WMP.wmiI.oOrientation;
// cParam.cfColorFormat = pFC->pDecoder->WMP.wmiI.cfColorFormat;
cParam.uAlphaMode = pFC->pDecoder->WMP.wmiSCP.uAlphaMode;
cParam.bfBitstreamFormat = pFC->pDecoder->WMP.wmiSCP.bfBitstreamFormat;
cParam.sbSubband = pFC->pDecoder->WMP.wmiSCP.sbSubband;
cParam.bIgnoreOverlap = pFC->pDecoder->WMP.bIgnoreOverlap;
Call(pIE->Transcode(pIE, pFC->pDecoder, &cParam));
}
else
{
// actual dec/enc with local buffer
Call(PKAllocAligned((void **) &pb, cbStride * pRect->Height, 128));
Call(pFC->Copy(pFC, pRect, pb, cbStride));
Call(pIE->WritePixels(pIE, pRect->Height, pb, cbStride));
}
Cleanup:
PKFreeAligned((void **) &pb);
return err;
}
ERR PKImageEncode_CreateNewFrame(
PKImageEncode* pIE,
void* pvParam,
size_t cbParam)
{
UNREFERENCED_PARAMETER( pIE );
UNREFERENCED_PARAMETER( pvParam );
UNREFERENCED_PARAMETER( cbParam );
// NYI
return WMP_errSuccess;
}
ERR PKImageEncode_Release(
PKImageEncode** ppIE)
{
PKImageEncode *pIE = *ppIE;
pIE->pStream->Close(&pIE->pStream);
return PKFree((void **) ppIE);
}
ERR PKImageEncode_Create(PKImageEncode** ppIE)
{
ERR err = WMP_errSuccess;
PKImageEncode* pIE = NULL;
Call(PKAlloc((void **) ppIE, sizeof(**ppIE)));
pIE = *ppIE;
pIE->Initialize = PKImageEncode_Initialize;
pIE->Terminate = PKImageEncode_Terminate;
pIE->SetPixelFormat = PKImageEncode_SetPixelFormat;
pIE->SetSize = PKImageEncode_SetSize;
pIE->SetResolution = PKImageEncode_SetResolution;
pIE->SetColorContext = PKImageEncode_SetColorContext;
pIE->SetDescriptiveMetadata = PKImageEncode_SetDescriptiveMetadata;
pIE->WritePixels = PKImageEncode_WritePixels;
// pIE->WriteSource = PKImageEncode_WriteSource;
pIE->WritePixelsBandedBegin = PKImageEncode_WritePixelsBandedBegin;
pIE->WritePixelsBanded = PKImageEncode_WritePixelsBanded;
pIE->WritePixelsBandedEnd = PKImageEncode_WritePixelsBandedEnd;
pIE->CreateNewFrame = PKImageEncode_CreateNewFrame;
pIE->Release = PKImageEncode_Release;
pIE->bWMP = FALSE;
Cleanup:
return err;
}
//================================================================
// PKImageDecode
//================================================================
ERR PKImageDecode_Initialize(
PKImageDecode* pID,
struct WMPStream* pStream)
{
ERR err = WMP_errSuccess;
pID->pStream = pStream;
pID->guidPixFormat = GUID_PKPixelFormatDontCare;
pID->fResX = 96;
pID->fResY = 96;
pID->cFrame = 1;
Call(pID->pStream->GetPos(pID->pStream, &pID->offStart));
memset(&pID->WMP.wmiDEMisc, 0, sizeof(pID->WMP.wmiDEMisc));
Cleanup:
return WMP_errSuccess;
}
ERR PKImageDecode_GetPixelFormat(
PKImageDecode* pID,
PKPixelFormatGUID* pPF)
{
*pPF = pID->guidPixFormat;
return WMP_errSuccess;
}
ERR PKImageDecode_GetSize(
PKImageDecode* pID,
I32* piWidth,
I32* piHeight)
{
*piWidth = (I32)pID->uWidth;
*piHeight = (I32)pID->uHeight;
return WMP_errSuccess;
}
ERR PKImageDecode_GetResolution(
PKImageDecode* pID,
Float* pfResX,
Float* pfResY)
{
*pfResX = pID->fResX;
*pfResY = pID->fResY;
return WMP_errSuccess;
}
ERR PKImageDecode_GetColorContext(PKImageDecode *pID, U8 *pbColorContext, U32 *pcbColorContext)
{
UNREFERENCED_PARAMETER( pID );
UNREFERENCED_PARAMETER( pbColorContext );
UNREFERENCED_PARAMETER( pcbColorContext );
return WMP_errNotYetImplemented;
}
ERR PKImageDecode_GetDescriptiveMetadata(PKImageDecode *pIE, DESCRIPTIVEMETADATA *pDescMetadata)
{
UNREFERENCED_PARAMETER( pIE );
UNREFERENCED_PARAMETER( pDescMetadata );
return WMP_errNotYetImplemented;
}
ERR PKImageDecode_Copy(
PKImageDecode* pID,
const PKRect* pRect,
U8* pb,
U32 cbStride)
{
UNREFERENCED_PARAMETER( pID );
UNREFERENCED_PARAMETER( pRect );
UNREFERENCED_PARAMETER( pb );
UNREFERENCED_PARAMETER( cbStride );
return WMP_errAbstractMethod;
}
ERR PKImageDecode_GetFrameCount(
PKImageDecode* pID,
U32* puCount)
{
*puCount = pID->cFrame;
return WMP_errSuccess;
}
ERR PKImageDecode_SelectFrame(
PKImageDecode* pID,
U32 uFrame)
{
UNREFERENCED_PARAMETER( pID );
UNREFERENCED_PARAMETER( uFrame );
// NYI
return WMP_errSuccess;
}
ERR PKImageDecode_Release(
PKImageDecode** ppID)
{
PKImageDecode* pID = *ppID;
pID->fStreamOwner && pID->pStream->Close(&pID->pStream);
return PKFree((void **) ppID);
}
ERR PKImageDecode_Create(
PKImageDecode** ppID)
{
ERR err = WMP_errSuccess;
PKImageDecode* pID = NULL;
Call(PKAlloc((void **) ppID, sizeof(**ppID)));
pID = *ppID;
pID->Initialize = PKImageDecode_Initialize;
pID->GetPixelFormat = PKImageDecode_GetPixelFormat;
pID->GetSize = PKImageDecode_GetSize;
pID->GetResolution = PKImageDecode_GetResolution;
pID->GetColorContext = PKImageDecode_GetColorContext;
pID->GetDescriptiveMetadata = PKImageDecode_GetDescriptiveMetadata;
pID->Copy = PKImageDecode_Copy;
pID->GetFrameCount = PKImageDecode_GetFrameCount;
pID->SelectFrame = PKImageDecode_SelectFrame;
pID->Release = PKImageDecode_Release;
Cleanup:
return err;
}

636
jxrlib/jxrgluelib/JXRGlue.h Normal file
View file

@ -0,0 +1,636 @@
//*@@@+++@@@@******************************************************************
//
// Copyright © Microsoft Corp.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// • Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// • Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//*@@@---@@@@******************************************************************
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <JXRMeta.h>
#include <guiddef.h>
//================================================================
#define WMP_SDK_VERSION 0x0101
#define PK_SDK_VERSION 0x0101
#define sizeof2(array) (sizeof(array)/sizeof(*(array)))
#ifndef max
#define max(a,b) ((a) > (b) ? (a) : (b))
#endif
#ifndef min
#define min(b,a) ((a) < (b) ? (a) : (b))
#endif
#ifdef __ANSI__
#define STRCPY_SAFE(pszDest, cbDest, pszSrc) (strncpy((pszDest), (pszSrc), (cbDest)) == (pszDest) ? 0 : 1)
#else
#define STRCPY_SAFE(pszDest, cbDest, pszSrc) (strcpy_s((pszDest), (cbDest), (pszSrc)))
#endif // __ANSI__
//================================================================
typedef struct tagPKRect
{
I32 X;
I32 Y;
I32 Width;
I32 Height;
} PKRect;
//================================================================
typedef U32 PKIID;
EXTERN_C const PKIID IID_PKImageScanEncode;
EXTERN_C const PKIID IID_PKImageFrameEncode;
EXTERN_C const PKIID IID_PKImageWmpEncode;
EXTERN_C const PKIID IID_PKImageWmpDecode;
struct IFDEntry
{
U16 uTag;
U16 uType;
U32 uCount;
U32 uValue;
};
EXTERN_C const U32 IFDEntryTypeSizes[13];
EXTERN_C const U32 SizeofIFDEntry;
//================================================================
typedef float Float;
typedef enum tagPKStreamFlags
{
PKStreamOpenRead = 0x00000000UL,
PKStreamOpenWrite = 0x00000001UL,
PKStreamOpenReadWrite = 0x00000002UL,
PKStreamNoLock = 0x00010000UL,
PKStreamNoSeek = 0x00020000UL,
PKStreamCompress = 0x00040000UL,
} PKStreamFlags;
/* Undefined formats */
#define GUID_PKPixelFormatUndefined GUID_PKPixelFormatDontCare
DEFINE_GUID(GUID_PKPixelFormatDontCare, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x00);
/* Indexed formats */
//DEFINE_GUID(GUID_PKPixelFormat1bppIndexed, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x01);
//DEFINE_GUID(GUID_PKPixelFormat2bppIndexed, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x02);
//DEFINE_GUID(GUID_PKPixelFormat4bppIndexed, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x03);
//DEFINE_GUID(GUID_PKPixelFormat8bppIndexed, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x04);
DEFINE_GUID(GUID_PKPixelFormatBlackWhite, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x05);
//DEFINE_GUID(GUID_PKPixelFormat2bppGray, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x06);
//DEFINE_GUID(GUID_PKPixelFormat4bppGray, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x07);
DEFINE_GUID(GUID_PKPixelFormat8bppGray, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x08);
/* sRGB formats (gamma is approx. 2.2) */
/* For a full definition, see the sRGB spec */
/* 16bpp formats */
DEFINE_GUID(GUID_PKPixelFormat16bppRGB555, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x09);
DEFINE_GUID(GUID_PKPixelFormat16bppRGB565, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0a);
DEFINE_GUID(GUID_PKPixelFormat16bppGray, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0b);
/* 24bpp formats */
DEFINE_GUID(GUID_PKPixelFormat24bppBGR, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0c);
DEFINE_GUID(GUID_PKPixelFormat24bppRGB, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0d);
/* 32bpp format */
DEFINE_GUID(GUID_PKPixelFormat32bppBGR, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0e);
DEFINE_GUID(GUID_PKPixelFormat32bppBGRA, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x0f);
DEFINE_GUID(GUID_PKPixelFormat32bppPBGRA, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x10);
DEFINE_GUID(GUID_PKPixelFormat32bppGrayFloat, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x11);
DEFINE_GUID(GUID_PKPixelFormat32bppRGB, 0xd98c6b95, 0x3efe, 0x47d6, 0xbb, 0x25, 0xeb, 0x17, 0x48, 0xab, 0x0c, 0xf1);
DEFINE_GUID(GUID_PKPixelFormat32bppRGBA, 0xf5c7ad2d, 0x6a8d, 0x43dd, 0xa7, 0xa8, 0xa2, 0x99, 0x35, 0x26, 0x1a, 0xe9);
DEFINE_GUID(GUID_PKPixelFormat32bppPRGBA, 0x3cc4a650, 0xa527, 0x4d37, 0xa9, 0x16, 0x31, 0x42, 0xc7, 0xeb, 0xed, 0xba);
/* 48bpp format */
DEFINE_GUID(GUID_PKPixelFormat48bppRGBFixedPoint, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x12);
/* scRGB formats. Gamma is 1.0 */
/* For a full definition, see the scRGB spec */
/* 16bpp format */
DEFINE_GUID(GUID_PKPixelFormat16bppGrayFixedPoint, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x13);
/* 32bpp format */
DEFINE_GUID(GUID_PKPixelFormat32bppRGB101010, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x14);
/* 48bpp format */
DEFINE_GUID(GUID_PKPixelFormat48bppRGB, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x15);
/* 64bpp format */
DEFINE_GUID(GUID_PKPixelFormat64bppRGBA, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x16);
DEFINE_GUID(GUID_PKPixelFormat64bppPRGBA, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x17);
/* 96bpp format */
DEFINE_GUID(GUID_PKPixelFormat96bppRGBFixedPoint, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x18);
DEFINE_GUID(GUID_PKPixelFormat96bppRGBFloat, 0xe3fed78f, 0xe8db, 0x4acf, 0x84, 0xc1, 0xe9, 0x7f, 0x61, 0x36, 0xb3, 0x27);
/* Floating point scRGB formats */
DEFINE_GUID(GUID_PKPixelFormat128bppRGBAFloat, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x19);
DEFINE_GUID(GUID_PKPixelFormat128bppPRGBAFloat, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1a);
DEFINE_GUID(GUID_PKPixelFormat128bppRGBFloat, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1b);
/* CMYK formats. */
DEFINE_GUID(GUID_PKPixelFormat32bppCMYK, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1c);
/* Photon formats */
DEFINE_GUID(GUID_PKPixelFormat64bppRGBAFixedPoint, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1d);
DEFINE_GUID(GUID_PKPixelFormat64bppRGBFixedPoint, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x40);
DEFINE_GUID(GUID_PKPixelFormat128bppRGBAFixedPoint, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1e);
DEFINE_GUID(GUID_PKPixelFormat128bppRGBFixedPoint, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x41);
DEFINE_GUID(GUID_PKPixelFormat64bppRGBAHalf, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3a);
DEFINE_GUID(GUID_PKPixelFormat64bppRGBHalf, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x42);
DEFINE_GUID(GUID_PKPixelFormat48bppRGBHalf, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3b);
DEFINE_GUID(GUID_PKPixelFormat32bppRGBE, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3d);
DEFINE_GUID(GUID_PKPixelFormat16bppGrayHalf, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3e);
DEFINE_GUID(GUID_PKPixelFormat32bppGrayFixedPoint, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x3f);
/* More CMYK formats and n-Channel formats */
DEFINE_GUID(GUID_PKPixelFormat64bppCMYK, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x1f);
DEFINE_GUID(GUID_PKPixelFormat24bpp3Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x20);
DEFINE_GUID(GUID_PKPixelFormat32bpp4Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x21);
DEFINE_GUID(GUID_PKPixelFormat40bpp5Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x22);
DEFINE_GUID(GUID_PKPixelFormat48bpp6Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x23);
DEFINE_GUID(GUID_PKPixelFormat56bpp7Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x24);
DEFINE_GUID(GUID_PKPixelFormat64bpp8Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x25);
DEFINE_GUID(GUID_PKPixelFormat48bpp3Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x26);
DEFINE_GUID(GUID_PKPixelFormat64bpp4Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x27);
DEFINE_GUID(GUID_PKPixelFormat80bpp5Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x28);
DEFINE_GUID(GUID_PKPixelFormat96bpp6Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x29);
DEFINE_GUID(GUID_PKPixelFormat112bpp7Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2a);
DEFINE_GUID(GUID_PKPixelFormat128bpp8Channels, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2b);
DEFINE_GUID(GUID_PKPixelFormat40bppCMYKAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2c);
DEFINE_GUID(GUID_PKPixelFormat80bppCMYKAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2d);
DEFINE_GUID(GUID_PKPixelFormat32bpp3ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2e);
DEFINE_GUID(GUID_PKPixelFormat40bpp4ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x2f);
DEFINE_GUID(GUID_PKPixelFormat48bpp5ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x30);
DEFINE_GUID(GUID_PKPixelFormat56bpp6ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x31);
DEFINE_GUID(GUID_PKPixelFormat64bpp7ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x32);
DEFINE_GUID(GUID_PKPixelFormat72bpp8ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x33);
DEFINE_GUID(GUID_PKPixelFormat64bpp3ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x34);
DEFINE_GUID(GUID_PKPixelFormat80bpp4ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x35);
DEFINE_GUID(GUID_PKPixelFormat96bpp5ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x36);
DEFINE_GUID(GUID_PKPixelFormat112bpp6ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x37);
DEFINE_GUID(GUID_PKPixelFormat128bpp7ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x38);
DEFINE_GUID(GUID_PKPixelFormat144bpp8ChannelsAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x39);
/* YCrCb from Advanced Profile */
DEFINE_GUID(GUID_PKPixelFormat12bppYCC420, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x44);
DEFINE_GUID(GUID_PKPixelFormat16bppYCC422, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x45);
DEFINE_GUID(GUID_PKPixelFormat20bppYCC422, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x46);
DEFINE_GUID(GUID_PKPixelFormat32bppYCC422, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x47);
DEFINE_GUID(GUID_PKPixelFormat24bppYCC444, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x48);
DEFINE_GUID(GUID_PKPixelFormat30bppYCC444, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x49);
DEFINE_GUID(GUID_PKPixelFormat48bppYCC444, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x4a);
DEFINE_GUID(GUID_PKPixelFormat16bpp48bppYCC444FixedPoint, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x4b);
DEFINE_GUID(GUID_PKPixelFormat20bppYCC420Alpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x4c);
DEFINE_GUID(GUID_PKPixelFormat24bppYCC422Alpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x4d);
DEFINE_GUID(GUID_PKPixelFormat30bppYCC422Alpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x4e);
DEFINE_GUID(GUID_PKPixelFormat48bppYCC422Alpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x4f);
DEFINE_GUID(GUID_PKPixelFormat32bppYCC444Alpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x50);
DEFINE_GUID(GUID_PKPixelFormat40bppYCC444Alpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x51);
DEFINE_GUID(GUID_PKPixelFormat64bppYCC444Alpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x52);
DEFINE_GUID(GUID_PKPixelFormat64bppYCC444AlphaFixedPoint, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x53);
//YUV
#define GUID_PKPixelFormat12bppYUV420 GUID_PKPixelFormat12bppYCC420
#define GUID_PKPixelFormat16bppYUV422 GUID_PKPixelFormat16bppYCC422
#define GUID_PKPixelFormat24bppYUV444 GUID_PKPixelFormat24bppYCC444
/* CMYKDIRECT from Advanced Profile */
DEFINE_GUID(GUID_PKPixelFormat32bppCMYKDIRECT, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x54);
DEFINE_GUID(GUID_PKPixelFormat64bppCMYKDIRECT, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x55);
DEFINE_GUID(GUID_PKPixelFormat40bppCMYKDIRECTAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x56);
DEFINE_GUID(GUID_PKPixelFormat80bppCMYKDIRECTAlpha, 0x6fddc324, 0x4e03, 0x4bfe, 0xb1, 0x85, 0x3d, 0x77, 0x76, 0x8d, 0xc9, 0x43);
// PhotometricInterpretation
#define PK_PI_W0 0 // WhiteIsZero
#define PK_PI_B0 1 // BlackIsZero
#define PK_PI_RGB 2
#define PK_PI_RGBPalette 3
#define PK_PI_TransparencyMask 4
#define PK_PI_CMYK 5
#define PK_PI_YCbCr 6
#define PK_PI_CIELab 8
#define PK_PI_NCH 100
#define PK_PI_RGBE 101
#define PK_pixfmtNul 0x00000000
#define PK_pixfmtHasAlpha 0x00000010
#define PK_pixfmtPreMul 0x00000020
#define PK_pixfmtBGR 0x00000040
#define PK_pixfmtNeedConvert 0x80000000
#define LOOKUP_FORWARD 0
#define LOOKUP_BACKWARD_TIF 1
typedef unsigned long WMP_GRBIT;
typedef GUID PKPixelFormatGUID;
typedef struct tagPKPixelInfo
{
const PKPixelFormatGUID* pGUIDPixFmt;
size_t cChannel;
COLORFORMAT cfColorFormat;
BITDEPTH_BITS bdBitDepth;
U32 cbitUnit;
WMP_GRBIT grBit;
// TIFF
U32 uInterpretation;
U32 uSamplePerPixel;
U32 uBitsPerSample;
U32 uSampleFormat;
} PKPixelInfo;
//================================================================
ERR PKAlloc(void** ppv, size_t cb);
ERR PKFree(void** ppv);
//----------------------------------------------------------------
//ERR GetPixelInfo(PKPixelFormatGUID enPixelFormat, const PKPixelInfo** ppPI);
ERR PixelFormatLookup(PKPixelInfo* pPI, U8 uLookupType);
const PKPixelFormatGUID* GetPixelFormatFromHash(const U8 uPFHash);
ERR GetImageEncodeIID(const char* szExt, const PKIID** ppIID);
ERR GetImageDecodeIID(const char* szExt, const PKIID** ppIID);
//================================================================
#ifdef __ANSI__
struct tagPKFactory;
struct tagPKCodecFactory;
struct tagPKImageDecode;
struct tagPKImageEncode;
struct tagPKFormatConverter;
#define PKFactory struct tagPKFactory
#define PKCodecFactory struct tagPKCodecFactory
#define PKImageDecode struct tagPKImageDecode
#define PKImageEncode struct tagPKImageEncode
#define PKFormatConverter struct tagPKFormatConverter
#else // __ANSI__
typedef struct tagPKFactory PKFactory;
typedef struct tagPKCodecFactory PKCodecFactory;
typedef struct tagPKImageDecode PKImageDecode;
typedef struct tagPKImageEncode PKImageEncode;
typedef struct tagPKFormatConverter PKFormatConverter;
#endif // __ANSI__
//================================================================
typedef struct tagPKStream
{
ERR (*InitializeFromFilename)(const char*, ULong);
ERR (*Release)(void);
FILE* fp;
} PKStream;
//================================================================
typedef struct tagPKFactory
{
ERR (*CreateStream)(PKStream**);
ERR (*CreateStreamFromFilename)(struct WMPStream**, const char*, const char*);
ERR (*CreateStreamFromMemory)(struct WMPStream**, void*, size_t);
ERR (*Release)(PKFactory**);
#ifdef __ANSI__
#undef PKFactory
#endif // __ANSI__
} PKFactory;
//----------------------------------------------------------------
ERR PKCreateFactory_CreateStream(PKStream** ppStream);
ERR PKCreateFactory_Release(PKFactory** ppFactory);
EXTERN_C ERR PKCreateFactory(PKFactory**, U32);
//================================================================
typedef struct tagPKCodecFactory
{
ERR (*CreateCodec)(const PKIID*, void**);
ERR (*CreateDecoderFromFile)(const char*, PKImageDecode**);
ERR (*CreateFormatConverter)(PKFormatConverter**);
ERR (*Release)(PKCodecFactory**);
#ifdef __ANSI__
#undef PKCodecFactory
#endif // __ANSI__
} PKCodecFactory;
//----------------------------------------------------------------
ERR PKCodecFactory_CreateCodec(const PKIID* iid, void** ppv);
ERR PKCreateCodecFactory_Release(PKCodecFactory** ppCFactory);
EXTERN_C ERR PKCreateCodecFactory(PKCodecFactory**, U32);
//================================================================
typedef enum BANDEDENCSTATE
{
BANDEDENCSTATE_UNINITIALIZED = 0,
BANDEDENCSTATE_INIT,
BANDEDENCSTATE_ENCODING,
BANDEDENCSTATE_TERMINATED,
BANDEDENCSTATE_NONBANDEDENCODE,
} BANDEDENCSTATE;
typedef struct tagPKImageEncode
{
//ERR (*GetPixelFormat)(MILPixelFormat*));
ERR (*Initialize)(PKImageEncode*, struct WMPStream*, void*, size_t);
ERR (*Terminate)(PKImageEncode*);
ERR (*SetPixelFormat)(PKImageEncode*, PKPixelFormatGUID);
ERR (*SetSize)(PKImageEncode*, I32, I32);
ERR (*SetResolution)(PKImageEncode*, Float, Float);
ERR (*SetColorContext)(PKImageEncode *pIE, const U8 *pbColorContext,
U32 cbColorContext);
ERR (*SetDescriptiveMetadata)(PKImageEncode *pIE,
const DESCRIPTIVEMETADATA *pDescMetadata);
ERR (*WritePixels)(PKImageEncode*, U32, U8*, U32);
ERR (*WriteSource)(PKImageEncode*, PKFormatConverter*, PKRect*);
// Banded encode API - currently only implemented for WMP encoder
ERR (*WritePixelsBandedBegin)(PKImageEncode* pEncoder, struct WMPStream *pPlanarAlphaTempFile);
ERR (*WritePixelsBanded)(PKImageEncode* pEncoder, U32 cLines, U8* pbPixels, U32 cbStride, Bool fLastCall);
ERR (*WritePixelsBandedEnd)(PKImageEncode* pEncoder);
#define TEMPFILE_COPYBUF_SIZE 8192 // Means when using tempfile for planar alpha banded encode, copy this many bytes at a time
ERR (*Transcode)(PKImageEncode*, PKImageDecode*, CWMTranscodingParam*);
ERR (*CreateNewFrame)(PKImageEncode*, void*, size_t);
ERR (*Release)(PKImageEncode**);
struct WMPStream* pStream;
size_t offStart;
PKPixelFormatGUID guidPixFormat;
U32 uWidth;
U32 uHeight;
U32 idxCurrentLine;
Float fResX;
Float fResY;
U32 cFrame;
Bool fHeaderDone;
size_t offPixel;
size_t cbPixel;
U8 *pbColorContext;
U32 cbColorContext;
U8 *pbEXIFMetadata;
U32 cbEXIFMetadataByteCount;
U8 *pbGPSInfoMetadata;
U32 cbGPSInfoMetadataByteCount;
U8 *pbIPTCNAAMetadata;
U32 cbIPTCNAAMetadataByteCount;
U8 *pbXMPMetadata;
U32 cbXMPMetadataByteCount;
U8 *pbPhotoshopMetadata;
U32 cbPhotoshopMetadataByteCount;
DESCRIPTIVEMETADATA sDescMetadata;
Bool bWMP;//for the encoder in decoding
struct
{
WmpDEMisc wmiDEMisc;
CWMImageInfo wmiI;
CWMIStrCodecParam wmiSCP;
CTXSTRCODEC ctxSC;
CWMImageInfo wmiI_Alpha;
CWMIStrCodecParam wmiSCP_Alpha;
CTXSTRCODEC ctxSC_Alpha;
Bool bHasAlpha;
Long nOffImage;
Long nCbImage;
Long nOffAlpha;
Long nCbAlpha;
ORIENTATION oOrientation;
// Banded encode state variables
BANDEDENCSTATE eBandedEncState;
struct WMPStream *pPATempFile;
} WMP;
#ifdef __ANSI__
#undef PKImageEncode
#endif // __ANSI__
} PKImageEncode;
//----------------------------------------------------------------
ERR PKImageEncode_Create_WMP(PKImageEncode** ppIE);
ERR PKImageEncode_Initialize(PKImageEncode* pIE, struct WMPStream* pStream, void* pvParam, size_t cbParam);
ERR PKImageEncode_Terminate(PKImageEncode* pIE);
ERR PKImageEncode_SetPixelFormat(PKImageEncode* pIE, PKPixelFormatGUID enPixelFormat);
ERR PKImageEncode_SetSize(PKImageEncode* pIE, I32 iWidth, I32 iHeight);
ERR PKImageEncode_SetResolution(PKImageEncode* pIE, Float rX, Float rY);
ERR PKImageEncode_SetColorContext(PKImageEncode *pIE, const U8 *pbColorContext, U32 cbColorContext);
ERR PKImageEncode_SetDescriptiveMetadata(PKImageEncode *pIE, const DESCRIPTIVEMETADATA *pDescMetadata);
ERR PKImageEncode_WritePixels(PKImageEncode* pIE, U32 cLine, U8* pbPixel, U32 cbStride);
ERR PKImageEncode_CreateNewFrame(PKImageEncode* pIE, void* pvParam, size_t cbParam);
ERR PKImageEncode_Release(PKImageEncode** ppIE);
ERR PKImageEncode_SetXMPMetadata_WMP(PKImageEncode *pIE, const U8 *pbXMPMetadata, U32 cbXMPMetadata);
ERR PKImageEncode_SetEXIFMetadata_WMP(PKImageEncode *pIE, const U8 *pbEXIFMetadata, U32 cbEXIFMetadata);
ERR PKImageEncode_SetGPSInfoMetadata_WMP(PKImageEncode *pIE, const U8 *pbGPSInfoMetadata, U32 cbGPSInfoMetadata);
ERR PKImageEncode_SetIPTCNAAMetadata_WMP(PKImageEncode *pIE, const U8 *pbIPTCNAAMetadata, U32 cbIPTCNAAMetadata);
ERR PKImageEncode_SetPhotoshopMetadata_WMP(PKImageEncode *pIE, const U8 *pbPhotoshopMetadata, U32 cbPhotoshopMetadata);
void FreeDescMetadata(DPKPROPVARIANT *pvar);
ERR PKImageEncode_Create(PKImageEncode** ppIE);
//================================================================
typedef struct tagPKImageDecode
{
ERR (*Initialize)(PKImageDecode*, struct WMPStream* pStream);
ERR (*GetPixelFormat)(PKImageDecode*, PKPixelFormatGUID*);
ERR (*GetSize)(PKImageDecode*, I32*, I32*);
ERR (*GetResolution)(PKImageDecode*, Float*, Float*);
ERR (*GetColorContext)(PKImageDecode *pID, U8 *pbColorContext,
U32 *pcbColorContext);
ERR (*GetDescriptiveMetadata)(PKImageDecode *pIE,
DESCRIPTIVEMETADATA *pDescMetadata);
ERR (*GetRawStream)(PKImageDecode*, struct WMPStream**);
ERR (*Copy)(PKImageDecode*, const PKRect*, U8*, U32);
ERR (*GetFrameCount)(PKImageDecode*, U32*);
ERR (*SelectFrame)(PKImageDecode*, U32);
ERR (*Release)(PKImageDecode**);
struct WMPStream* pStream;
Bool fStreamOwner;
size_t offStart;
PKPixelFormatGUID guidPixFormat;
U32 uWidth;
U32 uHeight;
U32 idxCurrentLine;
Float fResX;
Float fResY;
U32 cFrame;
struct
{
WmpDEMisc wmiDEMisc;
CWMImageInfo wmiI;
CWMIStrCodecParam wmiSCP;
CTXSTRCODEC ctxSC;
CWMImageInfo wmiI_Alpha;
CWMIStrCodecParam wmiSCP_Alpha;
CTXSTRCODEC ctxSC_Alpha;
Bool bHasAlpha;
Long nOffImage;
Long nCbImage;
Long nOffAlpha;
Long nCbAlpha;
Bool bIgnoreOverlap;
size_t DecoderCurrMBRow;
size_t DecoderCurrAlphaMBRow;
size_t cMarker;
size_t cLinesDecoded;
size_t cLinesCropped; // Lines may be cropped from the top - buffer for subsequent decodes must be adjusted
Bool fFirstNonZeroDecode;
Bool fOrientationFromContainer;
ORIENTATION oOrientationFromContainer; // Tag 0xBC02 in HD Photo container
DESCRIPTIVEMETADATA sDescMetadata;
} WMP;
#ifdef __ANSI__
#undef PKImageDecode
#endif // __ANSI__
} PKImageDecode;
//----------------------------------------------------------------
ERR PKImageDecode_Create_WMP(PKImageDecode** ppID);
ERR PKImageDecode_Initialize(PKImageDecode* pID, struct WMPStream* pStream);
ERR PKImageDecode_GetPixelFormat(PKImageDecode* pID, PKPixelFormatGUID* pPF);
ERR PKImageDecode_GetSize(PKImageDecode* pID, I32* piWidth, I32* piHeight);
ERR PKImageDecode_GetResolution(PKImageDecode* pID, Float* pfrX, Float* pfrY);
ERR PKImageDecode_GetColorContext(PKImageDecode *pID, U8 *pbColorContext, U32 *pcbColorContext);
ERR PKImageDecode_GetDescriptiveMetadata(PKImageDecode *pID, DESCRIPTIVEMETADATA *pDescMetadata);
ERR PKImageDecode_Copy(PKImageDecode* pID, const PKRect* pRect, U8* pb, U32 cbStride);
ERR PKImageDecode_GetFrameCount(PKImageDecode* pID, U32* puCount);
ERR PKImageDecode_SelectFrame(PKImageDecode* pID, U32 uFrame);
ERR PKImageDecode_Release(PKImageDecode** ppID);
ERR PKImageDecode_Create(PKImageDecode** ppID);
ERR PKCodecFactory_CreateDecoderFromFile(const char* szFilename, PKImageDecode** ppDecoder);
//================================================================
typedef struct tagPKFormatConverter
{
ERR (*Initialize)(PKFormatConverter*, PKImageDecode*, char *pExt, PKPixelFormatGUID);
ERR (*InitializeConvert)(PKFormatConverter* pFC, const PKPixelFormatGUID enPFFrom,
char *pExt, PKPixelFormatGUID enPFTTo);
ERR (*GetPixelFormat)(PKFormatConverter*, PKPixelFormatGUID*);
ERR (*GetSourcePixelFormat)(PKFormatConverter*, PKPixelFormatGUID*);
ERR (*GetSize)(PKFormatConverter*, I32*, I32*);
ERR (*GetResolution)(PKFormatConverter*, Float*, Float*);
ERR (*Copy)(PKFormatConverter*, const PKRect*, U8*, U32);
ERR (*Convert)(PKFormatConverter*, const PKRect*, U8*, U32);
ERR (*Release)(PKFormatConverter**);
PKImageDecode* pDecoder;
PKPixelFormatGUID enPixelFormat;
#ifdef __ANSI__
#undef PKFormatConverter
#endif // __ANSI__
} PKFormatConverter;
//----------------------------------------------------------------
ERR PKImageEncode_Transcode(PKImageEncode* pIE, PKFormatConverter* pFC, PKRect* pRect);
ERR PKImageEncode_WriteSource(PKImageEncode* pIE, PKFormatConverter* pFC, PKRect* pRect);
ERR PKFormatConverter_Initialize(PKFormatConverter* pFC, PKImageDecode* pID, char *pExt, PKPixelFormatGUID enPF);
ERR PKFormatConverter_InitializeConvert(PKFormatConverter* pFC, const PKPixelFormatGUID enPFFrom,
char *pExt, PKPixelFormatGUID enPFTo);
ERR PKFormatConverter_GetPixelFormat(PKFormatConverter* pFC, PKPixelFormatGUID* pPF);
ERR PKFormatConverter_GetSourcePixelFormat(PKFormatConverter* pFC, PKPixelFormatGUID* pPF);
ERR PKFormatConverter_GetSize(PKFormatConverter* pFC, I32* piWidth, I32* piHeight);
ERR PKFormatConverter_GetResolution(PKFormatConverter* pFC, Float* pfrX, Float* pfrY);
ERR PKFormatConverter_Copy(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride);
ERR PKFormatConverter_Convert(PKFormatConverter* pFC, const PKRect* pRect, U8* pb, U32 cbStride);
ERR PKFormatConverter_Release(PKFormatConverter** ppFC);
// Think of this as static member of PKFormatConverter "class"
ERR PKFormatConverter_EnumConversions(const PKPixelFormatGUID *pguidSourcePF,
const U32 iIndex,
const PKPixelFormatGUID **ppguidTargetPF);
ERR PKCodecFactory_CreateFormatConverter(PKFormatConverter** ppFConverter);
//----------------------------------------------------------------
ERR PKAlloc(void** ppv, size_t cb);
ERR PKFree(void** ppv);
ERR PKAllocAligned(void** ppv, size_t cb, size_t iAlign);
ERR PKFreeAligned(void** ppv);
#ifdef __cplusplus
} // extern "C"
#endif

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,178 @@
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<ItemGroup Label="ProjectConfigurations">
<ProjectConfiguration Include="Debug|Win32">
<Configuration>Debug</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Debug|x64">
<Configuration>Debug</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|Win32">
<Configuration>Release</Configuration>
<Platform>Win32</Platform>
</ProjectConfiguration>
<ProjectConfiguration Include="Release|x64">
<Configuration>Release</Configuration>
<Platform>x64</Platform>
</ProjectConfiguration>
</ItemGroup>
<PropertyGroup Label="Globals">
<ProjectName>JXRGlueLib</ProjectName>
<ProjectGuid>{A69603CC-65E8-443F-8E31-737DBD6BB0DB}</ProjectGuid>
<RootNamespace>JXRGlueLib</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
<CharacterSet>MultiByte</CharacterSet>
<PlatformToolset>v110</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<ImportGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="PropertySheets">
<Import Project="$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props" Condition="exists('$(UserRootDir)\Microsoft.Cpp.$(Platform).user.props')" Label="LocalAppDataPlatform" />
<Import Project="$(VCTargetsPath)Microsoft.CPP.UpgradeFromVC71.props" />
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup>
<_ProjectFileVersion>10.0.30319.1</_ProjectFileVersion>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(Configuration)/$(ProjectName)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(OutDir)</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(Configuration)\$(ProjectName)\$(Platform)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(OutDir)</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(Configuration)/$(ProjectName)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(OutDir)</IntDir>
<OutDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(Configuration)\$(ProjectName)\$(Platform)\</OutDir>
<IntDir Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(OutDir)</IntDir>
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" />
<CodeAnalysisRuleSet Condition="'$(Configuration)|$(Platform)'=='Release|x64'">AllRules.ruleset</CodeAnalysisRuleSet>
<CodeAnalysisRules Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
<CodeAnalysisRuleAssemblies Condition="'$(Configuration)|$(Platform)'=='Release|x64'" />
</PropertyGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\image\sys;..\image\x86;..\JXRGlueLib;..\common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)$(ProjectName).lib</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<Optimization>Disabled</Optimization>
<AdditionalIncludeDirectories>..\image\sys;..\image\x86;..\JXRGlueLib;..\common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;_DEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<MinimalRebuild>true</MinimalRebuild>
<BasicRuntimeChecks>EnableFastChecks</BasicRuntimeChecks>
<RuntimeLibrary>MultiThreadedDebug</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)$(ProjectName).lib</OutputFile>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
<ClCompile>
<Optimization>MaxSpeed</Optimization>
<WholeProgramOptimization>true</WholeProgramOptimization>
<AdditionalIncludeDirectories>..\image\sys;..\image\x86;..\JXRGlueLib;..\common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;ENABLE_OPTIMIZATIONS;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
</ClCompile>
<Lib>
<AdditionalOptions>/LTCG %(AdditionalOptions)</AdditionalOptions>
<OutputFile>$(OutDir)$(ProjectName).lib</OutputFile>
<LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
<Midl>
<TargetEnvironment>X64</TargetEnvironment>
</Midl>
<ClCompile>
<AdditionalIncludeDirectories>..\image\sys;..\image\x86;..\JXRGlueLib;..\common\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<PreprocessorDefinitions>WIN32;NDEBUG;_LIB;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<RuntimeLibrary>MultiThreaded</RuntimeLibrary>
<PrecompiledHeader>
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<DebugInformationFormat>ProgramDatabase</DebugInformationFormat>
<WholeProgramOptimization>true</WholeProgramOptimization>
</ClCompile>
<Lib>
<OutputFile>$(OutDir)$(ProjectName).lib</OutputFile>
<LinkTimeCodeGeneration>true</LinkTimeCodeGeneration>
</Lib>
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="JXRGlue.c" />
<ClCompile Include="JXRGluePFC.c" />
<ClCompile Include="JXRGlueJxr.c" />
<ClCompile Include="JXRMeta.c" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="JXRGlue.h" />
<ClInclude Include="JXRMeta.h" />
</ItemGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
</Project>

File diff suppressed because it is too large Load diff

905
jxrlib/jxrgluelib/JXRMeta.c Normal file
View file

@ -0,0 +1,905 @@
//*@@@+++@@@@******************************************************************
//
// Copyright © Microsoft Corp.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// • Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// • Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//*@@@---@@@@******************************************************************
#include "JXRMeta.h"
#include "JXRGlue.h"
// read and write big and little endian words/dwords from a buffer on both big and little endian cpu's
// with full buffer overflow checking
ERR getbfcpy(U8* pbdest, const U8* pb, size_t cb, size_t ofs, U32 n)
{
ERR err = WMP_errSuccess;
FailIf(ofs + n > cb, WMP_errBufferOverflow);
memcpy(pbdest, &pb[ofs], n);
Cleanup:
return err;
}
ERR getbfw(const U8* pb, size_t cb, size_t ofs, U16* pw)
{
ERR err = WMP_errSuccess;
FailIf(ofs + sizeof(U16) > cb, WMP_errBufferOverflow);
*pw = (U16)( pb[ofs] + ( pb[ofs + 1] << 8 ) );
Cleanup:
return err;
}
ERR getbfdw(const U8* pb, size_t cb, size_t ofs, U32* pdw)
{
ERR err = WMP_errSuccess;
FailIf(ofs + sizeof(U32) > cb, WMP_errBufferOverflow);
*pdw = pb[ofs] + ( pb[ofs + 1] << 8 ) + ( pb[ofs + 2] << 16UL ) + ( pb[ofs + 3] << 24UL );
Cleanup:
return err;
}
ERR getbfwbig(const U8* pb, size_t cb, size_t ofs, U16* pw)
{
ERR err = WMP_errSuccess;
FailIf(ofs + sizeof(U16) > cb, WMP_errBufferOverflow);
*pw = (U16)( pb[ofs + 1] + ( pb[ofs] << 8 ) );
Cleanup:
return err;
}
ERR getbfdwbig(const U8* pb, size_t cb, size_t ofs, U32* pdw)
{
ERR err = WMP_errSuccess;
FailIf(ofs + sizeof(U32) > cb, WMP_errBufferOverflow);
*pdw = pb[ofs + 3] + ( pb[ofs + 2] << 8 ) + ( pb[ofs + 1] << 16UL ) + ( pb[ofs] << 24UL );
Cleanup:
return err;
}
ERR getbfwe(const U8* pb, size_t cb, size_t ofs, U16* pw, U8 endian)
{
if ( endian == WMP_INTEL_ENDIAN )
return ( getbfw(pb, cb, ofs, pw) );
else
return ( getbfwbig(pb, cb, ofs, pw) );
}
ERR getbfdwe(const U8* pb, size_t cb, size_t ofs, U32* pdw, U8 endian)
{
if ( endian == WMP_INTEL_ENDIAN )
return ( getbfdw(pb, cb, ofs, pdw) );
else
return ( getbfdwbig(pb, cb, ofs, pdw) );
}
ERR setbfcpy(U8* pb, size_t cb, size_t ofs, const U8* pbset, size_t cbset)
{
ERR err = WMP_errSuccess;
FailIf(ofs + cbset > cb, WMP_errBufferOverflow);
memcpy(&pb[ofs], pbset, cbset);
Cleanup:
return err;
}
ERR setbfw(U8* pb, size_t cb, size_t ofs, U16 dw)
{
ERR err = WMP_errSuccess;
FailIf(ofs + sizeof(U16) > cb, WMP_errBufferOverflow);
pb[ofs] = (U8)dw;
pb[ofs + 1] = (U8)( dw >> 8 );
Cleanup:
return err;
}
ERR setbfdw(U8* pb, size_t cb, size_t ofs, U32 dw)
{
ERR err = WMP_errSuccess;
FailIf(ofs + sizeof(U32) > cb, WMP_errBufferOverflow);
pb[ofs] = (U8)dw;
pb[ofs + 1] = (U8)( dw >> 8 );
pb[ofs + 2] = (U8)( dw >> 16 );
pb[ofs + 3] = (U8)( dw >> 24 );
Cleanup:
return err;
}
ERR setbfwbig(U8* pb, size_t cb, size_t ofs, U16 dw)
{
ERR err = WMP_errSuccess;
FailIf(ofs + sizeof(U16) > cb, WMP_errBufferOverflow);
pb[ofs + 1] = (U8)dw;
pb[ofs] = (U8)( dw >> 8 );
Cleanup:
return err;
}
ERR setbfdwbig(U8* pb, size_t cb, size_t ofs, U32 dw)
{
ERR err = WMP_errSuccess;
FailIf(ofs + sizeof(U32) > cb, WMP_errBufferOverflow);
pb[ofs + 3] = (U8)dw;
pb[ofs + 2] = (U8)( dw >> 8 );
pb[ofs + 1] = (U8)( dw >> 16 );
pb[ofs] = (U8)( dw >> 24 );
Cleanup:
return err;
}
//================================================================
// BufferCalcIFDSize (arbitrary endian)
// StreamCalcIFDSize (little endian)
//
// count up the number of bytes needed to store the IFD and all
// associated data including a subordinate interoperability IFD if any
//================================================================
ERR BufferCalcIFDSize(const U8* pbdata, size_t cbdata, U32 ofsifd, U8 endian, U32* pcbifd)
{
ERR err = WMP_errSuccess;
U16 cDir;
U16 i;
U32 ofsdir;
U32 cbifd = 0;
U32 cbEXIFIFD = 0;
U32 cbGPSInfoIFD = 0;
U32 cbInteroperabilityIFD = 0;
*pcbifd = 0;
Call(getbfwe(pbdata, cbdata, ofsifd, &cDir, endian));
cbifd = sizeof(U16) + cDir * SizeofIFDEntry + sizeof(U32);
ofsdir = ofsifd + sizeof(U16);
for ( i = 0; i < cDir; i++ )
{
U16 tag;
U16 type;
U32 count;
U32 value;
U32 datasize;
Call(getbfwe(pbdata, cbdata, ofsdir, &tag, endian));
Call(getbfwe(pbdata, cbdata, ofsdir + sizeof(U16), &type, endian));
Call(getbfdwe(pbdata, cbdata, ofsdir + 2 * sizeof(U16), &count, endian));
Call(getbfdwe(pbdata, cbdata, ofsdir + 2 * sizeof(U16) + sizeof(U32), &value, endian));
FailIf(type == 0 || type >= sizeof(IFDEntryTypeSizes) / sizeof(IFDEntryTypeSizes[0]), WMP_errFail);
if ( tag == WMP_tagEXIFMetadata )
{
Call(BufferCalcIFDSize(pbdata, cbdata, value, endian, &cbEXIFIFD));
}
else if ( tag == WMP_tagGPSInfoMetadata )
{
Call(BufferCalcIFDSize(pbdata, cbdata, value, endian, &cbGPSInfoIFD));
}
else if ( tag == WMP_tagInteroperabilityIFD )
{
Call(BufferCalcIFDSize(pbdata, cbdata, value, endian, &cbInteroperabilityIFD));
}
else
{
datasize = IFDEntryTypeSizes[type] * count;
if ( datasize > 4 )
cbifd += datasize;
}
ofsdir += SizeofIFDEntry;
}
if ( cbEXIFIFD != 0 )
cbifd += ( cbifd & 1 ) + cbEXIFIFD;
if ( cbGPSInfoIFD != 0 )
cbifd += ( cbifd & 1 ) + cbGPSInfoIFD;
if ( cbInteroperabilityIFD != 0 )
cbifd += ( cbifd & 1 ) + cbInteroperabilityIFD;
*pcbifd = cbifd;
Cleanup:
return err;
}
ERR StreamCalcIFDSize(struct WMPStream* pWS, U32 uIFDOfs, U32 *pcbifd)
{
ERR err = WMP_errSuccess;
size_t offCurPos = 0;
Bool GetPosOK = FALSE;
U16 cDir;
U32 i;
U32 ofsdir;
U32 cbifd = 0;
U32 cbEXIFIFD = 0;
U32 cbGPSInfoIFD = 0;
U32 cbInteroperabilityIFD = 0;
*pcbifd = 0;
Call(pWS->GetPos(pWS, &offCurPos));
GetPosOK = TRUE;
Call(GetUShort(pWS, uIFDOfs, &cDir));
cbifd = sizeof(U16) + cDir * SizeofIFDEntry + sizeof(U32);
ofsdir = uIFDOfs + sizeof(U16);
for ( i = 0; i < cDir; i++ )
{
U16 tag;
U16 type;
U32 count;
U32 value;
U32 datasize;
Call(GetUShort(pWS, ofsdir, &tag));
Call(GetUShort(pWS, ofsdir + sizeof(U16), &type));
Call(GetULong(pWS, ofsdir + 2 * sizeof(U16), &count));
Call(GetULong(pWS, ofsdir + 2 * sizeof(U16) + sizeof(U32), &value));
FailIf(type == 0 || type >= sizeof(IFDEntryTypeSizes) / sizeof(IFDEntryTypeSizes[0]), WMP_errUnsupportedFormat);
if ( tag == WMP_tagEXIFMetadata )
{
Call(StreamCalcIFDSize(pWS, value, &cbEXIFIFD));
}
else if ( tag == WMP_tagGPSInfoMetadata )
{
Call(StreamCalcIFDSize(pWS, value, &cbGPSInfoIFD));
}
else if ( tag == WMP_tagInteroperabilityIFD )
{
Call(StreamCalcIFDSize(pWS, value, &cbInteroperabilityIFD));
}
else
{
datasize = IFDEntryTypeSizes[type] * count;
if ( datasize > 4 )
cbifd += datasize;
}
ofsdir += SizeofIFDEntry;
}
if ( cbEXIFIFD != 0 )
cbifd += ( cbifd & 1 ) + cbEXIFIFD;
if ( cbGPSInfoIFD != 0 )
cbifd += ( cbifd & 1 ) + cbGPSInfoIFD;
if ( cbInteroperabilityIFD != 0 )
cbifd += ( cbifd & 1 ) + cbInteroperabilityIFD;
*pcbifd = cbifd;
Cleanup:
if ( GetPosOK )
Call(pWS->SetPos(pWS, offCurPos));
return ( err );
}
// src IFD copied to dst IFD with any nested IFD's
// src IFD is arbitrary endian, arbitrary data arrangement
// dst IFD is little endian, data arranged in tag order
// dst IFD tags are ordered the same as src IFD so src IFD tags must be in order
ERR BufferCopyIFD(const U8* pbsrc, U32 cbsrc, U32 ofssrc, U8 endian, U8* pbdst, U32 cbdst, U32* pofsdst)
{
ERR err = WMP_errSuccess;
U16 cDir;
U16 i;
U16 ofsEXIFIFDEntry = 0;
U16 ofsGPSInfoIFDEntry = 0;
U16 ofsInteroperabilityIFDEntry = 0;
U32 ofsEXIFIFD = 0;
U32 ofsGPSInfoIFD = 0;
U32 ofsInteroperabilityIFD = 0;
U32 ofsdstnextdata;
U32 ofsdst = *pofsdst;
U32 ofssrcdir;
U32 ofsdstdir;
U32 ofsnextifd;
Call(getbfwe(pbsrc, cbsrc, ofssrc, &cDir, endian));
Call(setbfw(pbdst, cbdst, ofsdst, cDir));
ofsnextifd = ofsdst + sizeof(U16) + SizeofIFDEntry * cDir;
ofsdstnextdata = ofsnextifd + sizeof(U32);
ofssrcdir = ofssrc + sizeof(U16);
ofsdstdir = ofsdst + sizeof(U16);
for ( i = 0; i < cDir; i++ )
{
U16 tag;
U16 type;
U32 count;
U32 value;
U32 size;
Call(getbfwe(pbsrc, cbsrc, ofssrcdir, &tag, endian));
Call(setbfw(pbdst, cbdst, ofsdstdir, tag));
Call(getbfwe(pbsrc, cbsrc, ofssrcdir + sizeof(U16), &type, endian));
Call(setbfw(pbdst, cbdst, ofsdstdir + sizeof(U16), type));
Call(getbfdwe(pbsrc, cbsrc, ofssrcdir + 2 * sizeof(U16), &count, endian));
Call(setbfdw(pbdst, cbdst, ofsdstdir + 2 * sizeof(U16), count));
Call(getbfdwe(pbsrc, cbsrc, ofssrcdir + 2 * sizeof(U16) + sizeof(U32), &value, endian));
Call(setbfdw(pbdst, cbdst, ofsdstdir + 2 * sizeof(U16) + sizeof(U32), 0));
FailIf(type == 0 || type >= sizeof(IFDEntryTypeSizes) / sizeof(IFDEntryTypeSizes[0]), WMP_errFail);
if ( tag == WMP_tagEXIFMetadata )
{
ofsEXIFIFDEntry = (U16) ofsdstdir;
ofsEXIFIFD = value;
}
else if ( tag == WMP_tagGPSInfoMetadata )
{
ofsGPSInfoIFDEntry = (U16) ofsdstdir;
ofsGPSInfoIFD = value;
}
else if ( tag == WMP_tagInteroperabilityIFD )
{
ofsInteroperabilityIFDEntry = (U16) ofsdstdir;
ofsInteroperabilityIFD = value;
}
else
{
U32 ofsdstdata = ofsdstdir + 2 * sizeof(U16) + sizeof(U32);
U32 ofssrcdata = ofssrcdir + 2 * sizeof(U16) + sizeof(U32);
size = count * IFDEntryTypeSizes[type];
if ( size > 4 )
{
ofssrcdata = value;
Call(setbfdw(pbdst, cbdst, ofsdstdata, ofsdstnextdata));
ofsdstdata = ofsdstnextdata;
ofsdstnextdata += size;
}
FailIf(ofssrcdata + size > cbsrc || ofsdstdata + size > cbdst, WMP_errBufferOverflow);
if ( size == count || endian == WMP_INTEL_ENDIAN )
// size == count means 8-bit data means endian doesn't matter
memcpy(&pbdst[ofsdstdata], &pbsrc[ofssrcdata], size);
else
{ // big endian source and endian matters
U32 j;
switch ( IFDEntryTypeSizes[type] )
{
case 2:
for ( j = 0; j < count; j++ )
{
U16 w;
getbfwbig(pbsrc, cbsrc, ofssrcdata + j * sizeof(U16), &w);
setbfw(pbdst, cbdst, ofsdstdata + j * sizeof(U16), w);
}
break;
case 8:
if ( type == WMP_typDOUBLE )
{
for ( j = 0; j < count; j++ )
{
U32 dwlo;
U32 dwhi;
getbfdwbig(pbsrc, cbsrc, ofssrcdata + j * 8, &dwhi);
getbfdwbig(pbsrc, cbsrc, ofssrcdata + j * 8 + sizeof(U32), &dwlo);
setbfdw(pbdst, cbdst, ofsdstdata + j * 8, dwlo);
setbfdw(pbdst, cbdst, ofsdstdata + j * 8 + sizeof(U32), dwhi);
}
break;
}
count *= 2;
// RATIONAL's fall through to be handled as LONG's
case 4:
for ( j = 0; j < count; j++ )
{
U32 dw;
getbfdwbig(pbsrc, cbsrc, ofssrcdata + j * sizeof(U32), &dw);
setbfdw(pbdst, cbdst, ofsdstdata + j * sizeof(U32), dw);
}
break;
}
}
}
ofssrcdir += SizeofIFDEntry;
ofsdstdir += SizeofIFDEntry;
}
Call(setbfdw(pbdst, cbdst, ofsnextifd, 0)); // no nextIFD
if ( ofsEXIFIFDEntry != 0 )
{
ofsdstnextdata += ( ofsdstnextdata & 1 );
Call(setbfdw(pbdst, cbdst, ofsEXIFIFDEntry + 2 * sizeof(U16) + sizeof(U32), ofsdstnextdata));
Call(BufferCopyIFD(pbsrc, cbsrc, ofsEXIFIFD, endian, pbdst, cbdst, &ofsdstnextdata));
}
if ( ofsGPSInfoIFDEntry != 0 )
{
ofsdstnextdata += ( ofsdstnextdata & 1 );
Call(setbfdw(pbdst, cbdst, ofsGPSInfoIFDEntry + 2 * sizeof(U16) + sizeof(U32), ofsdstnextdata));
Call(BufferCopyIFD(pbsrc, cbsrc, ofsGPSInfoIFD, endian, pbdst, cbdst, &ofsdstnextdata));
}
if ( ofsInteroperabilityIFDEntry != 0 )
{
ofsdstnextdata += ( ofsdstnextdata & 1 );
Call(setbfdw(pbdst, cbdst, ofsInteroperabilityIFDEntry + 2 * sizeof(U16) + sizeof(U32), ofsdstnextdata));
Call(BufferCopyIFD(pbsrc, cbsrc, ofsInteroperabilityIFD, endian, pbdst, cbdst, &ofsdstnextdata));
}
*pofsdst = ofsdstnextdata;
Cleanup:
return err;
}
// src IFD copied to dst IFD with any nested IFD's
// src IFD is little endian, arbitrary data arrangement
// dst IFD is little endian, data arranged in tag order
// dst IFD tags are ordered the same as src IFD so src IFD tags must be in order
ERR StreamCopyIFD(struct WMPStream* pWS, U32 ofssrc, U8* pbdst, U32 cbdst, U32* pofsdst)
{
ERR err = WMP_errSuccess;
size_t offCurPos = 0;
Bool GetPosOK = FALSE;
U16 cDir;
U16 i;
U16 ofsEXIFIFDEntry = 0;
U16 ofsGPSInfoIFDEntry = 0;
U16 ofsInteroperabilityIFDEntry = 0;
U32 ofsEXIFIFD = 0;
U32 ofsGPSInfoIFD = 0;
U32 ofsInteroperabilityIFD = 0;
U32 ofsdstnextdata;
U32 ofsdst = *pofsdst;
U32 ofssrcdir;
U32 ofsdstdir;
U32 ofsnextifd;
Call(pWS->GetPos(pWS, &offCurPos));
GetPosOK = TRUE;
Call(GetUShort(pWS, ofssrc, &cDir));
Call(setbfw(pbdst, cbdst, ofsdst, cDir));
ofsnextifd = ofsdst + sizeof(U16) + SizeofIFDEntry * cDir;
ofsdstnextdata = ofsnextifd + sizeof(U32);
ofssrcdir = ofssrc + sizeof(U16);
ofsdstdir = ofsdst + sizeof(U16);
for ( i = 0; i < cDir; i++ )
{
U16 tag;
U16 type;
U32 count;
U32 value;
U32 size;
Call(GetUShort(pWS, ofssrcdir, &tag));
Call(setbfw(pbdst, cbdst, ofsdstdir, tag));
Call(GetUShort(pWS, ofssrcdir + sizeof(U16), &type));
Call(setbfw(pbdst, cbdst, ofsdstdir + sizeof(U16), type));
Call(GetULong(pWS, ofssrcdir + 2 * sizeof(U16), &count));
Call(setbfdw(pbdst, cbdst, ofsdstdir + 2 * sizeof(U16), count));
Call(GetULong(pWS, ofssrcdir + 2 * sizeof(U16) + sizeof(U32), &value));
Call(setbfdw(pbdst, cbdst, ofsdstdir + 2 * sizeof(U16) + sizeof(U32), 0));
FailIf(type == 0 || type >= sizeof(IFDEntryTypeSizes) / sizeof(IFDEntryTypeSizes[0]), WMP_errFail);
if ( tag == WMP_tagEXIFMetadata )
{
ofsEXIFIFDEntry = (U16) ofsdstdir;
ofsEXIFIFD = value;
}
else if ( tag == WMP_tagGPSInfoMetadata )
{
ofsGPSInfoIFDEntry = (U16) ofsdstdir;
ofsGPSInfoIFD = value;
}
else if ( tag == WMP_tagInteroperabilityIFD )
{
ofsInteroperabilityIFDEntry = (U16) ofsdstdir;
ofsInteroperabilityIFD = value;
}
else
{
U32 ofsdstdata = ofsdstdir + 2 * sizeof(U16) + sizeof(U32);
U32 ofssrcdata = ofssrcdir + 2 * sizeof(U16) + sizeof(U32);
size = count * IFDEntryTypeSizes[type];
if ( size > 4 )
{
ofssrcdata = value;
Call(setbfdw(pbdst, cbdst, ofsdstdata, ofsdstnextdata));
ofsdstdata = ofsdstnextdata;
ofsdstnextdata += size;
}
FailIf(ofsdstdata + size > cbdst, WMP_errBufferOverflow);
Call(pWS->SetPos(pWS, ofssrcdata));
Call(pWS->Read(pWS, &pbdst[ofsdstdata], size));
}
ofssrcdir += SizeofIFDEntry;
ofsdstdir += SizeofIFDEntry;
}
Call(setbfdw(pbdst, cbdst, ofsnextifd, 0)); // no nextIFD
if ( ofsEXIFIFDEntry != 0 )
{
ofsdstnextdata += ( ofsdstnextdata & 1 );
Call(setbfdw(pbdst, cbdst, ofsEXIFIFDEntry + 2 * sizeof(U16) + sizeof(U32), ofsdstnextdata));
Call(StreamCopyIFD(pWS, ofsEXIFIFD, pbdst, cbdst, &ofsdstnextdata));
}
if ( ofsGPSInfoIFDEntry != 0 )
{
ofsdstnextdata += ( ofsdstnextdata & 1 );
Call(setbfdw(pbdst, cbdst, ofsGPSInfoIFDEntry + 2 * sizeof(U16) + sizeof(U32), ofsdstnextdata));
Call(StreamCopyIFD(pWS, ofsGPSInfoIFD, pbdst, cbdst, &ofsdstnextdata));
}
if ( ofsInteroperabilityIFDEntry != 0 )
{
ofsdstnextdata += ( ofsdstnextdata & 1 );
Call(setbfdw(pbdst, cbdst, ofsInteroperabilityIFDEntry + 2 * sizeof(U16) + sizeof(U32), ofsdstnextdata));
Call(StreamCopyIFD(pWS, ofsInteroperabilityIFD, pbdst, cbdst, &ofsdstnextdata));
}
*pofsdst = ofsdstnextdata;
Cleanup:
if ( GetPosOK )
Call(pWS->SetPos(pWS, offCurPos));
return err;
}
//================================================================
ERR GetUShort(
__in_ecount(1) struct WMPStream* pWS,
size_t offPos,
__out_ecount(1) U16* puValue)
{
ERR err = WMP_errSuccess;
U8 cVal;
Call(pWS->SetPos(pWS, offPos));
Call(pWS->Read(pWS, &cVal, sizeof(cVal)));
puValue[0] = (U16) cVal;
Call(pWS->Read(pWS, &cVal, sizeof(cVal)));
puValue[0] += ((U16) cVal) << 8;
Cleanup:
return err;
}
ERR PutUShort(
__in_ecount(1) struct WMPStream* pWS,
size_t offPos,
U16 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)));
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)
{
case WMP_typASCII:
case WMP_typUNDEFINED:
case WMP_typBYTE:
if (pDE->uCount <= 4)
{
U8 pad[4] = {0};
Call(pWS->SetPos(pWS, offPos));
if (NULL == pbData)
pbData = (U8*)&pDE->uValueOrOffset;
Call(pWS->Write(pWS, pbData, pDE->uCount));
Call(pWS->Write(pWS, pad, 4 - pDE->uCount)); offPos += 4;
}
else
{
Call(PutULong(pWS, offPos, pDE->uValueOrOffset)); offPos += 4;
// Write the data if requested to do so
if (pbData)
{
Call(pWS->SetPos(pWS, pDE->uValueOrOffset));
Call(pWS->Write(pWS, pbData, pDE->uCount));
Call(pWS->SetPos(pWS, offPos));
*pcbDataWrittenToOffset = pDE->uCount;
}
}
break;
case WMP_typSHORT:
if (pDE->uCount <= 2)
{
U16 uiShrt1 = 0;
U16 uiShrt2 = 0;
if (NULL == pbData)
pbData = (U8*)&pDE->uValueOrOffset;
if (pDE->uCount > 0)
uiShrt1 = *((U16*)pbData);
if (pDE->uCount > 1)
{
assert(FALSE); // Untested - remove this assert after this has been tested
uiShrt2 = *(U16*)(pbData + 2);
}
Call(PutUShort(pWS, offPos, uiShrt1)); offPos += 2;
Call(PutUShort(pWS, offPos, uiShrt2)); offPos += 2;
}
else
{
assert(FALSE); // Untested - remove this assert after this has been tested
Call(PutULong(pWS, offPos, pDE->uValueOrOffset)); offPos += 4;
// Write the data if requested to do so
if (pbData)
{
U32 i;
Call(pWS->SetPos(pWS, pDE->uValueOrOffset));
for (i = 0; i < pDE->uCount; i++)
{
const U16 uiShort = *(U16*)(pbData + i*sizeof(U16));
Call(PutUShort(pWS, offPos, uiShort)); // Write one at a time for endian purposes - but inefficient
}
Call(pWS->SetPos(pWS, offPos));
*pcbDataWrittenToOffset = pDE->uCount * sizeof(U16);
}
}
break;
case WMP_typFLOAT:
case WMP_typLONG:
if (pDE->uCount <= 1)
{
if (NULL == pbData)
pbData = (U8*)&pDE->uValueOrOffset;
Call(PutULong(pWS, offPos, *(U32*)pbData)); offPos += 4;
}
else
{
assert(FALSE); // Untested - remove this assert after this has been tested
Call(PutULong(pWS, offPos, pDE->uValueOrOffset)); offPos += 4;
// Write the data if requested to do so
if (pbData)
{
U32 i;
Call(pWS->SetPos(pWS, pDE->uValueOrOffset));
for (i = 0; i < pDE->uCount; i++)
{
const U32 uLong = *(U32*)(pbData + i*sizeof(U32));
Call(PutULong(pWS, offPos, uLong)); // Write one at a time for endian purposes - but inefficient
}
Call(pWS->SetPos(pWS, offPos));
*pcbDataWrittenToOffset = pDE->uCount * sizeof(U32);
}
}
break;
default:
assert(FALSE); // Alert the programmer
Call(WMP_errInvalidParameter);
break;
}
Cleanup:
*pOffPos = offPos;
return err;
}

258
jxrlib/jxrgluelib/JXRMeta.h Normal file
View file

@ -0,0 +1,258 @@
//*@@@+++@@@@******************************************************************
//
// Copyright © Microsoft Corp.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// • Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// • Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
//*@@@---@@@@******************************************************************
#pragma once
#include <windowsmediaphoto.h>
#ifndef WIN32
#include <wmspecstring.h>
#endif
#ifndef UNREFERENCED_PARAMETER
#define UNREFERENCED_PARAMETER(P) { (P) = (P); }
#endif /*UNREFERENCED_PARAMETER*/
//================================================================
// Container
//================================================================
// Keep these in sort order so that we can easily confirm we are outputting tags in ascending order
#define WMP_tagNull 0
#define WMP_tagDocumentName 0x010d // Descriptive metadata tag
#define WMP_tagImageDescription 0x010e // Descriptive metadata tag
#define WMP_tagCameraMake 0x010f // Descriptive metadata tag
#define WMP_tagCameraModel 0x0110 // Descriptive metadata tag
#define WMP_tagPageName 0x011d // Descriptive metadata tag
#define WMP_tagPageNumber 0x0129 // Descriptive metadata tag
#define WMP_tagSoftware 0x0131 // Descriptive metadata tag
#define WMP_tagDateTime 0x0132 // Descriptive metadata tag
#define WMP_tagArtist 0x013b // Descriptive metadata tag
#define WMP_tagHostComputer 0x013c // Descriptive metadata tag
#define WMP_tagXMPMetadata 0x02bc
#define WMP_tagRatingStars 0x4746 // Descriptive metadata tag
#define WMP_tagRatingValue 0x4749 // Descriptive metadata tag
#define WMP_tagCopyright 0x8298 // Descriptive metadata tag
#define WMP_tagEXIFMetadata 0x8769
#define WMP_tagGPSInfoMetadata 0x8825
#define WMP_tagIPTCNAAMetadata 0x83bb
#define WMP_tagPhotoshopMetadata 0x8649
#define WMP_tagInteroperabilityIFD 0xa005
#define WMP_tagIccProfile 0x8773 // Need to use same tag as TIFF!!
#define WMP_tagCaption 0x9c9b // Descriptive metadata tag
#define WMP_tagPixelFormat 0xbc01
#define WMP_tagTransformation 0xbc02
#define WMP_tagCompression 0xbc03
#define WMP_tagImageType 0xbc04
#define WMP_tagImageWidth 0xbc80
#define WMP_tagImageHeight 0xbc81
#define WMP_tagWidthResolution 0xbc82
#define WMP_tagHeightResolution 0xbc83
#define WMP_tagImageOffset 0xbcc0
#define WMP_tagImageByteCount 0xbcc1
#define WMP_tagAlphaOffset 0xbcc2
#define WMP_tagAlphaByteCount 0xbcc3
#define WMP_tagImageDataDiscard 0xbcc4
#define WMP_tagAlphaDataDiscard 0xbcc5
#define WMP_typBYTE 1
#define WMP_typASCII 2
#define WMP_typSHORT 3
#define WMP_typLONG 4
#define WMP_typRATIONAL 5
#define WMP_typSBYTE 6
#define WMP_typUNDEFINED 7
#define WMP_typSSHORT 8
#define WMP_typSLONG 9
#define WMP_typSRATIONAL 10
#define WMP_typFLOAT 11
#define WMP_typDOUBLE 12
#define WMP_valCompression 0xbc
#define WMP_valWMPhotoID WMP_valCompression
#ifdef WIN32
#define __in_win __in
#define __out_win __out
#endif
//================================================================
typedef enum
{
DPKVT_EMPTY = 0,
DPKVT_UI1 = 17,
DPKVT_UI2 = 18,
DPKVT_UI4 = 19,
DPKVT_LPSTR = 30,
DPKVT_LPWSTR = 31,
DPKVT_BYREF = 0x4000,
} DPKVARTYPE;
typedef struct DPKPROPVARIANT
{
DPKVARTYPE vt;
union
{
U8 bVal; // DPKVT_UI1
U16 uiVal; // DPKVT_UI2
U32 ulVal; // DPKVT_UI4
char *pszVal; // DPKVT_LPSTR
U16 *pwszVal; // DPKVT_LPWSTR
U8 *pbVal; // DPKVT_BYREF | DPKVT_UI1
} VT;
} DPKPROPVARIANT;
typedef struct DESCRIPTIVEMETADATA
{
DPKPROPVARIANT pvarImageDescription; // WMP_tagImageDescription
DPKPROPVARIANT pvarCameraMake; // WMP_tagCameraMake
DPKPROPVARIANT pvarCameraModel; // WMP_tagCameraModel
DPKPROPVARIANT pvarSoftware; // WMP_tagSoftware
DPKPROPVARIANT pvarDateTime; // WMP_tagDateTime
DPKPROPVARIANT pvarArtist; // WMP_tagArtist
DPKPROPVARIANT pvarCopyright; // WMP_tagCopyright
DPKPROPVARIANT pvarRatingStars; // WMP_tagRatingStars
DPKPROPVARIANT pvarRatingValue; // WMP_tagRatingValue
DPKPROPVARIANT pvarCaption; // WMP_tagCaption
DPKPROPVARIANT pvarDocumentName; // WMP_tagDocumentName
DPKPROPVARIANT pvarPageName; // WMP_tagPageName
DPKPROPVARIANT pvarPageNumber; // WMP_tagPageNumber
DPKPROPVARIANT pvarHostComputer; // WMP_tagHostComputer
} DESCRIPTIVEMETADATA;
typedef struct tagWmpDE
{
U16 uTag;
U16 uType;
U32 uCount;
U32 uValueOrOffset;
} WmpDE;
typedef struct tagWmpDEMisc
{
U32 uImageOffset;
U32 uImageByteCount;
U32 uAlphaOffset;
U32 uAlphaByteCount;
U32 uOffPixelFormat;
U32 uOffImageByteCount;
U32 uOffAlphaOffset;
U32 uOffAlphaByteCount;
U32 uColorProfileOffset;
U32 uColorProfileByteCount;
U32 uXMPMetadataOffset;
U32 uXMPMetadataByteCount;
U32 uEXIFMetadataOffset;
U32 uEXIFMetadataByteCount;
U32 uGPSInfoMetadataOffset;
U32 uGPSInfoMetadataByteCount;
U32 uIPTCNAAMetadataOffset;
U32 uIPTCNAAMetadataByteCount;
U32 uPhotoshopMetadataOffset;
U32 uPhotoshopMetadataByteCount;
U32 uDescMetadataOffset;
U32 uDescMetadataByteCount;
} WmpDEMisc;
//================================================================
EXTERN_C ERR GetUShort(
__in_ecount(1) struct WMPStream* pWS,
size_t offPos,
__out_ecount(1) U16* puValue
);
EXTERN_C ERR PutUShort(
__in_ecount(1) struct WMPStream* pWS,
size_t offPos,
U16 uValue
);
EXTERN_C ERR GetULong(
__in_ecount(1) struct WMPStream* pWS,
size_t offPos,
__out_ecount(1) U32* puValue
);
EXTERN_C ERR PutULong(
__in_ecount(1) struct WMPStream* pWS,
size_t offPos,
U32 uValue
);
EXTERN_C ERR WriteWmpDE(
__in_ecount(1) struct WMPStream* pWS,
size_t *pOffPos,
const __in_ecount(1) WmpDE* pDE,
const U8 *pbData,
U32 *pcbDataWrittenToOffset
);
EXTERN_C 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);
// read and write little endian words/dwords from a buffer on both big and little endian cpu's
// with full buffer overflow checking
#define WMP_INTEL_ENDIAN ('I')
EXTERN_C ERR getbfcpy(U8* pbdest, const U8* pb, size_t cb, size_t ofs, U32 n);
EXTERN_C ERR getbfw(const U8* pb, size_t cb, size_t ofs, U16* pw);
EXTERN_C ERR getbfdw(const U8* pb, size_t cb, size_t ofs, U32* pdw);
EXTERN_C ERR getbfwbig(const U8* pb, size_t cb, size_t ofs, U16* pw);
EXTERN_C ERR getbfdwbig(const U8* pb, size_t cb, size_t ofs, U32* pdw);
EXTERN_C ERR getbfwe(const U8* pb, size_t cb, size_t ofs, U16* pw, U8 endian);
EXTERN_C ERR getbfdwe(const U8* pb, size_t cb, size_t ofs, U32* pdw, U8 endian);
EXTERN_C ERR setbfcpy(U8* pb, size_t cb, size_t ofs, const U8* pbset, size_t cbset);
EXTERN_C ERR setbfw(U8* pb, size_t cb, size_t ofs, U16 dw);
EXTERN_C ERR setbfdw(U8* pb, size_t cb, size_t ofs, U32 dw);
EXTERN_C ERR setbfwbig(U8* pb, size_t cb, size_t ofs, U16 dw);
EXTERN_C ERR setbfdwbig(U8* pb, size_t cb, size_t ofs, U32 dw);
EXTERN_C ERR BufferCalcIFDSize(const U8* pb, size_t cb, U32 uIFDOfs, U8 endian, U32 *pcbifd);
EXTERN_C ERR StreamCalcIFDSize(struct WMPStream* pWS, U32 uIFDOfs, U32 *pcbifd);
EXTERN_C ERR BufferCopyIFD(const U8* pbsrc, U32 cbsrc, U32 ofssrc, U8 endian, U8* pbdest, U32 cbdest, U32* pofsdest);
EXTERN_C ERR StreamCopyIFD(struct WMPStream* pWS, U32 ofssrc, U8* pbdest, U32 cbdest, U32* pofsdest);