From a6ef3e3c6759cf2a8d5464c5e83b9abe0f39e153 Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Mon, 6 Aug 2012 15:02:50 +0000 Subject: [PATCH] Simplify code underlying ST_AddBand(raster, raster[]) git-svn-id: http://svn.osgeo.org/postgis/trunk@10167 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/rt_pg/rt_pg.c | 43 ++++++++++++------------------------------- 1 file changed, 12 insertions(+), 31 deletions(-) diff --git a/raster/rt_pg/rt_pg.c b/raster/rt_pg/rt_pg.c index be740b5fa..837c08b34 100644 --- a/raster/rt_pg/rt_pg.c +++ b/raster/rt_pg/rt_pg.c @@ -4329,33 +4329,38 @@ Datum RASTER_addBandRasterArray(PG_FUNCTION_ARGS) deconstruct_array(array, etype, typlen, typbyval, typalign, &e, &nulls, &n); - /* quick check that the source band number is valid for all rasters */ + /* decrement srcnband and dstnband by 1, now 0-based */ + srcnband--; + dstnband--; + POSTGIS_RT_DEBUGF(4, "0-based nband (src, dst) = (%d, %d)", srcnband, dstnband); + + /* time to copy bands */ for (i = 0; i < n; i++) { if (nulls[i]) continue; src = NULL; - pgsrc = (rt_pgraster *) PG_DETOAST_DATUM_SLICE(e[i], 0, sizeof(struct rt_raster_serialized_t)); - src = rt_raster_deserialize(pgsrc, TRUE); + pgsrc = (rt_pgraster *) PG_DETOAST_DATUM(e[i]); + src = rt_raster_deserialize(pgsrc, FALSE); if (src == NULL) { elog(ERROR, "RASTER_addBandRasterArray: Could not deserialize source raster at index %d", i + 1); pfree(nulls); pfree(e); - if (raster != NULL) { + if (raster != NULL) rt_raster_destroy(raster); + if (pgraster != NULL) PG_FREE_IF_COPY(pgraster, 0); - } PG_RETURN_NULL(); } srcnumbands = rt_raster_get_num_bands(src); - rt_raster_destroy(src); POSTGIS_RT_DEBUGF(4, "source raster %d has %d bands", i + 1, srcnumbands); /* band index isn't valid */ - if (srcnband > srcnumbands) { + if (srcnband > srcnumbands - 1) { elog(NOTICE, "Invalid band index for source raster at index %d. Returning original raster", i + 1); pfree(nulls); pfree(e); + rt_raster_destroy(src); if (raster != NULL) { rt_raster_destroy(raster); PG_RETURN_POINTER(pgraster); @@ -4363,30 +4368,6 @@ Datum RASTER_addBandRasterArray(PG_FUNCTION_ARGS) else PG_RETURN_NULL(); } - } - - /* decrement srcnband and dstnband by 1, now 0-based */ - srcnband--; - dstnband--; - POSTGIS_RT_DEBUGF(4, "0-based nband (src, dst) = (%d, %d)", srcnband, dstnband); - - /* still here, time to copy bands */ - for (i = 0; i < n; i++) { - if (nulls[i]) continue; - src = NULL; - - pgsrc = (rt_pgraster *) PG_DETOAST_DATUM(e[i]); - src = rt_raster_deserialize(pgsrc, FALSE); - if (src == NULL) { - elog(ERROR, "RASTER_addBandRasterArray: Could not deserialize source raster at index %d", i + 1); - pfree(nulls); - pfree(e); - if (raster != NULL) - rt_raster_destroy(raster); - if (pgraster != NULL) - PG_FREE_IF_COPY(pgraster, 0); - PG_RETURN_NULL(); - } /* destination raster is empty, new raster */ if (raster == NULL) { -- 2.40.0