Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibJXR/image/sys/strcodec.c view on Meta::CPAN
//================================================================
// Memory access functions
//================================================================
#if (defined(WIN32) && !defined(UNDER_CE) && (!defined(__MINGW32__) || defined(__MINGW64_TOOLCHAIN__))) || (defined(UNDER_CE) && defined(_ARM_))
// WinCE ARM and Desktop x86
#else
// other platform
#ifdef _BIG__ENDIAN_
#define _byteswap_ulong(x) (x)
#else // _BIG__ENDIAN_
#ifndef __MINGW32__
U32 _byteswap_ulong(U32 bits)
{
U32 r = (bits & 0xffu) << 24;
r |= (bits << 8) & 0xff0000u;
r |= ((bits >> 8) & 0xff00u);
r |= ((bits >> 24) & 0xffu);
return r;
}
#endif
#endif // _BIG__ENDIAN_
#endif
U32 load4BE(void* pv)
{
#ifdef _BIG__ENDIAN_
return (*(U32*)pv);
#else // _BIG__ENDIAN_
#if defined(_M_IA64) || defined(_ARM_)
U32 v;
v = ((U16 *) pv)[0];
v |= ((U32)((U16 *) pv)[1]) << 16;
return _byteswap_ulong(v);
#else // _M_IA64
return _byteswap_ulong(*(U32*)pv);
#endif // _M_IA64
#endif // _BIG__ENDIAN_
}
#define LOAD16 load4BE
#ifdef _BIG__ENDIAN_
#define WRITESWAP_ENDIAN(a) ((a)>>16)
#else // _BIG__ENDIAN_
#define WRITESWAP_ENDIAN(a) _byteswap_ulong(a)
#endif // _BIG__ENDIAN_
//================================================================
// Bit I/O functions
//================================================================
Int allocateBitIOInfo(CWMImageStrCodec* pSC)
{
U32 cNumBitIO;
SUBBAND sbSubband = pSC->WMISCP.sbSubband;
pSC->cSB = (sbSubband == SB_DC_ONLY ? 1 : (sbSubband == SB_NO_HIGHPASS ? 2 : (sbSubband == SB_NO_FLEXBITS ? 3 : 4)));
// # of additional BitIOs other than pSC->pIOHeader
if (!pSC->m_param.bIndexTable) { // pure streaming mode, no index table, no additional BitIO!
assert (pSC->WMISCP.bfBitstreamFormat == SPATIAL && pSC->WMISCP.cNumOfSliceMinus1H + pSC->WMISCP.cNumOfSliceMinus1V == 0);
cNumBitIO = 0;
}
else if(pSC->WMISCP.bfBitstreamFormat == SPATIAL)
cNumBitIO = pSC->WMISCP.cNumOfSliceMinus1V + 1;
else
cNumBitIO = (pSC->WMISCP.cNumOfSliceMinus1V + 1) * pSC->cSB;
if(cNumBitIO > MAX_TILES * 4)
return ICERR_ERROR;
// allocate additional BitIos
if(cNumBitIO > 0){
U32 i = 0;
size_t cb = sizeof(BitIOInfo) * cNumBitIO + (PACKETLENGTH * 4 - 1) + PACKETLENGTH * 4 * cNumBitIO;
U8* pb = (U8*)malloc(cb);
if (NULL == pb) return ICERR_ERROR;
memset(pb, 0, cb);
pSC->m_ppBitIO = (BitIOInfo**)pb;
pb += sizeof(BitIOInfo) * cNumBitIO;
pb = (U8*)ALIGNUP(pb, PACKETLENGTH * 4) + PACKETLENGTH * 2;
for (i = 0; i < cNumBitIO; ++i){
pSC->m_ppBitIO[i] = (BitIOInfo*)pb;
pb += PACKETLENGTH * 4;
}
// allocate index table
if(cNumBitIO > MAX_TILES * 4 || pSC->WMISCP.cNumOfSliceMinus1H >= MAX_TILES)
return ICERR_ERROR;
pSC->pIndexTable = malloc(cNumBitIO * (pSC->WMISCP.cNumOfSliceMinus1H + 1) * sizeof(size_t));
if(NULL == pSC->pIndexTable) return ICERR_ERROR;
}
pSC->cNumBitIO = cNumBitIO;
return ICERR_OK;
}
Int setBitIOPointers(CWMImageStrCodec* pSC)
{
if(pSC->cNumBitIO > 0){
U32 i;
for(i = 0; i <= pSC->WMISCP.cNumOfSliceMinus1V; i ++){
CCodingContext * pContext = &pSC->m_pCodingContext[i];
if(pSC->WMISCP.bfBitstreamFormat == SPATIAL){
pContext->m_pIODC = pContext->m_pIOLP = pContext->m_pIOAC = pContext->m_pIOFL = pSC->m_ppBitIO[i];
}
else{
U32 j = pSC->cSB;
pContext->m_pIODC = pSC->m_ppBitIO[i * j];
if(j > 1)
pContext->m_pIOLP = pSC->m_ppBitIO[i * j + 1];
if(j > 2)
pContext->m_pIOAC = pSC->m_ppBitIO[i * j + 2];
if(j > 3)
( run in 2.093 seconds using v1.01-cache-2.11-cpan-e93a5daba3e )