Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make scalar code plain C #350

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ fn main() {
} else if !env.contains("windows") && !env.contains("wasm32") {
// build scalar on non-windows and non-mac
cc::Build::new()
.file("src/native/posix/scalar.cpp")
.file("src/native/posix/scalar.c")
.opt_level(3) // always build with opts for scaler so it's fast in debug also
.compile("libscalar.a")
}
Expand Down
25 changes: 12 additions & 13 deletions src/native/posix/scalar.cpp → src/native/posix/scalar.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include <stdint.h>
#include <stdio.h>

extern "C" void image_resize_linear(
void image_resize_linear(
uint32_t* dst,
const uint32_t dst_width,
const uint32_t dst_height,
Expand All @@ -10,8 +9,8 @@ extern "C" void image_resize_linear(
const uint32_t src_height,
const uint32_t src_stride
) {
const float x_ratio = float(src_width) / float(dst_width);
const float y_ratio = float(src_height) / float(dst_height);
const float x_ratio = (float)(src_width) / (float)(dst_width);
const float y_ratio = (float)(src_height) / (float)(dst_height);
const int step_x = x_ratio * 1024.0f;
const int step_y = y_ratio * 1024.0f;
int fixed_y = 0;
Expand Down Expand Up @@ -39,8 +38,8 @@ static void image_resize_linear_stride(
const uint32_t src_stride,
const uint32_t stride
) {
const float x_ratio = float(src_width) / float(dst_width);
const float y_ratio = float(src_height) / float(dst_height);
const float x_ratio = (float)(src_width) / (float)(dst_width);
const float y_ratio = (float)(src_height) / (float)(dst_height);
const int step_x = x_ratio * 1024.0f;
const int step_y = y_ratio * 1024.0f;
const int stride_step = stride - dst_width;
Expand All @@ -60,7 +59,7 @@ static void image_resize_linear_stride(
}
}

extern "C" void image_resize_linear_aspect_fill(
void image_resize_linear_aspect_fill(
uint32_t* dst,
const uint32_t dst_width,
const uint32_t dst_height,
Expand All @@ -75,19 +74,19 @@ extern "C" void image_resize_linear_aspect_fill(
dst[i] = bg_clear;
}

const float buffer_aspect = float(src_width) / float(src_height);
const float win_aspect = float(dst_width) / float(dst_height);
const float buffer_aspect = (float)(src_width) / (float)(src_height);
const float win_aspect = (float)(dst_width) / (float)(dst_height);

if (buffer_aspect > win_aspect) {
const uint32_t new_height = uint32_t(dst_width / buffer_aspect);
const uint32_t new_height = (uint32_t)(dst_width / buffer_aspect);
const int offset = (new_height - dst_height) / -2;
image_resize_linear(
dst + (offset * dst_width),
dst_width, new_height,
src, src_width, src_height, src_stride
);
} else {
const uint32_t new_width = uint32_t(dst_height * buffer_aspect);
const uint32_t new_width = (uint32_t)(dst_height * buffer_aspect);
const int offset = (new_width - dst_width) / -2;
image_resize_linear_stride(
dst + offset,
Expand All @@ -98,7 +97,7 @@ extern "C" void image_resize_linear_aspect_fill(
}
}

extern "C" void image_center(
void image_center(
uint32_t* dst,
const uint32_t dst_width,
const uint32_t dst_height,
Expand Down Expand Up @@ -173,7 +172,7 @@ extern "C" void image_center(
}
}

extern "C" void image_upper_left(
void image_upper_left(
uint32_t* dst,
const uint32_t dst_width,
const uint32_t dst_height,
Expand Down
Loading