-
Notifications
You must be signed in to change notification settings - Fork 483
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
--------- Co-authored-by: Thibault Malbranche <[email protected]>
- Loading branch information
1 parent
273beb5
commit 56cf8eb
Showing
2 changed files
with
90 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
import { importSkia, surface } from "../setup"; | ||
|
||
describe("Data Encoding", () => { | ||
it("encodeToBytes() from CPU image", async () => { | ||
const result = await surface.eval((Skia) => { | ||
const data = Skia.Data.fromBase64( | ||
"R0lGODlhAQABAIAAAGGqHwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" | ||
); | ||
const img = Skia.Image.MakeImageFromEncoded(data); | ||
if (!img) { | ||
return []; | ||
} | ||
return Array.from(img.encodeToBytes()); | ||
}); | ||
const { Skia } = importSkia(); | ||
const data = Skia.Data.fromBase64( | ||
"R0lGODlhAQABAIAAAGGqHwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" | ||
); | ||
const img = Skia.Image.MakeImageFromEncoded(data)!; | ||
expect(img).toBeTruthy(); | ||
expect(result).toEqual(Array.from(img.encodeToBytes())); | ||
}); | ||
it("encodeToBase64() from CPU image", async () => { | ||
const result = await surface.eval((Skia) => { | ||
const data = Skia.Data.fromBase64( | ||
"R0lGODlhAQABAIAAAGGqHwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" | ||
); | ||
const img = Skia.Image.MakeImageFromEncoded(data); | ||
if (!img) { | ||
return ""; | ||
} | ||
return img.encodeToBase64(); | ||
}); | ||
const { Skia } = importSkia(); | ||
|
||
const data = Skia.Data.fromBase64( | ||
"R0lGODlhAQABAIAAAGGqHwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" | ||
); | ||
const img = Skia.Image.MakeImageFromEncoded(data)!; | ||
expect(img).toBeTruthy(); | ||
expect(result).toEqual(img.encodeToBase64()); | ||
}); | ||
it("encodeToBytes() from GPU image", async () => { | ||
const result = await surface.eval((Skia) => { | ||
const data = Skia.Data.fromBase64( | ||
"R0lGODlhAQABAIAAAGGqHwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" | ||
); | ||
const img = Skia.Image.MakeImageFromEncoded(data); | ||
if (!img) { | ||
return []; | ||
} | ||
const offscreen = Skia.Surface.MakeOffscreen(1, 1)!; | ||
const canvas = offscreen.getCanvas(); | ||
canvas.drawImage(img, 0, 0); | ||
return Array.from(offscreen.makeImageSnapshot().encodeToBytes()); | ||
}); | ||
expect(result.length).toBeGreaterThan(0); | ||
}); | ||
it("encodeToBase64() from GPU image", async () => { | ||
const result = await surface.eval((Skia) => { | ||
const data = Skia.Data.fromBase64( | ||
"R0lGODlhAQABAIAAAGGqHwAAACH5BAAAAAAALAAAAAABAAEAAAICRAEAOw==" | ||
); | ||
const img = Skia.Image.MakeImageFromEncoded(data); | ||
if (!img) { | ||
return ""; | ||
} | ||
const offscreen = Skia.Surface.MakeOffscreen(1, 1)!; | ||
const canvas = offscreen.getCanvas(); | ||
canvas.drawImage(img, 0, 0); | ||
return offscreen.makeImageSnapshot().encodeToBase64(); | ||
}); | ||
expect(result.length).toBeGreaterThan(0); | ||
}); | ||
}); |