Browse Source

Rename olivec_copy -> olivec_sprite_blend

rexim 3 years ago
parent
commit
294ae6f4e1

BIN
assets/Sadge.png


+ 1 - 0
build.sh

@@ -19,6 +19,7 @@ mkdir -p ./build/
 clang $COMMON_CFLAGS -o ./build/png2c -Ithirdparty png2c.c -lm
 clang $COMMON_CFLAGS -o ./build/png2c -Ithirdparty png2c.c -lm
 mkdir -p ./build/assets/
 mkdir -p ./build/assets/
 ./build/png2c -n tsodinPog -o ./build/assets/tsodinPog.c ./assets/tsodinPog.png
 ./build/png2c -n tsodinPog -o ./build/assets/tsodinPog.c ./assets/tsodinPog.png
+./build/png2c -n Sadge -o ./build/assets/Sadge.c ./assets/Sadge.png
 
 
 # Build tests
 # Build tests
 clang $COMMON_CFLAGS -fsanitize=memory -o ./build/test -Ithirdparty test.c -lm
 clang $COMMON_CFLAGS -fsanitize=memory -o ./build/test -Ithirdparty test.c -lm

+ 1 - 1
demos/squish.c

@@ -26,7 +26,7 @@ Olivec_Canvas render(float dt)
     int w = tsodinPog_width*SRC_SCALE - t*factor;
     int w = tsodinPog_width*SRC_SCALE - t*factor;
     int h = tsodinPog_height*SRC_SCALE + t*factor;
     int h = tsodinPog_height*SRC_SCALE + t*factor;
 
 
-    olivec_copy(
+    olivec_sprite_blend(
         dst_canvas,
         dst_canvas,
         WIDTH/2 - w/2, HEIGHT - h, w, h,
         WIDTH/2 - w/2, HEIGHT - h, w, h,
         olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width));
         olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width));

+ 9 - 9
olive.c

@@ -301,7 +301,7 @@ OLIVECDEF void olivec_line(Olivec_Canvas oc, int x1, int y1, int x2, int y2, uin
 OLIVECDEF void olivec_triangle(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t color);
 OLIVECDEF void olivec_triangle(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t color);
 OLIVECDEF void olivec_triangle3(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t c1, uint32_t c2, uint32_t c3);
 OLIVECDEF void olivec_triangle3(Olivec_Canvas oc, int x1, int y1, int x2, int y2, int x3, int y3, uint32_t c1, uint32_t c2, uint32_t c3);
 OLIVECDEF void olivec_text(Olivec_Canvas oc, const char *text, int x, int y, Olivec_Font font, size_t size, uint32_t color);
 OLIVECDEF void olivec_text(Olivec_Canvas oc, const char *text, int x, int y, Olivec_Font font, size_t size, uint32_t color);
-OLIVECDEF void olivec_copy(Olivec_Canvas dst, int x, int y, int w, int h, Olivec_Canvas src);
+OLIVECDEF void olivec_sprite_blend(Olivec_Canvas oc, int x, int y, int w, int h, Olivec_Canvas sprite);
 
 
 typedef struct {
 typedef struct {
     // Safe ranges to iterate over.
     // Safe ranges to iterate over.
@@ -722,22 +722,22 @@ OLIVECDEF void olivec_text(Olivec_Canvas oc, const char *text, int tx, int ty, O
     }
     }
 }
 }
 
 
-// TODO: bilinear interpolation for olivec_copy
-OLIVECDEF void olivec_copy(Olivec_Canvas dst, int x, int y, int w, int h, Olivec_Canvas src)
+// TODO: bilinear interpolation for olivec_sprite_*
+OLIVECDEF void olivec_sprite_blend(Olivec_Canvas oc, int x, int y, int w, int h, Olivec_Canvas sprite)
 {
 {
-    if (src.width == 0) return;
-    if (src.height == 0) return;
+    if (sprite.width == 0) return;
+    if (sprite.height == 0) return;
 
 
     Olivec_Normalized_Rect nr = {0};
     Olivec_Normalized_Rect nr = {0};
-    if (!olivec_normalize_rect(x, y, w, h, dst.width, dst.height, &nr)) return;
+    if (!olivec_normalize_rect(x, y, w, h, oc.width, oc.height, &nr)) return;
 
 
     int xa = nr.ox1; if (w < 0) xa = nr.ox2;
     int xa = nr.ox1; if (w < 0) xa = nr.ox2;
     int ya = nr.oy1; if (h < 0) ya = nr.oy2;
     int ya = nr.oy1; if (h < 0) ya = nr.oy2;
     for (int y = nr.y1; y <= nr.y2; ++y) {
     for (int y = nr.y1; y <= nr.y2; ++y) {
         for (int x = nr.x1; x <= nr.x2; ++x) {
         for (int x = nr.x1; x <= nr.x2; ++x) {
-            size_t nx = (x - xa)*((int) src.width)/w;
-            size_t ny = (y - ya)*((int) src.height)/h;
-            olivec_blend_color(&OLIVEC_PIXEL(dst, x, y), OLIVEC_PIXEL(src, nx, ny));
+            size_t nx = (x - xa)*((int) sprite.width)/w;
+            size_t ny = (y - ya)*((int) sprite.height)/h;
+            olivec_blend_color(&OLIVEC_PIXEL(oc, x, y), OLIVEC_PIXEL(sprite, nx, ny));
         }
         }
     }
     }
 }
 }

+ 27 - 27
test.c

@@ -453,7 +453,7 @@ Olivec_Canvas test_frame(void)
     return oc;
     return oc;
 }
 }
 
 
-Olivec_Canvas test_blending_of_copy(void)
+Olivec_Canvas test_sprite_blend(void)
 {
 {
     size_t width = 128;
     size_t width = 128;
     size_t height = 128;
     size_t height = 128;
@@ -471,50 +471,50 @@ Olivec_Canvas test_blending_of_copy(void)
         }
         }
     }
     }
 
 
-    olivec_copy(dst, 0, 0, width, height, src);
+    olivec_sprite_blend(dst, 0, 0, width, height, src);
 
 
     return dst;
     return dst;
 }
 }
 
 
-Olivec_Canvas test_copy_out_of_bounds_cut(void)
+Olivec_Canvas test_sprite_blend_out_of_bounds_cut(void)
 {
 {
     size_t width = 128;
     size_t width = 128;
     size_t height = 128;
     size_t height = 128;
     Olivec_Canvas dst = canvas_alloc(width, height);
     Olivec_Canvas dst = canvas_alloc(width, height);
     Olivec_Canvas src = olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width);
     Olivec_Canvas src = olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width);
     olivec_fill(dst, RED_COLOR);
     olivec_fill(dst, RED_COLOR);
-    olivec_copy(dst, -width/2, -height/2, width, height, src);
-    olivec_copy(dst, width/2, -height/2, width, height, src);
-    olivec_copy(dst, -width/2, height/2, width, height, src);
-    olivec_copy(dst, width/2, height/2, width, height, src);
+    olivec_sprite_blend(dst, -width/2, -height/2, width, height, src);
+    olivec_sprite_blend(dst, width/2, -height/2, width, height, src);
+    olivec_sprite_blend(dst, -width/2, height/2, width, height, src);
+    olivec_sprite_blend(dst, width/2, height/2, width, height, src);
     return dst;
     return dst;
 }
 }
 
 
-Olivec_Canvas test_copy_flip(void)
+Olivec_Canvas test_sprite_blend_flip(void)
 {
 {
     size_t width = 128;
     size_t width = 128;
     size_t height = 128;
     size_t height = 128;
     Olivec_Canvas dst = canvas_alloc(width, height);
     Olivec_Canvas dst = canvas_alloc(width, height);
     Olivec_Canvas src = olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width);
     Olivec_Canvas src = olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width);
     olivec_fill(dst, RED_COLOR);
     olivec_fill(dst, RED_COLOR);
-    olivec_copy(dst, 0, 0, width/2, height/2, src);
-    olivec_copy(dst, width - 1, 0, -width/2, height/2, src);
-    olivec_copy(dst, 0, height - 1, width/2, -height/2, src);
-    olivec_copy(dst, width - 1, height - 1, -width/2, -height/2, src);
+    olivec_sprite_blend(dst, 0, 0, width/2, height/2, src);
+    olivec_sprite_blend(dst, width - 1, 0, -width/2, height/2, src);
+    olivec_sprite_blend(dst, 0, height - 1, width/2, -height/2, src);
+    olivec_sprite_blend(dst, width - 1, height - 1, -width/2, -height/2, src);
     return dst;
     return dst;
 }
 }
 
 
-Olivec_Canvas test_copy_flip_cut(void)
+Olivec_Canvas test_sprite_blend_flip_cut(void)
 {
 {
     size_t width = 128;
     size_t width = 128;
     size_t height = 128;
     size_t height = 128;
     Olivec_Canvas dst = canvas_alloc(width, height);
     Olivec_Canvas dst = canvas_alloc(width, height);
     Olivec_Canvas src = olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width);
     Olivec_Canvas src = olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width);
     olivec_fill(dst, RED_COLOR);
     olivec_fill(dst, RED_COLOR);
-    olivec_copy(dst, -width/2, -height/2, width, height, src);
-    olivec_copy(dst, width - 1 + width/2, -height/2, -width, height, src);
-    olivec_copy(dst, -width/2, height - 1 + height/2, width, -height, src);
-    olivec_copy(dst, width - 1 + width/2, height - 1 + height/2, -width, -height, src);
+    olivec_sprite_blend(dst, -width/2, -height/2, width, height, src);
+    olivec_sprite_blend(dst, width - 1 + width/2, -height/2, -width, height, src);
+    olivec_sprite_blend(dst, -width/2, height - 1 + height/2, width, -height, src);
+    olivec_sprite_blend(dst, width - 1 + width/2, height - 1 + height/2, -width, -height, src);
     return dst;
     return dst;
 }
 }
 
 
@@ -528,24 +528,24 @@ Olivec_Canvas test_empty_rect(void)
     return dst;
     return dst;
 }
 }
 
 
-Olivec_Canvas test_copy_empty_rect(void)
+Olivec_Canvas test_sprite_blend_empty_rect(void)
 {
 {
     size_t w = 8;
     size_t w = 8;
     size_t h = 8;
     size_t h = 8;
     Olivec_Canvas dst = canvas_alloc(w, h);
     Olivec_Canvas dst = canvas_alloc(w, h);
     Olivec_Canvas src = olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width);
     Olivec_Canvas src = olivec_canvas(tsodinPog_pixels, tsodinPog_width, tsodinPog_height, tsodinPog_width);
     olivec_fill(dst, BACKGROUND_COLOR);
     olivec_fill(dst, BACKGROUND_COLOR);
-    olivec_copy(dst, 0, 0, 0, 0, src);
+    olivec_sprite_blend(dst, 0, 0, 0, 0, src);
     return dst;
     return dst;
 }
 }
 
 
-Olivec_Canvas test_copy_null_src(void)
+Olivec_Canvas test_sprite_blend_null(void)
 {
 {
     size_t w = 8;
     size_t w = 8;
     size_t h = 8;
     size_t h = 8;
     Olivec_Canvas dst = canvas_alloc(w, h);
     Olivec_Canvas dst = canvas_alloc(w, h);
     olivec_fill(dst, BACKGROUND_COLOR);
     olivec_fill(dst, BACKGROUND_COLOR);
-    olivec_copy(dst, 0, 0, w, h, OLIVEC_CANVAS_NULL);
+    olivec_sprite_blend(dst, 0, 0, w, h, OLIVEC_CANVAS_NULL);
     return dst;
     return dst;
 }
 }
 
 
@@ -562,13 +562,13 @@ Test_Case test_cases[] = {
     DEFINE_TEST_CASE(lines_circle),
     DEFINE_TEST_CASE(lines_circle),
     DEFINE_TEST_CASE(line_edge_cases),
     DEFINE_TEST_CASE(line_edge_cases),
     DEFINE_TEST_CASE(frame),
     DEFINE_TEST_CASE(frame),
-    DEFINE_TEST_CASE(blending_of_copy),
-    DEFINE_TEST_CASE(copy_out_of_bounds_cut),
-    DEFINE_TEST_CASE(copy_flip),
-    DEFINE_TEST_CASE(copy_flip_cut),
-    DEFINE_TEST_CASE(copy_empty_rect),
+    DEFINE_TEST_CASE(sprite_blend),
+    DEFINE_TEST_CASE(sprite_blend_out_of_bounds_cut),
+    DEFINE_TEST_CASE(sprite_blend_flip),
+    DEFINE_TEST_CASE(sprite_blend_flip_cut),
+    DEFINE_TEST_CASE(sprite_blend_empty_rect),
     DEFINE_TEST_CASE(empty_rect),
     DEFINE_TEST_CASE(empty_rect),
-    DEFINE_TEST_CASE(copy_null_src),
+    DEFINE_TEST_CASE(sprite_blend_null),
 };
 };
 #define TEST_CASES_COUNT (sizeof(test_cases)/sizeof(test_cases[0]))
 #define TEST_CASES_COUNT (sizeof(test_cases)/sizeof(test_cases[0]))
 
 

+ 0 - 0
test/copy_empty_rect_expected.png → test/sprite_blend_empty_rect_expected.png


+ 0 - 0
test/blending_of_copy_expected.png → test/sprite_blend_expected.png


+ 0 - 0
test/copy_flip_cut_expected.png → test/sprite_blend_flip_cut_expected.png


+ 0 - 0
test/copy_flip_expected.png → test/sprite_blend_flip_expected.png


+ 0 - 0
test/copy_null_src_expected.png → test/sprite_blend_null_expected.png


+ 0 - 0
test/copy_out_of_bounds_cut_expected.png → test/sprite_blend_out_of_bounds_cut_expected.png


BIN
wasm/squish.wasm