| 71 | |
| 72 | template <class DataType, class EqualityTest> |
| 73 | static CPLErr GDALPolygonizeT(GDALRasterBandH hSrcBand, |
| 74 | GDALRasterBandH hMaskBand, OGRLayerH hOutLayer, |
| 75 | int iPixValField, CSLConstList papszOptions, |
| 76 | GDALProgressFunc pfnProgress, void *pProgressArg, |
| 77 | GDALDataType eDT) |
| 78 | |
| 79 | { |
| 80 | VALIDATE_POINTER1(hSrcBand, "GDALPolygonize", CE_Failure); |
| 81 | VALIDATE_POINTER1(hOutLayer, "GDALPolygonize", CE_Failure); |
| 82 | |
| 83 | if (pfnProgress == nullptr) |
| 84 | pfnProgress = GDALDummyProgress; |
| 85 | |
| 86 | const int nConnectedness = |
| 87 | CSLFetchNameValue(papszOptions, "8CONNECTED") ? 8 : 4; |
| 88 | |
| 89 | /* -------------------------------------------------------------------- */ |
| 90 | /* Confirm our output layer will support feature creation. */ |
| 91 | /* -------------------------------------------------------------------- */ |
| 92 | if (!OGR_L_TestCapability(hOutLayer, OLCSequentialWrite)) |
| 93 | { |
| 94 | CPLError(CE_Failure, CPLE_AppDefined, |
| 95 | "Output feature layer does not appear to support creation " |
| 96 | "of features in GDALPolygonize()."); |
| 97 | return CE_Failure; |
| 98 | } |
| 99 | |
| 100 | /* -------------------------------------------------------------------- */ |
| 101 | /* Allocate working buffers. */ |
| 102 | /* -------------------------------------------------------------------- */ |
| 103 | const int nXSize = GDALGetRasterBandXSize(hSrcBand); |
| 104 | const int nYSize = GDALGetRasterBandYSize(hSrcBand); |
| 105 | if (nXSize > std::numeric_limits<int>::max() - 2) |
| 106 | { |
| 107 | CPLError(CE_Failure, CPLE_AppDefined, "Too wide raster"); |
| 108 | return CE_Failure; |
| 109 | } |
| 110 | |
| 111 | DataType *panLastLineVal = |
| 112 | static_cast<DataType *>(VSI_MALLOC2_VERBOSE(sizeof(DataType), nXSize)); |
| 113 | DataType *panThisLineVal = |
| 114 | static_cast<DataType *>(VSI_MALLOC2_VERBOSE(sizeof(DataType), nXSize)); |
| 115 | GInt32 *panLastLineId = |
| 116 | static_cast<GInt32 *>(VSI_MALLOC2_VERBOSE(sizeof(GInt32), nXSize)); |
| 117 | GInt32 *panThisLineId = |
| 118 | static_cast<GInt32 *>(VSI_MALLOC2_VERBOSE(sizeof(GInt32), nXSize)); |
| 119 | |
| 120 | GByte *pabyMaskLine = static_cast<GByte *>(VSI_MALLOC_VERBOSE(nXSize)); |
| 121 | |
| 122 | if (panLastLineVal == nullptr || panThisLineVal == nullptr || |
| 123 | panLastLineId == nullptr || panThisLineId == nullptr || |
| 124 | pabyMaskLine == nullptr) |
| 125 | { |
| 126 | CPLFree(panThisLineId); |
| 127 | CPLFree(panLastLineId); |
| 128 | CPLFree(panThisLineVal); |
| 129 | CPLFree(panLastLineVal); |
| 130 | CPLFree(pabyMaskLine); |
nothing calls this directly
no test coverage detected