Changeset 14448

Show
Ignore:
Timestamp:
05/11/08 13:47:47 (2 months ago)
Author:
rouault
Message:

NITF: add test for Create() with IC=C8, Create() with BLOCKX/YSIZE options, Create() with SetRasterColorTable?

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/autotest/gdrivers/nitf.py

    r14446 r14448  
    6363    return tst.testCreateCopy() 
    6464 
     65 
    6566############################################################################### 
    6667# Test direction creation of an NITF file. 
    6768 
    68 def nitf_4(): 
     69def nitf_create(creation_options): 
     70 
    6971    drv = gdal.GetDriverByName( 'NITF' ) 
    70     ds = drv.Create( 'tmp/test_4.ntf', 200, 100, 3, gdal.GDT_Byte, 
    71                      [ 'ICORDS=G' ] ) 
     72 
     73    try: 
     74        os.remove( 'tmp/test_create.ntf' ) 
     75    except: 
     76        pass 
     77 
     78    ds = drv.Create( 'tmp/test_create.ntf', 200, 100, 3, gdal.GDT_Byte, 
     79                     creation_options ) 
    7280    ds.SetGeoTransform( (100, 0.1, 0.0, 30.0, 0.0, -0.1 ) ) 
    7381 
     
    8997 
    9098############################################################################### 
    91 # Verify previous file 
    92  
    93 def nitf_5(): 
    94     ds = gdal.Open( 'tmp/test_4.ntf' ) 
     99# Test direction creation of an non-compressed NITF file. 
     100 
     101def nitf_4(): 
     102 
     103    return nitf_create([ 'ICORDS=G' ]) 
     104 
     105 
     106############################################################################### 
     107# Verify created file 
     108 
     109def nitf_check_created_file(checksum1, checksum2, checksum3): 
     110    ds = gdal.Open( 'tmp/test_create.ntf' ) 
    95111     
    96112    chksum = ds.GetRasterBand(1).Checksum() 
    97     chksum_expect = 32498 
     113    chksum_expect = checksum1 
    98114    if chksum != chksum_expect: 
    99115        gdaltest.post_reason( 'Did not get expected chksum for band 1' ) 
     
    102118 
    103119    chksum = ds.GetRasterBand(2).Checksum() 
    104     chksum_expect = 4260
     120    chksum_expect = checksum
    105121    if chksum != chksum_expect: 
    106122        gdaltest.post_reason( 'Did not get expected chksum for band 2' ) 
     
    109125 
    110126    chksum = ds.GetRasterBand(3).Checksum() 
    111     chksum_expect = 38982 
     127    chksum_expect = checksum3 
    112128    if chksum != chksum_expect: 
    113129        gdaltest.post_reason( 'Did not get expected chksum for band 3' ) 
     
    141157 
    142158    return 'success' 
     159 
     160############################################################################### 
     161# Verify file created by nitf_4() 
     162 
     163def nitf_5(): 
     164 
     165    return nitf_check_created_file(32498, 42602, 38982) 
    143166         
    144167############################################################################### 
     
    483506    return tst.testCreateCopy() 
    484507 
     508############################################################################### 
     509# Test Create() with IC=NC compression, and multi-blocks 
     510 
     511def nitf_27(): 
     512 
     513    if nitf_create([ 'ICORDS=G', 'IC=NC', 'BLOCKXSIZE=10', 'BLOCKYSIZE=10' ]) != 'success': 
     514        return 'fail' 
     515 
     516    return nitf_check_created_file(32498, 42602, 38982) 
     517 
     518 
     519############################################################################### 
     520# Test Create() with IC=C8 compression 
     521 
     522def nitf_28(): 
     523    try: 
     524        jp2ecw_drv = gdal.GetDriverByName( 'JP2ECW' ) 
     525    except: 
     526        return 'skip' 
     527 
     528    if nitf_create([ 'ICORDS=G', 'IC=C8' ]) != 'success': 
     529        return 'fail' 
     530 
     531    return nitf_check_created_file(32398, 42502, 38882) 
     532 
     533############################################################################### 
     534# Test Create() with a LUT 
     535 
     536def nitf_29(): 
     537 
     538    drv = gdal.GetDriverByName( 'NITF' ) 
     539 
     540    ds = drv.Create( 'tmp/test_29.ntf', 1, 1, 1, gdal.GDT_Byte, 
     541                     [ 'IREP=RGB/LUT', 'LUT_SIZE=128' ] ) 
     542 
     543    ct = gdal.ColorTable() 
     544    ct.SetColorEntry( 0, (255,255,255,255) ) 
     545    ct.SetColorEntry( 1, (255,255,0,255) ) 
     546    ct.SetColorEntry( 2, (255,0,255,255) ) 
     547    ct.SetColorEntry( 3, (0,255,255,255) ) 
     548 
     549    ds.GetRasterBand( 1 ).SetRasterColorTable( ct ) 
     550 
     551    ds = None 
     552 
     553    ds = gdal.Open( 'tmp/test_29.ntf' ) 
     554 
     555    ct = ds.GetRasterBand( 1 ).GetRasterColorTable() 
     556    if ct.GetCount() != 129 or \ 
     557       ct.GetColorEntry(0) != (255,255,255,255) or \ 
     558       ct.GetColorEntry(1) != (255,255,0,255) or \ 
     559       ct.GetColorEntry(2) != (255,0,255,255) or \ 
     560       ct.GetColorEntry(3) != (0,255,255,255): 
     561        gdaltest.post_reason( 'Wrong color table entry.' ) 
     562        return 'fail' 
     563 
     564    ds = None 
     565 
     566    return 'success' 
    485567 
    486568############################################################################### 
     
    673755def nitf_cleanup(): 
    674756    try: 
    675         gdal.GetDriverByName('NITF').Delete( 'tmp/test_4.ntf' ) 
     757        gdal.GetDriverByName('NITF').Delete( 'tmp/test_create.ntf' ) 
    676758    except: 
    677759        pass 
     
    684766    try: 
    685767        gdal.GetDriverByName('NITF').Delete( 'tmp/test_13.ntf' ) 
     768    except: 
     769        pass 
     770 
     771    try: 
     772        gdal.GetDriverByName('NITF').Delete( 'tmp/test_29.ntf' ) 
    686773    except: 
    687774        pass 
     
    716803    nitf_25, 
    717804    nitf_26, 
     805    nitf_27, 
     806    nitf_28, 
     807    nitf_29, 
    718808    nitf_online_1, 
    719809    nitf_online_2,