Changeset 14410

Show
Ignore:
Timestamp:
05/09/08 10:33:53 (3 months ago)
Author:
rouault
Message:

Add tests for GTiff RGBA, grey+alpha and CIELAB images

Files:

Legend:

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

    r14408 r14410  
    653653            return 'fail' 
    654654 
     655    new_ds = None 
    655656    src_ds = None 
    656657 
    657658    gdaltest.tiff_drv.Delete( 'tmp/tags.tif' ) 
     659 
     660    return 'success' 
     661 
     662############################################################################### 
     663# Test RGBA images with TIFFTAG_EXTRASAMPLES=EXTRASAMPLE_ASSOCALPHA 
     664 
     665def tiff_write_21(): 
     666 
     667    src_ds = gdal.Open( 'data/stefan_full_rgba.tif' ) 
     668 
     669    new_ds = gdaltest.tiff_drv.CreateCopy( 'tmp/stefan_full_rgba.tif', src_ds ) 
     670 
     671    new_ds = None 
     672 
     673    new_ds = gdal.Open( 'tmp/stefan_full_rgba.tif' ) 
     674    if new_ds.RasterCount != 4: 
     675        return 'fail' 
     676    for i in range(4): 
     677        if new_ds.GetRasterBand(i+1).GetRasterColorInterpretation() != src_ds.GetRasterBand(i+1).GetRasterColorInterpretation(): 
     678            return 'fail' 
     679        if new_ds.GetRasterBand(i+1).Checksum() != src_ds.GetRasterBand(i+1).Checksum(): 
     680            return 'fail' 
     681 
     682    new_ds = None 
     683    src_ds = None 
     684 
     685    gdaltest.tiff_drv.Delete( 'tmp/stefan_full_rgba.tif' ) 
     686 
     687    return 'success' 
     688 
     689############################################################################### 
     690# Test RGBA images with TIFFTAG_EXTRASAMPLES=EXTRASAMPLE_UNSPECIFIED 
     691 
     692def tiff_write_22(): 
     693 
     694    src_ds = gdal.Open( 'data/stefan_full_rgba_photometric_rgb.tif' ) 
     695 
     696    new_ds = gdaltest.tiff_drv.CreateCopy( 'tmp/stefan_full_rgba_photometric_rgb.tif', src_ds, options = [ 'PHOTOMETRIC=RGB' ] ) 
     697 
     698    new_ds = None 
     699 
     700    new_ds = gdal.Open( 'tmp/stefan_full_rgba_photometric_rgb.tif' ) 
     701    if new_ds.RasterCount != 4: 
     702        return 'fail' 
     703    for i in range(4): 
     704        if new_ds.GetRasterBand(i+1).GetRasterColorInterpretation() != src_ds.GetRasterBand(i+1).GetRasterColorInterpretation(): 
     705            return 'fail' 
     706        if new_ds.GetRasterBand(i+1).Checksum() != src_ds.GetRasterBand(i+1).Checksum(): 
     707            return 'fail' 
     708 
     709    new_ds = None 
     710    src_ds = None 
     711 
     712    gdaltest.tiff_drv.Delete( 'tmp/stefan_full_rgba_photometric_rgb.tif' ) 
     713 
     714    return 'success' 
     715 
     716############################################################################### 
     717# Test grey+alpha images with ALPHA=YES 
     718 
     719def tiff_write_23(): 
     720 
     721    src_ds = gdal.Open( 'data/stefan_full_greyalpha.tif' ) 
     722 
     723    new_ds = gdaltest.tiff_drv.CreateCopy( 'tmp/stefan_full_greyalpha.tif', src_ds, options = [ 'ALPHA=YES' ] ) 
     724 
     725    new_ds = None 
     726 
     727    new_ds = gdal.Open( 'tmp/stefan_full_greyalpha.tif' ) 
     728    if new_ds.RasterCount != 2: 
     729        return 'fail' 
     730    for i in range(2): 
     731        if new_ds.GetRasterBand(i+1).GetRasterColorInterpretation() != src_ds.GetRasterBand(i+1).GetRasterColorInterpretation(): 
     732            return 'fail' 
     733        if new_ds.GetRasterBand(i+1).Checksum() != src_ds.GetRasterBand(i+1).Checksum(): 
     734            return 'fail' 
     735 
     736    new_ds = None 
     737    src_ds = None 
     738 
     739    gdaltest.tiff_drv.Delete( 'tmp/stefan_full_greyalpha.tif' ) 
     740 
     741    return 'success' 
     742 
     743############################################################################### 
     744# Test grey+alpha images without ALPHA=YES 
     745 
     746def tiff_write_24(): 
     747 
     748    src_ds = gdal.Open( 'data/stefan_full_greyalpha.tif' ) 
     749 
     750    new_ds = gdaltest.tiff_drv.CreateCopy( 'tmp/stefan_full_greyunspecified.tif', src_ds ) 
     751 
     752    new_ds = None 
     753 
     754    new_ds = gdal.Open( 'tmp/stefan_full_greyunspecified.tif' ) 
     755    if new_ds.GetRasterBand(2).GetRasterColorInterpretation() != gdal.GCI_Undefined: 
     756        return 'fail' 
     757 
     758    new_ds = None 
     759    src_ds = None 
     760 
     761    gdaltest.tiff_drv.Delete( 'tmp/stefan_full_greyunspecified.tif' ) 
     762 
     763    return 'success' 
     764 
     765############################################################################### 
     766# Read a CIELAB image to test the RGBA image TIFF interface 
     767 
     768def tiff_write_25(): 
     769 
     770    src_ds = gdal.Open( 'data/cielab.tif' ) 
     771    if src_ds.RasterCount != 4: 
     772        return 'fail' 
     773    if src_ds.GetRasterBand(1).Checksum() != 6: 
     774        return 'fail' 
     775    if src_ds.GetRasterBand(2).Checksum() != 3: 
     776        return 'fail' 
     777    if src_ds.GetRasterBand(3).Checksum() != 0: 
     778        return 'fail' 
     779    if src_ds.GetRasterBand(4).Checksum() != 3: 
     780        return 'fail' 
     781    if src_ds.GetRasterBand(1).GetRasterColorInterpretation() != gdal.GCI_RedBand: 
     782        return 'fail' 
     783    if src_ds.GetRasterBand(2).GetRasterColorInterpretation() != gdal.GCI_GreenBand: 
     784        return 'fail' 
     785    if src_ds.GetRasterBand(3).GetRasterColorInterpretation() != gdal.GCI_BlueBand: 
     786        return 'fail' 
     787    if src_ds.GetRasterBand(4).GetRasterColorInterpretation() != gdal.GCI_AlphaBand: 
     788        return 'fail' 
     789    src_ds = None 
    658790 
    659791    return 'success' 
     
    685817    tiff_write_19, 
    686818    tiff_write_20, 
     819    tiff_write_21, 
     820    tiff_write_22, 
     821    tiff_write_23, 
     822    tiff_write_24, 
     823    tiff_write_25, 
    687824    tiff_write_cleanup ] 
    688825