[mapserver-commits] r10017 - trunk/mapserver
svn at osgeo.org
svn at osgeo.org
Fri Mar 26 01:01:04 EDT 2010
Author: warmerdam
Date: 2010-03-26 01:01:03 -0400 (Fri, 26 Mar 2010)
New Revision: 10017
Modified:
trunk/mapserver/mapbits.c
trunk/mapserver/mapdrawgdal.c
trunk/mapserver/mapresample.c
trunk/mapserver/mapserver.h
trunk/mapserver/maputil.c
Log:
preliminary implementation of validity mask for raw valued raster handling (#2181)
Modified: trunk/mapserver/mapbits.c
===================================================================
--- trunk/mapserver/mapbits.c 2010-03-25 18:48:12 UTC (rev 10016)
+++ trunk/mapserver/mapbits.c 2010-03-26 05:01:03 UTC (rev 10017)
@@ -40,7 +40,6 @@
* Hardcoded size of our bit array.
* See function msGetNextBit for another hardcoded value.
*/
-#define MS_ARRAY_BIT 32
/* #define msGetBit(array, index) (*((array) + (index)/MS_ARRAY_BIT) & ( 1 << ((index) % MS_ARRAY_BIT))) */
Modified: trunk/mapserver/mapdrawgdal.c
===================================================================
--- trunk/mapserver/mapdrawgdal.c 2010-03-25 18:48:12 UTC (rev 10016)
+++ trunk/mapserver/mapdrawgdal.c 2010-03-26 05:01:03 UTC (rev 10017)
@@ -2112,6 +2112,10 @@
int *band_list, band_count;
int i, j, k, band;
CPLErr eErr;
+ float *f_nodatas = NULL;
+ unsigned char *b_nodatas = NULL;
+ GInt16 *i_nodatas = NULL;
+ int got_nodata=FALSE;
if( image->format->bands > 256 )
{
@@ -2121,6 +2125,18 @@
}
/* -------------------------------------------------------------------- */
+/* We need at least GDAL 1.2.0 for the DatasetRasterIO */
+/* function. */
+/* -------------------------------------------------------------------- */
+#if !defined(GDAL_VERSION_NUM) || GDAL_VERSION_NUM < 1200
+ msSetError(MS_IMGERR,
+ "RAWMODE raster support requires GDAL 1.2.0 or newer.",
+ "msDrawRasterLayerGDAL_RawMode()" );
+ free( pBuffer );
+ return -1;
+#endif
+
+/* -------------------------------------------------------------------- */
/* What data type do we need? */
/* -------------------------------------------------------------------- */
if( image->format->imagemode == MS_IMAGEMODE_INT16 )
@@ -2150,6 +2166,53 @@
}
/* -------------------------------------------------------------------- */
+/* Do we have nodata values? */
+/* -------------------------------------------------------------------- */
+ f_nodatas = (float *) calloc(sizeof(float),band_count);
+
+ if( band_count <= 3
+ && (layer->offsite.red != -1
+ || layer->offsite.green != -1
+ || layer->offsite.blue != -1) )
+ {
+ if( band_count > 0 )
+ f_nodatas[0] = layer->offsite.red;
+ if( band_count > 1 )
+ f_nodatas[1] = layer->offsite.green;
+ if( band_count > 2 )
+ f_nodatas[2] = layer->offsite.blue;
+ got_nodata = TRUE;
+ }
+
+ if( !got_nodata )
+ {
+ got_nodata = TRUE;
+ for( band = 0; band < band_count && got_nodata; band++ )
+ {
+ f_nodatas[band] = msGetGDALNoDataValue(
+ layer, GDALGetRasterBand(hDS,band_list[band]), &got_nodata );
+ }
+ }
+
+ if( !got_nodata )
+ {
+ msFree( f_nodatas );
+ f_nodatas = NULL;
+ }
+ else if( eDataType == GDT_Byte )
+ {
+ b_nodatas = (unsigned char *) f_nodatas;
+ for( band = 0; band < band_count; band++ )
+ b_nodatas[band] = (unsigned char) f_nodatas[band];
+ }
+ else if( eDataType == GDT_Int16 )
+ {
+ i_nodatas = (GInt16 *) f_nodatas;
+ for( band = 0; band < band_count; band++ )
+ i_nodatas[band] = (GInt16) f_nodatas[band];
+ }
+
+/* -------------------------------------------------------------------- */
/* Allocate buffer, and read data into it. */
/* -------------------------------------------------------------------- */
pBuffer = malloc(dst_xsize * dst_ysize * image->format->bands
@@ -2162,7 +2225,6 @@
return -1;
}
-#if defined(GDAL_VERSION_NUM) && GDAL_VERSION_NUM >= 1199
eErr = GDALDatasetRasterIO( hDS, GF_Read,
src_xoff, src_yoff, src_xsize, src_ysize,
pBuffer, dst_xsize, dst_ysize, eDataType,
@@ -2176,20 +2238,9 @@
CPLGetLastErrorMsg(),
"msDrawRasterLayerGDAL_RawMode()" );
free( pBuffer );
+ free( f_nodatas );
return -1;
}
-#else
- /*
- * The above could actually be implemented for pre-1.2.0 GDALs
- * reading band by band, but it would be hard to do and test and would
- * be very rarely useful so we skip it.
- */
- msSetError(MS_IMGERR,
- "RAWMODE raster support requires GDAL 1.2.0 or newer.",
- "msDrawRasterLayerGDAL_RawMode()" );
- free( pBuffer );
- return -1;
-#endif
/* -------------------------------------------------------------------- */
/* Transfer the data to the imageObj. */
@@ -2203,27 +2254,54 @@
{
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
{
- image->img.raw_16bit[j + i * image->width
- + band*image->width*image->height] =
- ((GInt16 *) pBuffer)[k++];
+ int off = j + i * image->width
+ + band*image->width*image->height;
+
+ if( i_nodatas
+ && ((GInt16 *) pBuffer)[k] == i_nodatas[band] )
+ {
+ k++;
+ continue;
+ }
+
+ image->img.raw_16bit[off] = ((GInt16 *) pBuffer)[k++];
+ MS_SET_BIT(image->img_mask,off);
}
}
else if( image->format->imagemode == MS_IMAGEMODE_FLOAT32 )
{
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
{
- image->img.raw_float[j + i * image->width
- + band*image->width*image->height] =
- ((float *) pBuffer)[k++];
+ int off = j + i * image->width
+ + band*image->width*image->height;
+
+ if( f_nodatas
+ && ((float *) pBuffer)[k] == f_nodatas[band] )
+ {
+ k++;
+ continue;
+ }
+
+ image->img.raw_float[off] = ((float *) pBuffer)[k++];
+ MS_SET_BIT(image->img_mask,off);
}
}
else if( image->format->imagemode == MS_IMAGEMODE_BYTE )
{
for( j = dst_xoff; j < dst_xoff + dst_xsize; j++ )
{
- image->img.raw_byte[j + i * image->width
- + band*image->width*image->height] =
- ((unsigned char *) pBuffer)[k++];
+ int off = j + i * image->width
+ + band*image->width*image->height;
+
+ if( b_nodatas
+ && ((unsigned char *) pBuffer)[k] == b_nodatas[band] )
+ {
+ k++;
+ continue;
+ }
+
+ image->img.raw_byte[off] = ((unsigned char *) pBuffer)[k++];
+ MS_SET_BIT(image->img_mask,off);
}
}
}
Modified: trunk/mapserver/mapresample.c
===================================================================
--- trunk/mapserver/mapresample.c 2010-03-25 18:48:12 UTC (rev 10016)
+++ trunk/mapserver/mapresample.c 2010-03-26 05:01:03 UTC (rev 10017)
@@ -83,7 +83,6 @@
static int
msNearestRasterResampler( imageObj *psSrcImage, rasterBufferObj *src_rb,
- colorObj offsite,
imageObj *psDstImage, rasterBufferObj *dst_rb,
int *panCMap,
SimpleTransformer pfnTransform, void *pCBData,
@@ -228,64 +227,43 @@
}
else if( MS_RENDERER_RAWDATA(psSrcImage->format) )
{
- int band;
+ int band, src_off, dst_off;
+
+ src_off = nSrcX + nSrcY * psSrcImage->width;
+ if( !MS_GET_BIT(psSrcImage->img_mask,src_off) )
+ continue;
+
+ nSetPoints++;
+
+ dst_off = nDstX + nDstY * psDstImage->width;
+
+ MS_SET_BIT(psDstImage->img_mask,dst_off);
+
for( band = 0; band < psSrcImage->format->bands; band++ )
{
if( psSrcImage->format->imagemode == MS_IMAGEMODE_INT16 )
{
- int nValue;
-
- nValue = psSrcImage->img.raw_16bit[
- nSrcX + nSrcY * psSrcImage->width
- + band*psSrcImage->width*psSrcImage->height];
-
- if( nValue == offsite.red )
- continue;
-
- nSetPoints++;
- psDstImage->img.raw_16bit[
- nDstX + nDstY * psDstImage->width
- + band*psDstImage->width*psDstImage->height]
- = nValue;
+ psDstImage->img.raw_16bit[dst_off]
+ = psSrcImage->img.raw_16bit[src_off];
}
else if( psSrcImage->format->imagemode
== MS_IMAGEMODE_FLOAT32)
{
- float fValue;
-
- fValue = psSrcImage->img.raw_float[
- nSrcX + nSrcY * psSrcImage->width
- + band*psSrcImage->width*psSrcImage->height];
-
- if( fValue == offsite.red )
- continue;
-
- nSetPoints++;
- psDstImage->img.raw_float[
- nDstX + nDstY * psDstImage->width
- + band*psDstImage->width*psDstImage->height]
- = fValue;
+ psDstImage->img.raw_float[dst_off]
+ = psSrcImage->img.raw_float[src_off];
}
else if(psSrcImage->format->imagemode == MS_IMAGEMODE_BYTE)
{
- nValue = psSrcImage->img.raw_byte[
- nSrcX + nSrcY * psSrcImage->width
- + band*psSrcImage->width*psSrcImage->height];
-
- if( nValue == offsite.red )
- continue;
-
- nSetPoints++;
- psDstImage->img.raw_byte[
- nDstX + nDstY * psDstImage->width
- + band*psDstImage->width*psDstImage->height]
- = (unsigned char) nValue;
+ psDstImage->img.raw_byte[dst_off]
+ = psSrcImage->img.raw_byte[src_off];
}
else
{
assert( 0 );
}
+ src_off += psSrcImage->width * psSrcImage->height;
+ dst_off += psDstImage->width * psDstImage->height;
}
}
}
@@ -318,8 +296,7 @@
static void msSourceSample( imageObj *psSrcImage, rasterBufferObj *rb,
int iSrcX, int iSrcY, double *padfPixelSum,
- double dfWeight, double *pdfWeightSum,
- colorObj *offsite )
+ double dfWeight, double *pdfWeightSum )
{
if( MS_RENDERER_GD(psSrcImage->format) )
@@ -348,21 +325,21 @@
else if( MS_RENDERER_RAWDATA(psSrcImage->format) )
{
int band;
+ int src_off;
+ src_off = iSrcX + iSrcY * psSrcImage->width;
+
+ if( !MS_GET_BIT(psSrcImage->img_mask,src_off) )
+ return;
+
for( band = 0; band < psSrcImage->format->bands; band++ )
{
if( psSrcImage->format->imagemode == MS_IMAGEMODE_INT16 )
{
int nValue;
- nValue = psSrcImage->img.raw_16bit[
- iSrcX + iSrcY * psSrcImage->width
- + band*psSrcImage->width*psSrcImage->height];
+ nValue = psSrcImage->img.raw_16bit[src_off];
- /* if band 1 is nodata, skip the rest */
- if( band == 0 && nValue == offsite->red )
- return;
-
padfPixelSum[band] += dfWeight * nValue;
}
else if( psSrcImage->format->imagemode
@@ -370,12 +347,7 @@
{
float fValue;
- fValue = psSrcImage->img.raw_float[
- iSrcX + iSrcY * psSrcImage->width
- + band*psSrcImage->width*psSrcImage->height];
-
- if( band == 0 && fValue == offsite->red )
- return;
+ fValue = psSrcImage->img.raw_float[src_off];
padfPixelSum[band] += fValue * dfWeight;
}
@@ -383,13 +355,8 @@
{
int nValue;
- nValue = psSrcImage->img.raw_byte[
- iSrcX + iSrcY * psSrcImage->width
- + band*psSrcImage->width*psSrcImage->height];
+ nValue = psSrcImage->img.raw_byte[src_off];
- if( band == 0 && nValue == offsite->red )
- continue;
-
padfPixelSum[band] += nValue * dfWeight;
}
else
@@ -397,6 +364,8 @@
assert( 0 );
return;
}
+
+ src_off += psSrcImage->width * psSrcImage->height;
}
*pdfWeightSum += dfWeight;
}
@@ -420,7 +389,6 @@
static int
msBilinearRasterResampler( imageObj *psSrcImage, rasterBufferObj *src_rb,
- colorObj offsite,
imageObj *psDstImage, rasterBufferObj *dst_rb,
int *panCMap,
SimpleTransformer pfnTransform, void *pCBData,
@@ -500,19 +468,19 @@
msSourceSample( psSrcImage, src_rb, nSrcX, nSrcY, padfPixelSum,
(1.0 - dfRatioX2) * (1.0 - dfRatioY2),
- &dfWeightSum, &offsite );
+ &dfWeightSum );
msSourceSample( psSrcImage, src_rb, nSrcX2, nSrcY, padfPixelSum,
(dfRatioX2) * (1.0 - dfRatioY2),
- &dfWeightSum, &offsite );
+ &dfWeightSum );
msSourceSample( psSrcImage, src_rb, nSrcX, nSrcY2, padfPixelSum,
(1.0 - dfRatioX2) * (dfRatioY2),
- &dfWeightSum, &offsite );
+ &dfWeightSum );
msSourceSample( psSrcImage, src_rb, nSrcX2, nSrcY2, padfPixelSum,
(dfRatioX2) * (dfRatioY2),
- &dfWeightSum, &offsite );
+ &dfWeightSum );
if( dfWeightSum == 0.0 )
continue;
@@ -581,30 +549,29 @@
else if( MS_RENDERER_RAWDATA(psSrcImage->format) )
{
int band;
+ int dst_off = nDstX + nDstY * psDstImage->width;
+ MS_SET_BIT(psDstImage->img_mask,dst_off);
+
for( band = 0; band < psSrcImage->format->bands; band++ )
{
if( psSrcImage->format->imagemode == MS_IMAGEMODE_INT16 )
{
- psDstImage->img.raw_16bit[
- nDstX + nDstY * psDstImage->width
- + band*psDstImage->width*psDstImage->height]
+ psDstImage->img.raw_16bit[dst_off]
= (short) padfPixelSum[band];
}
else if( psSrcImage->format->imagemode == MS_IMAGEMODE_FLOAT32)
{
- psDstImage->img.raw_float[
- nDstX + nDstY * psDstImage->width
- + band*psDstImage->width*psDstImage->height]
+ psDstImage->img.raw_float[dst_off]
= (float) padfPixelSum[band];
}
else if( psSrcImage->format->imagemode == MS_IMAGEMODE_BYTE )
{
- psDstImage->img.raw_byte[
- nDstX + nDstY * psDstImage->width
- + band*psDstImage->width*psDstImage->height]
+ psDstImage->img.raw_byte[dst_off]
= (unsigned char) padfPixelSum[band];
- }
+ }
+
+ dst_off += psDstImage->width*psDstImage->height;
}
}
}
@@ -639,7 +606,7 @@
static int
msAverageSample( imageObj *psSrcImage, rasterBufferObj *src_rb,
double dfXMin, double dfYMin, double dfXMax, double dfYMax,
- colorObj *offsite, double *padfPixelSum,
+ double *padfPixelSum,
double *pdfAlpha01 )
{
@@ -671,7 +638,7 @@
dfWeight = (dfXCellMax-dfXCellMin) * (dfYCellMax-dfYCellMin);
msSourceSample( psSrcImage, src_rb, iX, iY, padfPixelSum,
- dfWeight, &dfWeightSum, offsite );
+ dfWeight, &dfWeightSum );
dfMaxWeight += dfWeight;
}
}
@@ -693,7 +660,6 @@
static int
msAverageRasterResampler( imageObj *psSrcImage, rasterBufferObj *src_rb,
- colorObj offsite,
imageObj *psDstImage, rasterBufferObj *dst_rb,
int *panCMap,
SimpleTransformer pfnTransform, void *pCBData,
@@ -766,7 +732,7 @@
if( !msAverageSample( psSrcImage, src_rb,
dfXMin, dfYMin, dfXMax, dfYMax,
- &offsite, padfPixelSum, &dfAlpha01 ) )
+ padfPixelSum, &dfAlpha01 ) )
continue;
if( MS_RENDERER_GD(psSrcImage->format) )
@@ -830,30 +796,29 @@
else if( MS_RENDERER_RAWDATA(psSrcImage->format) )
{
int band;
+ int dst_off = nDstX + nDstY * psDstImage->width;
+ MS_SET_BIT(psDstImage->img_mask,dst_off);
+
for( band = 0; band < psSrcImage->format->bands; band++ )
{
if( psSrcImage->format->imagemode == MS_IMAGEMODE_INT16 )
{
- psDstImage->img.raw_16bit[
- nDstX + nDstY * psDstImage->width
- + band*psDstImage->width*psDstImage->height]
+ psDstImage->img.raw_16bit[dst_off]
= (short) padfPixelSum[band];
}
else if( psSrcImage->format->imagemode == MS_IMAGEMODE_FLOAT32)
{
- psDstImage->img.raw_float[
- nDstX + nDstY * psDstImage->width
- + band*psDstImage->width*psDstImage->height]
+ psDstImage->img.raw_float[dst_off]
= (float) padfPixelSum[band];
}
else if( psSrcImage->format->imagemode == MS_IMAGEMODE_BYTE )
{
- psDstImage->img.raw_byte[
- nDstX + nDstY * psDstImage->width
- + band*psDstImage->width*psDstImage->height]
+ psDstImage->img.raw_byte[dst_off]
= (unsigned char) padfPixelSum[band];
}
+
+ dst_off += psDstImage->width * psDstImage->height;
}
}
}
@@ -1782,20 +1747,17 @@
/* -------------------------------------------------------------------- */
if( EQUAL(resampleMode,"AVERAGE") )
result =
- msAverageRasterResampler( srcImage, src_rb, layer->offsite,
- image, rb,
+ msAverageRasterResampler( srcImage, src_rb, image, rb,
anCMap, msApproxTransformer, pACBData,
layer->debug );
else if( EQUAL(resampleMode,"BILINEAR") )
result =
- msBilinearRasterResampler( srcImage, src_rb, layer->offsite,
- image, rb,
+ msBilinearRasterResampler( srcImage, src_rb, image, rb,
anCMap, msApproxTransformer, pACBData,
layer->debug );
else
result =
- msNearestRasterResampler( srcImage, src_rb, layer->offsite,
- image, rb,
+ msNearestRasterResampler( srcImage, src_rb, image, rb,
anCMap, msApproxTransformer, pACBData,
layer->debug );
Modified: trunk/mapserver/mapserver.h
===================================================================
--- trunk/mapserver/mapserver.h 2010-03-25 18:48:12 UTC (rev 10016)
+++ trunk/mapserver/mapserver.h 2010-03-26 05:01:03 UTC (rev 10017)
@@ -1521,7 +1521,7 @@
#ifndef SWIG
union {
- void *plugin;
+ void *plugin;
gdImagePtr gd;
#ifdef USE_MING_FLASH
void *swf;
@@ -1537,6 +1537,7 @@
float *raw_float;
unsigned char *raw_byte;
} img;
+ ms_bitarray img_mask;
#endif
} imageObj;
@@ -1931,6 +1932,14 @@
MS_DLL_EXPORT int msDrawRasterLayer(mapObj *map, layerObj *layer, imageObj *image); /* in mapraster.c */
MS_DLL_EXPORT imageObj *msDrawReferenceMap(mapObj *map);
+/* mapbits.c - bit array handling functions and macros */
+
+#define MS_ARRAY_BIT 32
+
+#define MS_GET_BIT(array,i) (array[i>>5] & (1 <<(i & 0x3f)))
+#define MS_SET_BIT(array,i) {array[i>>5] |= (1 <<(i & 0x3f));}
+#define MS_CLR_BIT(array,i) {array[i>>5] &= (~(1 <<(i & 0x3f)));}
+
MS_DLL_EXPORT size_t msGetBitArraySize(int numbits); /* in mapbits.c */
MS_DLL_EXPORT ms_bitarray msAllocBitArray(int numbits);
MS_DLL_EXPORT int msGetBit(ms_bitarray array, int index);
@@ -1939,6 +1948,8 @@
MS_DLL_EXPORT void msFlipBit(ms_bitarray array, int index);
MS_DLL_EXPORT int msGetNextBit(ms_bitarray array, int index, int size);
+/* maplayer.c - layerObj api */
+
MS_DLL_EXPORT int msLayerInitItemInfo(layerObj *layer);
MS_DLL_EXPORT void msLayerFreeItemInfo(layerObj *layer);
Modified: trunk/mapserver/maputil.c
===================================================================
--- trunk/mapserver/maputil.c 2010-03-25 18:48:12 UTC (rev 10016)
+++ trunk/mapserver/maputil.c 2010-03-26 05:01:03 UTC (rev 10017)
@@ -870,6 +870,9 @@
image->imagepath = NULL;
image->imageurl = NULL;
+ msFree( image->img_mask );
+ image->img_mask= NULL;
+
msFree( image );
}
}
@@ -1390,23 +1393,23 @@
else if(MS_RENDERER_PLUGIN(format)) {
image = format->vtable->createImage(width,height,format,&map->imagecolor);
image->format = format;
- format->refcount++;
+ format->refcount++;
- image->width = width;
- image->height = height;
- image->imagepath = NULL;
- image->imageurl = NULL;
- image->tilecache = NULL;
- image->ntiles = 0;
- image->resolution = map->resolution;
- image->resolutionfactor = map->resolution/map->defresolution;
+ image->width = width;
+ image->height = height;
+ image->imagepath = NULL;
+ image->imageurl = NULL;
+ image->tilecache = NULL;
+ image->ntiles = 0;
+ image->resolution = map->resolution;
+ image->resolutionfactor = map->resolution/map->defresolution;
- if (imagepath)
- image->imagepath = strdup(imagepath);
- if (imageurl)
- image->imageurl = strdup(imageurl);
+ if (imagepath)
+ image->imagepath = strdup(imagepath);
+ if (imageurl)
+ image->imageurl = strdup(imageurl);
- return image;
+ return image;
}
#ifdef USE_AGG
else if( MS_RENDERER_AGG(format) )
@@ -1423,7 +1426,7 @@
&& format->imagemode != MS_IMAGEMODE_BYTE )
{
msSetError(MS_IMGERR,
- "Attempt to use illegal imagemode with rawdata renderer.",
+ "Attempt to use illegal imagemode with rawdata renderer.",
"msImageCreate()" );
return NULL;
}
@@ -1448,6 +1451,8 @@
"msImageCreate()" );
return NULL;
}
+
+ image->img_mask = msAllocBitArray( width*height );
image->format = format;
format->refcount++;
@@ -1490,7 +1495,7 @@
else
{
msSetError(MS_MISCERR,
- "Unsupported renderer requested, unable to initialize image.",
+ "Unsupported renderer requested, unable to initialize image.",
"msImageCreate()");
return NULL;
}
More information about the mapserver-commits
mailing list