MCPcopy Create free account
hub / github.com/CVCUDA/CV-CUDA / ResizeCropConvert

Function ResizeCropConvert

tests/cvcuda/system/TestOpResizeCropConvertReformat.cpp:77–172  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

75
76template<typename DstT, typename SrcT>
77void ResizeCropConvert( DstT *dst, NVCVSize2D dstSize, nvcv::ImageFormat dstFrmt,
78 const SrcT *src, NVCVSize2D srcSize, nvcv::ImageFormat srcFrmt,
79 int numImages, NVCVSize2D newSize, int2 crop, NVCVInterpolationType interp,
80 const NVCVChannelManip manip, float scale, float offset, bool srcCast = true)
81{
82 int channels = dstFrmt.numChannels();
83 int srcPlanes = srcFrmt.numPlanes();
84 int dstPlanes = dstFrmt.numPlanes();
85
86 size_t srcIncrX = channels / srcPlanes; // 1 if planar; channels if not.
87 size_t dstIncrX = channels / dstPlanes; // 1 if planar; channels if not.
88 size_t srcIncrY = srcIncrX * srcSize.w;
89 size_t dstIncrY = dstIncrX * dstSize.w;
90 size_t srcIncrC = (srcPlanes > 1 ? srcSize.w * srcSize.h : 1);
91 size_t dstIncrC = (dstPlanes > 1 ? dstSize.w * dstSize.h : 1);
92 size_t srcIncrN = srcSize.w * srcSize.h * channels;
93 size_t dstIncrN = dstSize.w * dstSize.h * channels;
94
95 int mapC[4] = {0, 1, 2, 3};
96
97 if (manip == NVCV_CHANNEL_REVERSE)
98 {
99 for (int c = 0; c < channels; ++c) mapC[c] = channels - c - 1;
100 }
101
102 float scaleW = static_cast<float>(srcSize.w) / newSize.w;
103 float scaleH = static_cast<float>(srcSize.h) / newSize.h;
104
105 for (int i = 0; i < numImages; i++)
106 {
107 const SrcT *srcBase = src + i * srcIncrN;
108 DstT *dstBase = dst + i * dstIncrN;
109
110 for (int dy = 0; dy < dstSize.h; dy++)
111 {
112 DstT *dstRow = dstBase + dy * dstIncrY;
113
114 for (int dx = 0; dx < dstSize.w; dx++)
115 {
116 DstT *dstPtr = dstRow + dx * dstIncrX;
117
118 if (interp == NVCV_INTERP_NEAREST)
119 {
120 int sx = std::floor(scaleW * (dx + crop.x + 0.5f));
121 int sy = std::floor(scaleH * (dy + crop.y + 0.5f));
122
123 const SrcT *src0 = srcBase + sy * srcIncrY + sx * srcIncrX;
124
125 for (int c = 0; c < channels; c++)
126 {
127 dstPtr[mapC[c] * dstIncrC] = cuda::SaturateCast<DstT>(scale * src0[c * srcIncrC] + offset);
128 }
129 }
130 else if (interp == NVCV_INTERP_LINEAR)
131 {
132 float fx = scaleW * (dx + crop.x + 0.5f) - 0.5f;
133 float fy = scaleH * (dy + crop.y + 0.5f) - 0.5f;
134

Callers 1

TYPED_TESTFunction · 0.85

Calls 4

minFunction · 0.85
numChannelsMethod · 0.45
numPlanesMethod · 0.45
dataMethod · 0.45

Tested by

no test coverage detected