-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into feat/dotlottie-support
- Loading branch information
Showing
6 changed files
with
169 additions
and
47 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,18 @@ | ||
name: Check PR | ||
|
||
on: | ||
pull_request: | ||
types: [opened] | ||
branches: [main] | ||
|
||
jobs: | ||
check-pr: | ||
if: github.head_ref != 'release' | ||
runs-on: macos-latest | ||
steps: | ||
- name: Cancel Previous Runs | ||
uses: styfle/[email protected] | ||
with: | ||
access_token: ${{ github.token }} | ||
- uses: actions/checkout@v4 | ||
- uses: Homebrew/actions/setup-homebrew@master | ||
- uses: maxim-lobanov/setup-xcode@v1 | ||
|
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
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,79 @@ | ||
import createDotLottiePlayerModule from "./release/wasm/DotLottiePlayer.mjs"; | ||
import fs from "fs"; | ||
import path from "path"; | ||
|
||
const wasmBinary = fs.readFileSync( | ||
path.join("./release/wasm/DotLottiePlayer.wasm") | ||
); | ||
|
||
const Module = await createDotLottiePlayerModule({ | ||
wasmBinary, | ||
}); | ||
|
||
const WIDTH = 200; | ||
const HEIGHT = 200; | ||
|
||
const dotLottie = new Module.DotLottiePlayer({ | ||
autoplay: false, | ||
loop_animation: false, | ||
mode: Module.Mode.values[1], | ||
speed: 1, | ||
use_frame_interpolation: false, | ||
}); | ||
|
||
const data = await fetch( | ||
"https://lottie.host/647eb023-6040-4b60-a275-e2546994dd7f/zDCfp5lhLe.json" | ||
).then((res) => res.text()); | ||
|
||
const loaded = dotLottie.load_animation_data(data, WIDTH, HEIGHT); | ||
|
||
if (!loaded) { | ||
console.log("failed to load animation data"); | ||
} | ||
|
||
dotLottie.set_frame(10.0); | ||
const rendered = dotLottie.render(); | ||
|
||
if (!rendered) { | ||
console.log("failed to render"); | ||
} | ||
|
||
const frameBuffer = dotLottie.buffer(); | ||
|
||
const bmpBuffer = createBMP(WIDTH, WIDTH, frameBuffer); | ||
|
||
fs.writeFileSync("./output.bmp", bmpBuffer); | ||
|
||
// This is for demonstration purposes only. to avoid adding a dependency | ||
function createBMP(width, height, frameBuffer) { | ||
// Each pixel in BMP is 4 bytes (BGRA) | ||
const bmpDataSize = width * height * 4; | ||
const headerSize = 54; | ||
const fileSize = bmpDataSize + headerSize; | ||
const bmpBuffer = Buffer.alloc(fileSize); | ||
|
||
// Bitmap file header | ||
bmpBuffer.write("BM", 0); // Signature | ||
bmpBuffer.writeInt32LE(fileSize, 2); // File size | ||
bmpBuffer.writeInt32LE(headerSize, 10); // Pixel data offset | ||
|
||
// DIB header | ||
bmpBuffer.writeInt32LE(40, 14); // DIB header size | ||
bmpBuffer.writeInt32LE(width, 18); // Width | ||
bmpBuffer.writeInt32LE(-height, 22); // Height (negative for top-down bitmap) | ||
bmpBuffer.writeInt16LE(1, 26); // Color planes | ||
bmpBuffer.writeInt16LE(32, 28); // Bits per pixel | ||
bmpBuffer.writeInt32LE(0, 30); // Compression (0 for none) | ||
|
||
// Convert RGBA to BGRA and write pixel data | ||
for (let i = 0; i < width * height; i++) { | ||
const rgbaIndex = i * 4; | ||
const bgraIndex = headerSize + i * 4; | ||
bmpBuffer[bgraIndex + 0] = frameBuffer[rgbaIndex + 2]; // Blue | ||
bmpBuffer[bgraIndex + 1] = frameBuffer[rgbaIndex + 1]; // Green | ||
bmpBuffer[bgraIndex + 2] = frameBuffer[rgbaIndex + 0]; // Red | ||
bmpBuffer[bgraIndex + 3] = frameBuffer[rgbaIndex + 3]; // Alpha | ||
} | ||
|
||
return bmpBuffer; | ||
} |
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