| | 1329 | LANGUAGE 'SQL' IMMUTABLE STRICT; |
| | 1330 | |
| | 1331 | ----------------------------------------------------------------------- |
| | 1332 | -- ST_AsPNG |
| | 1333 | ----------------------------------------------------------------------- |
| | 1334 | -- Cannot be strict as "options" can be NULL |
| | 1335 | CREATE OR REPLACE FUNCTION st_aspng(rast raster, options text[]) |
| | 1336 | RETURNS bytea |
| | 1337 | AS $$ |
| | 1338 | DECLARE |
| | 1339 | num_bands int; |
| | 1340 | i int; |
| | 1341 | pt text; |
| | 1342 | BEGIN |
| | 1343 | num_bands := st_numbands($1); |
| | 1344 | |
| | 1345 | -- PNG only allows 1 or 3 bands |
| | 1346 | IF num_bands > 3 THEN |
| | 1347 | RAISE NOTICE 'The PNG format only permits one or three bands. The first three bands will be used.'; |
| | 1348 | rast := st_band(rast, ARRAY[1, 2, 3]); |
| | 1349 | num_bands := st_numbands(rast); |
| | 1350 | ELSEIF num_bands > 1 THEN |
| | 1351 | RAISE NOTICE 'The PNG format only permits one or three bands. The first band will be used.'; |
| | 1352 | rast := st_band(rast, ARRAY[1]); |
| | 1353 | num_bands := st_numbands(rast); |
| | 1354 | END IF; |
| | 1355 | |
| | 1356 | -- PNG only supports 8BUI and 16BUI pixeltype |
| | 1357 | FOR i IN 1..num_bands LOOP |
| | 1358 | pt = st_bandpixeltype(rast, i); |
| | 1359 | IF pt != '8BUI' AND pt != '16BUI' THEN |
| | 1360 | 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; |
| | 1361 | END IF; |
| | 1362 | END LOOP; |
| | 1363 | |
| | 1364 | RETURN st_asgdalraster($1, 'PNG', $2, NULL); |
| | 1365 | END; |
| | 1366 | $$ LANGUAGE 'plpgsql' IMMUTABLE; |
| | 1367 | |
| | 1368 | CREATE OR REPLACE FUNCTION st_aspng(rast raster) |
| | 1369 | RETURNS bytea |
| | 1370 | AS $$ SELECT st_aspng($1, NULL::text[]) $$ |
| | 1371 | LANGUAGE 'SQL' IMMUTABLE STRICT; |
| | 1372 | |
| | 1373 | CREATE OR REPLACE FUNCTION st_aspng(rast raster, nbands int[], options text[]) |
| | 1374 | RETURNS bytea |
| | 1375 | AS $$ SELECT st_aspng(st_band($1, $2), $3) $$ |
| | 1376 | LANGUAGE 'SQL' IMMUTABLE STRICT; |
| | 1377 | |
| | 1378 | CREATE OR REPLACE FUNCTION st_aspng(rast raster, nbands int[]) |
| | 1379 | RETURNS bytea |
| | 1380 | AS $$ SELECT st_aspng(st_band($1, $2), NULL::text[]) $$ |
| | 1381 | LANGUAGE 'SQL' IMMUTABLE STRICT; |
| | 1382 | |
| | 1383 | CREATE OR REPLACE FUNCTION st_aspng(rast raster, nband int) |
| | 1384 | RETURNS bytea |
| | 1385 | AS $$ SELECT st_aspng(st_band($1, $2)) $$ |
| | 1386 | LANGUAGE 'SQL' IMMUTABLE STRICT; |
| | 1387 | |
| | 1388 | CREATE OR REPLACE FUNCTION st_aspng(rast raster, nbands int[], compression int) |
| | 1389 | RETURNS bytea |
| | 1390 | AS $$ |
| | 1391 | DECLARE |
| | 1392 | options text[]; |
| | 1393 | BEGIN |
| | 1394 | IF compression IS NOT NULL THEN |
| | 1395 | IF compression > 9 THEN |
| | 1396 | compression := 9; |
| | 1397 | ELSEIF compression < 1 THEN |
| | 1398 | compression := 1; |
| | 1399 | END IF; |
| | 1400 | |
| | 1401 | options := array_append(options, 'ZLEVEL=' || compression); |
| | 1402 | END IF; |
| | 1403 | |
| | 1404 | RETURN st_aspng(st_band($1, $2), options); |
| | 1405 | END; |
| | 1406 | $$ LANGUAGE 'plpgsql' IMMUTABLE STRICT; |
| | 1407 | |
| | 1408 | CREATE OR REPLACE FUNCTION st_aspng(rast raster, nband int, options text[]) |
| | 1409 | RETURNS bytea |
| | 1410 | AS $$ SELECT st_aspng(st_band($1, $2), $3) $$ |
| | 1411 | LANGUAGE 'SQL' IMMUTABLE STRICT; |
| | 1412 | |
| | 1413 | CREATE OR REPLACE FUNCTION st_aspng(rast raster, nband int, compression int) |
| | 1414 | RETURNS bytea |
| | 1415 | AS $$ SELECT st_aspng($1, ARRAY[$2], $3) $$ |