Skip to content

Commit

Permalink
GDALRegisterTransformer(): remove pfnTransformerFunc argument
Browse files Browse the repository at this point in the history
  • Loading branch information
rouault committed May 7, 2024
1 parent ee9e231 commit 038d28b
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 26 deletions.
1 change: 0 additions & 1 deletion alg/gdal_alg.h
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ typedef void *(*GDALTransformDeserializeFunc)(const CPLXMLNode *psTree);

void CPL_DLL *
GDALRegisterTransformer(const char *pszTransformName,
GDALTransformerFunc pfnTransformerFunc,
GDALTransformDeserializeFunc pfnDeserializeFunc,
GDALTransformerCreateForGenImgTransformer
pfnTransformerCreateForGenImgTransformerFunc);
Expand Down
71 changes: 46 additions & 25 deletions alg/gdaltransformer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ struct GDALTransformerRegistrationEntry
{
std::string osKey{};
int nRegistrationOrder = 0;
GDALTransformerFunc pfnTransformerFunc = nullptr;
GDALTransformerCreateForGenImgTransformer
pfnTransformerCreateForGenImgTransformerFunc = nullptr;
GDALTransformDeserializeFunc pfnDeserializeFunc = nullptr;
Expand Down Expand Up @@ -2312,7 +2311,18 @@ void *GDALCreateGenImgProjTransformer2(GDALDatasetH hSrcDS, GDALDatasetH hDstDS,
CPLDebug("WARP", "Using source %s transformer",
poEntry->osKey.c_str());
}
psInfo->pSrcTransformer = poEntry->pfnTransformerFunc;
GDALTransformerInfo *psSubInfo =
static_cast<GDALTransformerInfo *>(
psInfo->pSrcTransformArg);
if (memcmp(psSubInfo->abySignature, GDAL_GTI2_SIGNATURE,
strlen(GDAL_GTI2_SIGNATURE)) != 0)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Attempt to use non-GTI2 transformer with %s.",
poEntry->osKey.c_str());
return nullptr;
}
psInfo->pSrcTransformer = psSubInfo->pfnTransform;
break;
}
}
Expand Down Expand Up @@ -2431,7 +2441,18 @@ void *GDALCreateGenImgProjTransformer2(GDALDatasetH hSrcDS, GDALDatasetH hDstDS,
CPLDebug("WARP", "Using target %s transformer",
poEntry->osKey.c_str());
}
psInfo->pDstTransformer = poEntry->pfnTransformerFunc;
GDALTransformerInfo *psSubInfo =
static_cast<GDALTransformerInfo *>(
psInfo->pDstTransformArg);
if (memcmp(psSubInfo->abySignature, GDAL_GTI2_SIGNATURE,
strlen(GDAL_GTI2_SIGNATURE)) != 0)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Attempt to use non-GTI2 transformer with %s.",
poEntry->osKey.c_str());
return nullptr;
}
psInfo->pDstTransformer = psSubInfo->pfnTransform;
break;
}
}
Expand Down Expand Up @@ -4532,11 +4553,6 @@ CPLXMLNode *GDALSerializeTransformer(GDALTransformerFunc /* pfnFunc */,
* instanciate a transformer from its XML serialization,
* and must thus be a valid XML element name (possibly
* namespaced)
* @param pfnTransformerFunc Transformation function. Must not be NULL.
* It must also be the same value as the
* GDALTransformerInfo::pfnTransform member of the
* transformer instances returned by pfnDeserializeFunc
* and pfnTransformerCreateForGenImgTransformerFunc.
* @param pfnDeserializeFunc XML deserizaliation function. For example used to
* instantiate a transformer instance from a warped VRT.
* @param pfnTransformerCreateForGenImgTransformerFunc Function to instantiate
Expand All @@ -4548,13 +4564,11 @@ CPLXMLNode *GDALSerializeTransformer(GDALTransformerFunc /* pfnFunc */,
* or NULL in case of error.
*/
void *GDALRegisterTransformer(const char *pszTransformName,
GDALTransformerFunc pfnTransformerFunc,
GDALTransformDeserializeFunc pfnDeserializeFunc,
GDALTransformerCreateForGenImgTransformer
pfnTransformerCreateForGenImgTransformerFunc)
{
VALIDATE_POINTER1(pszTransformName, __func__, nullptr);
VALIDATE_POINTER1(pfnTransformerFunc, __func__, nullptr);

std::lock_guard oLock(oTransformerRegistrationMutex);

Expand All @@ -4575,7 +4589,6 @@ void *GDALRegisterTransformer(const char *pszTransformName,
poRegistrationEntry->osKey = osKey;
poRegistrationEntry->nRegistrationOrder =
static_cast<int>(oMapRegisteredTransformers.size());
poRegistrationEntry->pfnTransformerFunc = pfnTransformerFunc;
poRegistrationEntry->pfnTransformerCreateForGenImgTransformerFunc =
pfnTransformerCreateForGenImgTransformerFunc;
poRegistrationEntry->pfnDeserializeFunc = pfnDeserializeFunc;
Expand Down Expand Up @@ -4631,33 +4644,29 @@ void GDALRegisterBuiltinTransformersUnderLock()
if (oMapRegisteredTransformers.empty())
{
// Transformers that can be used as source/target transformer for GDALGenImgProjTransform
GDALRegisterTransformer("GCPTransformer", GDALGCPTransform,
GDALDeserializeGCPTransformer,
GDALRegisterTransformer("GCPTransformer", GDALDeserializeGCPTransformer,
GDALGCPTransformCreateForGenImgTransformer);

GDALRegisterTransformer("TPSTransformer", GDALTPSTransform,
GDALDeserializeTPSTransformer,
GDALRegisterTransformer("TPSTransformer", GDALDeserializeTPSTransformer,
GDALTPSTransformCreateForGenImgTransformer);

GDALRegisterTransformer("RPCTransformer", GDALRPCTransform,
GDALDeserializeRPCTransformer,
GDALRegisterTransformer("RPCTransformer", GDALDeserializeRPCTransformer,
GDALRPCTransformCreateForGenImgTransformer);

GDALRegisterTransformer("GeoLocTransformer", GDALGeoLocTransform,
GDALRegisterTransformer("GeoLocTransformer",
GDALDeserializeGeoLocTransformer,
GDALGeoLocTransformCreateForGenImgTransformer);

// Below ones cannot be used as source/target transformer for GDALGenImgProjTransform

GDALRegisterTransformer("GenImgProjTransformer",
GDALGenImgProjTransform,
GDALDeserializeGenImgProjTransformer, nullptr);

GDALRegisterTransformer(
"ReprojectionTransformer", GDALReprojectionTransform,
GDALDeserializeReprojectionTransformer, nullptr);
GDALRegisterTransformer("ReprojectionTransformer",
GDALDeserializeReprojectionTransformer,
nullptr);

GDALRegisterTransformer("ApproxTransformer", GDALApproxTransform,
GDALRegisterTransformer("ApproxTransformer",
GDALDeserializeApproxTransformer, nullptr);
}
}
Expand Down Expand Up @@ -4696,8 +4705,6 @@ CPLErr GDALDeserializeTransformer(CPLXMLNode *psTree,
return CE_Failure;
}
pfnDeserializeFunc = oIter->second->pfnDeserializeFunc;
if (pfnDeserializeFunc)
*ppfnFunc = oIter->second->pfnTransformerFunc;
}
if (!pfnDeserializeFunc)
{
Expand All @@ -4710,6 +4717,20 @@ CPLErr GDALDeserializeTransformer(CPLXMLNode *psTree,

CPLErrorReset();
*ppTransformArg = pfnDeserializeFunc(psTree);

if (*ppTransformArg)
{
GDALTransformerInfo *psInfo =
static_cast<GDALTransformerInfo *>(*ppTransformArg);
if (memcmp(psInfo->abySignature, GDAL_GTI2_SIGNATURE,
strlen(GDAL_GTI2_SIGNATURE)) != 0)
{
CPLError(CE_Failure, CPLE_AppDefined,
"Attempt to use non-GTI2 transformer.");
return CE_Failure;
}
*ppfnFunc = psInfo->pfnTransform;
}
return CPLGetLastErrorType();
}

Expand Down

0 comments on commit 038d28b

Please sign in to comment.