save-pixels
Advanced tools
Comparing version 2.1.0 to 2.2.0
{ | ||
"name": "save-pixels", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Saves an ndarray as an image to a file", | ||
@@ -12,2 +12,3 @@ "main": "save-pixels.js", | ||
"contentstream": "^1.0.0", | ||
"gif-encoder": "~0.4.1", | ||
"jpeg-js": "0.0.4", | ||
@@ -14,0 +15,0 @@ "pngjs": "~0.4.0-alpha", |
"use strict" | ||
var ContentStream = require("contentstream") | ||
var GifEncoder = require("gif-encoder") | ||
var jpegJs = require("jpeg-js") | ||
@@ -8,5 +9,14 @@ var PNG = require("pngjs").PNG | ||
function handleData(array, data) { | ||
function handleData(array, data, frame) { | ||
var i, j, ptr = 0, c | ||
if(array.shape.length === 3) { | ||
if(array.shape.length === 4) { | ||
for(j=0; j<array.shape[2]; ++j) { | ||
for(i=0; i<array.shape[1]; ++i) { | ||
data[ptr++] = array.get(frame,i,j,0)>>>0 | ||
data[ptr++] = array.get(frame,i,j,1)>>>0 | ||
data[ptr++] = array.get(frame,i,j,2)>>>0 | ||
data[ptr++] = array.get(frame,i,j,3)>>>0 | ||
} | ||
} | ||
} else if(array.shape.length === 3) { | ||
if(array.shape[2] === 3) { | ||
@@ -85,2 +95,17 @@ for(j=0; j<array.shape[1]; ++j) { | ||
case "GIF": | ||
case ".GIF": | ||
var frames = array.shape.length === 4 ? array.shape[0] : 1 | ||
var width = array.shape.length === 4 ? array.shape[1] : array.shape[0] | ||
var height = array.shape.length === 4 ? array.shape[2] : array.shape[1] | ||
var data = new Buffer(width * height * 4) | ||
var gif = new GifEncoder(width, height) | ||
gif.writeHeader() | ||
for (var i = 0; i < frames; i++) { | ||
data = handleData(array, data, i) | ||
gif.addFrame(data) | ||
} | ||
gif.finish() | ||
return gif | ||
case "PNG": | ||
@@ -87,0 +112,0 @@ case ".PNG": |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
6909
127
5
+ Addedgif-encoder@~0.4.1
+ Addedgif-encoder@0.4.3(transitive)
+ Addedreadable-stream@1.1.14(transitive)