Changeset 12343

Show
Ignore:
Timestamp:
10/06/07 00:12:24 (1 year ago)
Author:
warmerdam
Message:

Code reformatting ... no operational effect.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/gdal/frmts/png/pngdataset.cpp

    r11629 r12343  
    862862/*      Open overviews.                                                 */ 
    863863/* -------------------------------------------------------------------- */ 
    864     poDS->oOvManager.Initialize( poDS, poOpenInfo->pszFilename ); 
     864    poDS->oOvManager.Initialize( poDS, poOpenInfo->pszFilename, 
     865                                 poOpenInfo->papszSiblingFiles ); 
    865866 
    866867/* -------------------------------------------------------------------- */ 
     
    13021303CPLErr PNGRasterBand::IWriteBlock(int x, int y, void* pvData) 
    13031304{ 
    1304        // rcg, added to support Create(). 
    1305  
    1306        PNGDataset& ds = *(PNGDataset*)poDS; 
    1307  
    1308  
    1309        // Write the block (or consolidate into multichannel block) 
    1310        // and then write. 
    1311  
    1312        const GDALDataType dt = this->GetRasterDataType(); 
    1313        const size_t wordsize = ds.m_nBitDepth / 8; 
    1314        GDALCopyWords( pvData, dt, wordsize, 
    1315                ds.m_pabyBuffer + (nBand-1) * wordsize, 
    1316                           dt, ds.nBands * wordsize, 
    1317                nBlockXSize ); 
    1318  
    1319        // See if we got all the bands. 
    1320        size_t i; 
    1321        m_bBandProvided[nBand - 1] = TRUE; 
    1322        for(i = 0; i < ds.nBands; i++) 
    1323        
    1324                if(!m_bBandProvided[i]) 
    1325                        return CE_None; 
    1326        
    1327  
    1328        // We received all the bands, so 
    1329        // reset band flags and write pixels out. 
    1330        this->reset_band_provision_flags(); 
    1331  
    1332  
    1333        // If first block, write out file header. 
    1334        if(x == 0 && y == 0) 
    1335        
    1336                CPLErr err = ds.write_png_header(); 
    1337                if(err != CE_None) 
    1338                        return err; 
    1339        
     1305    // rcg, added to support Create(). 
     1306 
     1307    PNGDataset& ds = *(PNGDataset*)poDS; 
     1308 
     1309 
     1310    // Write the block (or consolidate into multichannel block) 
     1311    // and then write. 
     1312 
     1313    const GDALDataType dt = this->GetRasterDataType(); 
     1314    const size_t wordsize = ds.m_nBitDepth / 8; 
     1315    GDALCopyWords( pvData, dt, wordsize, 
     1316                   ds.m_pabyBuffer + (nBand-1) * wordsize, 
     1317                   dt, ds.nBands * wordsize, 
     1318                   nBlockXSize ); 
     1319 
     1320    // See if we got all the bands. 
     1321    size_t i; 
     1322    m_bBandProvided[nBand - 1] = TRUE; 
     1323    for(i = 0; i < ds.nBands; i++) 
     1324   
     1325        if(!m_bBandProvided[i]) 
     1326            return CE_None; 
     1327   
     1328 
     1329    // We received all the bands, so 
     1330    // reset band flags and write pixels out. 
     1331    this->reset_band_provision_flags(); 
     1332 
     1333 
     1334    // If first block, write out file header. 
     1335    if(x == 0 && y == 0) 
     1336   
     1337        CPLErr err = ds.write_png_header(); 
     1338        if(err != CE_None) 
     1339            return err; 
     1340   
    13401341 
    13411342#ifdef CPL_LSB 
     
    13451346    png_write_rows( ds.m_hPNG, &ds.m_pabyBuffer, 1 ); 
    13461347 
    1347        return CE_None; 
     1348    return CE_None; 
    13481349} 
    13491350 
     
    13551356CPLErr PNGDataset::SetGeoTransform( double * padfTransform ) 
    13561357{ 
    1357        // rcg, added to support Create(). 
     1358    // rcg, added to support Create(). 
    13581359 
    13591360    CPLErr eErr = CE_None; 
     
    13811382CPLErr PNGRasterBand::SetColorTable(GDALColorTable* poCT) 
    13821383{ 
    1383        // rcg, added to support Create(). 
    1384        // We get called even for grayscale files, since some  
    1385        // formats need a palette even then. PNG doesn't, so 
    1386        // if a gray palette is given, just ignore it. 
    1387  
    1388        GDALColorEntry sEntry; 
    1389        for( size_t i = 0; i < poCT->GetColorEntryCount(); i++ ) 
    1390        
    1391                poCT->GetColorEntryAsRGB( i, &sEntry ); 
    1392                if( sEntry.c1 != sEntry.c2 || sEntry.c1 != sEntry.c3) 
    1393                
    1394                        CPLErr err = GDALPamRasterBand::SetColorTable(poCT); 
    1395                        if(err != CE_None) 
    1396                                return err; 
    1397  
    1398                        PNGDataset& ds = *(PNGDataset*)poDS; 
    1399                        ds.m_nColorType = PNG_COLOR_TYPE_PALETTE; 
    1400                        break; 
    1401                        // band::IWriteBlock will emit color table as part of  
    1402                        // header preceding first block write. 
    1403                
    1404        
    1405  
    1406        return CE_None; 
     1384    // rcg, added to support Create(). 
     1385    // We get called even for grayscale files, since some  
     1386    // formats need a palette even then. PNG doesn't, so 
     1387    // if a gray palette is given, just ignore it. 
     1388 
     1389    GDALColorEntry sEntry; 
     1390    for( size_t i = 0; i < poCT->GetColorEntryCount(); i++ ) 
     1391   
     1392        poCT->GetColorEntryAsRGB( i, &sEntry ); 
     1393        if( sEntry.c1 != sEntry.c2 || sEntry.c1 != sEntry.c3) 
     1394       
     1395            CPLErr err = GDALPamRasterBand::SetColorTable(poCT); 
     1396            if(err != CE_None) 
     1397                return err; 
     1398 
     1399            PNGDataset& ds = *(PNGDataset*)poDS; 
     1400            ds.m_nColorType = PNG_COLOR_TYPE_PALETTE; 
     1401            break; 
     1402            // band::IWriteBlock will emit color table as part of  
     1403            // header preceding first block write. 
     1404       
     1405   
     1406 
     1407    return CE_None; 
    14071408} 
    14081409 
     
    14141415CPLErr PNGDataset::write_png_header() 
    14151416{ 
    1416        /* -------------------------------------------------------------------- */ 
    1417        /*      Initialize PNG access to the file.                              */ 
    1418        /* -------------------------------------------------------------------- */ 
    1419  
    1420        m_hPNG = png_create_write_struct(  
    1421                PNG_LIBPNG_VER_STRING, NULL,  
    1422                png_gdal_error, png_gdal_warning ); 
    1423  
    1424        m_psPNGInfo = png_create_info_struct( m_hPNG ); 
    1425  
    1426        png_set_write_fn( m_hPNG, m_fpImage, png_vsi_write_data, png_vsi_flush ); 
    1427  
    1428        png_set_IHDR( m_hPNG, m_psPNGInfo, nRasterXSize, nRasterYSize,  
    1429                                  m_nBitDepth, m_nColorType, PNG_INTERLACE_NONE,  
    1430                                  PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT ); 
     1417/* -------------------------------------------------------------------- */ 
     1418/*      Initialize PNG access to the file.                              */ 
     1419/* -------------------------------------------------------------------- */ 
     1420     
     1421    m_hPNG = png_create_write_struct(  
     1422        PNG_LIBPNG_VER_STRING, NULL,  
     1423        png_gdal_error, png_gdal_warning ); 
     1424 
     1425    m_psPNGInfo = png_create_info_struct( m_hPNG ); 
     1426 
     1427    png_set_write_fn( m_hPNG, m_fpImage, png_vsi_write_data, png_vsi_flush ); 
     1428 
     1429    png_set_IHDR( m_hPNG, m_psPNGInfo, nRasterXSize, nRasterYSize,  
     1430                  m_nBitDepth, m_nColorType, PNG_INTERLACE_NONE,  
     1431                  PNG_COMPRESSION_TYPE_DEFAULT, PNG_FILTER_TYPE_DEFAULT ); 
    14311432 
    14321433    png_set_compression_level(m_hPNG, Z_BEST_COMPRESSION); 
     
    14391440/*      palette).                                                       */ 
    14401441/* -------------------------------------------------------------------- */ 
    1441        //m_bHaveNoData = FALSE; 
    1442        //m_dfNoDataValue = -1; 
    1443        png_color_16 sTRNSColor; 
     1442    //m_bHaveNoData = FALSE; 
     1443    //m_dfNoDataValue = -1; 
     1444    png_color_16 sTRNSColor; 
    14441445 
    14451446 
     
    14471448    double      dfNoDataValue = -1; 
    14481449 
    1449        if( m_nColorType == PNG_COLOR_TYPE_GRAY ) 
    1450        
    1451        dfNoDataValue = this->GetRasterBand(1)->GetNoDataValue( &bHaveNoData ); 
    1452  
    1453        if ( dfNoDataValue > 0 && dfNoDataValue < 65536 ) 
    1454           { 
    1455                  sTRNSColor.gray = (png_uint_16) dfNoDataValue; 
    1456                  png_set_tRNS( m_hPNG, m_psPNGInfo, NULL, 0, &sTRNSColor ); 
    1457           } 
    1458        
     1450    if( m_nColorType == PNG_COLOR_TYPE_GRAY ) 
     1451   
     1452        dfNoDataValue = this->GetRasterBand(1)->GetNoDataValue( &bHaveNoData ); 
     1453 
     1454        if ( dfNoDataValue > 0 && dfNoDataValue < 65536 ) 
     1455        { 
     1456            sTRNSColor.gray = (png_uint_16) dfNoDataValue; 
     1457            png_set_tRNS( m_hPNG, m_psPNGInfo, NULL, 0, &sTRNSColor ); 
     1458        } 
     1459   
    14591460 
    14601461    // RGB nodata. 
    14611462    if( nColorType == PNG_COLOR_TYPE_RGB ) 
    14621463    { 
    1463        // First try to use the NODATA_VALUES metadata item. 
    1464        if ( this->GetMetadataItem( "NODATA_VALUES" ) != NULL ) 
    1465        
    1466            char **papszValues = CSLTokenizeString( 
    1467                this->GetMetadataItem( "NODATA_VALUES" ) ); 
     1464        // First try to use the NODATA_VALUES metadata item. 
     1465        if ( this->GetMetadataItem( "NODATA_VALUES" ) != NULL ) 
     1466       
     1467            char **papszValues = CSLTokenizeString( 
     1468                this->GetMetadataItem( "NODATA_VALUES" ) ); 
    14681469            
    1469            if( CSLCount(papszValues) >= 3 ) 
    1470            
    1471                sTRNSColor.red   = (png_uint_16) atoi(papszValues[0]); 
    1472                sTRNSColor.green = (png_uint_16) atoi(papszValues[1]); 
    1473                sTRNSColor.blue  = (png_uint_16) atoi(papszValues[2]); 
    1474                png_set_tRNS( m_hPNG, m_psPNGInfo, NULL, 0, &sTRNSColor ); 
    1475            
    1476  
    1477            CSLDestroy( papszValues ); 
    1478        
    1479        // Otherwise, get the nodata value from the bands. 
    1480        else 
    1481        
    1482           int   bHaveNoData = FALSE; 
    1483           double dfNoDataValueRed = -1; 
    1484           double dfNoDataValueGreen = -1; 
    1485           double dfNoDataValueBlue = -1; 
    1486  
    1487           dfNoDataValueRed  = this->GetRasterBand(1)->GetNoDataValue( &bHaveNoData ); 
    1488           dfNoDataValueGreen= this->GetRasterBand(2)->GetNoDataValue( &bHaveNoData ); 
    1489           dfNoDataValueBlue = this->GetRasterBand(3)->GetNoDataValue( &bHaveNoData ); 
    1490  
    1491           if ( ( dfNoDataValueRed > 0 && dfNoDataValueRed < 65536 ) && 
    1492              ( dfNoDataValueGreen > 0 && dfNoDataValueGreen < 65536 ) && 
    1493              ( dfNoDataValueBlue > 0 && dfNoDataValueBlue < 65536 ) ) 
    1494          
    1495              sTRNSColor.red   = (png_uint_16) dfNoDataValueRed; 
    1496              sTRNSColor.green = (png_uint_16) dfNoDataValueGreen; 
    1497              sTRNSColor.blue  = (png_uint_16) dfNoDataValueBlue; 
    1498              png_set_tRNS( m_hPNG, m_psPNGInfo, NULL, 0, &sTRNSColor ); 
    1499          
    1500        
     1470            if( CSLCount(papszValues) >= 3 ) 
     1471           
     1472                sTRNSColor.red   = (png_uint_16) atoi(papszValues[0]); 
     1473                sTRNSColor.green = (png_uint_16) atoi(papszValues[1]); 
     1474                sTRNSColor.blue  = (png_uint_16) atoi(papszValues[2]); 
     1475                png_set_tRNS( m_hPNG, m_psPNGInfo, NULL, 0, &sTRNSColor ); 
     1476           
     1477 
     1478            CSLDestroy( papszValues ); 
     1479       
     1480        // Otherwise, get the nodata value from the bands. 
     1481        else 
     1482       
     1483            int         bHaveNoData = FALSE; 
     1484            double dfNoDataValueRed = -1; 
     1485            double dfNoDataValueGreen = -1; 
     1486            double dfNoDataValueBlue = -1; 
     1487 
     1488            dfNoDataValueRed  = this->GetRasterBand(1)->GetNoDataValue( &bHaveNoData ); 
     1489            dfNoDataValueGreen= this->GetRasterBand(2)->GetNoDataValue( &bHaveNoData ); 
     1490            dfNoDataValueBlue = this->GetRasterBand(3)->GetNoDataValue( &bHaveNoData ); 
     1491 
     1492            if ( ( dfNoDataValueRed > 0 && dfNoDataValueRed < 65536 ) && 
     1493                 ( dfNoDataValueGreen > 0 && dfNoDataValueGreen < 65536 ) && 
     1494                 ( dfNoDataValueBlue > 0 && dfNoDataValueBlue < 65536 ) ) 
     1495           
     1496                sTRNSColor.red   = (png_uint_16) dfNoDataValueRed; 
     1497                sTRNSColor.green = (png_uint_16) dfNoDataValueGreen; 
     1498                sTRNSColor.blue  = (png_uint_16) dfNoDataValueBlue; 
     1499                png_set_tRNS( m_hPNG, m_psPNGInfo, NULL, 0, &sTRNSColor ); 
     1500           
     1501       
    15011502    } 
    15021503 
     
    15201521 
    15211522        m_pasPNGColors = (png_color *) CPLMalloc(sizeof(png_color) * 
    1522                                                poCT->GetColorEntryCount()); 
     1523                                                 poCT->GetColorEntryCount()); 
    15231524 
    15241525        for( iColor = 0; iColor < poCT->GetColorEntryCount(); iColor++ ) 
     
    15581559    } 
    15591560 
    1560        png_write_info( m_hPNG, m_psPNGInfo ); 
    1561        return CE_None; 
     1561    png_write_info( m_hPNG, m_psPNGInfo ); 
     1562    return CE_None; 
    15621563} 
    15631564 
     
    15801581    { 
    15811582        CPLError( CE_Failure, CPLE_AppDefined, 
    1582               "Attempt to create PNG dataset with an illegal\n" 
    1583               "data type (%s), only Byte and UInt16 supported by the format.\n", 
    1584               GDALGetDataTypeName(eType) ); 
     1583                  "Attempt to create PNG dataset with an illegal\n" 
     1584                  "data type (%s), only Byte and UInt16 supported by the format.\n", 
     1585                  GDALGetDataTypeName(eType) ); 
    15851586 
    15861587        return NULL; 
     
    15911592        CPLError( CE_Failure, CPLE_NotSupported, 
    15921593                  "PNG driver doesn't support %d bands. " 
    1593                                  "Must be 1 (gray/indexed color),\n" 
     1594                  "Must be 1 (gray/indexed color),\n" 
    15941595                  "2 (gray+alpha), 3 (rgb) or 4 (rgba) bands.\n",  
    15951596                  nBands ); 
     
    15991600 
    16001601 
    1601        // Bands are: 
    1602        // 1: grayscale or indexed color 
    1603        // 2: gray plus alpha 
    1604        // 3: rgb 
    1605        // 4: rgb plus alpha 
    1606  
    1607        if(nXSize < 1 || nYSize < 1) 
    1608        
     1602    // Bands are: 
     1603    // 1: grayscale or indexed color 
     1604    // 2: gray plus alpha 
     1605    // 3: rgb 
     1606    // 4: rgb plus alpha 
     1607 
     1608    if(nXSize < 1 || nYSize < 1) 
     1609   
    16091610        CPLError( CE_Failure, CPLE_NotSupported, 
    16101611                  "Specified pixel dimensions (% d x %d) are bad.\n", 
    16111612                  nXSize, nYSize ); 
    1612        
     1613   
    16131614 
    16141615/* -------------------------------------------------------------------- */ 
     
    16241625 
    16251626 
    1626        switch(nBands) 
    1627        
    1628                case 1: 
    1629                        poDS->m_nColorType = PNG_COLOR_TYPE_GRAY; 
    1630                        break;// if a non-gray palette is set, we'll change this. 
    1631  
    1632                case 2: 
    1633                        poDS->m_nColorType = PNG_COLOR_TYPE_GRAY_ALPHA; 
    1634                        break; 
    1635  
    1636                case 3: 
    1637                        poDS->m_nColorType = PNG_COLOR_TYPE_RGB; 
    1638                        break; 
     1627    switch(nBands) 
     1628   
     1629      case 1: 
     1630        poDS->m_nColorType = PNG_COLOR_TYPE_GRAY; 
     1631        break;// if a non-gray palette is set, we'll change this. 
     1632 
     1633      case 2: 
     1634        poDS->m_nColorType = PNG_COLOR_TYPE_GRAY_ALPHA; 
     1635        break; 
     1636 
     1637      case 3: 
     1638        poDS->m_nColorType = PNG_COLOR_TYPE_RGB; 
     1639        break; 
    16391640         
    1640                case 4: 
    1641                poDS->m_nColorType = PNG_COLOR_TYPE_RGB_ALPHA; 
    1642                        break; 
    1643        
    1644  
    1645        poDS->m_nBitDepth = (eType == GDT_Byte ? 8 : 16); 
     1641      case 4: 
     1642        poDS->m_nColorType = PNG_COLOR_TYPE_RGB_ALPHA; 
     1643        break; 
     1644   
     1645 
     1646    poDS->m_nBitDepth = (eType == GDT_Byte ? 8 : 16); 
    16461647 
    16471648    poDS->m_pabyBuffer = (GByte *) CPLMalloc( 
    1648                 nBands * nXSize * poDS->m_nBitDepth / 8 ); 
     1649        nBands * nXSize * poDS->m_nBitDepth / 8 ); 
    16491650 
    16501651/* -------------------------------------------------------------------- */ 
     
    16721673                  "Unable to create PNG file %s.\n",  
    16731674                  pszFilename ); 
    1674                delete poDS; 
     1675        delete poDS; 
    16751676        return NULL; 
    16761677    } 
     
    16781679    poDS->m_pszFilename = CPLStrdup(pszFilename); 
    16791680 
    1680        return poDS; 
     1681    return poDS; 
    16811682} 
    16821683