Changeset 14413

Show
Ignore:
Timestamp:
05/09/08 11:04:42 (3 months ago)
Author:
rouault
Message:

Add tests for color tables, 8 bit and 16 bit cases, for GTiff

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/autotest/gcore/tiff_write.py

    r14410 r14413  
    788788        return 'fail' 
    789789    src_ds = None 
     790 
     791    return 'success' 
     792 
     793 
     794############################################################################### 
     795# Test color table in a 8 bit image 
     796 
     797def tiff_write_26(): 
     798 
     799    ds = gdaltest.tiff_drv.Create( 'tmp/ct8.tif', 1, 1, 1, gdal.GDT_Byte) 
     800 
     801    ct = gdal.ColorTable() 
     802    ct.SetColorEntry( 0, (255,255,255,255) ) 
     803    ct.SetColorEntry( 1, (255,255,0,255) ) 
     804    ct.SetColorEntry( 2, (255,0,255,255) ) 
     805    ct.SetColorEntry( 3, (0,255,255,255) ) 
     806 
     807    ds.GetRasterBand( 1 ).SetRasterColorTable( ct ) 
     808 
     809    ds = None 
     810 
     811    ds = gdal.Open( 'tmp/ct8.tif' ) 
     812 
     813    ct = ds.GetRasterBand( 1 ).GetRasterColorTable() 
     814    if ct.GetCount() != 256 or \ 
     815       ct.GetColorEntry(0) != (255,255,255,255) or \ 
     816       ct.GetColorEntry(1) != (255,255,0,255) or \ 
     817       ct.GetColorEntry(2) != (255,0,255,255) or \ 
     818       ct.GetColorEntry(3) != (0,255,255,255): 
     819        gdaltest.post_reason( 'Wrong color table entry.' ) 
     820        return 'fail' 
     821 
     822    gdaltest.tiff_drv.Delete( 'tmp/ct8.tif' ) 
     823 
     824    return 'success' 
     825 
     826############################################################################### 
     827# Test color table in a 16 bit image 
     828 
     829def tiff_write_27(): 
     830 
     831    ds = gdaltest.tiff_drv.Create( 'tmp/ct16.tif', 1, 1, 1, gdal.GDT_UInt16) 
     832 
     833    ct = gdal.ColorTable() 
     834    ct.SetColorEntry( 0, (255,255,255,255) ) 
     835    ct.SetColorEntry( 1, (255,255,0,255) ) 
     836    ct.SetColorEntry( 2, (255,0,255,255) ) 
     837    ct.SetColorEntry( 3, (0,255,255,255) ) 
     838 
     839    ds.GetRasterBand( 1 ).SetRasterColorTable( ct ) 
     840 
     841    ds = None 
     842 
     843    ds = gdal.Open( 'tmp/ct16.tif' ) 
     844    new_ds = gdaltest.tiff_drv.CreateCopy( 'tmp/ct16_copy.tif', ds ) 
     845    new_ds = None 
     846    ds = None 
     847 
     848    ds = gdal.Open( 'tmp/ct16_copy.tif' ) 
     849 
     850    ct = ds.GetRasterBand( 1 ).GetRasterColorTable() 
     851    if ct.GetCount() != 65536 or \ 
     852       ct.GetColorEntry(0) != (255,255,255,255) or \ 
     853       ct.GetColorEntry(1) != (255,255,0,255) or \ 
     854       ct.GetColorEntry(2) != (255,0,255,255) or \ 
     855       ct.GetColorEntry(3) != (0,255,255,255): 
     856        gdaltest.post_reason( 'Wrong color table entry.' ) 
     857        return 'fail' 
     858 
     859    ds = None 
     860 
     861    gdaltest.tiff_drv.Delete( 'tmp/ct16.tif' ) 
     862    gdaltest.tiff_drv.Delete( 'tmp/ct16_copy.tif' ) 
    790863 
    791864    return 'success' 
     
    822895    tiff_write_24, 
    823896    tiff_write_25, 
     897    tiff_write_26, 
     898    tiff_write_27, 
    824899    tiff_write_cleanup ] 
    825900