Comments (3)
If you were using the included tests/driver.js, then you'll need to change the offset and length of the JPEG data block. I used DICOM files as tests, since I think it's only DICOM that uses this type of compression, but there is no DICOM reader in the code -- so you'll have to tell it where in the DICOM file the JPEG data starts. Here's a version of tests/driver.js that uses the file you linked to:
/*jslint browser: true, node: true */
/*global require, module */
"use strict";
var jpeg = require('../src/main.js');
var fs = require('fs');
function toArrayBuffer(buffer) {
var ab, view, i;
ab = new ArrayBuffer(buffer.length);
view = new Uint8Array(ab);
for (i = 0; i < buffer.length; i += 1) {
view[i] = buffer[i];
}
return ab;
}
var jpegDataOffset = 1596;//1654;
var jpegDataSize = 718923;//143474;
var buf = new Buffer(jpegDataSize);
var fd = fs.openSync('./tests/data/MR-MONO2-12-shoulder', "r");
fs.readSync(fd, buf, 0, buf.length, jpegDataOffset);
var data = toArrayBuffer(buf);
var decoder = new jpeg.lossless.Decoder(data);
var output = decoder.decode();
var assert = require("assert");
describe('JPEGLosslessDecoderJS', function () {
it('dimX should equal 1024', function () {
assert.equal(1024, decoder.frame.dimX);
});
it('dimY should equal 1024', function () {
assert.equal(1024, decoder.frame.dimY);
});
it('number of components should be 1', function () {
assert.equal(1, decoder.frame.numComp);
});
it('decompressed size should be 2097152', function () {
assert.equal(2097152, output.byteLength);
});
});
from jpeglosslessdecoderjs.
OK I see the problem - I am using dicomParser to extract the frame and it has an optimization in the case of a single fragment that returns the fragment as a Uint8Array view (offset + length) on the underlying ArrayBuffer (which covers the entire DICOM P10 instance). I can workaround this by removing the optimization and making a copy of the buffer, but it would be nice if this library could support a copyless buffer - perhaps accept Uint8Array or the ArrayBuffer with an offset and length
from jpeglosslessdecoderjs.
Ok, see the new usage:
var decoder = new jpeg.lossless.Decoder();
var decompressedData = decoder.decode(buffer [, offset [, length [, numBytes]]]);
// {ArrayBuffer} buffer
// {Number} offset offset into buffer (default = 0)
// {Number} length length of buffer (default = end of JPEG block)
// {Number} number of bytes per output unit (default = 2)
Let me know if this doesn't work for you.
from jpeglosslessdecoderjs.
Related Issues (13)
- Non GPL License possible? HOT 11
- uncorrect decode HOT 1
- npm test fails HOT 3
- performance
- JPEG lossless parsing failed
- Strange decoding behavior ? HOT 1
- Support RGB data HOT 2
- Unable to parse the attached JPEG Lossless file correctly HOT 3
- NPM package HOT 2
- Dicom Image decode jpeg lossless decoder HOT 1
- Problem showing image properly HOT 3
- Workaround for invalid JPEG encoding
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jpeglosslessdecoderjs.