MCPcopy Create free account
hub / github.com/MegEngine/MegEngine / interpolate_lanczos4

Function interpolate_lanczos4

dnn/src/naive/resize/resize_cv.cpp:388–411  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386 const DecimateAlpha* ytab, int ytab_size, const int* yofs);
387
388static inline void interpolate_lanczos4(float x, float* coeffs) {
389 static const double s45 = 0.70710678118654752440084436210485;
390 static const double cs[][2] = {{1, 0}, {-s45, -s45}, {0, 1}, {s45, -s45},
391 {-1, 0}, {s45, s45}, {0, -1}, {-s45, s45}};
392
393 if (x < FLT_EPSILON) {
394 for (int i = 0; i < 8; i++)
395 coeffs[i] = 0;
396 coeffs[3] = 1;
397 return;
398 }
399
400 float sum = 0;
401 double y0 = -(x + 3) * MEGCV_PI * 0.25, s0 = sin(y0), c0 = cos(y0);
402 for (int i = 0; i < 8; i++) {
403 double y = -(x + 3 - i) * MEGCV_PI * 0.25;
404 coeffs[i] = (float)((cs[i][0] * s0 + cs[i][1] * c0) / (y * y));
405 sum += coeffs[i];
406 }
407
408 sum = 1.f / sum;
409 for (int i = 0; i < 8; i++)
410 coeffs[i] *= sum;
411}
412
413template <typename T, typename WT, typename AT>
414struct HResizeLanczos4 {

Callers 1

resize_opencvFunction · 0.70

Calls 2

sinFunction · 0.50
cosFunction · 0.50

Tested by

no test coverage detected