| | 790 | |
|---|
| | 791 | return 'success' |
|---|
| | 792 | |
|---|
| | 793 | |
|---|
| | 794 | ############################################################################### |
|---|
| | 795 | # Test color table in a 8 bit image |
|---|
| | 796 | |
|---|
| | 797 | def 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 | |
|---|
| | 829 | def 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' ) |
|---|