Skip to content

Instantly share code, notes, and snippets.

@AllanChen
Created March 13, 2020 11:33
Show Gist options
  • Save AllanChen/a21844a517aaf1fcc23f8fd229568a8a to your computer and use it in GitHub Desktop.
Save AllanChen/a21844a517aaf1fcc23f8fd229568a8a to your computer and use it in GitHub Desktop.
bilinear c4, c3 also c1,c2 done
void resize_bilinear_c4(uint8_t *dst, const uint8_t *src,
uint64_t dst_h, uint64_t dst_w, uint64_t src_h,
uint64_t src_w) {
float scale_y = static_cast<float>(src_h) / static_cast<float>(dst_h);
float scale_x = static_cast<float>(src_w) / static_cast<float>(dst_w);
for (int h = 0; h < dst_h; h++) {
const int y = (int)MIN(static_cast<uint64_t>(h * scale_y), src_h - 1);
for (int w = 0; w < dst_w; w++) {
const int x = (int)MIN(static_cast<uint64_t>(w * scale_x), src_w - 1);
const uint8_t *input = &src[4 * (y * src_w + x)];
uint8_t *output = &dst[4 * (h * dst_w + w)];
for (int k = 0; k < 4; k++) {
*output++ = *input++;
}
}
}
}
void resize_bilinear_c3(uint8_t *dst, const uint8_t *src,
uint64_t dst_h, uint64_t dst_w, uint64_t src_h,
uint64_t src_w) {
float scale_y = static_cast<float>(src_h) / static_cast<float>(dst_h);
float scale_x = static_cast<float>(src_w) / static_cast<float>(dst_w);
for (int h = 0; h < dst_h; h++) {
const int y = (int)MIN(static_cast<uint64_t>(h * scale_y), src_h - 1);
for (int w = 0; w < dst_w; w++) {
const int x = (int)MIN(static_cast<uint64_t>(w * scale_x), src_w - 1);
const uint8_t *input = &src[3 * (y * src_w + x)];
uint8_t *output = &dst[3 * (h * dst_w + w)];
for (int k = 0; k < 3; k++) {
*output++ = *input++;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment