Skip to content

Bug in ColorFromPalette for CHSVPalette16 and CHSVPalette32 #602

Closed

Description

@schollman

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.

Activity

  1. focalintent commented on May 7, 2018

    @focalintent
    Contributor

    @kriegsman - thoughts?

  2. kriegsman commented on May 7, 2018

    @kriegsman
    Member

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

  3. kriegsman commented on May 17, 2018

    @kriegsman
    Member

    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.

  4. added a commit that references this issue on May 17, 2018
    dbd2d8b
  5. added a commit that references this issue on Feb 29, 2024
    ade8254
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions