Skip to content

Adjusting the brightness and contrast of an image #430

Answered by postspectacular
crofty asked this question in Q&A
Discussion options

You must be logged in to vote

Hi & welcome @crofty!

The best way to do these kind of matrix-based color transformations is to use a floating point pixel buffer rather than int's and also to operate on the underlying typed arrays directly (so avoiding the overhead of .getAt() and .setAt())...

I'd already started preparing an example to illustrate this a while ago, but I just now updated/finished it and you can find it here:

https://demo.thi.ng/umbrella/pixel-colormatrix/

Source code:
https://github.com/thi-ng/umbrella/blob/develop/examples/pixel-colormatrix/src/index.ts

I hope the comments in the source are sufficient to explain the overall approach. If not, then please get back to me here...

Hope that helps!

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@crofty
Comment options

@postspectacular
Comment options

Answer selected by crofty
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants