sharp
sharp copied to clipboard
Vectorized linear function
@lovell This looked easy enough to implement, and adds some good value. This pull request is not really production quality and my knowledge of the code base is very limited. A few things to consider:
- do the additional variables make sense (linearVecA/linearVecB) or could linearA/linearB be both number & number[]?
- are there other functions that can be generalised in a similar fashion?
- probably needs a good test case :)
- unclear what the behaviour is (or should be) if the arrays are different lengths or if only one array is defined
Hi, thanks for the PR.
How about we switch the (internal) this.options
so linearA
and linearB
are always arrays, and if someone provides a single value (the current behaviour) we convert to a single element array.
.linear(a, b)
// would be equivalent to
.linear([a], [b])
// but now we would also support
.linear([a1, a2, a3], [b1, b2, b3])
This should make the C++ code path a bit simpler as it will only deal with arrays of doubles.
@lovell Great suggestion, I have implemented it. Added some fancy logic for dealing with the alpha channel that you may wish to review. Only outstanding thing is test cases, which I can hopefully make some progress on shortly.
Handling the multi-band expansion for linear() looked tricky in the context of sharp's colourspace handling.
@lovell Done, all yours.
Coverage remained the same at 100.0% when pulling 0c55d0eb3115034c6e969fbe0defd2cea6da928d on antonmarsden:main into dd56a9699eebcec0cbbcc9f6563e5dd6cf4066ad on lovell:eagle.
Please can you add unit test(s) to ensure all the new logic is fully-covered - see https://coveralls.io/builds/51160601
Landed via commit https://github.com/lovell/sharp/commit/74e3f73934df4fa8096fe87ce1b57b9cf0d50a5f - this will be in v0.31.0, thanks again for working on this.