Ticket #342: st_aspng.patch
| File st_aspng.patch, 7.1 KB (added by dustymugs, 13 months ago) |
|---|
-
raster/rt_pg/rtpostgis.sql.in.c
diff -rupN postgis-old/raster/rt_pg/rtpostgis.sql.in.c postgis-new/raster/rt_pg/rtpostgis.sql.in.c
old new 664 664 LANGUAGE 'SQL' IMMUTABLE STRICT; 665 665 666 666 ----------------------------------------------------------------------- 667 -- ST_AsPNG 668 ----------------------------------------------------------------------- 669 -- Cannot be strict as "options" can be NULL 670 CREATE OR REPLACE FUNCTION st_aspng(rast raster, options text[]) 671 RETURNS bytea 672 AS $$ 673 DECLARE 674 num_bands int; 675 i int; 676 pt text; 677 BEGIN 678 num_bands := st_numbands($1); 679 680 -- PNG only allows 1 or 3 bands 681 IF num_bands > 3 THEN 682 RAISE WARNING 'The PNG format only permits one or three bands. The first three bands will be used.'; 683 rast := st_band(rast, ARRAY[1, 2, 3]); 684 num_bands := st_numbands(rast); 685 ELSEIF num_bands > 1 THEN 686 RAISE WARNING 'The PNG format only permits one or three bands. The first band will be used.'; 687 rast := st_band(rast, ARRAY[1]); 688 num_bands := st_numbands(rast); 689 END IF; 690 691 -- PNG only supports 8BUI and 16BUI pixeltype 692 FOR i IN 1..num_bands LOOP 693 pt = st_bandpixeltype(rast, i); 694 IF pt != '8BUI' AND pt != '16BUI' THEN 695 RAISE EXCEPTION 'The pixel type of band % in the raster is not 8BUI or 16BUI. The PNG format can only be used with 8BUI and 16BUI pixel types.', i; 696 END IF; 697 END LOOP; 698 699 RETURN st_asgdalraster($1, 'PNG', $2, NULL); 700 END; 701 $$ LANGUAGE 'plpgsql' IMMUTABLE; 702 703 CREATE OR REPLACE FUNCTION st_aspng(rast raster) 704 RETURNS bytea 705 AS $$ SELECT st_aspng($1, NULL::text[]) $$ 706 LANGUAGE 'SQL' IMMUTABLE STRICT; 707 708 CREATE OR REPLACE FUNCTION st_aspng(rast raster, nbands int[], options text[]) 709 RETURNS bytea 710 AS $$ SELECT st_aspng(st_band($1, $2), $3) $$ 711 LANGUAGE 'SQL' IMMUTABLE STRICT; 712 713 CREATE OR REPLACE FUNCTION st_aspng(rast raster, nbands int[]) 714 RETURNS bytea 715 AS $$ SELECT st_aspng(st_band($1, $2), NULL::text[]) $$ 716 LANGUAGE 'SQL' IMMUTABLE STRICT; 717 718 CREATE OR REPLACE FUNCTION st_aspng(rast raster, nband int) 719 RETURNS bytea 720 AS $$ SELECT st_aspng(st_band($1, $2)) $$ 721 LANGUAGE 'SQL' IMMUTABLE STRICT; 722 723 CREATE OR REPLACE FUNCTION st_aspng(rast raster, nbands int[], compression int) 724 RETURNS bytea 725 AS $$ 726 DECLARE 727 options text[]; 728 BEGIN 729 IF compression IS NOT NULL THEN 730 IF compression > 9 THEN 731 compression := 9; 732 ELSEIF compression < 1 THEN 733 compression := 1; 734 END IF; 735 736 options := array_append(options, 'ZLEVEL=' || compression); 737 END IF; 738 739 RETURN st_aspng(st_band($1, $2), options); 740 END; 741 $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; 742 743 CREATE OR REPLACE FUNCTION st_aspng(rast raster, nband int, options text[]) 744 RETURNS bytea 745 AS $$ SELECT st_aspng(st_band($1, $2), $3) $$ 746 LANGUAGE 'SQL' IMMUTABLE STRICT; 747 748 CREATE OR REPLACE FUNCTION st_aspng(rast raster, nband int, compression int) 749 RETURNS bytea 750 AS $$ SELECT st_aspng($1, ARRAY[$2], $3) $$ 751 LANGUAGE 'SQL' IMMUTABLE STRICT; 752 753 ----------------------------------------------------------------------- 667 754 -- MapAlgebra 668 755 ----------------------------------------------------------------------- 669 756 -- This function can not be STRICT, because nodatavalueexpr can be NULL (could be just '' though) -
raster/test/regress/Makefile.in
diff -rupN postgis-old/raster/test/regress/Makefile.in postgis-new/raster/test/regress/Makefile.in
old new 46 46 rt_asgdalraster.sql \ 47 47 rt_astiff.sql \ 48 48 rt_asjpeg.sql \ 49 rt_aspng.sql \ 49 50 $(NULL) 50 51 51 52 TEST_PROPS = \ -
raster/test/regress/rt_aspng.sql
diff -rupN postgis-old/raster/test/regress/rt_aspng.sql postgis-new/raster/test/regress/rt_aspng.sql
old new 1 SELECT md5( 2 ST_AsPNG( 3 ST_AddBand(ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1), 1, '8BSI', 123, NULL) 4 ) 5 ); 6 SELECT md5( 7 ST_AsPNG( 8 ST_AddBand(ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1), 1, '8BUI', 123, NULL) 9 ) 10 ); 11 SELECT md5( 12 ST_AsPNG( 13 ST_AddBand(ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1), 1, '8BSI', -123, NULL) 14 ) 15 ); 16 SELECT md5( 17 ST_AsPNG( 18 ST_AddBand(ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1), 1, '8BUI', 254, NULL) 19 ) 20 ); 21 SELECT md5( 22 ST_AsPNG( 23 ST_AddBand( 24 ST_AddBand( 25 ST_AddBand( 26 ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 27 , 1, '8BSI', 1, -1 28 ) 29 , 2, '8BSI', 11, -1 30 ) 31 , 3, '8BSI', 111, -1 32 ), 33 ARRAY['ZLEVEL=1'] 34 ) 35 ); 36 SELECT md5( 37 ST_AsPNG( 38 ST_AddBand( 39 ST_AddBand( 40 ST_AddBand( 41 ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 42 , 1, '8BSI', 1, -1 43 ) 44 , 2, '8BSI', 11, -1 45 ) 46 , 3, '8BSI', 111, -1 47 ), 48 ARRAY['ZLEVEL=9'] 49 ) 50 ); 51 SELECT md5( 52 ST_AsPNG( 53 ST_AddBand( 54 ST_AddBand( 55 ST_AddBand( 56 ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 57 , 1, '8BSI', 1, 1 58 ) 59 , 2, '8BSI', 11, 1 60 ) 61 , 3, '8BSI', 111, 1 62 ), 63 ARRAY['ZLEVEL=9'] 64 ) 65 ); 66 SELECT md5( 67 ST_AsPNG( 68 ST_AddBand( 69 ST_AddBand( 70 ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 71 , 1, '8BUI', 1, 1 72 ) 73 , 2, '8BUI', 11, 1 74 ), 75 ARRAY[1], 76 6 77 ) 78 ); 79 SELECT md5( 80 ST_AsPNG( 81 ST_AddBand( 82 ST_AddBand( 83 ST_AddBand( 84 ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 85 , 1, '8BUI', 1, 1 86 ) 87 , 2, '8BUI', 11, 1 88 ) 89 , 3, '8BUI', 111, 1 90 ), 91 ARRAY[3,1], 92 6 93 ) 94 ); -
raster/test/regress/rt_aspng_expected
diff -rupN postgis-old/raster/test/regress/rt_aspng_expected postgis-new/raster/test/regress/rt_aspng_expected
old new 1 ERROR: The pixel type of band 1 in the raster is not 8BUI or 16BUI. The PNG format can only be used with 8BUI and 16BUI pixel types. 2 55279950e29968bcf36b2c11ce8bf88b 3 ERROR: The pixel type of band 1 in the raster is not 8BUI or 16BUI. The PNG format can only be used with 8BUI and 16BUI pixel types. 4 24188762b5745acda4aa7b92776e7280 5 WARNING: The PNG format only permits one or three bands. The first band will be used. 6 ERROR: The pixel type of band 1 in the raster is not 8BUI or 16BUI. The PNG format can only be used with 8BUI and 16BUI pixel types. 7 WARNING: The PNG format only permits one or three bands. The first band will be used. 8 ERROR: The pixel type of band 1 in the raster is not 8BUI or 16BUI. The PNG format can only be used with 8BUI and 16BUI pixel types. 9 WARNING: The PNG format only permits one or three bands. The first band will be used. 10 ERROR: The pixel type of band 1 in the raster is not 8BUI or 16BUI. The PNG format can only be used with 8BUI and 16BUI pixel types. 11 3b859bf98d434fe1cbefb96844badfec 12 WARNING: The PNG format only permits one or three bands. The first band will be used. 13 58168aa11f7ccdf095e5ed02bde1e676
