Browse Source

Reorder arguments of olivec_copy so they make more sense

rexim 3 years ago
parent
commit
46bdb2a8e6
4 changed files with 19 additions and 20 deletions
  1. 2 2
      demos/squish.c
  2. 2 3
      olive.c
  3. 15 15
      test.c
  4. BIN
      wasm/squish.wasm

+ 2 - 2
demos/squish.c

@@ -27,9 +27,9 @@ Olivec_Canvas render(float dt)
     int h = png_height*SRC_SCALE + t*factor;
 
     olivec_copy(
-        olivec_canvas(png, png_width, png_height, png_width),
         dst_canvas,
-        WIDTH/2 - w/2, HEIGHT - h, w, h);
+        WIDTH/2 - w/2, HEIGHT - h, w, h,
+        olivec_canvas(png, png_width, png_height, png_width));
 
     return dst_canvas;
 }

+ 2 - 3
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_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_copy(Olivec_Canvas src, Olivec_Canvas dst, int x, int y, int w, int h);
+OLIVECDEF void olivec_copy(Olivec_Canvas dst, int x, int y, int w, int h, Olivec_Canvas src);
 
 typedef struct {
     // Safe ranges to iterate over.
@@ -723,8 +723,7 @@ OLIVECDEF void olivec_text(Olivec_Canvas oc, const char *text, int tx, int ty, O
 }
 
 // TODO: bilinear interpolation for olivec_copy
-// TODO: dst must come before src, 'cause otherwise it's inconsistent with the rest of the functions
-OLIVECDEF void olivec_copy(Olivec_Canvas src, Olivec_Canvas dst, int x, int y, int w, int h)
+OLIVECDEF void olivec_copy(Olivec_Canvas dst, int x, int y, int w, int h, Olivec_Canvas src)
 {
     if (src.width == 0) return;
     if (src.height == 0) return;

+ 15 - 15
test.c

@@ -471,7 +471,7 @@ Olivec_Canvas test_blending_of_copy(void)
         }
     }
 
-    olivec_copy(src, dst, 0, 0, width, height);
+    olivec_copy(dst, 0, 0, width, height, src);
 
     return dst;
 }
@@ -483,10 +483,10 @@ Olivec_Canvas test_copy_out_of_bounds_cut(void)
     Olivec_Canvas dst = canvas_alloc(width, height);
     Olivec_Canvas src = olivec_canvas(png, png_width, png_height, png_width);
     olivec_fill(dst, RED_COLOR);
-    olivec_copy(src, dst, -width/2, -height/2, width, height);
-    olivec_copy(src, dst, width/2, -height/2, width, height);
-    olivec_copy(src, dst, -width/2, height/2, width, height);
-    olivec_copy(src, dst, width/2, height/2, width, height);
+    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);
     return dst;
 }
 
@@ -497,10 +497,10 @@ Olivec_Canvas test_copy_flip(void)
     Olivec_Canvas dst = canvas_alloc(width, height);
     Olivec_Canvas src = olivec_canvas(png, png_width, png_height, png_width);
     olivec_fill(dst, RED_COLOR);
-    olivec_copy(src, dst, 0, 0, width/2, height/2);
-    olivec_copy(src, dst, width - 1, 0, -width/2, height/2);
-    olivec_copy(src, dst, 0, height - 1, width/2, -height/2);
-    olivec_copy(src, dst, width - 1, height - 1, -width/2, -height/2);
+    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);
     return dst;
 }
 
@@ -511,10 +511,10 @@ Olivec_Canvas test_copy_flip_cut(void)
     Olivec_Canvas dst = canvas_alloc(width, height);
     Olivec_Canvas src = olivec_canvas(png, png_width, png_height, png_width);
     olivec_fill(dst, RED_COLOR);
-    olivec_copy(src, dst, -width/2, -height/2, width, height);
-    olivec_copy(src, dst, width - 1 + width/2, -height/2, -width, height);
-    olivec_copy(src, dst, -width/2, height - 1 + height/2, width, -height);
-    olivec_copy(src, dst, width - 1 + width/2, height - 1 + height/2, -width, -height);
+    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);
     return dst;
 }
 
@@ -535,7 +535,7 @@ Olivec_Canvas test_copy_empty_rect(void)
     Olivec_Canvas dst = canvas_alloc(w, h);
     Olivec_Canvas src = olivec_canvas(png, png_width, png_height, png_width);
     olivec_fill(dst, BACKGROUND_COLOR);
-    olivec_copy(src, dst, 0, 0, 0, 0);
+    olivec_copy(dst, 0, 0, 0, 0, src);
     return dst;
 }
 
@@ -545,7 +545,7 @@ Olivec_Canvas test_copy_null_src(void)
     size_t h = 8;
     Olivec_Canvas dst = canvas_alloc(w, h);
     olivec_fill(dst, BACKGROUND_COLOR);
-    olivec_copy(OLIVEC_CANVAS_NULL, dst, 0, 0, w, h);
+    olivec_copy(dst, 0, 0, w, h, OLIVEC_CANVAS_NULL);
     return dst;
 }
 

BIN
wasm/squish.wasm