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

Method start

dnn/src/common/cv/filter.cpp:113–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

111
112template <typename ST, typename FT>
113void FilterEngine<ST, FT>::start(const Mat<ST>& src) {
114 m_whole_size.cols() = src.cols();
115 m_whole_size.rows() = src.rows();
116
117 int element_size = (int)sizeof(ST) * m_ch;
118 int buf_elem_size = (int)sizeof(FT) * m_ch;
119
120 int cn = m_ch;
121 m_src_row.resize(element_size * (m_whole_size.width() + m_ksize.width() - 1));
122 if (m_bmode == BorderMode::BORDER_CONSTANT) {
123 m_const_border_row.resize(
124 buf_elem_size *
125 (m_whole_size.width() + m_ksize.width() - 1 + VEC_ALIGN));
126 uchar *dst = align_ptr(&m_const_border_row[0], VEC_ALIGN), *tdst;
127 int n = (int)m_const_border_value.size(), N;
128 N = (m_whole_size.width() + m_ksize.width() - 1) * element_size;
129 tdst = &m_src_row[0];
130
131 for (int i = 0; i < N; i += n) {
132 n = std::min<int>((int)n, (int)(N - i));
133 for (int j = 0; j < n; j++)
134 tdst[i + j] = m_const_border_row[j];
135 }
136
137 (*m_row_filter)(&m_src_row[0], dst, m_whole_size.width(), cn);
138 }
139
140 m_buf_step = buf_elem_size *
141 (int)align_size(m_whole_size.width() + m_ksize.width() - 1, VEC_ALIGN);
142 m_ring_buf.resize(m_buf_step * m_ksize.height() + VEC_ALIGN);
143 m_left_width = m_anchor.x;
144 m_right_width = m_ksize.width() - m_anchor.x - 1;
145
146 //! init the row with border values
147 if (m_left_width > 0 || m_right_width > 0) {
148 //! calc the index of the border value, we will not calc it when process
149 //! border each time
150 if (m_bmode == BorderMode::BORDER_CONSTANT) {
151 memcpy(m_src_row.data(), m_const_border_row.data(),
152 m_left_width * element_size);
153 memcpy(m_src_row.data() +
154 (m_whole_size.width() + m_left_width) * element_size,
155 m_const_border_row.data(), m_right_width * element_size);
156 } else {
157 //! calc the index of the border value, we will not calc it when
158 //! process border each time
159 for (int i = 0; i < m_left_width; i++) {
160 int p0 = gaussian_blur::border_interpolate(
161 i - m_left_width, m_whole_size.width(), m_bmode) *
162 m_border_elem_size;
163 for (int j = 0; j < m_border_elem_size; j++)
164 m_border_table[i * m_border_elem_size + j] = p0 + j;
165 }
166
167 for (int i = 0; i < m_right_width; i++) {
168 int p0 = gaussian_blur::border_interpolate(
169 m_whole_size.width() + i, m_whole_size.width(),
170 m_bmode) *

Callers 1

Calls 11

resizeMethod · 0.80
align_ptrFunction · 0.70
align_sizeFunction · 0.70
border_interpolateFunction · 0.70
colsMethod · 0.45
rowsMethod · 0.45
widthMethod · 0.45
sizeMethod · 0.45
heightMethod · 0.45
dataMethod · 0.45
resetMethod · 0.45

Tested by

no test coverage detected