Skip to content

Commit

Permalink
disableChromaSubsampling: false -> chromaSubsampling: true
Browse files Browse the repository at this point in the history
  • Loading branch information
zbjornson committed Apr 21, 2018
1 parent 731989e commit 4e04eff
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ var stream = canvas.jpegStream({
bufsize: 4096 // output buffer size in bytes, default: 4096
, quality: 75 // JPEG quality (0-100) default: 75
, progressive: false // true for progressive compression, default: false
, disableChromaSubsampling: false // true to disable 2x2 subsampling of the chroma components, default: false
, chromaSubsampling: true // false to disable 2x2 subsampling of the chroma components, default: true
});
```

Expand Down
13 changes: 11 additions & 2 deletions lib/canvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,21 @@ Canvas.prototype.createJPEGStream = function(options){
// Don't allow the buffer size to exceed the size of the canvas (#674)
var maxBufSize = this.width * this.height * 4;
var clampedBufSize = Math.min(options.bufsize || 4096, maxBufSize);
var chromaFactor;
if (typeof options.chromaSubsampling === "number") {
// libjpeg-turbo seems to complain about values above 2, but hopefully this
// can be supported in the future. For now 1 and 2 are valid.
// https://github.com/Automattic/node-canvas/pull/1092#issuecomment-366558028
chromaFactor = options.chromaSubsampling;
} else {
chromaFactor = options.chromaSubsampling === false ? 1 : 2;
}
return new JPEGStream(this, {
bufsize: clampedBufSize
, quality: options.quality || 75
, progressive: options.progressive || false
, chromaHSampFactor: options.disableChromaSubsampling ? 1 : 2
, chromaVSampFactor: options.disableChromaSubsampling ? 1 : 2
, chromaHSampFactor: chromaFactor
, chromaVSampFactor: chromaFactor
});
};

Expand Down

0 comments on commit 4e04eff

Please sign in to comment.