Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.1.1 #4

Merged
merged 4 commits into from Feb 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
File renamed without changes.
3 changes: 2 additions & 1 deletion js/package.json
@@ -1,9 +1,10 @@
{
"name": "lzw-tiff-decoder",
"version": "0.1.0",
"version": "0.1.1",
"author": "Trevor James Manz",
"license": "MIT",
"description": "WASM LZW decoder for TIFF images.",
"type": "module",
"main": "index.cjs",
"module": "index.mjs",
"types": "index.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion js/rollup.config.js
Expand Up @@ -15,7 +15,7 @@ const resolveImportMetaEmpty = () => ({
});

export default {
input: './src.js',
input: './index.js',
output: [
{ file: './index.mjs', format: 'es' },
{ file: './index.cjs', format: 'cjs' },
Expand Down
7 changes: 3 additions & 4 deletions src/lib.rs
@@ -1,20 +1,19 @@
use wasm_bindgen::prelude::*;
use weezl;

// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global
// allocator.
// When the `wee_alloc` feature is enabled, use `wee_alloc` as the global allocator.
#[cfg(feature = "wee_alloc")]
#[global_allocator]
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;

// Adapted from: https://github.com/image-rs/image-tiff/blob/4900c8287193158e0c9b391b0586a5aa4be23ba3/src/decoder/stream.rs#L301-L353
#[wasm_bindgen]
pub fn decompress(compressed: &[u8], max_uncompressed_length: usize) -> Vec<u8> {
let mut decoder = weezl::decode::Decoder::with_tiff_size_switch(weezl::BitOrder::Msb, 8);
let mut uncompressed = Vec::with_capacity(max_uncompressed_length);
let mut bytes_read = 0;

// adapted from https://github.com/image-rs/image-tiff/blob/master/src/decoder/stream.rs#L248
while uncompressed.len() < max_uncompressed_length {
while uncompressed.len() < max_uncompressed_length {
let bytes_written = uncompressed.len();

// Resize vector only if needed
Expand Down