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

Bug in ColorFromPalette for CHSVPalette16 and CHSVPalette32 #602

Closed
schollman opened this Issue Apr 21, 2018 · 3 comments

Comments

Projects
None yet
3 participants
@schollman

schollman commented Apr 21, 2018

Hi,

I think there is a bug in ColorFromPalette when the hues decrease in value (go backwards)
The following code does the hue interpolation.

uint8_t deltaHue = (uint8_t)(hue2 - hue1);
if( deltaHue & 0x80 ) {
// go backwards
hue1 -= scale8( 255 - deltaHue, f2);
} else {
// go forwards
hue1 += scale8( deltaHue, f2);
}

The first parameter to scale8 in the backwards case should be equal to the abs(deltaHue) but as coded is equal to abs(deltaHue) - 1. As a result, the value of hue2 + 1 is never returned.

For a concrete example, imagine the two cases

  1. hue1 = 0, hue2 = 10
    deltaHue = 10
  2. hue1 = 10, hue2 = 0
    deltaHue = -10 (246)

In 1), the forward case, the first parameter to scale8 will be 10, returning values in the range 0 to 9 as desired.

In 2), the backwards case, the first parameter to scale8 will be 9 (255-246), returning values in the range 0 to 8, one short of desired.

@focalintent

This comment has been minimized.

Member

focalintent commented May 7, 2018

@kriegsman - thoughts?

@kriegsman

This comment has been minimized.

Contributor

kriegsman commented May 7, 2018

Yep, I think this is a bug; I'll get on it.

@kriegsman kriegsman closed this in ade8254 May 17, 2018

@kriegsman

This comment has been minimized.

Contributor

kriegsman commented May 17, 2018

Thanks for the clear bug report; I believe that the change that I just committed helps solve this problem. Please do let me know if it solves it for you, or if you're seeing further issues, and we'll reopen the ticket if needed. Thanks again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment