From: Bborie Park Date: Thu, 30 Jun 2011 13:28:47 +0000 (+0000) Subject: fixed logic issues in ST_AsJPEG X-Git-Tag: 2.0.0alpha1~1315 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=c2bd42d81061050ab344b0cdb8d512dd8f1487ed;p=postgis fixed logic issues in ST_AsJPEG git-svn-id: http://svn.osgeo.org/postgis/trunk@7527 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/raster/rt_core/rt_api.c b/raster/rt_core/rt_api.c index a0dd7a091..a746cdf3e 100644 --- a/raster/rt_core/rt_api.c +++ b/raster/rt_core/rt_api.c @@ -4746,6 +4746,7 @@ rt_raster_serialize(rt_raster raster) { /* Serialize bands now */ for (i = 0; i < raster->numBands; ++i) { rt_band band = raster->bands[i]; + RASTER_DEBUGF(3, "band %d at %p", i, raster->bands[i]); assert(NULL != band); rt_pixtype pixtype = band->pixtype; @@ -4775,9 +4776,11 @@ rt_raster_serialize(rt_raster raster) { ptr += 1; /* Add padding (if needed) */ + RASTER_DEBUGF(3, "modulus: %d", (((uintptr_t) ptr) % pixbytes)); if (pixbytes > 1) { memset(ptr, '\0', pixbytes - 1); ptr += pixbytes - 1; + RASTER_DEBUG(3, "added padding"); } #if POSTGIS_DEBUG_LEVEL > 2 @@ -4872,7 +4875,7 @@ rt_raster_serialize(rt_raster raster) { *ptr = 0; ++ptr; - RASTER_DEBUGF(3, "PAD at %d", (uint64_t) ptr % 8); + RASTER_DEBUGF(3, "PAD at %d", (uintptr_t) ptr % 8); } diff --git a/raster/rt_pg/rtpostgis.sql.in.c b/raster/rt_pg/rtpostgis.sql.in.c index 9da849964..268d9ca62 100644 --- a/raster/rt_pg/rtpostgis.sql.in.c +++ b/raster/rt_pg/rtpostgis.sql.in.c @@ -1289,16 +1289,9 @@ CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, options text[] DEFAULT NULL) BEGIN num_bands := st_numbands($1); - -- JPEG only supports 8BUI pixeltype - FOR i IN 1..num_bands LOOP - IF st_bandpixeltype(rast, i) != '8BUI' THEN - 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; - END IF; - END LOOP; - -- JPEG only allows 1 or 3 bands -- we only use the first - IF num_bands <> 1 AND num_bands <> 333 THEN + IF num_bands <> 1 AND num_bands <> 3 THEN RAISE NOTICE 'The JPEG format only permits one or three bands. The first band will be used.'; rast2 := st_band(rast, ARRAY[1]); num_bands := st_numbands(rast); @@ -1306,6 +1299,13 @@ CREATE OR REPLACE FUNCTION st_asjpeg(rast raster, options text[] DEFAULT NULL) rast2 := rast; END IF; + -- JPEG only supports 8BUI pixeltype + FOR i IN 1..num_bands LOOP + IF st_bandpixeltype(rast, i) != '8BUI' THEN + 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; + END IF; + END LOOP; + RETURN st_asgdalraster(rast2, 'JPEG', $2, NULL); END; $$ LANGUAGE 'plpgsql' IMMUTABLE; diff --git a/raster/test/regress/rt_asjpeg_expected b/raster/test/regress/rt_asjpeg_expected index 144c30e3c..e441e9725 100644 --- a/raster/test/regress/rt_asjpeg_expected +++ b/raster/test/regress/rt_asjpeg_expected @@ -2,8 +2,8 @@ ERROR: The pixel type of band 1 in the raster is not 8BUI. The JPEG format can 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. 1 -NOTICE: The JPEG format only permits one or three bands. The first band will be used. 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. +NOTICE: The JPEG format only permits one or three bands. The first band will be used. 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. 1