Ticket #340: st_asjpeg.3.patch
| File st_asjpeg.3.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 1243 1243 $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; 1244 1244 1245 1245 ----------------------------------------------------------------------- 1246 -- ST_AsJPEG 1247 ----------------------------------------------------------------------- 1248 -- Cannot be strict as "options" can be NULL 1249 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, options text[]) 1250 RETURNS bytea 1251 AS $$ 1252 DECLARE 1253 num_bands int; 1254 i int; 1255 BEGIN 1256 num_bands := st_numbands($1); 1257 1258 -- JPEG only supports 8BUI pixeltype 1259 FOR i IN 1..num_bands LOOP 1260 IF st_bandpixeltype(rast, i) != '8BUI' THEN 1261 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; 1262 END IF; 1263 END LOOP; 1264 1265 -- JPEG only allows 1 or 3 bands 1266 -- we only use the first 1267 IF num_bands > 3 THEN 1268 RAISE NOTICE 'The JPEG format only permits one or three bands. The first three bands will be used.'; 1269 rast := st_band(rast, ARRAY[1, 2, 3]); 1270 num_bands := st_numbands(rast); 1271 ELSEIF num_bands > 1 THEN 1272 RAISE NOTICE 'The JPEG format only permits one or three bands. The first band will be used.'; 1273 rast := st_band(rast, ARRAY[1]); 1274 num_bands := st_numbands(rast); 1275 END IF; 1276 1277 RETURN st_asgdalraster($1, 'JPEG', $2, NULL); 1278 END; 1279 $$ LANGUAGE 'plpgsql' IMMUTABLE; 1280 1281 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster) 1282 RETURNS bytea 1283 AS $$ SELECT st_asjpeg($1, NULL::text[]) $$ 1284 LANGUAGE 'SQL' IMMUTABLE STRICT; 1285 1286 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nbands int[], options text[]) 1287 RETURNS bytea 1288 AS $$ SELECT st_asjpeg(st_band($1, $2), $3) $$ 1289 LANGUAGE 'SQL' IMMUTABLE STRICT; 1290 1291 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nbands int[]) 1292 RETURNS bytea 1293 AS $$ SELECT st_asjpeg(st_band($1, $2), NULL::text[]) $$ 1294 LANGUAGE 'SQL' IMMUTABLE STRICT; 1295 1296 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nband int) 1297 RETURNS bytea 1298 AS $$ SELECT st_asjpeg(st_band($1, $2)) $$ 1299 LANGUAGE 'SQL' IMMUTABLE STRICT; 1300 1301 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nbands int[], quality int) 1302 RETURNS bytea 1303 AS $$ 1304 DECLARE 1305 options text[]; 1306 BEGIN 1307 IF quality IS NOT NULL THEN 1308 IF quality > 100 THEN 1309 quality := 100; 1310 ELSEIF quality < 10 THEN 1311 quality := 10; 1312 END IF; 1313 1314 options := array_append(options, 'QUALITY=' || quality); 1315 END IF; 1316 1317 RETURN st_asjpeg(st_band($1, $2), options); 1318 END; 1319 $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; 1320 1321 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nband int, options text[]) 1322 RETURNS bytea 1323 AS $$ SELECT st_asjpeg(st_band($1, $2), $3) $$ 1324 LANGUAGE 'SQL' IMMUTABLE STRICT; 1325 1326 CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, nband int, quality int) 1327 RETURNS bytea 1328 AS $$ SELECT st_asjpeg($1, ARRAY[$2], $3) $$ 1329 LANGUAGE 'SQL' IMMUTABLE STRICT; 1330 1331 ----------------------------------------------------------------------- 1246 1332 -- MapAlgebra 1247 1333 ----------------------------------------------------------------------- 1248 1334 -- 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 44 44 rt_band.sql \ 45 45 rt_asgdalraster.sql \ 46 46 rt_astiff.sql \ 47 rt_asjpeg.sql \ 47 48 $(NULL) 48 49 49 50 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 NOTICE: The JPEG format only permits one or three bands. The first band will be used. 6 bca07d85db735e4eaf2334969a548b10 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
