@@ -5350,6 +5350,41 @@ def test_tiff_write_123():
53505350 gdaltest .tiff_drv .Delete ("/vsimem/tiff_write_123_rgba_to_undefined.tif" )
53515351
53525352
5353+ ###############################################################################
5354+ # Test implicit photometric interpretation
5355+
5356+
5357+ def test_tiff_write_RGBNir (tmp_vsimem ):
5358+
5359+ out_filename = tmp_vsimem / "test_tiff_write_RGBNir.tif"
5360+ ds = gdaltest .tiff_drv .Create (out_filename , 1 , 1 , 4 , gdal .GDT_Int16 )
5361+ ds .GetRasterBand (1 ).SetColorInterpretation (gdal .GCI_RedBand )
5362+ ds .GetRasterBand (2 ).SetColorInterpretation (gdal .GCI_GreenBand )
5363+ ds .GetRasterBand (3 ).SetColorInterpretation (gdal .GCI_BlueBand )
5364+ ds .GetRasterBand (4 ).SetColorInterpretation (gdal .GCI_NIRBand )
5365+
5366+ errors = []
5367+
5368+ def handler (lvl , no , msg ):
5369+ errors .append ({"level" : lvl , "number" : no , "message" : msg })
5370+
5371+ with gdaltest .error_handler (handler ):
5372+ ds .Close ()
5373+
5374+ assert len (errors ) == 0
5375+
5376+ statBuf = gdal .VSIStatL (
5377+ str (out_filename ) + ".aux.xml" ,
5378+ gdal .VSI_STAT_EXISTS_FLAG | gdal .VSI_STAT_NATURE_FLAG | gdal .VSI_STAT_SIZE_FLAG ,
5379+ )
5380+ assert statBuf is None , "did not expect PAM file"
5381+ src_ds = gdal .Open (out_filename )
5382+ assert src_ds .GetRasterBand (1 ).GetColorInterpretation () == gdal .GCI_RedBand
5383+ assert src_ds .GetRasterBand (2 ).GetColorInterpretation () == gdal .GCI_GreenBand
5384+ assert src_ds .GetRasterBand (3 ).GetColorInterpretation () == gdal .GCI_BlueBand
5385+ assert src_ds .GetRasterBand (4 ).GetColorInterpretation () == gdal .GCI_NIRBand
5386+
5387+
53535388###############################################################################
53545389# Test error cases with palette creation
53555390
0 commit comments