]> granicus.if.org Git - postgis/commitdiff
fixed logic issues in ST_AsJPEG
authorBborie Park <bkpark at ucdavis.edu>
Thu, 30 Jun 2011 13:28:47 +0000 (13:28 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Thu, 30 Jun 2011 13:28:47 +0000 (13:28 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@7527 b70326c6-7e19-0410-871a-916f4a2858ee

raster/rt_core/rt_api.c
raster/rt_pg/rtpostgis.sql.in.c
raster/test/regress/rt_asjpeg_expected

index a0dd7a0917fcf20bec0c561f860f83b4157271d8..a746cdf3e8b88321e5289e37a7cd4c08f1afd9c0 100644 (file)
@@ -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);
 
         }
 
index 9da849964a093f9b4d89d1add8c3ae61cdf49264..268d9ca626d512b9caf2c85a77cbb3f80afdc37f 100644 (file)
@@ -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;
index 144c30e3cb913d6f287328ef9a81416b5838001f..e441e972587d17a3a5afe010d76159b372f8c7dc 100644 (file)
@@ -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