Skip to content

Commit

Permalink
Make scalar plain C
Browse files Browse the repository at this point in the history
This removes the need for a C++ compiler to be installed.
It is much more likely for a C compiler to be installed on someone's Linux machine in comparison.
  • Loading branch information
Speykious committed Apr 11, 2024
1 parent d132cbc commit d794ee8
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
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
13 changes: 6 additions & 7 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_c(uint32_t* target, const uint32_t* source, int w, int h, int s, int w2, int h2) {
void Image_resize_linear_c(uint32_t* target, const uint32_t* source, int w, int h, int s, int w2, int h2) {
if (w2 <= 0) { w2 = 1; }
if (h2 <= 0) { h2 = 1; }

Expand Down Expand Up @@ -51,7 +50,7 @@ static void resize_linear_c_stride(uint32_t* target, const uint32_t* source, int
}
}

extern "C" void Image_resize_linear_aspect_fill_c(
void Image_resize_linear_aspect_fill_c(
uint32_t* target,
const uint32_t* source,
int w, int h, int s,
Expand All @@ -62,8 +61,8 @@ extern "C" void Image_resize_linear_aspect_fill_c(
target[i] = bg_clear;
}

float buffer_aspect = float(w) / float(h);
float win_aspect = float(window_width) / float(window_height);
float buffer_aspect = (float)w / (float)h;
float win_aspect = (float)window_width / (float)window_height;

if (buffer_aspect > win_aspect) {
int new_height = (int)(window_width / buffer_aspect);
Expand All @@ -81,7 +80,7 @@ extern "C" void Image_resize_linear_aspect_fill_c(
}
}

extern "C" void Image_center(
void Image_center(
uint32_t* target,
const uint32_t* source,
int w, int h, int s,
Expand Down Expand Up @@ -155,7 +154,7 @@ extern "C" void Image_center(
}
}

extern "C" void Image_upper_left(
void Image_upper_left(
uint32_t* target,
const uint32_t* source,
int w, int h, int s,
Expand Down

0 comments on commit d794ee8

Please sign in to comment.