Skip to content
This repository has been archived by the owner on Jul 15, 2019. It is now read-only.

Commit

Permalink
Update method names to encode/decode to be more consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
marcelerz committed Aug 28, 2015
1 parent a554d49 commit 4c68078
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 58 deletions.
12 changes: 6 additions & 6 deletions lib/png/chunks/IHDR.js
Original file line number Diff line number Diff line change
Expand Up @@ -497,11 +497,11 @@ module.exports = {

// Decompress
compressor = new Compressor();
localImage = compressor.decompress(localImage);
localImage = compressor.decode(localImage);

// Run through filters
filter = new Filter(this);
localImage = filter.reverse(localImage);
localImage = filter.decode(localImage);

// Parses scanlines
parser = new Parser(this);
Expand Down Expand Up @@ -536,7 +536,7 @@ module.exports = {

// Run through interlace method
interlace = new Interlace(this);
localImage = interlace.reverse(localImage);
localImage = interlace.decode(localImage);

return localImage;
},
Expand Down Expand Up @@ -649,7 +649,7 @@ module.exports = {

// Run through interlace method
interlace = new Interlace(this);
image = interlace.interlace(image, 0);
image = interlace.encode(image);

if (this.isColorTypeIndexedColor()) {
// We expect the PLTE chunk to do the work
Expand Down Expand Up @@ -720,11 +720,11 @@ module.exports = {

// Run through filters
filter = new Filter(this);
image = filter.filter(image, 0);
image = filter.encode(image);

// Compress
compressor = new Compressor();
image = compressor.compress(image);
image = compressor.encode(image);

// Combine all data chunks
this._separate(image);
Expand Down
4 changes: 2 additions & 2 deletions lib/png/chunks/iCCP.js
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ module.exports = {

// Decompress
compressor = new Compressor();
buffer = compressor.decompress(buffer);
buffer = compressor.decode(buffer);

// Set profile
this.setProfile(buffer);
Expand Down Expand Up @@ -212,7 +212,7 @@ module.exports = {

// Compress
compressor = new Compressor();
buffer = compressor.compress(buffer);
buffer = compressor.encode(buffer);

// Write compressed data to stream
stream.writeBuffer(buffer);
Expand Down
4 changes: 2 additions & 2 deletions lib/png/chunks/zTXt.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ module.exports = {

// Decompress
compressor = new Compressor();
buffer = compressor.decompress(buffer);
buffer = compressor.decode(buffer);

// Convert text content from latin1
string = iconv.decode(buffer, 'latin1');
Expand Down Expand Up @@ -234,7 +234,7 @@ module.exports = {

// Compress
compressor = new Compressor();
buffer = compressor.compress(buffer);
buffer = compressor.encode(buffer);

// Write compressed data to stream
stream.writeBuffer(buffer);
Expand Down
4 changes: 2 additions & 2 deletions lib/png/custom/jsOn.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ module.exports = {

// Decompress
compressor = new Compressor();
data = compressor.decompress(data);
data = compressor.decode(data);

// Convert buffer into string
this.setContent(JSON.parse(data.toString('utf8')));
Expand Down Expand Up @@ -208,7 +208,7 @@ module.exports = {

// Compress the data
compressor = new Compressor();
data = compressor.compress(new Buffer(dataStr, 'utf8'));
data = compressor.encode(new Buffer(dataStr, 'utf8'));

// Write title to stream
string = this.getKeyword();
Expand Down
4 changes: 2 additions & 2 deletions lib/png/custom/stRT.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ module.exports = {

// Decompress
compressor = new Compressor();
data = compressor.decompress(data);
data = compressor.decode(data);

// Convert buffer into string
this.setContent(JSON.parse(data.toString('utf8')));
Expand Down Expand Up @@ -255,7 +255,7 @@ module.exports = {

// Compress the data
compressor = new Compressor();
data = compressor.compress(new Buffer(dataStr, 'utf8'));
data = compressor.encode(new Buffer(dataStr, 'utf8'));

// Write the data-type
stream.writeASCIIString(this.getDataType());
Expand Down
8 changes: 4 additions & 4 deletions lib/png/processor/compressor.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ Compressor.prototype.getOptions = function () {
/**
* Compresses data
*
* @method compress
* @method encode
* @param {Buffer} data
* @return {Buffer}
*/
Compressor.prototype.compress = function (data) {
Compressor.prototype.encode = function (data) {
if (!zlib.deflateSync) {
return new Buffer(require("pako").deflate(data, this.getOptions()));
} else {
Expand All @@ -43,11 +43,11 @@ Compressor.prototype.compress = function (data) {
/**
* Decompresses data
*
* @method decompress
* @method decode
* @param {Buffer} data
* @return {Buffer}
*/
Compressor.prototype.decompress = function (data) {
Compressor.prototype.decode = function (data) {
if (!zlib.inflateSync) {
return new Buffer(require("pako").inflate(data, this.getOptions()));
} else {
Expand Down
72 changes: 36 additions & 36 deletions lib/png/processor/filter.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ Filter.prototype.getHeaderChunk = function () {
/**
* Applies filters to the data
*
* @method filter
* @method encode
* @param {Buffer} image
* @return {Buffer}
*/
Filter.prototype.filter = function (image) {
return this._filter(image);
Filter.prototype.encode = function (image) {
return this._encode(image);
};

/**
* Applies filters to the data
*
* @method _filter
* @method _encode
* @param {Buffer} image
* @return {Buffer}
* @private
*/
Filter.prototype._filter = function (image) {
Filter.prototype._encode = function (image) {

var input,
output,
Expand Down Expand Up @@ -73,7 +73,7 @@ Filter.prototype._filter = function (image) {

for (var y = 0; y < height; y++) {
//TODO: Find a better way than just use the simplest
this._filterNone(input, output);
this._encodeNone(input, output);
input.previousLineOffset = input.offset;
input.offset += input.scanLineLength;
output.offset += input.scanLineLength + 1;
Expand All @@ -85,25 +85,25 @@ Filter.prototype._filter = function (image) {
/**
* Applies no filter at all - this is just a pass-through
*
* @method _filterNone
* @method _encodeNone
* @param {object} input Input data
* @param {object} output Output data
* @private
*/
Filter.prototype._filterNone = function (input, output) {
Filter.prototype._encodeNone = function (input, output) {
output.data[output.offset] = 0;
input.data.copy(output.data, output.offset + 1, input.offset, input.offset + input.scanLineLength);
};

/**
* Applies the Sub filter
*
* @method _filterSub
* @method _encodeSub
* @param {object} input Input data
* @param {object} output Output data
* @private
*/
Filter.prototype._filterSub = function (input, output) {
Filter.prototype._encodeSub = function (input, output) {
output.data[output.offset] = 1;
for (var x = 0; x < input.scanLineLength; x++) {
output.data[output.offset + x + 1] = Math.abs(this._getPixel(input, x) - this._getLeftPixel(input, x));
Expand All @@ -113,12 +113,12 @@ Filter.prototype._filterSub = function (input, output) {
/**
* Applies the Up filter
*
* @method _filterUp
* @method _encodeUp
* @param {object} input Input data
* @param {object} output Output data
* @private
*/
Filter.prototype._filterUp = function (input, output) {
Filter.prototype._encodeUp = function (input, output) {
output.data[output.offset] = 2;
for (var x = 0; x < input.scanLineLength; x++) {
output.data[output.offset + x + 1] = Math.abs(this._getPixel(input, x) - this._getTopPixel(input, x));
Expand All @@ -128,12 +128,12 @@ Filter.prototype._filterUp = function (input, output) {
/**
* Applies the Average filter
*
* @method _filterAverage
* @method _encodeAverage
* @param {object} input Input data
* @param {object} output Output data
* @private
*/
Filter.prototype._filterAverage = function (input, output) {
Filter.prototype._encodeAverage = function (input, output) {
output.data[output.offset] = 3;
for (var x = 0; x < input.scanLineLength; x++) {
output.data[output.offset + x + 1] = Math.abs(this._getPixel(input, x) - Math.floor((this._getLeftPixel(input, x) + this._getTopPixel(input, x)) / 2));
Expand All @@ -143,12 +143,12 @@ Filter.prototype._filterAverage = function (input, output) {
/**
* Applies the Paeth filter
*
* @method _filterPaeth
* @method _encodePaeth
* @param {object} input Input data
* @param {object} output Output data
* @private
*/
Filter.prototype._filterPaeth = function (input, output) {
Filter.prototype._encodePaeth = function (input, output) {
output.data[output.offset] = 4;
for (var x = 0; x < input.scanLineLength; x++) {
output.data[output.offset + x + 1] = Math.abs(
Expand All @@ -165,11 +165,11 @@ Filter.prototype._filterPaeth = function (input, output) {
/**
* Reverses all filters
*
* @method reverse
* @method decode
* @param {Buffer} image
* @return {Buffer} Reversed data
*/
Filter.prototype.reverse = function (image) {
Filter.prototype.decode = function (image) {

var headerChunk = this.getHeaderChunk(),
interlace = new Interlace(headerChunk),
Expand Down Expand Up @@ -206,7 +206,7 @@ Filter.prototype.reverse = function (image) {
previousLineOffset: null
};

this._reverse(info);
this._decode(info);

}.bind(this));

Expand All @@ -216,22 +216,22 @@ Filter.prototype.reverse = function (image) {
/**
* Reverses all filters
*
* @method _reverse
* @method _decode
* @param {object} info
* @private
*/
Filter.prototype._reverse = function (info) {
Filter.prototype._decode = function (info) {

var filterType,
filterMapping;

// Reverse mapping for filter-types
filterMapping = {
0: this._reverseNone,
1: this._reverseSub,
2: this._reverseUp,
3: this._reverseAverage,
4: this._reversePaeth
0: this._decodeNone,
1: this._decodeSub,
2: this._decodeUp,
3: this._decodeAverage,
4: this._decodePaeth
};

// Run through all scanlines
Expand All @@ -256,22 +256,22 @@ Filter.prototype._reverse = function (info) {
/**
* Reverses nothing at all - this is just a pass-through
*
* @method _reverseNone
* @method _decodeNone
* @param {object} info
* @private
*/
Filter.prototype._reverseNone = function (info) {
Filter.prototype._decodeNone = function (info) {
info.inputData.copy(info.outputData, info.outputOffset, info.inputOffset, info.inputOffset + info.scanLineLength);
};

/**
* Reverses the Sub filter
*
* @method _reverseSub
* @method _decodeSub
* @param {object} info
* @private
*/
Filter.prototype._reverseSub = function (info) {
Filter.prototype._decodeSub = function (info) {
for (var x = 0; x < info.scanLineLength; x++) {
info.outputData[info.outputOffset + x] = (this._getPixel(info, x) + this._getLeftPixel(info, x)) & 0xff;
}
Expand All @@ -280,11 +280,11 @@ Filter.prototype._reverseSub = function (info) {
/**
* Reverses the Up filter
*
* @method _reverseUp
* @method _decodeUp
* @param {object} info
* @private
*/
Filter.prototype._reverseUp = function (info) {
Filter.prototype._decodeUp = function (info) {
for (var x = 0; x < info.scanLineLength; x++) {
info.outputData[info.outputOffset + x] = (this._getPixel(info, x) + this._getTopPixel(info, x)) & 0xff;
}
Expand All @@ -293,11 +293,11 @@ Filter.prototype._reverseUp = function (info) {
/**
* Reverses the Average filter
*
* @method _reverseAverage
* @method _decodeAverage
* @param {object} info
* @private
*/
Filter.prototype._reverseAverage = function (info) {
Filter.prototype._decodeAverage = function (info) {
for (var x = 0; x < info.scanLineLength; x++) {
info.outputData[info.outputOffset + x] = (this._getPixel(info, x) + Math.floor((this._getLeftPixel(info, x) + this._getTopPixel(info, x)) / 2)) & 0xff;
}
Expand All @@ -306,11 +306,11 @@ Filter.prototype._reverseAverage = function (info) {
/**
* Reverses the Paeth filter
*
* @method _reversePaeth
* @method _decodePaeth
* @param {object} info
* @private
*/
Filter.prototype._reversePaeth = function (info) {
Filter.prototype._decodePaeth = function (info) {
for (var x = 0; x < info.scanLineLength; x++) {
info.outputData[info.outputOffset + x] =
this._getPixel(info, x) + this._paethPredictor(
Expand Down

0 comments on commit 4c68078

Please sign in to comment.