Browse Source

Make olivec_copy blend the colors properly

rexim 3 years ago
parent
commit
5b9288f891
3 changed files with 25 additions and 1 deletions
  1. 1 1
      olive.c
  2. 24 0
      test.c
  3. BIN
      test/blending_of_copy_expected.png

+ 1 - 1
olive.c

@@ -707,7 +707,7 @@ void olivec_copy(Olivec_Canvas src, Olivec_Canvas dst)
         for (size_t x = 0; x < dst.width; ++x) {
         for (size_t x = 0; x < dst.width; ++x) {
             size_t nx = x*src.width/dst.width;
             size_t nx = x*src.width/dst.width;
             size_t ny = y*src.height/dst.height;
             size_t ny = y*src.height/dst.height;
-            OLIVEC_PIXEL(dst, x, y) = OLIVEC_PIXEL(src, nx, ny);
+            olivec_blend_color(&OLIVEC_PIXEL(dst, x, y), OLIVEC_PIXEL(src, nx, ny));
         }
         }
     }
     }
 }
 }

+ 24 - 0
test.c

@@ -445,6 +445,29 @@ Olivec_Canvas test_frame(void)
     return oc;
     return oc;
 }
 }
 
 
+Olivec_Canvas test_blending_of_copy(void)
+{
+    size_t width = 128;
+    size_t height = 128;
+    Olivec_Canvas dst = canvas_alloc(width, height);
+    olivec_fill(dst, RED_COLOR);
+    Olivec_Canvas src = canvas_alloc(width, height);
+
+    for (size_t y = 0; y < src.height; ++y) {
+        for (size_t x = 0; x < src.width; ++x) {
+            if ((x + y)%2 == 0) {
+                OLIVEC_PIXEL(src, x, y) = 0;
+            } else {
+                OLIVEC_PIXEL(src, x, y) = GREEN_COLOR;
+            }
+        }
+    }
+
+    olivec_copy(src, dst);
+
+    return dst;
+}
+
 Test_Case test_cases[] = {
 Test_Case test_cases[] = {
     DEFINE_TEST_CASE(fill_rect),
     DEFINE_TEST_CASE(fill_rect),
     DEFINE_TEST_CASE(fill_circle),
     DEFINE_TEST_CASE(fill_circle),
@@ -458,6 +481,7 @@ 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_CASES_COUNT (sizeof(test_cases)/sizeof(test_cases[0]))
 #define TEST_CASES_COUNT (sizeof(test_cases)/sizeof(test_cases[0]))
 
 

BIN
test/blending_of_copy_expected.png