Changeset 11081

Show
Ignore:
Timestamp:
03/26/07 23:21:26 (2 years ago)
Author:
warmerdam
Message:

write out all dirty bands of pixel intereleaved data in one pass (bug #1470)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/gtiff/geotiff.cpp

    r10963 r11081  
    584584 
    585585/* -------------------------------------------------------------------- */ 
    586 /*      Handle simple case of eight bit data, and pixel interleaving.   */ 
    587 /* -------------------------------------------------------------------- */ 
    588     int i, nBlockPixels, nWordBytes; 
    589     GByte       *pabyImage; 
    590  
    591     nWordBytes = poGDS->nBitsPerSample / 8; 
    592     pabyImage = poGDS->pabyBlockBuf + (nBand - 1) * nWordBytes; 
    593      
    594     nBlockPixels = nBlockXSize * nBlockYSize; 
    595     for( i = 0; i < nBlockPixels; i++ ) 
    596     { 
    597         for( int j = 0; j < nWordBytes; j++ ) 
    598         { 
    599             pabyImage[j] = ((GByte *) pImage)[i*nWordBytes + j]; 
    600         } 
    601         pabyImage += poGDS->nBands * nWordBytes; 
     586/*      On write of pixel interleaved data, we might as well flush      */ 
     587/*      out any other bands that are dirty in our cache.  This is       */ 
     588/*      especially helpful when writing compressed blocks.              */ 
     589/* -------------------------------------------------------------------- */ 
     590    int iBand;  
     591    int nWordBytes = poGDS->nBitsPerSample / 8; 
     592 
     593    for( iBand = 0; iBand < poGDS->nBands; iBand++ ) 
     594    { 
     595        const GByte *pabyThisImage = NULL; 
     596        GDALRasterBlock *poBlock = NULL; 
     597 
     598        if( iBand+1 == nBand ) 
     599            pabyThisImage = (GByte *) pImage; 
     600        else 
     601        { 
     602            poBlock = ((GTiffRasterBand *)poGDS->GetRasterBand( iBand+1 )) 
     603                ->TryGetLockedBlockRef( nBlockXOff, nBlockYOff ); 
     604 
     605            if( poBlock == NULL ) 
     606                continue; 
     607 
     608            if( !poBlock->GetDirty() ) 
     609            { 
     610                poBlock->DropLock(); 
     611                continue; 
     612            } 
     613 
     614            pabyThisImage = (GByte *) poBlock->GetDataRef(); 
     615        } 
     616 
     617        int i, nBlockPixels = nBlockXSize * nBlockYSize; 
     618        GByte *pabyOut = poGDS->pabyBlockBuf + iBand*nWordBytes; 
     619 
     620        for( i = 0; i < nBlockPixels; i++ ) 
     621        { 
     622            memcpy( pabyOut, pabyThisImage, nWordBytes ); 
     623             
     624            pabyOut += nWordBytes * poGDS->nBands; 
     625            pabyThisImage += nWordBytes; 
     626        } 
     627         
     628        if( poBlock != NULL ) 
     629        { 
     630            poBlock->MarkClean(); 
     631            poBlock->DropLock(); 
     632        } 
    602633    } 
    603634