| 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() |
|---|
| 111 | | |
|---|
| 112 | | ############################################################################### |
|---|
| 113 | | # Test RGBA 16bit read support. |
|---|
| 114 | | |
|---|
| 115 | | def png_5(): |
|---|
| 116 | | |
|---|
| 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' ) |
|---|
| 152 | | |
|---|
| 153 | | return 'success' |
|---|
| 154 | | |
|---|