Page MenuHome

Optimisation to rgb <-> hsv/l conversion
ClosedPublic

Authored by Kévin Dietrich (kevindietrich) on Jun 14 2014, 8:12 AM.

Details

Summary

Basically avoid redundant computations. Gives ~1-4% speedup in the compositor depending on the use case.

For more info see: http://lolengine.net/blog/2013/01/13/fast-rgb-to-hsv

Diff Detail

Repository
rB Blender

Event Timeline

Very nice work here! I'll check on the logic a bit more and commit.

source/blender/blenlib/intern/math_color.c
57

*picky*, prefer all lowercase names, also C is used for context.

59

should use fabsf

Kévin Dietrich (kevindietrich) updated this revision to Unknown Object (????).Jun 19 2014, 7:00 PM

Corrections according to Campbell's comments

minor tweaks

@Antonis Ryakiotakis (psy-fi) & @Kévin Dietrich (kevindietrich)

Suggest we have some comprehensive tests first in tests/gtests/blenlib/BLI_math_color_test.cc, basics are already there, but worth adding checks for corner cases too.

Quick testing here seems to be OK.

I'd also like to convert rgb to HSL calculation but that can be done later too.

Kévin Dietrich (kevindietrich) updated this revision to Unknown Object (????).Jun 22 2014, 12:33 PM

Update with Campbell's tweaks (forgot to remove cast to float...)

Hi guys,

Just to let you know that my hard drive decided to "retire" over the night, well, it's dead now... :/ At the moment I'm on a live session of Crunchbang that I managed to make work. And I've got some exams too, so I won't really be able to make further coding on this, at least for the upcoming week. But we have time.

As per the rgb_to_hsl calculation: I did try to convert it, similarly to the rgb_to_hsv, but somehow the hue always ended up being slightly off, generally by 180° (or 0.5 in the 0...1 range). I might give it another try with fresh eyes when my computer issue is resolved.

And for the tests: I haven't had the chance to look at how things are going there yet (and browsing the source on this here website is a PITA).

I took the time to reset my work space up. I also set up arcanist, which could be useful for the future. Will arc let me update this one ? Because I would like to convert Cycles' and GLSL's ones too (by making use of their branchless capabilities, perhaps OSL too, will check).

By going over the code I noticed there are rgb <-> hsv conversions in the fluid systems (dafuq) ?! I guess they can be removed ? See:
https://developer.blender.org/diffusion/B/browse/master/intern/smoke/intern/VEC3.h;98cb7ad237c4b727a679feeced7790bf716b5791$849
https://developer.blender.org/diffusion/B/browse/master/intern/elbeem/intern/ntl_vector3dim.h;98cb7ad237c4b727a679feeced7790bf716b5791$1027

I will probably hit you guys on IRC (when I have my IRC client setup and running) for the tests part, I'm a little confused as to how to operate for this kind of work (but it seems pretty much straight forward).

@Antonis Ryakiotakis (psy-fi), seems reasonable change. Shall you go ahead and commit?

Aaargh! Commited with arc land, but arc changed my amended commit message where I included who the author is :/. Sorry for that, I will surely avoid arc land in the future. And thanks for the patch!