提交 090d0935 编写于 作者: 赵奇可

use shared ptr to manage coeff tab memory

上级 6ef87a81
......@@ -33,25 +33,27 @@ namespace kernels {
static const int64_t kTableSize = (1 << 10);
inline const float *InitCoeffsTable() {
inline const std::shared_ptr<float> InitCoeffsTable() {
// Allocate and initialize coefficients table using Bicubic
// convolution algorithm.
// https://en.wikipedia.org/wiki/Bicubic_interpolation
float *coeffs_tab = new float[(kTableSize + 1) * 2];
auto coeffs_tab = std::shared_ptr<float>(new float[(kTableSize + 1) * 2],
std::default_delete<float[]>());
float *coeffs_tab_ptr = coeffs_tab.get();
static const double A = -0.75;
for (int i = 0; i <= kTableSize; ++i) {
float x = i * 1.0 / kTableSize;
coeffs_tab[i * 2] = ((A + 2) * x - (A + 3)) * x * x + 1;
coeffs_tab_ptr[i * 2] = ((A + 2) * x - (A + 3)) * x * x + 1;
x += 1.0;
coeffs_tab[i * 2 + 1] = ((A * x - 5 * A) * x + 8 * A) * x - 4 * A;
coeffs_tab_ptr[i * 2 + 1] = ((A * x - 5 * A) * x + 8 * A) * x - 4 * A;
}
return coeffs_tab;
}
inline const float *GetCoeffsTable() {
// Static so that we initialize it on first use
static const float *coeffs_tab = InitCoeffsTable();
return coeffs_tab;
static const std::shared_ptr<float> coeffs_tab = InitCoeffsTable();
return coeffs_tab.get();
}
inline int64_t Bound(int64_t val, int64_t limit) {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册