Skip to content

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

Merged
lovell merged 5 commits into
lovell:masterfrom
rn4391:feature-advanced-webp-options
Jan 19, 2017
Merged

lovell merged 5 commits into
lovell:masterfrom
rn4391:feature-advanced-webp-options

Conversation

@rn4391

@rn4391 rn4391 commented Jan 17, 2017

Copy link
Copy Markdown

No description provided.

@lovell lovell left a comment

Copy link
Copy Markdown
Owner

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.

Comment thread lib/constructor.js
webpQuality: 80,
webpAlphaQuality: 100,
webpLossless: false,
tiffQuality: 80,

Copy link
Copy Markdown
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
Copy Markdown
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.

Comment thread lib/output.js
* @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
Copy Markdown
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?

@rn4391 rn4391 Jan 18, 2017 •

Copy link
Copy Markdown
Author

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
Copy Markdown
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?

Comment thread src/pipeline.cc Outdated
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
Copy Markdown
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
Copy Markdown
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

Comment thread test/unit/io.js Outdated
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
Copy Markdown
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
Copy Markdown
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

Comment thread test/unit/io.js
});
});

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

Copy link
Copy Markdown
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
Copy Markdown
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

rn4391 commented Jan 18, 2017

Copy link
Copy Markdown
Author

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

Comment thread docs/api-operation.md Outdated
sharp(input)
.resize(140)
.background({r: 0, g: 0, b: 0, a: 0})
.background({r: 0, g: 0, b: 0, alpha: 0})

Copy link
Copy Markdown
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.

Comment thread lib/output.js
* @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
Copy Markdown
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

rn4391 commented Jan 19, 2017 •

Copy link
Copy Markdown
Author

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

coveralls commented Jan 19, 2017 •

Copy link
Copy Markdown

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

lovell commented Jan 19, 2017

Copy link
Copy Markdown
Owner

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