Skip to content
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

tests/unittests: test black corner case for color_rgb2hsv() #9940

Merged
merged 1 commit into from
Sep 27, 2019

Conversation

miri64
Copy link
Member

@miri64 miri64 commented Sep 15, 2018

Contribution description

Tests a (currently undocumented) behavior of color_rgb2hsv(), that a
black RGB value (all zero) causes the HSV value to be all zero.

Testing procedure

Run the unittests for color (make -C tests/unittests tests-color test). With current master they will fail, but #9939 fixes them.

Issues/PRs references

Requires #9939 for the test to succeed.

@miri64 miri64 added Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Sep 15, 2018
Copy link
Member

@jnohlgard jnohlgard left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know about the HSV(0,0,0), but the float comparison is flaky. Do the hue and saturation values matter when it is all black or all white?
This is not my area of expertise, but it seems kind of irrelevant to compare the hue of black.

tests/unittests/tests-color/tests-color.c Outdated Show resolved Hide resolved
@pekkanikander
Copy link
Contributor

Mostly FYI in the case someone is interested. I converted the HSV data structures partially into fixed point, since I suspected that floats could have caused instability. The result is in this commit:

AaltoNEPPI@7389247

It is not ready to land, but maybe someone wants to pick it up or have a look at it. I am not planning to continue with it; if anyone feels like grabbing, please go ahead.

@miri64
Copy link
Member Author

miri64 commented Mar 26, 2019

@gebart I adapted the PR according to @pekkanikander's proposal. Can you have another look?

@miri64
Copy link
Member Author

miri64 commented Sep 10, 2019

@kaspar030 could you maybe have a look at this :-/?

@miri64
Copy link
Member Author

miri64 commented Sep 26, 2019

@benpicco you want to maybe have a look at this 😁?

@benpicco
Copy link
Contributor

It should suffice to test if hsv.v is within epsilon of 0.

Screenshot at 2019-09-26 22-59-34

hsv.h = 0 would be red anway.

@miri64
Copy link
Member Author

miri64 commented Sep 26, 2019

True, but that doesn't test the case this PR was originally introduced for: #9939

@benpicco
Copy link
Contributor

Well technically they could be any random value…
hsv.s = 0 makes sense to stay on the black - white spectrum, but hue should be truly irrelevant.

Maybe someone comes up with a better implementation where it's left uninitialized, that would still be valid.

@miri64
Copy link
Member Author

miri64 commented Sep 27, 2019

Well technically they could be any random value…
hsv.s = 0 makes sense to stay on the black - white spectrum, but hue should be truly irrelevant.

Maybe someone comes up with a better implementation where it's left uninitialized, that would still be valid.

so what are you asking?

@benpicco
Copy link
Contributor

I'd remove the test for hsv.h == 0 since it's value is undefined in this case.

@miri64
Copy link
Member Author

miri64 commented Sep 27, 2019

Done

@benpicco
Copy link
Contributor

Looks good, please squash!

Copy link
Contributor

@benpicco benpicco left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For black, Value must be 0, Saturation can be 0 and Hue is not defined.
This test ensures that.

Tests a (currently undocumented) behavior of `color_rgb2hsv()`, that a
black RGB value (all zero) causes the HSV value to be all zero.
@miri64
Copy link
Member Author

miri64 commented Sep 27, 2019

Squashed

@miri64
Copy link
Member Author

miri64 commented Sep 27, 2019

I believe @gebart's comments were addressed.

@benpicco
Copy link
Contributor

tbh, comparing a float with 0 to test if it's 0 should always be fine.

@benpicco benpicco dismissed jnohlgard’s stale review September 27, 2019 12:58

comment has been addressed.

@miri64 miri64 merged commit aa84406 into RIOT-OS:master Sep 27, 2019
@miri64 miri64 deleted the tests/enh/rgb2hsv-black branch September 27, 2019 13:02
@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 29, 2019
bors bot added a commit that referenced this pull request Jun 5, 2023
19693: sys/color: extend unittest and fix module r=kfessel a=kfessel

### Contribution description

this extends the unittest for sys_color testing more colors 

### Testing procedure

```
RIOT_tree/tests/unittests$ make tests-color test
```
will fail since our `rgb2hsv` implementation is wrong (or is using an other colorspace than hsv2rgb (without documenting))

the new `hsv2rgb` test will succeed

### Issues/PRs references

#19614  was the reason i had a look at this 

#1315 added the rgb2hsv and hsv2rgb function

#9940 added the test for black special case

https://www.vagrearg.org/content/hsvrgb << some optimization for that function (avoiding float)


Co-authored-by: Karl Fessel <[email protected]>
bors bot added a commit that referenced this pull request Jun 5, 2023
19378: sys: add common imath module mv isin() form test/driver_dac_dds r=kfessel a=benpicco



19693: sys/color: extend unittest and fix module r=kfessel a=kfessel

### Contribution description

this extends the unittest for sys_color testing more colors 

### Testing procedure

```
RIOT_tree/tests/unittests$ make tests-color test
```
will fail since our `rgb2hsv` implementation is wrong (or is using an other colorspace than hsv2rgb (without documenting))

the new `hsv2rgb` test will succeed

### Issues/PRs references

#19614  was the reason i had a look at this 

#1315 added the rgb2hsv and hsv2rgb function

#9940 added the test for black special case

https://www.vagrearg.org/content/hsvrgb << some optimization for that function (avoiding float)


Co-authored-by: Benjamin Valentin <[email protected]>
Co-authored-by: Karl Fessel <[email protected]>
bors bot added a commit that referenced this pull request Jun 5, 2023
19378: sys: add common imath module mv isin() form test/driver_dac_dds r=maribu a=benpicco



19693: sys/color: extend unittest and fix module r=kfessel a=kfessel

### Contribution description

this extends the unittest for sys_color testing more colors 

### Testing procedure

```
RIOT_tree/tests/unittests$ make tests-color test
```
will fail since our `rgb2hsv` implementation is wrong (or is using an other colorspace than hsv2rgb (without documenting))

the new `hsv2rgb` test will succeed

### Issues/PRs references

#19614  was the reason i had a look at this 

#1315 added the rgb2hsv and hsv2rgb function

#9940 added the test for black special case

https://www.vagrearg.org/content/hsvrgb << some optimization for that function (avoiding float)


Co-authored-by: Benjamin Valentin <[email protected]>
Co-authored-by: Karl Fessel <[email protected]>
bors bot added a commit that referenced this pull request Jun 5, 2023
19693: sys/color: extend unittest and fix module r=kfessel a=kfessel

### Contribution description

this extends the unittest for sys_color testing more colors 

### Testing procedure

```
RIOT_tree/tests/unittests$ make tests-color test
```
will fail since our `rgb2hsv` implementation is wrong (or is using an other colorspace than hsv2rgb (without documenting))

the new `hsv2rgb` test will succeed

### Issues/PRs references

#19614  was the reason i had a look at this 

#1315 added the rgb2hsv and hsv2rgb function

#9940 added the test for black special case

https://www.vagrearg.org/content/hsvrgb << some optimization for that function (avoiding float)


Co-authored-by: Karl Fessel <[email protected]>
bors bot added a commit that referenced this pull request Jun 6, 2023
19693: sys/color: extend unittest and fix module r=maribu a=kfessel

### Contribution description

this extends the unittest for sys_color testing more colors 

### Testing procedure

```
RIOT_tree/tests/unittests$ make tests-color test
```
will fail since our `rgb2hsv` implementation is wrong (or is using an other colorspace than hsv2rgb (without documenting))

the new `hsv2rgb` test will succeed

### Issues/PRs references

#19614  was the reason i had a look at this 

#1315 added the rgb2hsv and hsv2rgb function

#9940 added the test for black special case

https://www.vagrearg.org/content/hsvrgb << some optimization for that function (avoiding float)


Co-authored-by: Karl Fessel <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants