⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tif_overview.c

📁 下载来的一个看图软件的源代码
💻 C
📖 第 1 页 / 共 3 页
字号:
            /*             * Fetch the destination overview tile             */            nOMult = panOvList[iOverview];            nOXOff = (nSXOff/nOMult) / nOBlockXSize;            nOYOff = (nSYOff/nOMult) / nOBlockYSize;            if( bSubsampled )            {                pabyOTile = TIFFGetOvrBlock_Subsampled( poRBI, nOXOff, nOYOff );                /*                 * Establish the offset into this tile at which we should                 * start placing data.                 */                nTXOff = (nSXOff - nOXOff*nOMult*nOBlockXSize) / nOMult;                nTYOff = (nSYOff - nOYOff*nOMult*nOBlockYSize) / nOMult;#ifdef DBMALLOC                malloc_chain_check( 1 );#endif                TIFF_DownSample_Subsampled( pabySrcTile, iSample,                                            nBlockXSize, nBlockYSize,                                            pabyOTile,                                            poRBI->nBlockXSize, poRBI->nBlockYSize,                                            nTXOff, nTYOff,                                            nOMult, pszResampling,                                            nHorSubsampling, nVerSubsampling );#ifdef DBMALLOC                malloc_chain_check( 1 );#endif            }            else            {                pabyOTile = TIFFGetOvrBlock( poRBI, nOXOff, nOYOff, iSample );                /*                 * Establish the offset into this tile at which we should                 * start placing data.                 */                nTXOff = (nSXOff - nOXOff*nOMult*nOBlockXSize) / nOMult;                nTYOff = (nSYOff - nOYOff*nOMult*nOBlockYSize) / nOMult;                /*                 * Figure out the skew (extra space between ``our samples'') and                 * the byte offset to the first sample.                 */                assert( (nBitsPerPixel % 8) == 0 );                if( nPlanarConfig == PLANARCONFIG_SEPARATE )                {                    nSkewBits = 0;                    nSampleByteOffset = 0;                }                else                {                    nSkewBits = nBitsPerPixel * (nSamples-1);                    nSampleByteOffset = (nBitsPerPixel/8) * iSample;                }                /*                 * Perform the downsampling.                 */#ifdef DBMALLOC                malloc_chain_check( 1 );#endif                TIFF_DownSample( pabySrcTile + nSampleByteOffset,                               nBlockXSize, nBlockYSize,                               nSkewBits, nBitsPerPixel, pabyOTile,                               poRBI->nBlockXSize, poRBI->nBlockYSize,                               nTXOff, nTYOff,                               nOMult, nSampleFormat, pszResampling );#ifdef DBMALLOC                malloc_chain_check( 1 );#endif            }        }    }}/************************************************************************//*                        TIFF_BuildOverviews()                         *//*                                                                      *//*      Build the requested list of overviews.  Overviews are           *//*      maintained in a bunch of temporary files and then these are     *//*      written back to the TIFF file.  Only one pass through the       *//*      source TIFF file is made for any number of output               *//*      overviews.                                                      *//************************************************************************/void TIFFBuildOverviews( TIFF *hTIFF, int nOverviews, int * panOvList,                         int bUseSubIFDs, const char *pszResampleMethod,                         int (*pfnProgress)( double, void * ),                         void * pProgressData ){    TIFFOvrCache	**papoRawBIs;    uint32		nXSize, nYSize, nBlockXSize, nBlockYSize;    uint16		nBitsPerPixel, nPhotometric, nCompressFlag, nSamples,        nPlanarConfig, nSampleFormat;    int         bSubsampled;    uint16      nHorSubsampling, nVerSubsampling;    int			bTiled, nSXOff, nSYOff, i;    unsigned char	*pabySrcTile;    uint16		*panRedMap, *panGreenMap, *panBlueMap;    TIFFErrorHandler    pfnWarning;/* -------------------------------------------------------------------- *//*      Get the base raster size.                                       *//* -------------------------------------------------------------------- */    TIFFGetField( hTIFF, TIFFTAG_IMAGEWIDTH, &nXSize );    TIFFGetField( hTIFF, TIFFTAG_IMAGELENGTH, &nYSize );    TIFFGetField( hTIFF, TIFFTAG_BITSPERSAMPLE, &nBitsPerPixel );    /* TODO: nBitsPerPixel seems misnomer and may need renaming to nBitsPerSample */    TIFFGetField( hTIFF, TIFFTAG_SAMPLESPERPIXEL, &nSamples );    TIFFGetFieldDefaulted( hTIFF, TIFFTAG_PLANARCONFIG, &nPlanarConfig );    TIFFGetFieldDefaulted( hTIFF, TIFFTAG_PHOTOMETRIC, &nPhotometric );    TIFFGetFieldDefaulted( hTIFF, TIFFTAG_COMPRESSION, &nCompressFlag );    TIFFGetFieldDefaulted( hTIFF, TIFFTAG_SAMPLEFORMAT, &nSampleFormat );    if( nPhotometric == PHOTOMETRIC_YCBCR || nPhotometric == PHOTOMETRIC_ITULAB )    {        if( nBitsPerPixel != 8 || nSamples != 3 || nPlanarConfig != PLANARCONFIG_CONTIG ||            nSampleFormat != SAMPLEFORMAT_UINT)        {            /* TODO: use of TIFFError is inconsistent with use of fprintf in addtiffo.c, sort out */            TIFFErrorExt( TIFFClientdata(hTIFF), "TIFFBuildOverviews",                          "File `%s' has an unsupported subsampling configuration.\n",                          TIFFFileName(hTIFF) );            /* If you need support for this particular flavor, please contact either             * Frank Warmerdam warmerdam@pobox.com             * Joris Van Damme info@awaresystems.be             */            return;        }        bSubsampled = 1;        TIFFGetField( hTIFF, TIFFTAG_YCBCRSUBSAMPLING, &nHorSubsampling, &nVerSubsampling );        /* TODO: find out if maybe TIFFGetFieldDefaulted is better choice for YCbCrSubsampling tag */    }    else    {        if( nBitsPerPixel < 8 )        {            /* TODO: use of TIFFError is inconsistent with use of fprintf in addtiffo.c, sort out */            TIFFErrorExt( TIFFClientdata(hTIFF), "TIFFBuildOverviews",                          "File `%s' has samples of %d bits per sample.  Sample\n"                          "sizes of less than 8 bits per sample are not supported.\n",                          TIFFFileName(hTIFF), nBitsPerPixel );            return;        }        bSubsampled = 0;        nHorSubsampling = 1;        nVerSubsampling = 1;    }/* -------------------------------------------------------------------- *//*      Turn off warnings to avoid alot of repeated warnings while      *//*      rereading directories.                                          *//* -------------------------------------------------------------------- */    pfnWarning = TIFFSetWarningHandler( NULL );/* -------------------------------------------------------------------- *//*      Get the base raster block size.                                 *//* -------------------------------------------------------------------- */    if( TIFFGetField( hTIFF, TIFFTAG_ROWSPERSTRIP, &(nBlockYSize) ) )    {        nBlockXSize = nXSize;        bTiled = FALSE;    }    else    {        TIFFGetField( hTIFF, TIFFTAG_TILEWIDTH, &nBlockXSize );        TIFFGetField( hTIFF, TIFFTAG_TILELENGTH, &nBlockYSize );        bTiled = TRUE;    }/* -------------------------------------------------------------------- *//*	Capture the pallette if there is one.				*//* -------------------------------------------------------------------- */    if( TIFFGetField( hTIFF, TIFFTAG_COLORMAP,                      &panRedMap, &panGreenMap, &panBlueMap ) )    {        uint16		*panRed2, *panGreen2, *panBlue2;        int             nColorCount = 1 << nBitsPerPixel;        panRed2 = (uint16 *) _TIFFmalloc(2*nColorCount);        panGreen2 = (uint16 *) _TIFFmalloc(2*nColorCount);        panBlue2 = (uint16 *) _TIFFmalloc(2*nColorCount);        memcpy( panRed2, panRedMap, 2 * nColorCount );        memcpy( panGreen2, panGreenMap, 2 * nColorCount );        memcpy( panBlue2, panBlueMap, 2 * nColorCount );        panRedMap = panRed2;        panGreenMap = panGreen2;        panBlueMap = panBlue2;    }    else    {        panRedMap = panGreenMap = panBlueMap = NULL;    }/* -------------------------------------------------------------------- *//*      Initialize overviews.                                           *//* -------------------------------------------------------------------- */    papoRawBIs = (TIFFOvrCache **) _TIFFmalloc(nOverviews*sizeof(void*));    for( i = 0; i < nOverviews; i++ )    {        int	nOXSize, nOYSize, nOBlockXSize, nOBlockYSize;        uint32  nDirOffset;        nOXSize = (nXSize + panOvList[i] - 1) / panOvList[i];        nOYSize = (nYSize + panOvList[i] - 1) / panOvList[i];        nOBlockXSize = MIN((int)nBlockXSize,nOXSize);        nOBlockYSize = MIN((int)nBlockYSize,nOYSize);        if( bTiled )        {            if( (nOBlockXSize % 16) != 0 )                nOBlockXSize = nOBlockXSize + 16 - (nOBlockXSize % 16);            if( (nOBlockYSize % 16) != 0 )                nOBlockYSize = nOBlockYSize + 16 - (nOBlockYSize % 16);        }        nDirOffset = TIFF_WriteOverview( hTIFF, nOXSize, nOYSize,                                         nBitsPerPixel, nPlanarConfig,                                         nSamples, nOBlockXSize, nOBlockYSize,                                         bTiled, nCompressFlag, nPhotometric,                                         nSampleFormat,                                         panRedMap, panGreenMap, panBlueMap,                                         bUseSubIFDs,                                         nHorSubsampling, nVerSubsampling );                papoRawBIs[i] = TIFFCreateOvrCache( hTIFF, nDirOffset );    }    if( panRedMap != NULL )    {        _TIFFfree( panRedMap );        _TIFFfree( panGreenMap );        _TIFFfree( panBlueMap );    }    /* -------------------------------------------------------------------- *//*      Allocate a buffer to hold a source block.                       *//* -------------------------------------------------------------------- */    if( bTiled )        pabySrcTile = (unsigned char *) _TIFFmalloc(TIFFTileSize(hTIFF));    else        pabySrcTile = (unsigned char *) _TIFFmalloc(TIFFStripSize(hTIFF));    /* -------------------------------------------------------------------- *//*      Loop over the source raster, applying data to the               *//*      destination raster.                                             *//* -------------------------------------------------------------------- */    for( nSYOff = 0; nSYOff < (int) nYSize; nSYOff += nBlockYSize )    {        for( nSXOff = 0; nSXOff < (int) nXSize; nSXOff += nBlockXSize )        {            /*             * Read and resample into the various overview images.             */                        TIFF_ProcessFullResBlock( hTIFF, nPlanarConfig,                                      bSubsampled,nHorSubsampling,nVerSubsampling,                                      nOverviews, panOvList,                                      nBitsPerPixel, nSamples, papoRawBIs,                                      nSXOff, nSYOff, pabySrcTile,                                      nBlockXSize, nBlockYSize,                                      nSampleFormat, pszResampleMethod );        }    }    _TIFFfree( pabySrcTile );/* -------------------------------------------------------------------- *//*      Cleanup the rawblockedimage files.                              *//* -------------------------------------------------------------------- */    for( i = 0; i < nOverviews; i++ )    {        TIFFDestroyOvrCache( papoRawBIs[i] );    }    if( papoRawBIs != NULL )        _TIFFfree( papoRawBIs );    TIFFSetWarningHandler( pfnWarning );}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -