Skip to content
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

advanced webp output options - alpha quality, lossless and near lossless #685

Merged
merged 5 commits into from
Jan 19, 2017
Merged

advanced webp output options - alpha quality, lossless and near lossless #685

merged 5 commits into from
Jan 19, 2017

Conversation

rn4391
Copy link

@rn4391 rn4391 commented Jan 17, 2017

No description provided.

Copy link
Owner

@lovell lovell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hello, thanks for this, I'll added some comments inline.

@@ -145,6 +145,8 @@ const Sharp = function (input, options) {
pngCompressionLevel: 6,
pngAdaptiveFiltering: true,
webpQuality: 80,
webpAlphaQuality: 100,
webpLossless: false,
tiffQuality: 80,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this missing a webpNearLossless: false default? This might be the reason for the "Partial image extraction WebP" test failure.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tests on my system passed without this as well. Still added it.

@@ -168,6 +168,9 @@ const png = function png (options) {
* Use these WebP options for output image.
* @param {Object} [options] - output options
* @param {Number} [options.quality=80] - quality, integer 1-100
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
* @param {Boolean} [options.lossless=false] - use lossless compression mode
* @param {Boolean} [options.nearLossless=false] - use near_lossless compression mode
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are lossless and nearLossless mutually exclusive?

Copy link
Author

@rn4391 rn4391 Jan 18, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nearLossless has to be used in conjunction with Q. nearLossless with Q=100 is equivalent to lossless . But with other quality settings, it will lead to a smaller file size than lossless. This does make lossless kind of redundant (https://groups.google.com/a/webmproject.org/forum/#!topic/webp-discuss/0GmxDmlexek) as a shorthand way of saying nearLossless, Q=100

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my question wasn't very clear. What happens when trying to combine the two?

.webp({
  lossless: true,
  nearLossless: true
})...

Is this valid?

@@ -1209,6 +1218,11 @@ NAN_METHOD(pipeline) {
baton->pngCompressionLevel = AttrTo<uint32_t>(options, "pngCompressionLevel");
baton->pngAdaptiveFiltering = AttrTo<bool>(options, "pngAdaptiveFiltering");
baton->webpQuality = AttrTo<uint32_t>(options, "webpQuality");
baton->webpAlphaQuality = AttrTo<uint32_t>(options, "webpAlphaQuality");
baton->webpLossless = AttrTo<bool>(options, "webpLossless");
if(HasAttr(options, "webpNearLossless")) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this attribute need the HasAttr check given there is (or should be) a default?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed the check since the default has been added

if (err) throw err;
assert.strictEqual(true, data.length > 0);
assert.strictEqual('webp', info.format);
fixtures.assertSimilar(fixtures.expected('webp-alpha-80.webp'), data, function (err) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The inline function can be rolled up to use done, something like:

fixtures.assertSimilar(fixtures.expected('webp-alpha-80.webp'), data, done);

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing this out

@@ -735,6 +779,12 @@ describe('Input/output', function () {
});
});

it('Invalid WebP alpha quality throws error', function () {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please can you add tests for invalid lossless and nearLossless attributes also.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalid lossless and nearLossless attributes are ignored and are set to default boolean false. Similar to what is done for jpegOvershootDeringing and other such params

@rn4391
Copy link
Author

rn4391 commented Jan 18, 2017

If it looks good now, I can squash it into a single commit?

@@ -169,7 +169,7 @@ This operation will always occur after resizing and extraction, if any.
// to the top, left and right edges and 20 to the bottom edge
sharp(input)
.resize(140)
.background({r: 0, g: 0, b: 0, a: 0})
.background({r: 0, g: 0, b: 0, alpha: 0})
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change was included in commit 4730554 so I think this file can be removed from the PR.

@@ -168,6 +168,9 @@ const png = function png (options) {
* Use these WebP options for output image.
* @param {Object} [options] - output options
* @param {Number} [options.quality=80] - quality, integer 1-100
* @param {Number} [options.alphaQuality=100] - quality of alpha layer, integer 0-100
* @param {Boolean} [options.lossless=false] - use lossless compression mode
* @param {Boolean} [options.nearLossless=false] - use near_lossless compression mode
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, my question wasn't very clear. What happens when trying to combine the two?

.webp({
  lossless: true,
  nearLossless: true
})...

Is this valid?

@rn4391
Copy link
Author

rn4391 commented Jan 19, 2017

Since this is valid vips copy x.jpg x.webp[lossless,near_lossless] and uses near_lossless with default Q setting, then I guess even

.webp({
  lossless: true,
  nearLossless: true
})

should be considered valid. I will add a test for the same, that when both lossless and nearLossless are provided, nearLossless should kick in.

@coveralls
Copy link

coveralls commented Jan 19, 2017

Coverage Status

Coverage increased (+0.007%) to 99.497% when pulling 0ac8a6e on rnanwani:feature-advanced-webp-options into 815d076 on lovell:master.

@lovell lovell merged commit a1b8efe into lovell:master Jan 19, 2017
@lovell
Copy link
Owner

lovell commented Jan 19, 2017

Fantastic, thank you very much for this Rahul.

@lovell lovell added this to the v0.17.2 milestone Jan 19, 2017
lovell added a commit that referenced this pull request Jan 22, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants