Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibJXR/image/decode/strdec.c view on Meta::CPAN
case BD_10:
case BD_565:
default:
break;
}
}
#endif
return ICERR_OK;
}
/*************************************************************************
Read variable length byte aligned integer
*************************************************************************/
static size_t GetVLWordEsc(BitIOInfo* pIO, Int *iEscape)
{
size_t s;
if (iEscape)
*iEscape = 0;
s = getBit32(pIO, 8);
if (s == 0xfd || s == 0xfe || s == 0xff) {
if (iEscape)
*iEscape = (Int) s;
s = 0;
}
else if (s < 0xfb) {
s = (s << 8) | getBit32(pIO, 8);
}
else {
s -= 0xfb;
if (s) {
s = getBit32(pIO, 16) << 16;
s = (s | getBit32(pIO, 16)) << 16;
s <<= 16;
}
s |= (getBit32(pIO, 16) << 16);
s |= getBit32(pIO, 16);
}
return s;
}
//================================================================
Int readIndexTable(CWMImageStrCodec * pSC)
{
BitIOInfo* pIO = pSC->pIOHeader;
readIS_L1(pSC, pIO);
if(pSC->cNumBitIO > 0){
size_t *pTable = pSC->pIndexTable;
U32 iEntry = (U32)pSC->cNumBitIO * (pSC->WMISCP.cNumOfSliceMinus1H + 1), i;
// read index table header [0x0001] - 2 bytes
if (getBit32(pIO, 16) != 1)
return ICERR_ERROR;
//iBits = getBit16(pIO, 5) + 1; // how many bits per entry
for(i = 0; i < iEntry; i ++){
readIS_L1(pSC, pIO);
pTable[i] = GetVLWordEsc(pIO, NULL); // escape handling is not important since the respective band is not accessed
}
}
pSC->cHeaderSize = GetVLWordEsc(pIO, NULL); // escape handling is not important
flushToByte(pIO);
pSC->cHeaderSize += getPosRead(pSC->pIOHeader); // get header length
return ICERR_OK;
}
Int StrIODecInit(CWMImageStrCodec* pSC)
{
if(allocateBitIOInfo(pSC) != ICERR_OK){
return ICERR_ERROR;
}
attachISRead(pSC->pIOHeader, pSC->WMISCP.pWStream, pSC);
readIndexTable(pSC);
if(pSC->WMISCP.bVerbose){
U32 i, j;
printf("\n%d horizontal tiles:\n", pSC->WMISCP.cNumOfSliceMinus1H + 1);
for(i = 0; i <= pSC->WMISCP.cNumOfSliceMinus1H; i ++){
printf(" offset of tile %d in MBs: %d\n", i, pSC->WMISCP.uiTileY[i]);
}
printf("\n%d vertical tiles:\n", pSC->WMISCP.cNumOfSliceMinus1V + 1);
for(i = 0; i <= pSC->WMISCP.cNumOfSliceMinus1V; i ++){
printf(" offset of tile %d in MBs: %d\n", i, pSC->WMISCP.uiTileX[i]);
}
if(pSC->WMISCP.bfBitstreamFormat == SPATIAL){
printf("\nSpatial order bitstream\n");
}
else{
printf("\nFrequency order bitstream\n");
}
if(!pSC->m_param.bIndexTable){
printf("\nstreaming mode, no index table.\n");
}
else if(pSC->WMISCP.bfBitstreamFormat == SPATIAL){
for(j = 0; j <= pSC->WMISCP.cNumOfSliceMinus1H; j ++){
for(i = 0; i <= pSC->WMISCP.cNumOfSliceMinus1V; i ++){
size_t * p = &pSC->pIndexTable[j * (pSC->WMISCP.cNumOfSliceMinus1V + 1) + i];
if(i + j != pSC->WMISCP.cNumOfSliceMinus1H + pSC->WMISCP.cNumOfSliceMinus1V){
printf("bitstream size for tile (%d, %d): %d.\n", j, i, (int) (p[1] - p[0]));
}
else{
printf("bitstream size for tile (%d, %d): unknown.\n", j, i);
}
}
}
}
else{
for(j = 0; j <= pSC->WMISCP.cNumOfSliceMinus1H; j ++){
for(i = 0; i <= pSC->WMISCP.cNumOfSliceMinus1V; i ++){
size_t * p = &pSC->pIndexTable[(j * (pSC->WMISCP.cNumOfSliceMinus1V + 1) + i) * 4];
if(i + j != pSC->WMISCP.cNumOfSliceMinus1H + pSC->WMISCP.cNumOfSliceMinus1V){
printf("bitstream size of (DC, LP, AC, FL) for tile (%d, %d): %d %d %d %d.\n", j, i,
(int) (p[1] - p[0]), (int) (p[2] - p[1]), (int) (p[3] - p[2]), (int) (p[4] - p[3]));
( run in 0.482 second using v1.01-cache-2.11-cpan-172d661cebc )