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

RGB is being ignored in sample() #1

Closed
eleweek opened this issue Sep 3, 2019 · 1 comment
Closed

RGB is being ignored in sample() #1

eleweek opened this issue Sep 3, 2019 · 1 comment

Comments

@eleweek
Copy link

eleweek commented Sep 3, 2019

Thanks for the library, it works great for computing a dominant color in the image. The results are great for our purposes.

However, I noticed that RGB components are being ignored and only H, S and M are taking into account.

 ((img.data[i] & mask) << shiftR) +
 ((img.data[i + 1] & mask) << shiftG) +
((img.data[i + 2] & mask << shiftB));

This evaluates to 0, because shiftR. shiftG and shiftB are all negative:

var shiftR:number = -lowBits + 2 * topBits;
var shiftG:number = -lowBits + topBits;
var shiftB:number = -lowBits;

Just check 42 << -1 or 42 >> -1

There are two ways to fix this:

  1. Either get rid of negative bitshifts. This leads to different palettes with more similar colors.
  2. Drop RGB from the space entirely. This should bring the memory consumption to 1KB, while keeping the results the same.

I'll let you decide what do with this.

darosh added a commit that referenced this issue Sep 3, 2019
fixing #1 and #2, updating build toolchain and dependencies
@darosh
Copy link
Owner

darosh commented Sep 3, 2019

@eleweek Thanks a lot! I dropped the RGB completely.

@darosh darosh closed this as completed Sep 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants