1
1
import { expect , describe , beforeEach , it } from "vitest" ;
2
2
3
- import { Bitmap , Context , make } from "../src/index" ;
4
- import { write_png } from "./common" ;
3
+ import { Bitmap , Context , make , decodePNGFromStream } from "../src/index" ;
4
+ import { save } from "./common" ;
5
5
import { OPAQUE_BLACK } from "../src/named_colors" ;
6
+ import * as fs from "node:fs" ;
6
7
7
8
describe ( "clipping tests" , ( ) => {
8
9
let image : Bitmap ;
@@ -25,30 +26,34 @@ describe("clipping tests", () => {
25
26
context . clip ( ) ;
26
27
context . fillStyle = "red" ;
27
28
context . fillRect ( 0 , 0 , 200 , 200 ) ;
28
- await write_png ( image , "clipcolor" ) ;
29
- console . log ( "wrote out clipcolor.png" ) ;
29
+ await save ( image , "clip/clip-color" ) ;
30
30
expect ( image . getPixelRGBA ( 0 , 0 ) ) . to . eq ( 0xffffffff ) ;
31
31
expect ( image . getPixelRGBA ( 100 , 100 ) ) . to . eq ( 0xff0000ff ) ;
32
32
} ) ;
33
33
34
34
it ( "can draw an image inside of a clip" , async ( ) => {
35
+ let bird = await decodePNGFromStream (
36
+ fs . createReadStream ( "test/unit/fixtures/images/bird.png" ) ,
37
+ ) ;
38
+
35
39
context . fillStyle = "red" ;
36
40
context . fillRect ( 0 , 0 , 200 , 200 ) ;
37
41
context . beginPath ( ) ;
38
- context . arc ( 100 , 100 , 10 , 0 , Math . PI * 2 , false ) ;
42
+ context . arc ( 100 , 100 , 50 , 0 , Math . PI * 2 , false ) ;
39
43
context . clip ( ) ;
40
44
context . fillStyle = "white" ;
41
45
context . fillRect ( 0 , 0 , 200 , 200 ) ;
42
- let src = make ( 50 , 50 ) ;
43
- const c = src . getContext ( "2d" ) ;
44
- c . fillStyle = "white" ;
45
- c . fillRect ( 0 , 0 , 50 , 50 ) ;
46
- c . fillStyle = "black" ;
47
- c . fillRect ( 25 , 0 , 25 , 50 ) ;
48
- context . drawImage ( src , 75 , 75 , 50 , 50 ) ;
49
- await write_png ( image , "clipimage" ) ;
50
- expect ( image . getPixelRGBA ( 0 , 0 ) ) . to . eq ( 0xff0000ff ) ;
51
- expect ( image . getPixelRGBA ( 99 , 100 ) ) . to . eq ( 0xffffffff ) ;
52
- expect ( image . getPixelRGBA ( 80 , 100 ) ) . to . eq ( 0xff0000ff ) ;
46
+ // let src = make(50, 50);
47
+ // const c = src.getContext("2d");
48
+ // c.fillStyle = "white";
49
+ // c.fillRect(0, 0, 50, 50);
50
+ // c.fillStyle = "black";
51
+ // c.fillRect(25, 0, 25, 50);
52
+ context . drawImage ( bird , 0 , 0 , 200 , 200 ) ;
53
+ // context.drawImage(src, 75, 75, 50, 50);
54
+ await save ( image , "clip/clip-image" ) ;
55
+ // expect(image.getPixelRGBA(0, 0)).to.eq(0xff0000ff);
56
+ // expect(image.getPixelRGBA(99, 100)).to.eq(0xffffffff);
57
+ // expect(image.getPixelRGBA(80, 100)).to.eq(0xff0000ff);
53
58
} ) ;
54
59
} ) ;
0 commit comments