Changeset 13409

Show
Ignore:
Timestamp:
12/20/07 19:51:00 (5 months ago)
Author:
warmerdam
Message:

implement GTiffBitmapBand::IWriteBlock() to fix 1bit createcopy (#2115)

Files:

Legend:

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

    r13326 r13409  
    12331233/************************************************************************/ 
    12341234 
    1235 CPLErr GTiffBitmapBand::IWriteBlock( int, int, void * ) 
    1236  
    1237 
    1238     CPLError( CE_Failure, CPLE_AppDefined,  
    1239               "One bit raster bands are read-only." ); 
    1240     return CE_Failure; 
     1235CPLErr GTiffBitmapBand::IWriteBlock( int nBlockXOff, int nBlockYOff, 
     1236                                     void * pImage ) 
     1237 
     1238
     1239    int         nBlockId, nBlockBufSize; 
     1240    CPLErr      eErr = CE_None; 
     1241 
     1242    poGDS->Crystalize(); 
     1243    poGDS->SetDirectory(); 
     1244 
     1245    CPLAssert( poGDS != NULL 
     1246               && nBlockXOff >= 0 
     1247               && nBlockYOff >= 0 
     1248               && pImage != NULL ); 
     1249 
     1250    // First downsample to the particular number of bits in 
     1251    // a temporary buffer. 
     1252    int nLineOffset, iLine; 
     1253    GByte *pabyOddImg = (GByte *) CPLCalloc(nBlockXSize,nBlockYSize); 
     1254     
     1255    nLineOffset = (nBlockXSize * poGDS->nBitsPerSample + 7) / 8; 
     1256     
     1257    for( iLine = 0; iLine < nBlockYSize; iLine++ ) 
     1258    { 
     1259        GDALCopyBits( (GByte *) pImage,  
     1260                      iLine*nBlockXSize*8 + 8 - poGDS->nBitsPerSample, 8,  
     1261                      pabyOddImg,  
     1262                      iLine * nLineOffset * 8, poGDS->nBitsPerSample, 
     1263                      poGDS->nBitsPerSample, nBlockXSize ); 
     1264    } 
     1265     
     1266    // Then write as appropriate. 
     1267    nBlockId = nBlockXOff + nBlockYOff * nBlocksPerRow 
     1268        + (nBand-1) * poGDS->nBlocksPerBand; 
     1269     
     1270    if( TIFFIsTiled(poGDS->hTIFF) ) 
     1271    { 
     1272        nBlockBufSize = TIFFTileSize( poGDS->hTIFF ); 
     1273        if( TIFFWriteEncodedTile( poGDS->hTIFF, nBlockId, pabyOddImg,  
     1274                                  nBlockBufSize ) == -1 ) 
     1275            eErr = CE_Failure; 
     1276    } 
     1277    else 
     1278    { 
     1279        nBlockBufSize = TIFFStripSize( poGDS->hTIFF ); 
     1280        if( TIFFWriteEncodedStrip( poGDS->hTIFF, nBlockId, pabyOddImg,  
     1281                                   nBlockBufSize ) == -1 ) 
     1282            eErr = CE_Failure; 
     1283    } 
     1284     
     1285    CPLFree( pabyOddImg ); 
     1286     
     1287    return eErr; 
    12411288} 
    12421289