Ticket #340: st_asjpeg.patch
| File st_asjpeg.patch, 6.4 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 578 578 $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; 579 579 580 580 ----------------------------------------------------------------------- 581 -- ST_AsJPEG 582 ----------------------------------------------------------------------- 583 -- Cannot be strict as "options" can be NULL 584 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, options text[]) 585 RETURNS bytea 586 AS $$ 587 DECLARE 588 num_bands int; 589 i int; 590 BEGIN 591 num_bands := st_numbands($1); 592 593 -- JPEG only supports 8BUI pixeltype 594 FOR i IN 1..num_bands LOOP 595 IF st_bandpixeltype(rast, i) != '8BUI' THEN 596 RAISE EXCEPTION 'The pixel type of band % in the raster is not 8BUI. The JPEG format can only be used with the 8BUI pixel type.', i; 597 END IF; 598 END LOOP; 599 600 -- JPEG only allows 1 or 3 bands 601 -- we only use the first 602 IF num_bands > 3 THEN 603 RAISE WARNING 'The JPEG format only permits one or three bands. The first three bands will be used.'; 604 rast := st_band(rast, ARRAY[1, 2, 3]); 605 num_bands := st_numbands(rast); 606 ELSEIF num_bands > 1 THEN 607 RAISE WARNING 'The JPEG format only permits one or three bands. The first band will be used.'; 608 rast := st_band(rast, ARRAY[1]); 609 num_bands := st_numbands(rast); 610 END IF; 611 612 RETURN st_asgdalraster($1, 'JPEG', $2, NULL); 613 END; 614 $$ LANGUAGE 'plpgsql' IMMUTABLE; 615 616 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster) 617 RETURNS bytea 618 AS $$ SELECT st_asjpeg($1, NULL::text[]) $$ 619 LANGUAGE 'SQL' IMMUTABLE STRICT; 620 621 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nbands int[], options text[]) 622 RETURNS bytea 623 AS $$ SELECT st_asjpeg(st_band($1, $2), $3) $$ 624 LANGUAGE 'SQL' IMMUTABLE STRICT; 625 626 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nbands int[]) 627 RETURNS bytea 628 AS $$ SELECT st_asjpeg(st_band($1, $2), NULL::text[]) $$ 629 LANGUAGE 'SQL' IMMUTABLE STRICT; 630 631 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nband int) 632 RETURNS bytea 633 AS $$ SELECT st_asjpeg(st_band($1, $2)) $$ 634 LANGUAGE 'SQL' IMMUTABLE STRICT; 635 636 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nbands int[], quality int) 637 RETURNS bytea 638 AS $$ 639 DECLARE 640 options text[]; 641 BEGIN 642 IF quality IS NOT NULL THEN 643 IF quality > 100 THEN 644 quality := 100; 645 ELSEIF quality < 10 THEN 646 quality := 10; 647 END IF; 648 649 options := array_append(options, 'QUALITY=' || quality); 650 END IF; 651 652 RETURN st_asjpeg(st_band($1, $2), options); 653 END; 654 $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; 655 656 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nband int, options text[]) 657 RETURNS bytea 658 AS $$ SELECT st_asjpeg(st_band($1, $2), $3) $$ 659 LANGUAGE 'SQL' IMMUTABLE STRICT; 660 661 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nband int, quality int) 662 RETURNS bytea 663 AS $$ SELECT st_asjpeg($1, ARRAY[$2], $3) $$ 664 LANGUAGE 'SQL' IMMUTABLE STRICT; 665 666 ----------------------------------------------------------------------- 581 667 -- MapAlgebra 582 668 ----------------------------------------------------------------------- 583 669 -- 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 45 45 rt_reclass.sql \ 46 46 rt_asgdalraster.sql \ 47 47 rt_astiff.sql \ 48 rt_asjpeg.sql \ 48 49 $(NULL) 49 50 50 51 TEST_PROPS = \ -
raster/test/regress/rt_asjpeg.sql
diff -rupN postgis-old/raster/test/regress/rt_asjpeg.sql postgis-new/raster/test/regress/rt_asjpeg.sql
old new 1 SELECT md5( 2 ST_AsJPEG( 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_AsJPEG( 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_AsJPEG( 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_AsJPEG( 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_AsJPEG( 23 ST_AddBand( 24 ST_AddBand( 25 ST_AddBand( 26 ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 27 , 1, '8BUI', 1, 255 28 ) 29 , 2, '8BUI', 11, 0 30 ) 31 , 3, '8BUI', 111, 127 32 ) 33 ) 34 ); 35 SELECT md5( 36 ST_AsJPEG( 37 ST_AddBand( 38 ST_AddBand( 39 ST_AddBand( 40 ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 41 , 1, '8BSI', 1, -1 42 ) 43 , 2, '8BSI', 11, -1 44 ) 45 , 3, '8BSI', 111, -1 46 ), 47 ARRAY['QUALITY=90','PROGRESSIVE=ON'] 48 ) 49 ); 50 SELECT md5( 51 ST_AsJPEG( 52 ST_AddBand( 53 ST_AddBand( 54 ST_AddBand( 55 ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 56 , 1, '8BSI', 1, -1 57 ) 58 , 2, '8BSI', 11, -1 59 ) 60 , 3, '8BSI', 111, -1 61 ), 62 ARRAY[3,1], 63 50 64 ) 65 ); 66 SELECT md5( 67 ST_AsJPEG( 68 ST_AddBand( 69 ST_AddBand( 70 ST_AddBand( 71 ST_MakeEmptyRaster(200, 200, 10, 10, 2, 2, 0, 0, -1) 72 , 1, '8BSI', 1, -1 73 ) 74 , 2, '8BSI', 11, -1 75 ) 76 , 3, '8BUI', 111, -1 77 ), 78 ARRAY[3], 79 10 80 ) 81 ); -
raster/test/regress/rt_asjpeg_expected
diff -rupN postgis-old/raster/test/regress/rt_asjpeg_expected postgis-new/raster/test/regress/rt_asjpeg_expected
old new 1 ERROR: The pixel type of band 1 in the raster is not 8BUI. The JPEG format can only be used with the 8BUI pixel type. 2 f0de16a21de438249ec0bbd28eafe63c 3 ERROR: The pixel type of band 1 in the raster is not 8BUI. The JPEG format can only be used with the 8BUI pixel type. 4 83b6012757444ff7786b5e8473e6cea3 5 WARNING: The JPEG format only permits one or three bands. The first band will be used. 6 c6be69047e807df076ec653be790eb25 7 ERROR: The pixel type of band 1 in the raster is not 8BUI. The JPEG format can only be used with the 8BUI pixel type. 8 ERROR: The pixel type of band 1 in the raster is not 8BUI. The JPEG format can only be used with the 8BUI pixel type. 9 d687ffc7b8dcb3ef05cd4fe99656e45d
