packages feed

qr-imager-0.1.2.1: src/Data/QRCodes/Image.hs

-- | A few functions to deal with the image itself
module Data.QRCodes.Image where

import Data.Word (Word8)
import Codec.Picture.Types as T
import Prelude as P
import qualified Data.Vector.Storable as V

-- | Encode a png, given a matrix
encodePng :: [[Word8]] -> T.Image Word8
encodePng matrix = Image dim dim vector
    where dim    = P.length matrix
          vector = V.map ((*255) . swapWord) $ V.fromList $ P.concat matrix

-- | To help scale the image up
fattenList :: Int -> [a] -> [a]
fattenList i l = P.concat $ P.foldr ((:) . (P.replicate i)) [] l

swapWord :: Word8 -> Word8
swapWord 1 = 0
swapWord 0 = 1