Skip to content

Commit

Permalink
VRT expression: move GDALCopyWords out of inner loop
Browse files Browse the repository at this point in the history
  • Loading branch information
dbaston committed Nov 8, 2024
1 parent 0178709 commit 43a7c75
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions frmts/vrt/pixelfunctions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1669,6 +1669,9 @@ static CPLErr ExprPixelFunc(void **papoSources, int nSources, void *pData,
return CE_Failure;
}

double *padfResults =
static_cast<double *>(CPLMalloc(nXSize * sizeof(double)));

/* ---- Set pixels ---- */
size_t ii = 0;
for (int iLine = 0; iLine < nYSize; ++iLine)
Expand All @@ -1682,16 +1685,17 @@ static CPLErr ExprPixelFunc(void **papoSources, int nSources, void *pData,
GetSrcVal(papoSources[iSrc], eSrcType, ii);
}

double dfPixVal = oExpression.value();

GDALCopyWords(&dfPixVal, GDT_Float64, 0,
static_cast<GByte *>(pData) +
static_cast<GSpacing>(nLineSpace) * iLine +
iCol * nPixelSpace,
eBufType, nPixelSpace, 1);
padfResults[iCol] = oExpression.value();
}

GDALCopyWords(padfResults, GDT_Float64, sizeof(double),
static_cast<GByte *>(pData) +
static_cast<GSpacing>(nLineSpace) * iLine,
eBufType, nPixelSpace, nXSize);
}

CPLFree(padfResults);

/* ---- Return success ---- */
return CE_None;
} // ExprPixelFunc
Expand Down

0 comments on commit 43a7c75

Please sign in to comment.