Socket
Socket
Sign inDemoInstall

jpeg-js

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

jpeg-js - npm Package Compare versions

Comparing version 0.1.2 to 0.2.0

10

lib/decoder.js

@@ -972,3 +972,3 @@ /* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- /

function decode(jpegData) {
function decode(jpegData, useTArray) {
var arr = new Uint8Array(jpegData);

@@ -981,8 +981,10 @@ var decoder = new JpegImage();

height: decoder.height,
data: new Buffer(decoder.width * decoder.height * 4)
data: useTArray ?
new Uint8Array(decoder.width * decoder.height * 4) :
new Buffer(decoder.width * decoder.height * 4)
};
decoder.copyToImageData(image);
return image;
}

2

package.json
{
"name": "jpeg-js",
"version": "0.1.2",
"version": "0.2.0",
"description": "A pure javascript JPEG encoder and decoder",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -19,10 +19,35 @@ # jpeg-js

Will decode a buffer or typed array into a `Buffer`;
``` js
var jpeg = require('jpeg-js');
var jpegData = fs.readFileSync('grumpycat.jpg');
var rawImageData = jpeg.decode(jpegData);
console.log(jpegData.data);
/*
{ width: 320,
height: 180,
data: <Buffer 5b 40 29 ff 59 3e 29 ff 54 3c 26 ff 55 3a 27 ff 5a 3e 2f ff 5c 3c 31 ff 58 35 2d ff 5b 36 2f ff 55 35 32 ff 5a 3a 37 ff 54 36 32 ff 4b 32 2c ff 4b 36 ... > }
*/
```
To decode directly into a `Uint8Array`, pass `true` as the second argument to
`decode`:
``` js
var jpeg = require('jpeg-js');
var jpegData = fs.readFileSync('grumpycat.jpg');
var rawImageData = jpeg.decode(jpegData, true); // return as Uint8Array
console.log(jpegData.data);
/*
{ width: 320,
height: 180,
data: { '0': 91, '1': 64, ... } } // typed array
*/
```
### Encoding JPEGs
``` js
var jpeg = require('jpeg-js');
var width = 320, height = 180;

@@ -43,2 +68,6 @@ var frameData = new Buffer(width * height * 4);

var jpegImageData = jpeg.encode(rawImageData, 50);
console.log(jpegImageData);
/*
<Buffer 5b 40 29 ff 59 3e 29 ff 54 3c 26 ff 55 3a 27 ff 5a 3e 2f ff 5c 3c 31 ff 58 35 2d ff 5b 36 2f ff 55 35 32 ff 5a 3a 37 ff 54 36 32 ff 4b 32 2c ff 4b 36 ... >
*/
```

@@ -45,0 +74,0 @@

@@ -145,1 +145,22 @@ var redtape = require('redtape'),

it('should be able to decode a JPEG into a typed array', function(t) {
var jpegData = fixture('grumpycat.jpg');
var rawImageData = jpeg.decode(jpegData, true);
t.equal(rawImageData.width, 320);
t.equal(rawImageData.height, 180);
var expected = fixture('grumpycat.rgba');
t.bufferEqual(rawImageData.data, expected);
t.assert(rawImageData.data instanceof Uint8Array, 'data is a typed array');
t.end();
});
it('should be able to decode a JPEG from a typed array into a typed array', function(t) {
var jpegData = fixture('grumpycat.jpg');
var rawImageData = jpeg.decode(new Uint8Array(jpegData), true);
t.equal(rawImageData.width, 320);
t.equal(rawImageData.height, 180);
var expected = fixture('grumpycat.rgba');
t.bufferEqual(rawImageData.data, expected);
t.assert(rawImageData.data instanceof Uint8Array, 'data is a typed array');
t.end();
});

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc