Adjusting the brightness and contrast of an image #430
-
Hello 👋, Currently I'm looping through all the pixels in the buffer and doing something like:
It seems to work but is very slow so I'm sure there must be a much better way of applying these transformations to an image? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
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 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: 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! |
Beta Was this translation helpful? Give feedback.
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!