mirror of
https://github.com/danbulant/pngjs
synced 2026-07-09 21:21:08 +00:00
configure the rest of eslint.
This commit is contained in:
parent
8155d300f0
commit
bf5ae3c54e
16 changed files with 737 additions and 713 deletions
136
.eslintrc
136
.eslintrc
|
|
@ -2,10 +2,10 @@
|
||||||
"ecmaFeatures": {},
|
"ecmaFeatures": {},
|
||||||
"rules": {
|
"rules": {
|
||||||
"no-alert": 2,
|
"no-alert": 2,
|
||||||
"no-array-constructor": 1,
|
"no-array-constructor": 0,
|
||||||
"no-bitwise": 0,
|
"no-bitwise": 0,
|
||||||
"no-caller": 2,
|
"no-caller": 2,
|
||||||
"no-catch-shadow": 1,
|
"no-catch-shadow": 2,
|
||||||
"no-class-assign": 2,
|
"no-class-assign": 2,
|
||||||
"no-cond-assign": 2,
|
"no-cond-assign": 2,
|
||||||
"no-console": 2,
|
"no-console": 2,
|
||||||
|
|
@ -26,15 +26,15 @@
|
||||||
"no-eq-null": 0,
|
"no-eq-null": 0,
|
||||||
"no-eval": 2,
|
"no-eval": 2,
|
||||||
"no-ex-assign": 2,
|
"no-ex-assign": 2,
|
||||||
"no-extend-native": 0,
|
"no-extend-native": 2,
|
||||||
"no-extra-bind": 1,
|
"no-extra-bind": 1,
|
||||||
"no-extra-boolean-cast": 2,
|
"no-extra-boolean-cast": 2,
|
||||||
"no-extra-parens": 0,
|
"no-extra-parens": 0,
|
||||||
"no-extra-semi": 2,
|
"no-extra-semi": 2,
|
||||||
"no-fallthrough": 2,
|
"no-fallthrough": 2,
|
||||||
"no-floating-decimal": 0,
|
"no-floating-decimal": 1,
|
||||||
"no-func-assign": 2,
|
"no-func-assign": 2,
|
||||||
"no-implicit-coercion": 0,
|
"no-implicit-coercion": 1,
|
||||||
"no-implied-eval": 1,
|
"no-implied-eval": 1,
|
||||||
"no-inline-comments": 0,
|
"no-inline-comments": 0,
|
||||||
"no-inner-declarations": [2, "functions"],
|
"no-inner-declarations": [2, "functions"],
|
||||||
|
|
@ -45,26 +45,26 @@
|
||||||
"no-label-var": 1,
|
"no-label-var": 1,
|
||||||
"no-labels": 1,
|
"no-labels": 1,
|
||||||
"no-lone-blocks": 1,
|
"no-lone-blocks": 1,
|
||||||
"no-lonely-if": 0,
|
"no-lonely-if": 1,
|
||||||
"no-loop-func": 1,
|
"no-loop-func": 1,
|
||||||
"no-mixed-requires": [0, false],
|
"no-mixed-requires": [1, false],
|
||||||
"no-mixed-spaces-and-tabs": [2, false],
|
"no-mixed-spaces-and-tabs": [2, false],
|
||||||
"linebreak-style": [0, "unix"],
|
"linebreak-style": [0, "unix"],
|
||||||
"no-multi-spaces": 1,
|
"no-multi-spaces": 1,
|
||||||
"no-multi-str": 0,
|
"no-multi-str": 0,
|
||||||
"no-multiple-empty-lines": [0, {"max": 2}],
|
"no-multiple-empty-lines": [1, {"max": 2}],
|
||||||
"no-native-reassign": 0,
|
"no-native-reassign": 2,
|
||||||
"no-negated-in-lhs": 2,
|
"no-negated-in-lhs": 2,
|
||||||
"no-nested-ternary": 0,
|
"no-nested-ternary": 1,
|
||||||
"no-new": 0,
|
"no-new": 1,
|
||||||
"no-new-func": 0,
|
"no-new-func": 1,
|
||||||
"no-new-object": 0,
|
"no-new-object": 1,
|
||||||
"no-new-require": 0,
|
"no-new-require": 1,
|
||||||
"no-new-wrappers": 0,
|
"no-new-wrappers": 1,
|
||||||
"no-obj-calls": 2,
|
"no-obj-calls": 2,
|
||||||
"no-octal": 2,
|
"no-octal": 2,
|
||||||
"no-octal-escape": 0,
|
"no-octal-escape": 0,
|
||||||
"no-param-reassign": 0,
|
"no-param-reassign": 1,
|
||||||
"no-path-concat": 0,
|
"no-path-concat": 0,
|
||||||
"no-plusplus": 0,
|
"no-plusplus": 0,
|
||||||
"no-process-env": 0,
|
"no-process-env": 0,
|
||||||
|
|
@ -73,23 +73,23 @@
|
||||||
"no-redeclare": 2,
|
"no-redeclare": 2,
|
||||||
"no-regex-spaces": 2,
|
"no-regex-spaces": 2,
|
||||||
"no-restricted-modules": 0,
|
"no-restricted-modules": 0,
|
||||||
"no-return-assign": 0,
|
"no-return-assign": 1,
|
||||||
"no-script-url": 0,
|
"no-script-url": 0,
|
||||||
"no-self-compare": 0,
|
"no-self-compare": 1,
|
||||||
"no-sequences": 0,
|
"no-sequences": 1,
|
||||||
"no-shadow": 1,
|
"no-shadow": 1,
|
||||||
"no-shadow-restricted-names": 0,
|
"no-shadow-restricted-names": 1,
|
||||||
"no-spaced-func": 1,
|
"no-spaced-func": 1,
|
||||||
"no-sparse-arrays": 2,
|
"no-sparse-arrays": 2,
|
||||||
"no-sync": 0,
|
"no-sync": 0,
|
||||||
"no-ternary": 0,
|
"no-ternary": 0,
|
||||||
"no-trailing-spaces": 1,
|
"no-trailing-spaces": 1,
|
||||||
"no-this-before-super": 0,
|
"no-this-before-super": 1,
|
||||||
"no-throw-literal": 0,
|
"no-throw-literal": 1,
|
||||||
"no-undef": 2,
|
"no-undef": 2,
|
||||||
"no-undef-init": 0,
|
"no-undef-init": 1,
|
||||||
"no-undefined": 0,
|
"no-undefined": 0,
|
||||||
"no-unexpected-multiline": 0,
|
"no-unexpected-multiline": 1,
|
||||||
"no-underscore-dangle": 0,
|
"no-underscore-dangle": 0,
|
||||||
"no-unneeded-ternary": 0,
|
"no-unneeded-ternary": 0,
|
||||||
"no-unreachable": 2,
|
"no-unreachable": 2,
|
||||||
|
|
@ -99,73 +99,75 @@
|
||||||
"no-useless-call": 2,
|
"no-useless-call": 2,
|
||||||
"no-void": 0,
|
"no-void": 0,
|
||||||
"no-var": 0,
|
"no-var": 0,
|
||||||
"no-warning-comments": [0, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
|
"no-warning-comments": [1, { "terms": ["todo", "fixme", "xxx"], "location": "start" }],
|
||||||
"no-with": 0,
|
"no-with": 1,
|
||||||
|
|
||||||
"array-bracket-spacing": [0, "never"],
|
"array-bracket-spacing": [1, "never"],
|
||||||
"arrow-parens": 0,
|
"arrow-parens": 1,
|
||||||
"arrow-spacing": 0,
|
"arrow-spacing": 1,
|
||||||
"accessor-pairs": 0,
|
"accessor-pairs": 1,
|
||||||
"block-scoped-var": 0,
|
"block-scoped-var": 0,
|
||||||
"brace-style": [0, "1tbs"],
|
"brace-style": [1, "1tbs"],
|
||||||
"callback-return": 0,
|
"callback-return": [2, ["callback", "cb", "next"]],
|
||||||
"camelcase": 0,
|
"camelcase": [2, {"properties": "always"}],
|
||||||
"comma-dangle": [2, "never"],
|
"comma-dangle": [2, "never"],
|
||||||
"comma-spacing": 0,
|
"comma-spacing": 2,
|
||||||
"comma-style": 0,
|
"comma-style": 1,
|
||||||
"complexity": [0, 11],
|
"complexity": [1, 10],
|
||||||
"computed-property-spacing": [0, "never"],
|
"computed-property-spacing": [0, "never"],
|
||||||
"consistent-return": 0,
|
"consistent-return": 0,
|
||||||
"consistent-this": [0, "that"],
|
"consistent-this": [0, "that"],
|
||||||
"constructor-super": 0,
|
"constructor-super": 1,
|
||||||
"curly": [0, "all"],
|
"curly": [1, "all"],
|
||||||
"default-case": 0,
|
"default-case": 1,
|
||||||
"dot-location": 0,
|
"dot-location": [1, "property"],
|
||||||
"dot-notation": [0, { "allowKeywords": true }],
|
"dot-notation": [1, { "allowKeywords": true }],
|
||||||
"eol-last": 0,
|
"eol-last": 0,
|
||||||
"eqeqeq": 0,
|
"eqeqeq": 1,
|
||||||
"func-names": 0,
|
"func-names": 0,
|
||||||
"func-style": [0, "declaration"],
|
"func-style": [0, "declaration"],
|
||||||
"generator-star-spacing": 0,
|
"generator-star-spacing": 0,
|
||||||
"guard-for-in": 0,
|
"guard-for-in": 1,
|
||||||
"handle-callback-err": 0,
|
"handle-callback-err": 2,
|
||||||
"id-length": 0,
|
"id-length": [2, {"min": 3, "max": 20, "exceptions":["x", "y", "i", "j"]}],
|
||||||
"indent": 0,
|
"indent": [1, 2, {"SwitchCase": 1}],
|
||||||
"init-declarations": 0,
|
"init-declarations": 0,
|
||||||
"key-spacing": [0, { "beforeColon": false, "afterColon": true }],
|
"key-spacing": [1, { "beforeColon": false, "afterColon": true }],
|
||||||
"lines-around-comment": 0,
|
"lines-around-comment": 0,
|
||||||
"max-depth": [0, 4],
|
"max-depth": [1, 4],
|
||||||
"max-len": [0, 80, 4],
|
"max-len": [1, 160, 2],
|
||||||
"max-nested-callbacks": [0, 2],
|
"max-nested-callbacks": [1, 2],
|
||||||
"max-params": [0, 3],
|
"max-params": [1, 5],
|
||||||
"max-statements": [0, 10],
|
"max-statements": [1, 30],
|
||||||
"new-cap": 0,
|
"new-cap": 1,
|
||||||
"new-parens": 0,
|
"new-parens": 1,
|
||||||
"newline-after-var": 0,
|
"newline-after-var": 0,
|
||||||
"object-curly-spacing": [0, "never"],
|
"object-curly-spacing": [1, "always"],
|
||||||
"object-shorthand": 0,
|
"object-shorthand": 0,
|
||||||
"one-var": 0,
|
"one-var": [1, {
|
||||||
|
"initialized": "never"
|
||||||
|
}],
|
||||||
"operator-assignment": [0, "always"],
|
"operator-assignment": [0, "always"],
|
||||||
"operator-linebreak": 0,
|
"operator-linebreak": [1, "after"],
|
||||||
"padded-blocks": 0,
|
"padded-blocks": 0,
|
||||||
"prefer-const": 0,
|
"prefer-const": 0,
|
||||||
"prefer-spread": 0,
|
"prefer-spread": 0,
|
||||||
"prefer-reflect": 0,
|
"prefer-reflect": 0,
|
||||||
"quote-props": 0,
|
"quote-props": 0,
|
||||||
"quotes": [0, "double"],
|
"quotes": [1, "single"],
|
||||||
"radix": 0,
|
"radix": 0,
|
||||||
"id-match": 0,
|
"id-match": 0,
|
||||||
"require-yield": 0,
|
"require-yield": 0,
|
||||||
"semi": 0,
|
"semi": [1, "always"],
|
||||||
"semi-spacing": [0, {"before": false, "after": true}],
|
"semi-spacing": [1, {"before": false, "after": true}],
|
||||||
"sort-vars": 0,
|
"sort-vars": 0,
|
||||||
"space-after-keywords": [0, "always"],
|
"space-after-keywords": [1, "always"],
|
||||||
"space-before-blocks": [0, "always"],
|
"space-before-blocks": [1, "always"],
|
||||||
"space-before-function-paren": [0, "always"],
|
"space-before-function-paren": [1, "never"],
|
||||||
"space-in-parens": [0, "never"],
|
"space-in-parens": [1, "never"],
|
||||||
"space-infix-ops": 0,
|
"space-infix-ops": 1,
|
||||||
"space-return-throw-case": 0,
|
"space-return-throw-case": 1,
|
||||||
"space-unary-ops": [0, { "words": true, "nonwords": false }],
|
"space-unary-ops": [1, { "words": true, "nonwords": false }],
|
||||||
"spaced-comment": 0,
|
"spaced-comment": 0,
|
||||||
"strict": [2, "global"],
|
"strict": [2, "global"],
|
||||||
"use-isnan": 2,
|
"use-isnan": 2,
|
||||||
|
|
|
||||||
|
|
@ -33,16 +33,17 @@ function bitRetriever(data, depth) {
|
||||||
|
|
||||||
var leftOver = [];
|
var leftOver = [];
|
||||||
var i = 0;
|
var i = 0;
|
||||||
|
|
||||||
function split() {
|
function split() {
|
||||||
if (i === data.length) {
|
if (i === data.length) {
|
||||||
throw new Error("Ran out of data");
|
throw new Error('Ran out of data');
|
||||||
}
|
}
|
||||||
var byte = data[i];
|
var byte = data[i];
|
||||||
i++;
|
i++;
|
||||||
var byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1
|
var byte8, byte7, byte6, byte5, byte4, byte3, byte2, byte1;
|
||||||
switch (depth) {
|
switch (depth) {
|
||||||
default:
|
default:
|
||||||
throw new Error("unrecognised depth");
|
throw new Error('unrecognised depth');
|
||||||
case 16:
|
case 16:
|
||||||
byte2 = data[i];
|
byte2 = data[i];
|
||||||
i++;
|
i++;
|
||||||
|
|
@ -73,6 +74,7 @@ function bitRetriever(data, depth) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
get: function(count) {
|
get: function(count) {
|
||||||
while (leftOver.length < count) {
|
while (leftOver.length < count) {
|
||||||
|
|
@ -87,7 +89,8 @@ function bitRetriever(data, depth) {
|
||||||
},
|
},
|
||||||
end: function() {
|
end: function() {
|
||||||
if (i !== data.length) {
|
if (i !== data.length) {
|
||||||
throw new Error("extra data found");
|
// todo these exceptions should be emitting errors
|
||||||
|
throw new Error('extra data found');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
@ -138,7 +141,7 @@ exports.dataToBitMap = function(data, width, height, bpp, depth, interlace) {
|
||||||
var idx = pixelBppMap[bpp][i];
|
var idx = pixelBppMap[bpp][i];
|
||||||
if (depth === 8) {
|
if (depth === 8) {
|
||||||
if (i === data.length) {
|
if (i === data.length) {
|
||||||
throw new Error("Ran out of data");
|
throw new Error('Ran out of data');
|
||||||
}
|
}
|
||||||
pxData[pxPos + i] = idx !== 0xff ? data[idx + rawPos] : maxBit;
|
pxData[pxPos + i] = idx !== 0xff ? data[idx + rawPos] : maxBit;
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -155,7 +158,7 @@ exports.dataToBitMap = function(data, width, height, bpp, depth, interlace) {
|
||||||
}
|
}
|
||||||
if (depth === 8) {
|
if (depth === 8) {
|
||||||
if (rawPos !== data.length) {
|
if (rawPos !== data.length) {
|
||||||
throw new Error("extra data found");
|
throw new Error('extra data found');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bits.end();
|
bits.end();
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var util = require('util'),
|
var util = require('util');
|
||||||
Stream = require('stream');
|
var Stream = require('stream');
|
||||||
|
|
||||||
|
|
||||||
var ChunkStream = module.exports = function() {
|
var ChunkStream = module.exports = function() {
|
||||||
|
|
@ -67,24 +67,31 @@ ChunkStream.prototype.write = function(data, encoding) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Buffer.isBuffer(data))
|
var dataBuffer;
|
||||||
data = new Buffer(data, encoding || this._encoding);
|
if (Buffer.isBuffer(data)) {
|
||||||
|
dataBuffer = data;
|
||||||
|
} else {
|
||||||
|
dataBuffer = new Buffer(data, encoding || this._encoding);
|
||||||
|
}
|
||||||
|
|
||||||
this._buffers.push(data);
|
this._buffers.push(dataBuffer);
|
||||||
this._buffered += data.length;
|
this._buffered += dataBuffer.length;
|
||||||
|
|
||||||
this._process();
|
this._process();
|
||||||
|
|
||||||
// ok if there are no more read requests
|
// ok if there are no more read requests
|
||||||
if (this._reads && this._reads.length == 0)
|
if (this._reads && this._reads.length == 0) {
|
||||||
this._paused = true;
|
this._paused = true;
|
||||||
|
}
|
||||||
|
|
||||||
return this.writable && !this._paused;
|
return this.writable && !this._paused;
|
||||||
};
|
};
|
||||||
|
|
||||||
ChunkStream.prototype.end = function(data, encoding) {
|
ChunkStream.prototype.end = function(data, encoding) {
|
||||||
|
|
||||||
if (data) this.write(data, encoding);
|
if (data) {
|
||||||
|
this.write(data, encoding);
|
||||||
|
}
|
||||||
|
|
||||||
this.writable = false;
|
this.writable = false;
|
||||||
|
|
||||||
|
|
@ -115,7 +122,9 @@ ChunkStream.prototype._end = function() {
|
||||||
|
|
||||||
ChunkStream.prototype.destroy = function() {
|
ChunkStream.prototype.destroy = function() {
|
||||||
|
|
||||||
if (!this._buffers) return;
|
if (!this._buffers) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this.writable = false;
|
this.writable = false;
|
||||||
this._reads = null;
|
this._reads = null;
|
||||||
|
|
@ -161,15 +170,15 @@ ChunkStream.prototype._process = function() {
|
||||||
|
|
||||||
this._reads.shift(); // == read
|
this._reads.shift(); // == read
|
||||||
|
|
||||||
var pos = 0,
|
var pos = 0;
|
||||||
count = 0,
|
var count = 0;
|
||||||
data = new Buffer(read.length);
|
var data = new Buffer(read.length);
|
||||||
|
|
||||||
// create buffer for all data
|
// create buffer for all data
|
||||||
while (pos < read.length) {
|
while (pos < read.length) {
|
||||||
|
|
||||||
var buf = this._buffers[count++],
|
var buf = this._buffers[count++];
|
||||||
len = Math.min(buf.length, read.length - pos);
|
var len = Math.min(buf.length, read.length - pos);
|
||||||
|
|
||||||
buf.copy(data, pos, 0, len);
|
buf.copy(data, pos, 0, len);
|
||||||
pos += len;
|
pos += len;
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,10 @@ module.exports = {
|
||||||
TYPE_IEND: 0x49454e44,
|
TYPE_IEND: 0x49454e44,
|
||||||
TYPE_IDAT: 0x49444154,
|
TYPE_IDAT: 0x49444154,
|
||||||
TYPE_PLTE: 0x504c5445,
|
TYPE_PLTE: 0x504c5445,
|
||||||
|
/*eslint camelcase: 0*/
|
||||||
TYPE_tRNS: 0x74524e53,
|
TYPE_tRNS: 0x74524e53,
|
||||||
TYPE_gAMA: 0x67414d41,
|
TYPE_gAMA: 0x67414d41,
|
||||||
|
/*eslint camelcase: 1*/
|
||||||
|
|
||||||
COLOR_PALETTE: 1,
|
COLOR_PALETTE: 1,
|
||||||
COLOR_COLOR: 2,
|
COLOR_COLOR: 2,
|
||||||
|
|
|
||||||
10
lib/crc.js
10
lib/crc.js
|
|
@ -24,15 +24,15 @@ var crcTable = [];
|
||||||
|
|
||||||
(function() {
|
(function() {
|
||||||
for (var i = 0; i < 256; i++) {
|
for (var i = 0; i < 256; i++) {
|
||||||
var c = i;
|
var currentCrc = i;
|
||||||
for (var j = 0; j < 8; j++) {
|
for (var j = 0; j < 8; j++) {
|
||||||
if (c & 1) {
|
if (currentCrc & 1) {
|
||||||
c = 0xedb88320 ^ (c >>> 1);
|
currentCrc = 0xedb88320 ^ (currentCrc >>> 1);
|
||||||
} else {
|
} else {
|
||||||
c = c >>> 1;
|
currentCrc = currentCrc >>> 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
crcTable[i] = c;
|
crcTable[i] = currentCrc;
|
||||||
}
|
}
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,9 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var util = require('util'),
|
var util = require('util');
|
||||||
ChunkStream = require('./chunkstream'),
|
var ChunkStream = require('./chunkstream');
|
||||||
Filter = require('./filter');
|
var Filter = require('./filter');
|
||||||
|
|
||||||
|
|
||||||
var FilterAsync = module.exports = function(width, height, Bpp, depth, interlace, options) {
|
var FilterAsync = module.exports = function(width, height, Bpp, depth, interlace, options) {
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@
|
||||||
|
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
var SyncReader = require('./sync-reader'),
|
var SyncReader = require('./sync-reader');
|
||||||
Filter = require('./filter');
|
var Filter = require('./filter');
|
||||||
|
|
||||||
|
|
||||||
exports.process = function(inBuffer, width, height, Bpp, depth, interlace, options) {
|
exports.process = function(inBuffer, width, height, Bpp, depth, interlace, options) {
|
||||||
|
|
@ -33,7 +33,8 @@ exports.process = function(inBuffer, width, height, Bpp, depth, interlace, optio
|
||||||
write: function(bufferPart) {
|
write: function(bufferPart) {
|
||||||
outBuffers.push(bufferPart);
|
outBuffers.push(bufferPart);
|
||||||
},
|
},
|
||||||
complete: function(){}
|
complete: function() {
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
filter.start();
|
filter.start();
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var util = require('util'),
|
var util = require('util');
|
||||||
Stream = require('stream'),
|
var Stream = require('stream');
|
||||||
zlib = require('zlib'),
|
var zlib = require('zlib');
|
||||||
Filter = require('./filter'),
|
var Filter = require('./filter');
|
||||||
CrcStream = require('./crc'),
|
var CrcStream = require('./crc');
|
||||||
constants = require('./constants');
|
var constants = require('./constants');
|
||||||
|
|
||||||
|
|
||||||
var Packer = module.exports = function(options) {
|
var Packer = module.exports = function(options) {
|
||||||
|
|
|
||||||
|
|
@ -21,12 +21,12 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var util = require('util'),
|
var util = require('util');
|
||||||
zlib = require('zlib'),
|
var zlib = require('zlib');
|
||||||
ChunkStream = require('./chunkstream'),
|
var ChunkStream = require('./chunkstream');
|
||||||
FilterAsync = require('./filter-async'),
|
var FilterAsync = require('./filter-async');
|
||||||
Parser = require('./parser'),
|
var Parser = require('./parser');
|
||||||
bitmapper = require('./bitmapper');
|
var bitmapper = require('./bitmapper');
|
||||||
|
|
||||||
|
|
||||||
var ParserAsync = module.exports = function(options) {
|
var ParserAsync = module.exports = function(options) {
|
||||||
|
|
|
||||||
|
|
@ -21,11 +21,11 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var zlib = require('zlib'),
|
var zlib = require('zlib');
|
||||||
SyncReader = require('./sync-reader'),
|
var SyncReader = require('./sync-reader');
|
||||||
FilterSync = require('./filter-sync'),
|
var FilterSync = require('./filter-sync');
|
||||||
Parser = require('./parser'),
|
var Parser = require('./parser');
|
||||||
bitmapper = require('./bitmapper');
|
var bitmapper = require('./bitmapper');
|
||||||
|
|
||||||
|
|
||||||
var ParserSync = module.exports = function(buffer, options) {
|
var ParserSync = module.exports = function(buffer, options) {
|
||||||
|
|
@ -38,7 +38,8 @@ var ParserSync = module.exports = function(buffer, options) {
|
||||||
error: this._handleError.bind(this),
|
error: this._handleError.bind(this),
|
||||||
metadata: this._metaData.bind(this),
|
metadata: this._metaData.bind(this),
|
||||||
gamma: this._gamma.bind(this),
|
gamma: this._gamma.bind(this),
|
||||||
finished: function() {},
|
finished: function() {
|
||||||
|
},
|
||||||
inflateData: this._inflateData.bind(this),
|
inflateData: this._inflateData.bind(this),
|
||||||
createData: this._createData.bind(this)
|
createData: this._createData.bind(this)
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -21,8 +21,8 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var constants = require('./constants'),
|
var constants = require('./constants');
|
||||||
CrcCalculator = require('./crc');
|
var CrcCalculator = require('./crc');
|
||||||
|
|
||||||
|
|
||||||
var Parser = module.exports = function(options, dependencies) {
|
var Parser = module.exports = function(options, dependencies) {
|
||||||
|
|
|
||||||
|
|
@ -26,8 +26,7 @@ var Parser = require('./parser-sync');
|
||||||
|
|
||||||
exports.read = function(buffer, options) {
|
exports.read = function(buffer, options) {
|
||||||
|
|
||||||
options = options || {};
|
var parser = new Parser(buffer, options || {});
|
||||||
var parser = new Parser(buffer, options);
|
|
||||||
|
|
||||||
if (parser.err) {
|
if (parser.err) {
|
||||||
throw parser.err;
|
throw parser.err;
|
||||||
|
|
|
||||||
59
lib/png.js
59
lib/png.js
|
|
@ -21,17 +21,17 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
var util = require('util'),
|
var util = require('util');
|
||||||
Stream = require('stream'),
|
var Stream = require('stream');
|
||||||
Parser = require('./parser-async'),
|
var Parser = require('./parser-async');
|
||||||
Packer = require('./packer'),
|
var Packer = require('./packer');
|
||||||
PNGSync = require('./png-sync');
|
var PNGSync = require('./png-sync');
|
||||||
|
|
||||||
|
|
||||||
var PNG = exports.PNG = function(options) {
|
var PNG = exports.PNG = function(options) {
|
||||||
Stream.call(this);
|
Stream.call(this);
|
||||||
|
|
||||||
options = options || {};
|
options = options || {}; // eslint-disable-line no-param-reassign
|
||||||
|
|
||||||
this.width = options.width || 0;
|
this.width = options.width || 0;
|
||||||
this.height = options.height || 0;
|
this.height = options.height || 0;
|
||||||
|
|
@ -81,21 +81,23 @@ PNG.prototype.pack = function() {
|
||||||
PNG.prototype.parse = function(data, callback) {
|
PNG.prototype.parse = function(data, callback) {
|
||||||
|
|
||||||
if (callback) {
|
if (callback) {
|
||||||
var onParsed = null, onError = null;
|
var onParsed, onError;
|
||||||
|
|
||||||
this.once('parsed', onParsed = function(parsedData) {
|
onParsed = function(parsedData) {
|
||||||
this.removeListener('error', onError);
|
this.removeListener('error', onError);
|
||||||
|
|
||||||
this.data = parsedData;
|
this.data = parsedData;
|
||||||
callback(null, this);
|
callback(null, this);
|
||||||
|
}.bind(this);
|
||||||
|
|
||||||
}.bind(this));
|
onError = function(err) {
|
||||||
|
|
||||||
this.once('error', onError = function(err) {
|
|
||||||
this.removeListener('parsed', onParsed);
|
this.removeListener('parsed', onParsed);
|
||||||
|
|
||||||
callback(err, null);
|
callback(err, null);
|
||||||
}.bind(this));
|
}.bind(this);
|
||||||
|
|
||||||
|
this.once('parsed', onParsed);
|
||||||
|
this.once('error', onError);
|
||||||
}
|
}
|
||||||
|
|
||||||
this.end(data);
|
this.end(data);
|
||||||
|
|
@ -123,32 +125,35 @@ PNG.prototype._gamma = function(gamma) {
|
||||||
};
|
};
|
||||||
|
|
||||||
PNG.prototype._handleClose = function() {
|
PNG.prototype._handleClose = function() {
|
||||||
if (!this._parser.writable && !this._packer.readable)
|
if (!this._parser.writable && !this._packer.readable) {
|
||||||
this.emit('close');
|
this.emit('close');
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PNG.bitblt = function(src, dst, sx, sy, w, h, dx, dy) {
|
|
||||||
|
|
||||||
if (sx > src.width || sy > src.height
|
PNG.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) { // eslint-disable-line max-params
|
||||||
|| sx + w > src.width || sy + h > src.height)
|
|
||||||
|
if (srcX > src.width || srcY > src.height || srcX + width > src.width || srcY + height > src.height) {
|
||||||
throw new Error('bitblt reading outside image');
|
throw new Error('bitblt reading outside image');
|
||||||
if (dx > dst.width || dy > dst.height
|
}
|
||||||
|| dx + w > dst.width || dy + h > dst.height)
|
|
||||||
throw new Error('bitblt writing outside image');
|
|
||||||
|
|
||||||
for (var y = 0; y < h; y++) {
|
if (deltaX > dst.width || deltaY > dst.height || deltaX + width > dst.width || deltaY + height > dst.height) {
|
||||||
|
throw new Error('bitblt writing outside image');
|
||||||
|
}
|
||||||
|
|
||||||
|
for (var y = 0; y < height; y++) {
|
||||||
src.data.copy(dst.data,
|
src.data.copy(dst.data,
|
||||||
((dy + y) * dst.width + dx) << 2,
|
((deltaY + y) * dst.width + deltaX) << 2,
|
||||||
((sy + y) * src.width + sx) << 2,
|
((srcY + y) * src.width + srcX) << 2,
|
||||||
((sy + y) * src.width + sx + w) << 2
|
((srcY + y) * src.width + srcX + width) << 2
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
PNG.prototype.bitblt = function(dst, sx, sy, w, h, dx, dy) {
|
PNG.prototype.bitblt = function(src, dst, srcX, srcY, width, height, deltaX, deltaY) { // eslint-disable-line max-params
|
||||||
|
|
||||||
PNG.bitblt(this, dst, sx, sy, w, h, dx, dy);
|
PNG.bitblt(this, dst, srcX, srcY, width, height, deltaX, deltaY);
|
||||||
return this;
|
return this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -169,4 +174,6 @@ PNG.adjustGamma = function(src) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
PNG.prototype.adjustGamma = function() { PNG.adjustGamma(this); };
|
PNG.prototype.adjustGamma = function() {
|
||||||
|
PNG.adjustGamma(this);
|
||||||
|
};
|
||||||
Loading…
Reference in a new issue