1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 module PortablePixmap where 99 100 data PixMap = Pixmap Integer Integer Int [(Int,Int,Int)] 101 102 createPixmap::Integer -> Integer -> Int -> [(Int,Int,Int)] -> PixMap 103 createPixmap width height max colours = Pixmap width height max colours 104 105 instance Show PixMap where 106 showsPrec prec (Pixmap x y z rgbs) = showHeader x y z . showRGB rgbs 107 108 109 showHeader::Integer -> Integer -> Int -> ShowS 110 showHeader x y z = showString "P6\n" . showBanner . 111 shows x . showReturn . 112 shows y . showReturn . 113 shows z . showReturn 114 115 showRGB::[(Int,Int,Int)] -> ShowS 116 showRGB [] = id 117 showRGB ((r,g,b):rest) = showChar (toEnum r) . 118 showChar (toEnum g) . 119 showChar (toEnum b) . 120 showRGB rest 121 122 showSpace = showChar ' ' 123 showReturn = showChar '\n' 124 125 showBanner = showString "# Portable pixmap created by Haskell Program :\n" . 126 showString "#\tPortablePixmap.lhs (Jon.Hill 28/5/92)\n" 127