Skip to content

disableChromaSubsampling: false -> chromaSubsampling: true #1153

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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