Changeset 13424

Show
Ignore:
Timestamp:
12/21/07 08:23:54 (5 months ago)
Author:
rouault
Message:

Various ADRG fixes (ticket #2116)

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.5/autotest/gdrivers/adrg.py

    r12708 r13424  
    11#!/usr/bin/env python 
    22############################################################################### 
    3 # $Id: png.py 12180 2007-09-17 20:40:27Z warmerdam
     3# $Id: adrg.py
    44# 
    55# Project:  GDAL/OGR Test Suite 
     
    5050def adrg_2(): 
    5151 
    52 #    tst = gdaltest.GDALTest( 'ADRG', 'SMALL_ADRG/ABCDEF01.GEN', 1, 62833 ) 
    53  
    54 #    return tst.testCreateCopy() 
    55  
    5652    drv = gdal.GetDriverByName( 'ADRG' ) 
    5753    srcds = gdal.Open( 'data/SMALL_ADRG/ABCDEF01.GEN' ) 
     
    5955    dstds = drv.CreateCopy( 'tmp/ABCDEF01.GEN', srcds ) 
    6056     
     57    chksum = dstds.GetRasterBand(1).Checksum() 
     58 
     59    if chksum != 62833: 
     60        gdaltest.post_reason('Wrong checksum') 
     61        return 'fail' 
     62 
    6163    dstds = None 
    6264     
     
    6567    return 'success' 
    6668     
    67 ############################################################################### 
    68 # Verify the geotransform, colormap, and nodata setting for test file.  
    69  
    70 def png_3(): 
    71  
    72     ds = gdal.Open( 'data/test.png' ) 
    73     cm = ds.GetRasterBand(1).GetRasterColorTable() 
    74     if cm.GetCount() != 16 \ 
    75        or cm.GetColorEntry(0) != (255,255,255,0) \ 
    76        or cm.GetColorEntry(1) != (255,255,208,255): 
    77         gdaltest.post_reason( 'Wrong colormap entries' ) 
    78         return 'fail' 
    79  
    80     cm = None 
    81  
    82     if int(ds.GetRasterBand(1).GetNoDataValue()) != 0: 
    83         gdaltest.post_reason( 'Wrong nodata value.' ) 
    84         return 'fail' 
    85  
    86     # This geotransform test is also verifying the fix for bug 1414, as 
    87     # the world file is in a mixture of numeric representations for the 
    88     # numbers.  (mixture of "," and "." in file) 
    89  
    90     gt_expected = (700000.305, 0.38, 0.01, 4287500.695, -0.01, -0.38) 
    91  
    92     gt = ds.GetGeoTransform() 
    93     for i in range(6): 
    94         if abs(gt[i] - gt_expected[i]) > 0.0001: 
    95             print 'expected:', gt_expected 
    96             print 'got:', gt 
    97              
    98             gdaltest.post_reason( 'Mixed locale world file read improperly.' ) 
    99             return 'fail' 
    100  
    101     return 'success' 
    102      
    103 ############################################################################### 
    104 # Test RGB mode creation and reading. 
    105  
    106 def png_4(): 
    107  
    108     tst = gdaltest.GDALTest( 'PNG', 'rgb.ntf', 3, 21349 ) 
    109  
    110     return tst.testCreateCopy() 
    11169 
    11270############################################################################### 
    113 # Test RGBA 16bit read support. 
     71# Cleanup procedure 
    11472 
    115 def png_5(): 
     73def adrg_cleanup(): 
    11674 
    117     tst = gdaltest.GDALTest( 'PNG', 'rgba16.png', 3, 1815 ) 
    118     return tst.testOpen() 
    119  
    120 ############################################################################### 
    121 # Test RGBA 16bit mode creation and reading. 
    122  
    123 def png_6(): 
    124  
    125     tst = gdaltest.GDALTest( 'PNG', 'rgba16.png', 4, 4873 ) 
    126  
    127     return tst.testCreateCopy() 
    128  
    129 ############################################################################### 
    130 # Test RGB NODATA_VALUES metadata write (and read) support. 
    131 # This is handled via the tRNS block in PNG. 
    132  
    133 def png_7(): 
    134  
    135     drv = gdal.GetDriverByName( 'PNG' ) 
    136     srcds = gdal.Open( 'data/tbbn2c16.png' ) 
    137      
    138     dstds = drv.CreateCopy( 'tmp/png7.png', srcds ) 
    139     srcds = None 
    140  
    141     dstds = gdal.Open( 'tmp/png7.png' ) 
    142     md = dstds.GetMetadata() 
    143     dstds = None 
    144  
    145     if md['NODATA_VALUES'] != '32639 32639 32639': 
    146         gdaltest.post_reason( 'NODATA_VALUES wrong' ) 
    147         return 'fail' 
    148  
    149     dstds = None 
    150  
    151     drv.Delete( 'tmp/png7.png' ) 
     75    try: 
     76        os.remove('tmp/ABCDEF01.IMG') 
     77        os.remove('tmp/TRANSH01.THF') 
     78    except: 
     79        pass 
    15280 
    15381    return 'success' 
    15482 
    155  
     83############################################################################### 
    15684gdaltest_list = [ 
    15785    adrg_1, 
    158     adrg_2 ] 
     86    adrg_2, 
     87    adrg_cleanup ] 
    15988 
    16089if __name__ == '__main__': 
  • branches/1.5/gdal/frmts/adrg/adrgdataset.cpp

    r12833 r13424  
    213213    } 
    214214    CPLDebug("ADRG", "(%d,%d) -> nBlock = %d", nBlockXOff, nBlockYOff, nBlock); 
    215      
    216     if (poDS->bCreation) 
    217     { 
    218         memset(pImage, 0, 128 * 128); 
    219         return CE_None; 
    220     } 
    221      
     215 
    222216    if (poDS->TILEINDEX) 
    223217    { 
     
    12681262    CPLString fileName(poOpenInfo->pszFilename); 
    12691263    CPLString NAM; 
    1270      
     1264 
     1265    if( poOpenInfo->eAccess == GA_Update ) 
     1266    { 
     1267        CPLError( CE_Failure, CPLE_NotSupported,  
     1268                  "The ADRG driver does not support update access to existing" 
     1269                  " datasets.\n" ); 
     1270        return NULL; 
     1271    } 
     1272 
    12711273    if (EQUAL(CPLGetExtension((const char*)fileName), "thf")) 
    12721274    { 
     
    13701372                    /*      Initialize any PAM information.                                 */ 
    13711373                    /* -------------------------------------------------------------------- */ 
    1372                     //poDS->SetDescription( poOpenInfo->pszFilename ); 
    1373                     //poDS->TryLoadXML(); 
     1374                    poDS->SetDescription( poOpenInfo->pszFilename ); 
     1375                    poDS->TryLoadXML(); 
    13741376 
    13751377                } 
     
    13951397 
    13961398/************************************************************************/ 
    1397 /*                                Open()                                */ 
     1399/*                               Create()                               */ 
    13981400/************************************************************************/ 
    13991401 
     
    14721474     
    14731475    CPLString imgFilename = CPLResetExtension(pszFilename, "IMG"); 
    1474     FILE* fdIMG = VSIFOpenL((const char*)imgFilename, "wb"); 
     1476    FILE* fdIMG = VSIFOpenL((const char*)imgFilename, "w+b"); 
    14751477    if (fdIMG == NULL) 
    14761478    {