-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Linear transform #1024
Linear transform #1024
Changes from 5 commits
8a49988
b31d064
773fd1e
30986c3
d417788
4f07488
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -39,6 +39,7 @@ | |
"Guy Maliar <[email protected]>", | ||
"Nicolas Coden <[email protected]>", | ||
"Matt Parrish <[email protected]>", | ||
"Marcel Bretschneider <[email protected]>" | ||
"Matthew McEachen <[email protected]>", | ||
"Jarda Kotěšovec <[email protected]>", | ||
"Kenric D'Souza <[email protected]>", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -79,6 +79,8 @@ struct PipelineBaton { | |
int threshold; | ||
bool thresholdGrayscale; | ||
int trimTolerance; | ||
double linearA; | ||
double linearB; | ||
double gamma; | ||
bool greyscale; | ||
bool normalise; | ||
|
@@ -160,6 +162,8 @@ struct PipelineBaton { | |
threshold(0), | ||
thresholdGrayscale(true), | ||
trimTolerance(0), | ||
linearA(1.0), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just spotted that these fields need to be initialised in the same order as they are declared to avoid a compiler warning.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like to change this - but how do i actually see these compiler warnings. I use npm install to build a new release (unfortunately under windows) and there i can't see these warnings. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for updating - MSVC doesn't appear to warn about this but gcc and clang do. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
linearB(0.0), | ||
gamma(0.0), | ||
greyscale(false), | ||
normalise(false), | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
'use strict'; | ||
|
||
const sharp = require('../../'); | ||
const fixtures = require('../fixtures'); | ||
|
||
const assert = require('assert'); | ||
|
||
describe('Linear adjustment', function () { | ||
const blackPoint = 70; | ||
const whitePoint = 203; | ||
const a = 255 / (whitePoint - blackPoint); | ||
const b = -blackPoint * a; | ||
|
||
it('applies linear levels adjustment w/o alpha ch', function (done) { | ||
sharp(fixtures.inputJpgWithLowContrast) | ||
.linear(a, b) | ||
.toBuffer(function (err, data, info) { | ||
if (err) throw err; | ||
fixtures.assertSimilar(fixtures.expected('low-contrast-linear.jpg'), data, done); | ||
}); | ||
}); | ||
|
||
it('applies slope level adjustment w/o alpha ch', function (done) { | ||
sharp(fixtures.inputJpgWithLowContrast) | ||
.linear(a) | ||
.toBuffer(function (err, data, info) { | ||
if (err) throw err; | ||
fixtures.assertSimilar(fixtures.expected('low-contrast-slope.jpg'), data, done); | ||
}); | ||
}); | ||
|
||
it('applies offset level adjustment w/o alpha ch', function (done) { | ||
sharp(fixtures.inputJpgWithLowContrast) | ||
.linear(null, b) | ||
.toBuffer(function (err, data, info) { | ||
if (err) throw err; | ||
fixtures.assertSimilar(fixtures.expected('low-contrast-offset.jpg'), data, done); | ||
}); | ||
}); | ||
|
||
it('applies linear levels adjustment w alpha ch', function (done) { | ||
sharp(fixtures.inputPngOverlayLayer1) | ||
.linear(a, b) | ||
.toBuffer(function (err, data, info) { | ||
if (err) throw err; | ||
fixtures.assertSimilar(fixtures.expected('alpha-layer-1-fill-linear.png'), data, done); | ||
}); | ||
}); | ||
|
||
it('applies slope level adjustment w alpha ch', function (done) { | ||
sharp(fixtures.inputPngOverlayLayer1) | ||
.linear(a) | ||
.toBuffer(function (err, data, info) { | ||
if (err) throw err; | ||
fixtures.assertSimilar(fixtures.expected('alpha-layer-1-fill-slope.png'), data, done); | ||
}); | ||
}); | ||
|
||
it('applies offset level adjustment w alpha ch', function (done) { | ||
sharp(fixtures.inputPngOverlayLayer1) | ||
.linear(null, b) | ||
.toBuffer(function (err, data, info) { | ||
if (err) throw err; | ||
fixtures.assertSimilar(fixtures.expected('alpha-layer-1-fill-offset.png'), data, done); | ||
}); | ||
}); | ||
|
||
it('Invalid linear arguments', function () { | ||
assert.throws(function () { | ||
sharp(fixtures.inputPngOverlayLayer1) | ||
.linear('foo'); | ||
}); | ||
|
||
assert.throws(function () { | ||
sharp(fixtures.inputPngOverlayLayer1) | ||
.linear(undefined, { 'bar': 'baz' }); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think a trailing comma is required here.