v0.4.0-alpha

This commit is contained in:
Kuba Niegowski 2012-11-29 00:39:43 +01:00
parent a6406c85f2
commit a527d93d7b
2 changed files with 24 additions and 27 deletions

View file

@ -59,7 +59,8 @@ As input any color type is accepted (grayscale, rgb, palette, grayscale with alp
- `checkCRC` - whether parser should be strict about checksums in source stream (default: `true`) - `checkCRC` - whether parser should be strict about checksums in source stream (default: `true`)
- `deflateChunkSize` - chunk size used for deflating data chunks, this should be power of 2 and must not be less than 256 and more than 32*1024 (default: 32 kB) - `deflateChunkSize` - chunk size used for deflating data chunks, this should be power of 2 and must not be less than 256 and more than 32*1024 (default: 32 kB)
- `deflateLevel` - compression level for delate (default: 9) - `deflateLevel` - compression level for delate (default: 9)
- `filterType` - png filtering method for scanlines (default: -1 => auto) - `deflateStrategy` - compression strategy for delate (default: 3)
- `filterType` - png filtering method for scanlines (default: -1 => auto, accepts array of numbers 0-4)
### Event "metadata" ### Event "metadata"
@ -120,6 +121,10 @@ Gamma of image (0 if not specified)
Changelog Changelog
============ ============
### 0.4.0-alpha - 29 Nov 2012
- added zlib deflateStrategy option, default to Z_RLE (by pdpotter)
- added possibility to use multiple filters (by pdpotter, modified by niegowski)
### 0.3.0-alpha - 23 Aug 2012 ### 0.3.0-alpha - 23 Aug 2012
- Processing data as Streams, not complete Buffers of data - Processing data as Streams, not complete Buffers of data

View file

@ -36,29 +36,20 @@ var Filter = module.exports = function(width, height, Bpp, data, options) {
this._line = 0; this._line = 0;
options.filterTypes = options.filterTypes || [0,1,2,3,4]; if (!('filterType' in options) || options.filterType == -1) {
this._filters = {}; options.filterType = [0, 1, 2, 3, 4];
for (var filterType in options.filterTypes) { } else if (typeof options.filterType == 'number') {
switch (filterType) { options.filterType = [options.filterType];
case '0':
this._filters[filterType] = this._filterNone.bind(this);
break;
case '1':
this._filters[filterType] = this._filterSub.bind(this);
break;
case '2':
this._filters[filterType] = this._filterUp.bind(this);
break;
case '3':
this._filters[filterType] = this._filterAvg.bind(this);
break;
case '4':
this._filters[filterType] = this._filterPaeth.bind(this);
break;
default:
}
} }
this._filters = {
0: this._filterNone.bind(this),
1: this._filterSub.bind(this),
2: this._filterUp.bind(this),
3: this._filterAvg.bind(this),
4: this._filterPaeth.bind(this)
};
this.read(this._width * Bpp + 1, this._reverseFilterLine.bind(this)); this.read(this._width * Bpp + 1, this._reverseFilterLine.bind(this));
}; };
util.inherits(Filter, ChunkStream); util.inherits(Filter, ChunkStream);
@ -98,7 +89,7 @@ Filter.prototype._reverseFilterLine = function(rawData) {
pxRowPos = this._line * pxLineLength, pxRowPos = this._line * pxLineLength,
filter = rawData[0]; filter = rawData[0];
if (filter === 0) { if (filter == 0) {
for (var x = 0; x < this._width; x++) { for (var x = 0; x < this._width; x++) {
var pxPos = pxRowPos + (x << 2), var pxPos = pxRowPos + (x << 2),
rawPos = 1 + x * this._Bpp; rawPos = 1 + x * this._Bpp;
@ -190,13 +181,14 @@ Filter.prototype.filter = function() {
for (var y = 0; y < this._height; y++) { for (var y = 0; y < this._height; y++) {
// find best filter for this line (with lowest sum of values) // find best filter for this line (with lowest sum of values)
var min = Infinity, var filterTypes = this._options.filterType,
min = Infinity,
sel = 0; sel = 0;
for (var f in this._filters) { for (var i = 0; i < filterTypes.length; i++) {
var sum = this._filters[f](pxData, y, null); var sum = this._filters[filterTypes[i]](pxData, y, null);
if (sum < min) { if (sum < min) {
sel = f; sel = filterTypes[i];
min = sum; min = sum;
} }
} }