Twinside / Juicy.Pixels

Haskell library to load & save pictures

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Uniform quantization of GIF images is broken

william42 opened this issue · comments

The following code:

module Main where

import Codec.Picture
import Codec.Picture.Gif
import Codec.Picture.ColorQuant

imagePal :: (Image Pixel8,Palette)
imagePal = uniformize $ generateImage renderer 256 256
  where renderer x y = PixelRGB8 (fromIntegral x) (fromIntegral y) 128

gradientPaletteOptions = PaletteOptions
  { paletteCreationMethod = Uniform,
    enableImageDithering = False,
    paletteColorCount = 256 }

uniformize = palettize gradientPaletteOptions



main :: IO ()
main = case writeGifImageWithPalette "grad.gif" im pal of
         Left err -> putStrLn err
         Right action -> action >> putStrLn "done!"
    where (im,pal) = imagePal

should produce a rather simplistic gradient. Instead, it produces this incorrect grid. My examination of the source code suggests that the quantization you're doing is using a slightly wrong binary operation, with some 255-dr and such that should be 256-dr so that the bitmask actually clears off the lower bits.

I'll upload the fixed version to hackage during next week

Cool. Inform me when you do.

Up on hackage