游戏
JavaScript/Web Assembly 构建 字符。 。 。 .
试试看!
在浏览器中尝试 这里
安装
使用 npm 在您的 JavaScript 工程中安装 :
# NOTE - this is not published yet so won't work yet...
#npm install --save-dev charls-js
使用量
在使用此库之前, 您必须等待其初始化 :
const charls = require('charlsjs')
charls.onRuntimeInitialized = async _ => {
// Now you can use it
}
要解码 JPEG- LS 图像, 创建解码器实例, 复制 JPEG- LS 比特流 将已解码的像素复制出内存 最后,删除解码器实例.
function decode(jpeglsEncodedBitStream) {
// Create a decoder instance
const decoder = new charls.JpegLSDecoder();
// get pointer to the source/encoded bit stream buffer in WASM memory
// that can hold the encoded bitstream
const encodedBufferInWASM = decoder.getEncodedBuffer(jpeglsEncodedBitStream.length);
// copy the encoded bitstream into WASM memory buffer
encodedBufferInWASM.set(jpeglsEncodedBitStream);
// decode it
decoder.decode();
// get information about the decoded image
const frameInfo = decoder.getFrameInfo();
const interleaveMode = decoder.getInterleaveMode();
const nearLossless = decoder.getNearLossless();
// get the decoded pixels
const decodedPixelsInWASM = decoder.getDecodedBuffer();
// TODO: do something with the decoded pixels here (e.g. display them)
// The pixel arrangement for color images varies depending upon the
// interleaveMode parameter, see documentation in JpegLSDecode::getInterleaveMode()
// delete the instance. Note that this frees up memory including the
// encodedBufferInWASM and decodedPixelsInWASM invalidating them.
// Do not use either after calling delete!
decoder.delete();
}
const jpeglsEncodedBitStream = // read from file, load from URL, etc
decode(jpeglsEncodedBitStream)
见示例 浏览器 财务报告和审定财务报表 节点。 。 。 . 还读取 API 文档 JpegLSDecoder.hpp (英语) 财务报告和审定财务报表 JpegLS 编码器.hpp
大楼
见建筑信息 这里
设计
读取进入此图书馆的设计考虑 这里
业绩
使用 NodeJS 14 读取此库的编码/代码性能 , Google Chrome and FireFox vs 土著 这里
测试
pnpm run build # compile wasm into dist/
pnpm run test # run vitest against dist/
测试在 dist/ 缺席.