47
48
* implement the reprojection, and will default a variety of other
50
* By default all bands are transferred, with no masking or nodata values
51
* in effect. No metadata, projection info, or color tables are transferred
51
* No metadata, projection info, or color tables are transferred
52
52
* to the output file.
54
54
* @param hSrcDS the source image file.
409
420
float fNoData = (float) padfNoData[0];
410
421
float *pafData = (float *) *ppImageData;
413
// nothing to do if value is out of range.
414
if( padfNoData[1] != 0.0 )
417
for( iOffset = nXSize*nYSize-1; iOffset >= 0; iOffset-- )
419
if( pafData[iOffset] == fNoData )
423
int bIsNoDataNan = CPLIsNan(fNoData);
425
// nothing to do if value is out of range.
426
if( padfNoData[1] != 0.0 )
429
for( iOffset = nXSize*nYSize-1; iOffset >= 0; iOffset-- )
431
float fVal = pafData[iOffset];
432
if( (bIsNoDataNan && CPLIsNan(fVal)) || (!bIsNoDataNan && ARE_REAL_EQUAL(fVal, fNoData)) )
434
panValidityMask[iOffset>>5] &= ~(0x01 << (iOffset & 0x1f));
442
double dfNoData = padfNoData[0];
443
double *padfData = (double *) *ppImageData;
445
int bIsNoDataNan = CPLIsNan(dfNoData);
447
// nothing to do if value is out of range.
448
if( padfNoData[1] != 0.0 )
451
for( iOffset = nXSize*nYSize-1; iOffset >= 0; iOffset-- )
453
double dfVal = padfData[iOffset];
454
if( (bIsNoDataNan && CPLIsNan(dfVal)) || (!bIsNoDataNan && ARE_REAL_EQUAL(dfVal, dfNoData)) )
421
456
panValidityMask[iOffset>>5] &= ~(0x01 << (iOffset & 0x1f));
440
478
for( iPixel = 0; iPixel < nXSize; iPixel++ )
442
if( padfWrk[iPixel*2] == padfNoData[0]
443
&& padfWrk[iPixel*2+1] == padfNoData[1] )
480
if( ((bIsNoDataRealNan && CPLIsNan(padfWrk[iPixel*2])) ||
481
(!bIsNoDataRealNan && ARE_REAL_EQUAL(padfWrk[iPixel*2], padfNoData[0])))
482
&& ((bIsNoDataImagNan && CPLIsNan(padfWrk[iPixel*2+1])) ||
483
(!bIsNoDataImagNan && ARE_REAL_EQUAL(padfWrk[iPixel*2+1], padfNoData[1]))) )
445
485
int iOffset = iPixel + iLine * nXSize;
522
562
/************************************************************************/
563
/* GDALWarpSrcMaskMasker() */
565
/* GDALMaskFunc for reading source simple 8bit validity mask */
566
/* information and building a one bit validity mask. */
567
/************************************************************************/
570
GDALWarpSrcMaskMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
571
int nXOff, int nYOff, int nXSize, int nYSize,
572
GByte ** /*ppImageData */,
573
int bMaskIsFloat, void *pValidityMask )
576
GDALWarpOptions *psWO = (GDALWarpOptions *) pMaskFuncArg;
577
GUInt32 *panMask = (GUInt32 *) pValidityMask;
579
/* -------------------------------------------------------------------- */
580
/* Do some minimal checking. */
581
/* -------------------------------------------------------------------- */
594
/* -------------------------------------------------------------------- */
595
/* Allocate a temporary buffer to read mask byte data into. */
596
/* -------------------------------------------------------------------- */
599
pabySrcMask = (GByte *) VSIMalloc2(nXSize,nYSize);
600
if( pabySrcMask == NULL )
602
CPLError( CE_Failure, CPLE_OutOfMemory,
603
"Failed to allocate pabySrcMask (%dx%d) in GDALWarpSrcMaskMasker()",
608
/* -------------------------------------------------------------------- */
609
/* Fetch our mask band. */
610
/* -------------------------------------------------------------------- */
611
GDALRasterBandH hSrcBand, hMaskBand = NULL;
613
hSrcBand = GDALGetRasterBand( psWO->hSrcDS, psWO->panSrcBands[0] );
614
if( hSrcBand != NULL )
615
hMaskBand = GDALGetMaskBand( hSrcBand );
617
if( hMaskBand == NULL )
623
/* -------------------------------------------------------------------- */
624
/* Read the mask band. */
625
/* -------------------------------------------------------------------- */
628
eErr = GDALRasterIO( hMaskBand, GF_Read, nXOff, nYOff, nXSize, nYSize,
629
pabySrcMask, nXSize, nYSize, GDT_Byte, 0, 0 );
631
if( eErr != CE_None )
633
CPLFree( pabySrcMask );
637
/* -------------------------------------------------------------------- */
638
/* Pack into 1 bit per pixel for validity. */
639
/* -------------------------------------------------------------------- */
640
for( int iPixel = nXSize * nYSize - 1; iPixel >= 0; iPixel-- )
642
if( pabySrcMask[iPixel] == 0 )
643
panMask[iPixel>>5] &= ~(0x01 << (iPixel & 0x1f));
646
CPLFree( pabySrcMask );
651
/************************************************************************/
523
652
/* GDALWarpDstAlphaMasker() */
525
654
/* GDALMaskFunc for reading or writing the destination simple */
689
818
* - CUTLINE: This may contain the WKT geometry for a cutline. It will
690
819
* be converted into a geometry by GDALWarpOperation::Initialize() and assigned
691
* to the GDALWarpOptions hCutline field.
820
* to the GDALWarpOptions hCutline field. The coordinates must be expressed
821
* in source pixel/line coordinates. Note: this is different from the assumptions
822
* made for the -cutline option of the gdalwarp utility !
693
824
* - CUTLINE_BLEND_DIST: This may be set with a distance in pixels which
694
825
* will be assigned to the dfCutlineBlendDist field in the GDALWarpOptions.
755
886
#define COPY_MEM(target,type,count) \
756
if( (psSrcOptions->target) != NULL && (count) != 0 ) \
887
do { if( (psSrcOptions->target) != NULL && (count) != 0 ) \
758
(psDstOptions->target) = (type *) CPLMalloc(sizeof(type)*count); \
889
(psDstOptions->target) = (type *) CPLMalloc(sizeof(type)*(count)); \
759
890
memcpy( (psDstOptions->target), (psSrcOptions->target), \
760
sizeof(type) * count ); \
891
sizeof(type) * (count) ); \
894
(psDstOptions->target) = NULL; } while(0)
763
896
/************************************************************************/
764
897
/* GDALCloneWarpOptions() */
927
1061
CXT_Text, CPLString().Printf( "%d", psWO->panDstBands[i] ) );
929
1063
if( psWO->padfSrcNoDataReal != NULL )
930
CPLCreateXMLElementAndValue(
931
psBand, "SrcNoDataReal",
932
CPLString().Printf( "%.16g", psWO->padfSrcNoDataReal[i] ) );
1065
if (CPLIsNan(psWO->padfSrcNoDataReal[i]))
1066
CPLCreateXMLElementAndValue(psBand, "SrcNoDataReal", "nan");
1068
CPLCreateXMLElementAndValue(
1069
psBand, "SrcNoDataReal",
1070
CPLString().Printf( "%.16g", psWO->padfSrcNoDataReal[i] ) );
934
1073
if( psWO->padfSrcNoDataImag != NULL )
935
CPLCreateXMLElementAndValue(
936
psBand, "SrcNoDataImag",
937
CPLString().Printf( "%.16g", psWO->padfSrcNoDataImag[i] ) );
1075
if (CPLIsNan(psWO->padfSrcNoDataImag[i]))
1076
CPLCreateXMLElementAndValue(psBand, "SrcNoDataImag", "nan");
1078
CPLCreateXMLElementAndValue(
1079
psBand, "SrcNoDataImag",
1080
CPLString().Printf( "%.16g", psWO->padfSrcNoDataImag[i] ) );
939
1083
if( psWO->padfDstNoDataReal != NULL )
940
CPLCreateXMLElementAndValue(
941
psBand, "DstNoDataReal",
942
CPLString().Printf( "%.16g", psWO->padfDstNoDataReal[i] ) );
1085
if (CPLIsNan(psWO->padfDstNoDataReal[i]))
1086
CPLCreateXMLElementAndValue(psBand, "DstNoDataReal", "nan");
1088
CPLCreateXMLElementAndValue(
1089
psBand, "DstNoDataReal",
1090
CPLString().Printf( "%.16g", psWO->padfDstNoDataReal[i] ) );
944
1093
if( psWO->padfDstNoDataImag != NULL )
945
CPLCreateXMLElementAndValue(
946
psBand, "DstNoDataImag",
947
CPLString().Printf( "%.16g", psWO->padfDstNoDataImag[i] ) );
1095
if (CPLIsNan(psWO->padfDstNoDataImag[i]))
1096
CPLCreateXMLElementAndValue(psBand, "DstNoDataImag", "nan");
1098
CPLCreateXMLElementAndValue(
1099
psBand, "DstNoDataImag",
1100
CPLString().Printf( "%.16g", psWO->padfDstNoDataImag[i] ) );
950
1104
/* -------------------------------------------------------------------- */