@@ -329,3 +329,35 @@ def test_gdalalg_raster_rgb_to_palette_bit_depth_8(tmp_vsimem):
329329 ) as alg :
330330 ds = alg .Output ()
331331 assert ds .GetRasterBand (1 ).Checksum () == 7593
332+
333+
334+ def test_gdalalg_raster_rgb_to_palette_rgba_single_color ():
335+
336+ src_ds = gdal .GetDriverByName ("MEM" ).Create ("" , 1 , 1 , 4 )
337+ src_ds .GetRasterBand (1 ).SetColorInterpretation (gdal .GCI_RedBand )
338+ src_ds .GetRasterBand (2 ).SetColorInterpretation (gdal .GCI_GreenBand )
339+ src_ds .GetRasterBand (3 ).SetColorInterpretation (gdal .GCI_BlueBand )
340+ src_ds .GetRasterBand (4 ).SetColorInterpretation (gdal .GCI_AlphaBand )
341+ src_ds .GetRasterBand (4 ).Fill (255 )
342+
343+ with gdal .Run (get_alg (), input = src_ds , output = "" , output_format = "MEM" ) as alg :
344+ ds = alg .Output ()
345+ assert ds .GetRasterBand (1 ).GetColorTable ().GetCount () == 2
346+ assert ds .GetRasterBand (1 ).GetColorTable ().GetColorEntry (0 ) == (0 , 0 , 0 , 0 )
347+ assert ds .GetRasterBand (1 ).GetColorTable ().GetColorEntry (1 ) == (0 , 0 , 0 , 255 )
348+ assert ds .GetRasterBand (1 ).Checksum () == 1
349+
350+
351+ def test_gdalalg_raster_rgb_to_palette_rgba_all_transparent ():
352+
353+ src_ds = gdal .GetDriverByName ("MEM" ).Create ("" , 1 , 1 , 4 )
354+ src_ds .GetRasterBand (1 ).SetColorInterpretation (gdal .GCI_RedBand )
355+ src_ds .GetRasterBand (2 ).SetColorInterpretation (gdal .GCI_GreenBand )
356+ src_ds .GetRasterBand (3 ).SetColorInterpretation (gdal .GCI_BlueBand )
357+ src_ds .GetRasterBand (4 ).SetColorInterpretation (gdal .GCI_AlphaBand )
358+
359+ with gdal .Run (get_alg (), input = src_ds , output = "" , output_format = "MEM" ) as alg :
360+ ds = alg .Output ()
361+ assert ds .GetRasterBand (1 ).GetColorTable ().GetCount () == 1
362+ assert ds .GetRasterBand (1 ).GetColorTable ().GetColorEntry (0 ) == (0 , 0 , 0 , 0 )
363+ assert ds .GetRasterBand (1 ).Checksum () == 0
0 commit comments