RM开发 Posted on 2021-12-19 | Views: Symbols count in article: 662 | Reading time ≈ 1 mins. uint32_t lut_cal(uint32_t *lut, uint32_t x_base, uint32_t x_step, uint32_t index_base, uint32_t in_max, uint32_t in_data, uint32_t lut_sz) { uint32_t index_off = (in_data - x_base) >> x_step; uint32_t index = index_off + index_base; assert(index < lut_sz && index >= 0); uint32_t y0 = lut[index]; uint32_t y1 = lut[min(index + 1, lut_sz - 1)]; uint32_t frac = in_data - ((index_off << x_step) + x_base); uint32_t y; assert(y1 >= y0); if (in_data <= in_max) { y = (((y1 - y0) * frac) >> x_step) + y0; } else { y = y0; } return y;}