Skip to content

Commit 4e04eff

Browse files
committed
disableChromaSubsampling: false -> chromaSubsampling: true
1 parent 731989e commit 4e04eff

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Readme.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ var stream = canvas.jpegStream({
171171
bufsize: 4096 // output buffer size in bytes, default: 4096
172172
, quality: 75 // JPEG quality (0-100) default: 75
173173
, progressive: false // true for progressive compression, default: false
174-
, disableChromaSubsampling: false // true to disable 2x2 subsampling of the chroma components, default: false
174+
, chromaSubsampling: true // false to disable 2x2 subsampling of the chroma components, default: true
175175
});
176176
```
177177

lib/canvas.js

+11-2
Original file line numberDiff line numberDiff line change
@@ -90,12 +90,21 @@ Canvas.prototype.createJPEGStream = function(options){
9090
// Don't allow the buffer size to exceed the size of the canvas (#674)
9191
var maxBufSize = this.width * this.height * 4;
9292
var clampedBufSize = Math.min(options.bufsize || 4096, maxBufSize);
93+
var chromaFactor;
94+
if (typeof options.chromaSubsampling === "number") {
95+
// libjpeg-turbo seems to complain about values above 2, but hopefully this
96+
// can be supported in the future. For now 1 and 2 are valid.
97+
// https://github.com/Automattic/node-canvas/pull/1092#issuecomment-366558028
98+
chromaFactor = options.chromaSubsampling;
99+
} else {
100+
chromaFactor = options.chromaSubsampling === false ? 1 : 2;
101+
}
93102
return new JPEGStream(this, {
94103
bufsize: clampedBufSize
95104
, quality: options.quality || 75
96105
, progressive: options.progressive || false
97-
, chromaHSampFactor: options.disableChromaSubsampling ? 1 : 2
98-
, chromaVSampFactor: options.disableChromaSubsampling ? 1 : 2
106+
, chromaHSampFactor: chromaFactor
107+
, chromaVSampFactor: chromaFactor
99108
});
100109
};
101110

0 commit comments

Comments
 (0)