Skip to content

Commit

Permalink
Premultiply alpha in shm example
Browse files Browse the repository at this point in the history
  • Loading branch information
queezle42 committed Jul 27, 2024
1 parent 64d3832 commit 75f0b60
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions examples/ShmClient.hs
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,13 @@ mkPosition dimensions pixelX pixelY = Position { dimensions, pixelX, pixelY, u,
y = fromIntegral (pixelY - (height' `div` 2)) / fromIntegral innerRadius

rgb :: Double -> Double -> Double -> PixelRGBA8
rgb r g b = PixelRGBA8 (toWord r) (toWord g) (toWord b) 0
where
toWord :: Double -> Word8
toWord = truncate . (* 255) . max 0 . min 1
rgb r g b = PixelRGBA8 (toWord r) (toWord g) (toWord b) (toWord 1)

toWord :: Double -> Word8
toWord = truncate . (* 255) . max 0 . min 1

rgba :: Double -> Double -> Double -> Double -> PixelRGBA8
rgba r g b a = PixelRGBA8 (toWord r) (toWord g) (toWord b) (toWord a)
where
toWord :: Double -> Word8
toWord = truncate . (* 255) . max 0 . min 1
rgba r g b a = PixelRGBA8 (toWord (r * a)) (toWord (g * a)) (toWord (b * a)) (toWord a)

gradient :: Position -> PixelRGBA8
gradient p = rgb (u p) 0 (v p)
Expand Down

0 comments on commit 75f0b60

Please sign in to comment.