Alien-FreeImage
view release on metacpan or search on metacpan
src/Source/LibJXR/image/encode/strenc.c view on Meta::CPAN
PutVLWordEsc(pIO, (pTable[i] <= MINIMUM_PACKET_LENGTH) ? 0xff : 0, iSize[l]);
iSize[l] += (pTable[i] <= MINIMUM_PACKET_LENGTH) ? 0 : pTable[i];
}
}
writeIS_L1(pSC, pIO);
PutVLWordEsc(pIO, 0xff, 0); // escape to end
fillToByte(pIO);
}
return ICERR_OK;
}
Int copyTo(struct WMPStream * pSrc, struct WMPStream * pDst, size_t iBytes)
{
char pData[PACKETLENGTH];
if (iBytes <= MINIMUM_PACKET_LENGTH){
pSrc->Read(pSrc, pData, iBytes);
return ICERR_OK;
}
while(iBytes > PACKETLENGTH){
pSrc->Read(pSrc, pData, PACKETLENGTH);
pDst->Write(pDst, pData, PACKETLENGTH);
iBytes -= PACKETLENGTH;
}
pSrc->Read(pSrc, pData, iBytes);
pDst->Write(pDst, pData, iBytes);
return ICERR_OK;
}
Int StrIOEncTerm(CWMImageStrCodec* pSC)
{
BitIOInfo * pIO = pSC->pIOHeader;
fillToByte(pIO);
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 ++){
printf("bitstream size for tile (%d, %d): %d.\n", j, i, (int) pSC->pIndexTable[j * (pSC->WMISCP.cNumOfSliceMinus1V + 1) + 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];
printf("bitstream size of (DC, LP, AC, FL) for tile (%d, %d): %d %d %d %d.\n", j, i,
(int) p[0], (int) p[1], (int) p[2], (int) p[3]);
}
}
}
}
writeIndexTable(pSC); // write index table to the header
detachISWrite(pSC, pIO);
if(pSC->cNumBitIO > 0){
size_t i, j, k, l;
struct WMPStream * pDst = pSC->WMISCP.pWStream;
size_t * pTable = pSC->pIndexTable;
for(i = 0; i < pSC->cNumBitIO; i ++){
detachISWrite(pSC, pSC->m_ppBitIO[i]);
}
for(i = 0; i < pSC->cNumBitIO; i ++){
pSC->ppWStream[i]->SetPos(pSC->ppWStream[i], 0); // seek back for read
}
for(l = 0; l < (size_t)(pSC->WMISCP.bfBitstreamFormat == FREQUENCY && pSC->WMISCP.bProgressiveMode ? pSC->cSB : 1); l ++){
for(i = 0, k = l; i <= pSC->WMISCP.cNumOfSliceMinus1H; i ++){ // loop through tiles
for(j = 0; j <= pSC->WMISCP.cNumOfSliceMinus1V; j ++){
if(pSC->WMISCP.bfBitstreamFormat == SPATIAL)
copyTo(pSC->ppWStream[j], pDst, pTable[k ++]);
else if (!pSC->WMISCP.bProgressiveMode){
copyTo(pSC->ppWStream[j * pSC->cSB + 0], pDst, pTable[k ++]);
if(pSC->cSB > 1)
copyTo(pSC->ppWStream[j * pSC->cSB + 1], pDst, pTable[k ++]);
if(pSC->cSB > 2)
copyTo(pSC->ppWStream[j * pSC->cSB + 2], pDst, pTable[k ++]);
if(pSC->cSB > 3)
copyTo(pSC->ppWStream[j * pSC->cSB + 3], pDst, pTable[k ++]);
}
else{
copyTo(pSC->ppWStream[j * pSC->cSB + l], pDst, pTable[k]);
k += pSC->cSB;
}
}
}
}
if (pSC->cmbHeight * pSC->cmbWidth * pSC->WMISCP.cChannel >= MAX_MEMORY_SIZE_IN_WORDS){
src/Source/LibJXR/image/encode/strenc.c view on Meta::CPAN
else
PUTBITS(pIO, CODEC_SUBVERSION_NEWSCALING_SOFT_TILES, 4);
// 9 primary parameters
PUTBITS(pIO, (pSCP->cNumOfSliceMinus1V || pSCP->cNumOfSliceMinus1H) ? 1 : 0, 1); // tiling present
PUTBITS(pIO, (Int) pSCP->bfBitstreamFormat, 1); // bitstream layout
PUTBITS(pIO, pII->oOrientation, 3); // m_iRotateFlip
PUTBITS(pIO, pSC->m_param.bIndexTable, 1); // index table present
PUTBITS(pIO, pSCP->olOverlap, 2); // overlap
// 10
PUTBITS(pIO, bAbbreviatedHeader, 1); // short words for size and tiles
PUTBITS(pIO, 1, 1); // long word length (use intelligence later)
PUTBITS(pIO, bInscribed, 1); // windowing
PUTBITS(pIO, pSC->m_param.bTrimFlexbitsFlag, 1); // trim flexbits flag sent
PUTBITS(pIO, 0, 1); // tile stretching parameters (not enabled)
PUTBITS(pIO, 0, 2); // reserved bits
PUTBITS(pIO, (Int) pSC->m_param.bAlphaChannel, 1); // alpha channel present
// 11 - informational
PUTBITS(pIO, (Int) pII->cfColorFormat, 4); // source color format
if(BD_1 == pII->bdBitDepth && pSCP->bBlackWhite)
PUTBITS(pIO, (Int) BD_1alt, 4); // source bit depth
else
PUTBITS(pIO, (Int) pII->bdBitDepth, 4); // source bit depth
// 12 - Variable length fields
// size
putBit32(pIO, (U32)(pII->cWidth - 1), bAbbreviatedHeader ? 16 : 32);
putBit32(pIO, (U32)(pII->cHeight - 1), bAbbreviatedHeader ? 16 : 32);
// tiling
if (pSCP->cNumOfSliceMinus1V || pSCP->cNumOfSliceMinus1H) {
PUTBITS(pIO, pSCP->cNumOfSliceMinus1V, LOG_MAX_TILES); // # of vertical slices
PUTBITS(pIO, pSCP->cNumOfSliceMinus1H, LOG_MAX_TILES); // # of horizontal slices
}
// tile sizes
for(i = 0; i < pSCP->cNumOfSliceMinus1V; i ++){ // width in MB of vertical slices, not needed for last slice!
PUTBITS(pIO, pSCP->uiTileX[i + 1] - pSCP->uiTileX[i], bAbbreviatedHeader ? 8 : 16);
}
for(i = 0; i < pSCP->cNumOfSliceMinus1H; i ++){ // width in MB of horizontal slices, not needed for last slice!
PUTBITS(pIO, pSCP->uiTileY[i + 1] - pSCP->uiTileY[i], bAbbreviatedHeader ? 8 : 16);
}
// window due to compressed domain processing
if (bInscribed) {
PUTBITS(pIO, (U32)pCoreParam->cExtraPixelsTop, 6);
PUTBITS(pIO, (U32)pCoreParam->cExtraPixelsLeft, 6);
PUTBITS(pIO, (U32)pCoreParam->cExtraPixelsBottom, 6);
PUTBITS(pIO, (U32)pCoreParam->cExtraPixelsRight, 6);
}
fillToByte(pIO); // redundant
// write image plane headers
WriteImagePlaneHeader(pSC);
return ICERR_OK;
}
// streaming codec init/term
Int StrEncInit(CWMImageStrCodec* pSC)
{
COLORFORMAT cf = pSC->m_param.cfColorFormat;
COLORFORMAT cfE = pSC->WMII.cfColorFormat;
U16 iQPIndexY = 0, iQPIndexYLP = 0, iQPIndexYHP = 0;
U16 iQPIndexU = 0, iQPIndexULP = 0, iQPIndexUHP = 0;
U16 iQPIndexV = 0, iQPIndexVLP = 0, iQPIndexVHP = 0;
size_t i;
Bool b32bit = sizeof(size_t) == 4;
/** color transcoding with resolution change **/
pSC->m_bUVResolutionChange = (((cfE == CF_RGB || cfE == YUV_444 || cfE == CMYK || cfE == CF_RGBE) &&
(cf == YUV_422 || cf == YUV_420))
|| (cfE == YUV_422 && cf == YUV_420)) && !pSC->WMISCP.bYUVData;
if(pSC->m_bUVResolutionChange){
size_t cSize = ((cfE == YUV_422 ? 128 : 256) + (cf == YUV_420 ? 32 : 0)) * pSC->cmbWidth + 256;
if(b32bit){ // integer overlow/underflow check for 32-bit system
if(((pSC->cmbWidth >> 16) * ((cfE == YUV_422 ? 128 : 256) + (cf == YUV_420 ? 32 : 0))) & 0xffff0000)
return ICERR_ERROR;
if(cSize >= 0x3fffffff)
return ICERR_ERROR;
}
pSC->pResU = (PixelI *)malloc(cSize * sizeof(PixelI));
pSC->pResV = (PixelI *)malloc(cSize * sizeof(PixelI));
if(pSC->pResU == NULL || pSC->pResV == NULL){
return ICERR_ERROR;
}
}
pSC->cTileColumn = pSC->cTileRow = 0;
if(allocateTileInfo(pSC) != ICERR_OK)
return ICERR_ERROR;
if(pSC->m_param.bTranscode == FALSE){
pSC->m_param.uQPMode = 0x150; // 101010 000
// 000 == uniform (not per tile) DC, LP, HP
// 101010 == cChMode == 2 == independent (not same) DC, LP, HP
/** lossless or Y component lossless condition: all subbands present, uniform quantization with QPIndex 1 **/
pSC->m_param.bScaledArith = !((pSC->m_param.uQPMode & 7) == 0 &&
1 == pSC->WMISCP.uiDefaultQPIndex <= 1 &&
pSC->WMISCP.sbSubband == SB_ALL &&
pSC->m_bUVResolutionChange == FALSE) &&
!pSC->WMISCP.bUnscaledArith;
if (BD_32 == pSC->WMII.bdBitDepth || BD_32S == pSC->WMII.bdBitDepth || BD_32F == pSC->WMII.bdBitDepth) {
pSC->m_param.bScaledArith = FALSE;
}
pSC->m_param.uQPMode |= 0x600; // don't use DC QP for LP, LP QP for HP
// default QPs
iQPIndexY = pSC->m_param.bAlphaChannel && pSC->m_param.cNumChannels == 1?
pSC->WMISCP.uiDefaultQPIndexAlpha : pSC->WMISCP.uiDefaultQPIndex;
// determine the U,V index
iQPIndexU = pSC->WMISCP.uiDefaultQPIndexU!=0?
pSC->WMISCP.uiDefaultQPIndexU: iQPIndexY;
iQPIndexV = pSC->WMISCP.uiDefaultQPIndexV!=0?
( run in 0.782 second using v1.01-cache-2.11-cpan-e93a5daba3e )