Code Monkey home page Code Monkey logo

Comments (3)

rii-mango avatar rii-mango commented on August 23, 2024

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.

chafey avatar chafey commented on August 23, 2024

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.

rii-mango avatar rii-mango commented on August 23, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.