📄 tif_overview.c
字号:
break; /* * For now use simple subsampling, from the top left corner * of the source block of pixels. */ for( k = 0; k < nPixelBytes; k++ ) pabyDst[k] = pabySrc[k]; pabyDst += nPixelBytes * nPixelGroupBytes; pabySrc += nOMult * nPixelGroupBytes; } }/* -------------------------------------------------------------------- *//* Handle the case of averaging. For this we also have to *//* handle each sample format we are concerned with. *//* -------------------------------------------------------------------- */ else if( strncmp(pszResampling,"averag",6) == 0 || strncmp(pszResampling,"AVERAG",6) == 0 ) { pabySrc = pabySrcTile + j*nOMult*nBlockXSize * nPixelGroupBytes; for( i = 0; i*nOMult < nBlockXSize; i++ ) { double dfTotal; int iSample; int nXSize, nYSize; if( i + nTXOff >= nOBlockXSize ) break; nXSize = MIN(nOMult,nBlockXSize-i); nYSize = MIN(nOMult,nBlockYSize-j); TIFF_GetSourceSamples( padfSamples, pabySrc, nPixelBytes, nSampleFormat, nXSize, nYSize, nPixelGroupBytes, nPixelGroupBytes * nBlockXSize ); dfTotal = 0; for( iSample = 0; iSample < nXSize*nYSize; iSample++ ) { dfTotal += padfSamples[iSample]; } TIFF_SetSample( pabyDst, nPixelBytes, nSampleFormat, dfTotal / (nXSize*nYSize) ); pabySrc += nOMult * nPixelGroupBytes; pabyDst += nPixelBytes; } } } free( padfSamples );}staticvoid TIFF_DownSample_Subsampled( unsigned char *pabySrcTile, int nSample, int nBlockXSize, int nBlockYSize, unsigned char * pabyOTile, int nOBlockXSize, int nOBlockYSize, int nTXOff, int nTYOff, int nOMult, const char * pszResampling, int nHorSubsampling, int nVerSubsampling ){ /* TODO: test with variety of subsampling values, and incovinient tile/strip sizes */ int nSampleBlockSize; int nSourceSampleRowSize; int nDestSampleRowSize; int nSourceX, nSourceY; int nSourceXSec, nSourceYSec; int nSourceXSecEnd, nSourceYSecEnd; int nDestX, nDestY; int nSampleOffsetInSampleBlock; unsigned char * pSourceBase; unsigned char * pDestBase; int nSourceBaseInc; unsigned char * pSourceBaseEnd; unsigned int nCummulator; unsigned int nCummulatorCount; nSampleBlockSize = nHorSubsampling * nVerSubsampling + 2; nSourceSampleRowSize = ( ( nBlockXSize + nHorSubsampling - 1 ) / nHorSubsampling ) * nSampleBlockSize; nDestSampleRowSize = ( ( nOBlockXSize + nHorSubsampling - 1 ) / nHorSubsampling ) * nSampleBlockSize; if( strncmp(pszResampling,"nearest",4) == 0 || strncmp(pszResampling,"NEAR",4) == 0 ) { if( nSample == 0 ) {#ifdef NOOPTIMIZATION /* * This version is not optimized, and should not be used except as documentation and as more clear * starting point for bug fixes (hope not) and extension */ for( nSourceY = 0, nDestY = nTYOff; nSourceY < nBlockYSize; nSourceY += nOMult, nDestY ++) { for( nSourceX = 0, nDestX = nTXOff; nSourceX < nBlockXSize; nSourceX += nOMult, nDestX ++) { * ( pabyOTile + ( nDestY / nVerSubsampling ) * nDestSampleRowSize + ( nDestY % nVerSubsampling ) * nHorSubsampling + ( nDestX / nHorSubsampling ) * nSampleBlockSize + ( nDestX % nHorSubsampling ) ) = * ( pabySrcTile + ( nSourceY / nVerSubsampling ) * nSourceSampleRowSize + ( nSourceY % nVerSubsampling ) * nHorSubsampling + ( nSourceX / nHorSubsampling ) * nSampleBlockSize + ( nSourceX % nHorSubsampling ) ); } }#else for( nSourceY = 0, nDestY = nTYOff; nSourceY < nBlockYSize; nSourceY += nOMult, nDestY ++) { pSourceBase = pabySrcTile + ( nSourceY / nVerSubsampling ) * nSourceSampleRowSize + ( nSourceY % nVerSubsampling ) * nHorSubsampling; pDestBase = pabyOTile + ( nDestY / nVerSubsampling ) * nDestSampleRowSize + ( nDestY % nVerSubsampling ) * nHorSubsampling; for( nSourceX = 0, nDestX = nTXOff; nSourceX < nBlockXSize; nSourceX += nOMult, nDestX ++) { * ( pDestBase + ( nDestX / nHorSubsampling ) * nSampleBlockSize + ( nDestX % nHorSubsampling ) ) = * ( pSourceBase + ( nSourceX / nHorSubsampling ) * nSampleBlockSize + ( nSourceX % nHorSubsampling ) ); } }#endif } else {#ifdef NOOPTIMIZATION /* * This version is not optimized, and should not be used except as documentation and as more clear * starting point for bug fixes (hope not) and extension */ nSampleOffsetInSampleBlock = nHorSubsampling * nVerSubsampling + nSample - 1; for( nSourceY = 0, nDestY = ( nTYOff / nVerSubsampling ); nSourceY < ( nBlockYSize / nVerSubsampling ); nSourceY += nOMult, nDestY ++) { for( nSourceX = 0, nDestX = ( nTXOff / nHorSubsampling ); nSourceX < ( nBlockXSize / nHorSubsampling ); nSourceX += nOMult, nDestX ++) { * ( pabyOTile + nDestY * nDestSampleRowSize + nDestX * nSampleBlockSize + nSampleOffsetInSampleBlock ) = * ( pabySrcTile + nSourceY * nSourceSampleRowSize + nSourceX * nSampleBlockSize + nSampleOffsetInSampleBlock ); } }#else nSampleOffsetInSampleBlock = nHorSubsampling * nVerSubsampling + nSample - 1; nSourceBaseInc = nOMult * nSampleBlockSize; for( nSourceY = 0, nDestY = ( nTYOff / nVerSubsampling ); nSourceY < ( nBlockYSize / nVerSubsampling); nSourceY += nOMult, nDestY ++) { pSourceBase = pabySrcTile + nSourceY * nSourceSampleRowSize + nSampleOffsetInSampleBlock; pSourceBaseEnd = pSourceBase + ( ( ( nBlockXSize / nHorSubsampling ) + nOMult - 1 ) / nOMult ) * nSourceBaseInc; pDestBase = pabyOTile + nDestY * nDestSampleRowSize + ( nTXOff / nHorSubsampling ) * nSampleBlockSize + nSampleOffsetInSampleBlock; for( ; pSourceBase < pSourceBaseEnd; pSourceBase += nSourceBaseInc, pDestBase += nSampleBlockSize) * pDestBase = * pSourceBase; }#endif } } else if( strncmp(pszResampling,"averag",6) == 0 || strncmp(pszResampling,"AVERAG",6) == 0 ) { if( nSample == 0 ) { for( nSourceY = 0, nDestY = nTYOff; nSourceY < nBlockYSize; nSourceY += nOMult, nDestY ++) { for( nSourceX = 0, nDestX = nTXOff; nSourceX < nBlockXSize; nSourceX += nOMult, nDestX ++) { nSourceXSecEnd = nSourceX + nOMult; if( nSourceXSecEnd > nBlockXSize ) nSourceXSecEnd = nBlockXSize; nSourceYSecEnd = nSourceY + nOMult; if( nSourceYSecEnd > nBlockYSize ) nSourceYSecEnd = nBlockYSize; nCummulator = 0; for( nSourceYSec = nSourceY; nSourceYSec < nSourceYSecEnd; nSourceYSec ++) { for( nSourceXSec = nSourceX; nSourceXSec < nSourceXSecEnd; nSourceXSec ++) { nCummulator += * ( pabySrcTile + ( nSourceYSec / nVerSubsampling ) * nSourceSampleRowSize + ( nSourceYSec % nVerSubsampling ) * nHorSubsampling + ( nSourceXSec / nHorSubsampling ) * nSampleBlockSize + ( nSourceXSec % nHorSubsampling ) ); } } nCummulatorCount = ( nSourceXSecEnd - nSourceX ) * ( nSourceYSecEnd - nSourceY ); * ( pabyOTile + ( nDestY / nVerSubsampling ) * nDestSampleRowSize + ( nDestY % nVerSubsampling ) * nHorSubsampling + ( nDestX / nHorSubsampling ) * nSampleBlockSize + ( nDestX % nHorSubsampling ) ) = ( ( nCummulator + ( nCummulatorCount >> 1 ) ) / nCummulatorCount ); } } } else { nSampleOffsetInSampleBlock = nHorSubsampling * nVerSubsampling + nSample - 1; for( nSourceY = 0, nDestY = ( nTYOff / nVerSubsampling ); nSourceY < ( nBlockYSize / nVerSubsampling ); nSourceY += nOMult, nDestY ++) { for( nSourceX = 0, nDestX = ( nTXOff / nHorSubsampling ); nSourceX < ( nBlockXSize / nHorSubsampling ); nSourceX += nOMult, nDestX ++) { nSourceXSecEnd = nSourceX + nOMult; if( nSourceXSecEnd > ( nBlockXSize / nHorSubsampling ) ) nSourceXSecEnd = ( nBlockXSize / nHorSubsampling ); nSourceYSecEnd = nSourceY + nOMult; if( nSourceYSecEnd > ( nBlockYSize / nVerSubsampling ) ) nSourceYSecEnd = ( nBlockYSize / nVerSubsampling ); nCummulator = 0; for( nSourceYSec = nSourceY; nSourceYSec < nSourceYSecEnd; nSourceYSec ++) { for( nSourceXSec = nSourceX; nSourceXSec < nSourceXSecEnd; nSourceXSec ++) { nCummulator += * ( pabySrcTile + nSourceYSec * nSourceSampleRowSize + nSourceXSec * nSampleBlockSize + nSampleOffsetInSampleBlock ); } } nCummulatorCount = ( nSourceXSecEnd - nSourceX ) * ( nSourceYSecEnd - nSourceY ); * ( pabyOTile + nDestY * nDestSampleRowSize + nDestX * nSampleBlockSize + nSampleOffsetInSampleBlock ) = ( ( nCummulator + ( nCummulatorCount >> 1 ) ) / nCummulatorCount ); } } } }}/************************************************************************//* TIFF_ProcessFullResBlock() *//* *//* Process one block of full res data, downsampling into each *//* of the overviews. *//************************************************************************/void TIFF_ProcessFullResBlock( TIFF *hTIFF, int nPlanarConfig, int bSubsampled, int nHorSubsampling, int nVerSubsampling, int nOverviews, int * panOvList, int nBitsPerPixel, int nSamples, TIFFOvrCache ** papoRawBIs, int nSXOff, int nSYOff, unsigned char *pabySrcTile, int nBlockXSize, int nBlockYSize, int nSampleFormat, const char * pszResampling ) { int iOverview, iSample; for( iSample = 0; iSample < nSamples; iSample++ ) { /* * We have to read a tile/strip for each sample for * PLANARCONFIG_SEPARATE. Otherwise, we just read all the samples * at once when handling the first sample. */ if( nPlanarConfig == PLANARCONFIG_SEPARATE || iSample == 0 ) { if( TIFFIsTiled(hTIFF) ) { TIFFReadEncodedTile( hTIFF, TIFFComputeTile(hTIFF, nSXOff, nSYOff, 0, (tsample_t)iSample ), pabySrcTile, TIFFTileSize(hTIFF)); } else { TIFFReadEncodedStrip( hTIFF, TIFFComputeStrip(hTIFF, nSYOff, (tsample_t) iSample), pabySrcTile, TIFFStripSize(hTIFF) ); } } /* * Loop over destination overview layers */ for( iOverview = 0; iOverview < nOverviews; iOverview++ ) { TIFFOvrCache *poRBI = papoRawBIs[iOverview]; unsigned char *pabyOTile; int nTXOff, nTYOff, nOXOff, nOYOff, nOMult; int nOBlockXSize = poRBI->nBlockXSize; int nOBlockYSize = poRBI->nBlockYSize; int nSkewBits, nSampleByteOffset;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -