Skip to content

Commit

Permalink
Simply use Browserify builtins instead of the separate stream.js
Browse files Browse the repository at this point in the history
  • Loading branch information
arian committed Jan 2, 2016
1 parent 5c453c6 commit 0d8222c
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 1,346 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -2,3 +2,4 @@ node_modules/
test.png
png-js-test.js
v8*
html/png.js
11 changes: 0 additions & 11 deletions Makefile

This file was deleted.

36 changes: 6 additions & 30 deletions PNGReader.js
@@ -1,36 +1,12 @@
/*global Uint8Array:true ArrayBuffer:true */
"use strict";

var zlib = require('zlib');
var PNG = require('./PNG');

var isNode = typeof process !== 'undefined' && !process.browser;

var inflate = (function(){
if (isNode){
var zlib = require('zlib');
return function(data, callback){
return zlib.inflate(new Buffer(data), callback);
};
} else {
var stream = require('./stream');
return function(data, callback){
data = new stream.FlateStream(new stream.Stream(data));
callback(null, data.getBytes());
};
}
})();

var ByteBuffer = isNode ? Buffer : (function(){
if (typeof ArrayBuffer == 'function'){
return function(length){
return new Uint8Array(new ArrayBuffer(length));
};
} else {
return function(length){
return new Array(length);
};
}
})();
var inflate = function(data, callback){
return zlib.inflate(new Buffer(data), callback);
};

var slice = Array.prototype.slice;
var toString = Object.prototype.toString;
Expand Down Expand Up @@ -204,7 +180,7 @@ PNGReader.prototype.decodePixels = function(callback){
var length = 0;
var i, j, k, l;
for (l = this.dataChunks.length; l--;) length += this.dataChunks[l].length;
var data = new ByteBuffer(length);
var data = new Buffer(length);
for (i = 0, k = 0, l = this.dataChunks.length; i < l; i++){
var chunk = this.dataChunks[i];
for (j = 0; j < chunk.length; j++) data[k++] = chunk[j];
Expand Down Expand Up @@ -238,7 +214,7 @@ PNGReader.prototype.interlaceNone = function(data){
// color bytes per row
var cpr = bpp * png.width;

var pixels = new ByteBuffer(bpp * png.width * png.height);
var pixels = new Buffer(bpp * png.width * png.height);
var scanline;
var offset = 0;

Expand Down
9 changes: 2 additions & 7 deletions README.md
Expand Up @@ -120,11 +120,6 @@ Building Browser Version
------------------------

PNG.js uses CommonJS modules which can be used in browsers after building it
with [wrapup](https://github.com/mootools/wrapup):

wrup -r PNGReader ./PNGReader.js

# or with the predefined make commands
make build-browser
make build-browser-min
with [browserify](http://browserify.org/):

browserify ./PNGReader.js -s PNGReader

0 comments on commit 0d8222c

Please sign in to comment.