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

Bug in isColorCountBelow in ColorQuant.hs #40

Closed
jeffreyrosenbluth opened this issue Jan 23, 2014 · 2 comments
Closed

Bug in isColorCountBelow in ColorQuant.hs #40

jeffreyrosenbluth opened this issue Jan 23, 2014 · 2 comments
Labels

Comments

@jeffreyrosenbluth
Copy link
Collaborator

In the code below count should only be incremented when a new color is added to the
set, but we are incrementing every time through the loop, which means we almost always return False. This actually causes problems when making GIFs with diagrams since they often have less than 256 colors. A fix is below which i think is fine since Set.size is O(1)

isColorCountBelow :: Int -> Image PixelRGB8 -> (Set.Set PixelRGB8, Bool)
isColorCountBelow maxColorCount img = go 0 0 Set.empty
  where rawData = imageData img
        maxIndex = VS.length rawData

        go !count !idx !allColors
            | count > maxColorCount = (Set.empty, False)
            | idx >= maxIndex - 2 = (allColors, True)
            | otherwise = go (count + 1) (idx + 3)
                        $ Set.insert px allColors
                where px = unsafePixelAt rawData idx 
| otherwise = go ((Set.size allColors) + 1) (idx + 3)
                        $ Set.insert px allColors
                where px = unsafePixelAt rawData idx
@Twinside
Copy link
Owner

I've also bumped the hackage version ( http://hackage.haskell.org/package/JuicyPixels-3.1.3.1 ), so the fix is cabal update ready

@jeffreyrosenbluth
Copy link
Collaborator Author

Great thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants