Changeset 14841

Show
Ignore:
Timestamp:
07/06/08 13:44:59 (5 months ago)
Author:
rouault
Message:

Add test for #2360

Files:

Legend:

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

    r14801 r14841  
    12761276 
    12771277    drv.Delete( 'tmp/tw_35.tif' ) 
     1278 
     1279    return 'success' 
     1280 
     1281############################################################################### 
     1282# Generic functions for the 8 following tests 
     1283 
     1284def tiff_write_big_odd_bits(vrtfilename, tmpfilename, nbits, interleaving): 
     1285    drv = gdal.GetDriverByName( 'GTiff' ) 
     1286 
     1287    ds_in = gdal.Open(vrtfilename) 
     1288 
     1289    ds = drv.CreateCopy( tmpfilename, ds_in, options = [ 'NBITS=' + str(nbits), 'INTERLEAVE='+ interleaving ] ) 
     1290 
     1291    ds_in = None 
     1292 
     1293    ds = None 
     1294 
     1295    ds = gdal.Open( tmpfilename ) 
     1296    bnd = ds.GetRasterBand(1) 
     1297    if bnd.Checksum() != 4672: 
     1298        gdaltest.post_reason( 'Didnt get expected checksum on band 1') 
     1299        return 'fail' 
     1300    md = bnd.GetMetadata('IMAGE_STRUCTURE') 
     1301    if md['NBITS'] != str(nbits): 
     1302        gdaltest.post_reason( 'Didnt get expected NBITS value') 
     1303        return 'fail' 
     1304 
     1305    bnd = ds.GetRasterBand(2) 
     1306    if bnd.Checksum() != 4672: 
     1307        gdaltest.post_reason( 'Didnt get expected checksum on band 2') 
     1308        return 'fail' 
     1309    bnd = ds.GetRasterBand(3) 
     1310    if bnd.Checksum() != 4672: 
     1311        gdaltest.post_reason( 'Didnt get expected checksum on band 3') 
     1312        return 'fail' 
     1313 
     1314    md = ds.GetMetadata('IMAGE_STRUCTURE'); 
     1315    if md['INTERLEAVE'] != interleaving: 
     1316        gdaltest.post_reason( 'Didnt get expected interleaving') 
     1317        return 'fail' 
     1318 
     1319    ds = None 
     1320 
     1321    drv.Delete( tmpfilename ) 
     1322 
     1323    return 'success' 
     1324 
     1325 
     1326############################################################################### 
     1327# Test copy with NBITS=9, INTERLEAVE=PIXEL 
     1328 
     1329def tiff_write_36(): 
     1330    return tiff_write_big_odd_bits('data/uint16_3band.vrt', 'tmp/tw_36.tif', 9, 'PIXEL' ) 
     1331 
     1332 
     1333############################################################################### 
     1334# Test copy with NBITS=9, INTERLEAVE=BAND 
     1335 
     1336def tiff_write_37(): 
     1337    return tiff_write_big_odd_bits('data/uint16_3band.vrt', 'tmp/tw_37.tif', 9, 'BAND' ) 
     1338 
     1339############################################################################### 
     1340# Test copy with NBITS=12, INTERLEAVE=PIXEL 
     1341 
     1342def tiff_write_38(): 
     1343    return tiff_write_big_odd_bits('data/uint16_3band.vrt', 'tmp/tw_38.tif', 12, 'PIXEL' ) 
     1344 
     1345############################################################################### 
     1346# Test copy with NBITS=12, INTERLEAVE=BAND 
     1347 
     1348def tiff_write_39(): 
     1349    return tiff_write_big_odd_bits('data/uint16_3band.vrt', 'tmp/tw_39.tif', 12, 'BAND' ) 
     1350 
     1351############################################################################### 
     1352# Test copy with NBITS=17, INTERLEAVE=PIXEL 
     1353 
     1354def tiff_write_40(): 
     1355    return tiff_write_big_odd_bits('data/uint32_3band.vrt', 'tmp/tw_40tif', 17, 'PIXEL' ) 
     1356 
     1357############################################################################### 
     1358# Test copy with NBITS=17, INTERLEAVE=BAND 
     1359 
     1360def tiff_write_41(): 
     1361    return tiff_write_big_odd_bits('data/uint32_3band.vrt', 'tmp/tw_41.tif', 17, 'BAND' ) 
     1362 
     1363############################################################################### 
     1364# Test copy with NBITS=24, INTERLEAVE=PIXEL 
     1365 
     1366def tiff_write_42(): 
     1367    return tiff_write_big_odd_bits('data/uint32_3band.vrt', 'tmp/tw_42.tif', 24, 'PIXEL' ) 
     1368 
     1369############################################################################### 
     1370# Test copy with NBITS=24, INTERLEAVE=BAND 
     1371 
     1372def tiff_write_43(): 
     1373    return tiff_write_big_odd_bits('data/uint32_3band.vrt', 'tmp/tw_43.tif', 24, 'BAND' ) 
     1374 
     1375 
     1376############################################################################### 
     1377# Test create with NBITS=9 and preservation through CreateCopy of NBITS 
     1378 
     1379def tiff_write_44(): 
     1380    drv = gdal.GetDriverByName( 'GTiff' ) 
     1381    ds = drv.Create( 'tmp/tw_44.tif', 1, 1, 1, gdal.GDT_UInt16, options = [ 'NBITS=9' ] ) 
     1382    ds = None 
     1383    ds = gdal.Open( 'tmp/tw_44.tif' ) 
     1384    bnd = ds.GetRasterBand(1) 
     1385    md = bnd.GetMetadata('IMAGE_STRUCTURE') 
     1386    if md['NBITS'] != '9': 
     1387        gdaltest.post_reason( 'Didnt get expected NBITS value') 
     1388        return 'fail' 
     1389 
     1390    ds2 = drv.CreateCopy( 'tmp/tw_44_copy.tif', ds ) 
     1391    ds2 = None 
     1392 
     1393    ds2 = gdal.Open('tmp/tw_44_copy.tif') 
     1394    bnd = ds.GetRasterBand(1) 
     1395    md = bnd.GetMetadata('IMAGE_STRUCTURE') 
     1396    if md['NBITS'] != '9': 
     1397        gdaltest.post_reason( 'Didnt get expected NBITS value') 
     1398        return 'fail' 
     1399 
     1400    ds = None 
     1401    ds2 = None 
     1402 
     1403    drv.Delete( 'tmp/tw_44.tif' ) 
     1404    drv.Delete( 'tmp/tw_44_copy.tif' ) 
     1405 
     1406    return 'success' 
     1407 
     1408############################################################################### 
     1409# Test create with NBITS=17 and preservation through CreateCopy of NBITS 
     1410 
     1411def tiff_write_45(): 
     1412    drv = gdal.GetDriverByName( 'GTiff' ) 
     1413    ds = drv.Create( 'tmp/tw_45.tif', 1, 1, 1, gdal.GDT_UInt32, options = [ 'NBITS=17' ] ) 
     1414    ds = None 
     1415    ds = gdal.Open( 'tmp/tw_45.tif' ) 
     1416    bnd = ds.GetRasterBand(1) 
     1417    md = bnd.GetMetadata('IMAGE_STRUCTURE') 
     1418    if md['NBITS'] != '17': 
     1419        gdaltest.post_reason( 'Didnt get expected NBITS value') 
     1420        return 'fail' 
     1421 
     1422    ds2 = drv.CreateCopy( 'tmp/tw_45_copy.tif', ds ) 
     1423    ds2 = None 
     1424 
     1425    ds2 = gdal.Open('tmp/tw_45_copy.tif') 
     1426    bnd = ds.GetRasterBand(1) 
     1427    md = bnd.GetMetadata('IMAGE_STRUCTURE') 
     1428    if md['NBITS'] != '17': 
     1429        gdaltest.post_reason( 'Didnt get expected NBITS value') 
     1430        return 'fail' 
     1431 
     1432    ds = None 
     1433    ds2 = None 
     1434 
     1435    drv.Delete( 'tmp/tw_45.tif' ) 
     1436    drv.Delete( 'tmp/tw_45_copy.tif' ) 
     1437 
     1438    return 'success' 
     1439 
     1440 
     1441############################################################################### 
     1442# Test correct round-tripping of ReadBlock/WriteBlock 
     1443 
     1444def tiff_write_46(): 
     1445    import struct 
     1446 
     1447    drv = gdal.GetDriverByName( 'GTiff' ) 
     1448 
     1449    oldSize = gdal.GetCacheMax() 
     1450    gdal.SetCacheMax(0) 
     1451 
     1452    ds = drv.Create("tmp/tiff_write_46_1.tif", 10, 10, 1, options = [ 'NBITS=1' ]) 
     1453    ds.GetRasterBand(1).Fill(0) 
     1454 
     1455    ds2 = drv.Create("tmp/tiff_write_46_2.tif", 10, 10, 1, options = [ 'NBITS=1' ]) 
     1456    ds2.GetRasterBand(1).Fill(1) 
     1457    ones = ds2.ReadRaster(0, 0, 10, 1) 
     1458 
     1459    # Load the working block 
     1460    data = ds.ReadRaster(0, 0, 10, 1) 
     1461 
     1462    # Write the working bloc 
     1463    ds.WriteRaster(0, 0, 10, 1, ones) 
     1464 
     1465    # This will discard the cached block for ds 
     1466    ds3 = drv.Create("tmp/tiff_write_46_3.tif", 10, 10, 1) 
     1467    ds3.GetRasterBand(1).Fill(1) 
     1468 
     1469    # Load the working block again 
     1470    data = ds.ReadRaster(0, 0, 10, 1) 
     1471 
     1472    # We expect (1, 1, 1, 1, 1, 1, 1, 1, 1, 1) 
     1473    got = struct.unpack('B' * 10, data) 
     1474    for i in range(len(got)): 
     1475        if got[i] != 1: 
     1476            print got 
     1477            gdal.SetCacheMax(oldSize) 
     1478            return 'fail' 
     1479 
     1480    gdal.SetCacheMax(oldSize) 
     1481 
     1482    ds = None 
     1483    ds2 = None 
     1484    ds3 = None 
     1485    drv.Delete( 'tmp/tiff_write_46_1.tif' ) 
     1486    drv.Delete( 'tmp/tiff_write_46_2.tif' ) 
     1487    drv.Delete( 'tmp/tiff_write_46_3.tif' ) 
    12781488 
    12791489    return 'success' 
     
    13211531    tiff_write_34, 
    13221532    tiff_write_35, 
     1533    tiff_write_36, 
     1534    tiff_write_37, 
     1535    tiff_write_38, 
     1536    tiff_write_39, 
     1537    tiff_write_40, 
     1538    tiff_write_41, 
     1539    tiff_write_42, 
     1540    tiff_write_43, 
     1541    tiff_write_44, 
     1542    tiff_write_45, 
     1543    tiff_write_46, 
    13231544    tiff_write_cleanup ] 
    13241545