packages feed

definitive-graphics (empty) → 1.0

raw patch · 4 files changed

+155/−0 lines, 4 filesdep +JuicyPixelsdep +arraydep +base

Dependencies added: JuicyPixels, array, base, binary, bytestring, containers, cpu, deepseq, definitive-base, definitive-parser, mtl, primitive, stb-truetype, transformers, utf8-string, vector, zlib

Files

+ Data/Font.hs view
@@ -0,0 +1,31 @@+{-# LANGUAGE TupleSections, GeneralizedNewtypeDeriving #-}+module Data.Font (+  Font,+  font,glyph+  ) where++import Algebra+import Data.Raster+import Graphics.Rendering.TrueType.STB hiding (Font,findGlyph)+import qualified Graphics.Rendering.TrueType.STB as TT+import Control.Exception (SomeException)+import Data.Vector.Storable (unsafeFromForeignPtr0)+import Codec.Picture++newtype Font = Font [TT.Font]+             deriving (Semigroup,Monoid)+                   +font :: Chunk -> Either SomeException Font+font s = by thunk $ catch (return . Left) $ Right . Font <$> do+  let tt = TrueType s+  enumerateFonts tt >>= traverse (initFont tt)++glyph :: Font -> (Char,Float) -> Maybe Raster+glyph (Font fs) = \(c,sc) -> foldMap (charBM c sc) fs+  where charBM c sc f = fg f c <&> \g -> bm  f g (scl sc,scl sc) & bitmap2Image+          where scl = scaleForPixelHeight (getFontVerticalMetrics f^.thunk)+        fg = map2 (by thunk) TT.findGlyph+        bm = map3 (fst.by thunk) TT.newGlyphBitmap+bitmap2Image :: Bitmap -> Raster+bitmap2Image (Bitmap (w,h) p) = ImageY8 (Image w h (unsafeFromForeignPtr0 p (w*h)))^.raster+
+ Data/Raster.hs view
@@ -0,0 +1,36 @@+{-# LANGUAGE TypeOperators #-}+module Data.Raster (+  Raster,PNG,BMP,JPG,bmp,jpg,png,raster,+  ) where++import Algebra+import Data.Serialize+import Codec.Picture++data Raster = Raster DynamicImage+newtype JPG = JPG Raster+newtype PNG = PNG Raster+newtype BMP = BMP Raster++jpg :: Raster:<->:JPG+jpg = iso JPG (\(JPG r) -> r)+bmp :: Raster:<->:BMP+bmp = iso BMP (\(BMP r) -> r)+png :: Raster:<->:PNG+png = iso PNG (\(PNG r) -> r)++instance Serializable JPG where+  encode (yb (raster.jpg) -> ImageYCbCr8 i) = encodeJpeg i^.bytesBuilder+  encode _ = error "Unsupported image format for JPeg encoding"+  serializable = convert.decodeJpeg.by chunk^.mapping (mapping (raster.jpg.pureWriter)).parser+instance Serializable PNG where+  encode (yb (raster.png) -> i) = (error<|>by bytesBuilder) (encodeDynamicPng i)+  serializable = convert.decodePng.by chunk^.mapping (mapping (raster.png.pureWriter)).parser+instance Serializable BMP where+  encode (yb (raster.bmp) -> i) = (error<|>by bytesBuilder) (encodeDynamicBitmap i)+  serializable = convert.decodeBitmap.by chunk^.mapping (mapping (raster.bmp.pureWriter)).parser+     +raster :: DynamicImage:<->:Raster+raster = iso Raster (\(Raster i) -> i)++
+ LICENSE view
@@ -0,0 +1,69 @@+Bill and Ted's Public License+=============================++Everyone is permitted to copy and distribute verbatim or modified+copies of this license document, and changing it is allowed as long as+the name of the license is changed.++PREAMBLE+--------++The “Greater Lunduke License” is inspired, in part, by the wisdom of+the Two Great Ones, Bill S. Preston, Esq. and Ted “Theodore” Logan.+Namely that we should all “be excellent to each other”, that being+“bogus” is “most non-triumphant” and that all dudes should “party on”.++This license applies those concepts in such a way that it is+applicable to all forms of content, including, but not limited to:+software, books, music, movies and various works of art.++TERMS AND CONDITIONS+--------------------++### 1. Be Excellent To Each Other.++The consumer of this work is granted the right to utilize this work in+conjunction with any mechanism that is capable of utilizing it, in the+form supplied by the content creator, without limitation as to+specific hardware or software.++The consumer of this work may make copies of this work (physical or+otherwise) for backup purposes.++The consumer of this work may lend this work to another individual+provided that the following two conditions are met :+  +  1. the lender no longer utilizes or possesses the work+  2. the work is not presently lent to another individual++The consumer of this work may sell this work to another individual+provided that the following two conditions are met :++  1. the seller no longer utilizes or possesses the work +  2. once the work is sold, the seller relinquishes all rights and+      copies of the work to the buyer.++### 2. Don’t Be Bogus.++The consumer of this work shall not redistribute modified, or+unmodified, copies of this work without explicit written permission+from the creator of this work.  The only exceptions allowed to this+rule are the provisions outlined in section 1 of this license++The consumer of this work shall not hold the creator of this work+liable for anything the consumer does, or does not, do, or the results+of utilizing this work.++### 3. Party On, Dudes!++The creator of this work provides the work in a form that contains no+mechanism to disable the utilization of the work after a specific+date, period of time or number of uses.++If additional works, which are created and wholly owned by the work’s+creator, are required to utilize this work, those additional works+must also be made available to the consumer so long as the following+conditions are met :+  +  1. doing so is possible+  2. doing so does not cause harm to the creator of the work.
+ definitive-graphics.cabal view
@@ -0,0 +1,19 @@+name:          definitive-graphics+version:       1.0++synopsis:      A definitive package allowing you to open windows, read image files and render text to be displayed or saved+description:   +author:        Marc Coiffier+maintainer:    marc.coiffier@gmail.com+license:       OtherLicense+license-file:  LICENSE++build-type:    Simple+cabal-version: >=1.10++library+  exposed-modules: Data.Raster Data.Font+  build-depends: base (== 4.6.*), definitive-base (== 1.0.*), containers (== 0.5.*), deepseq (== 1.3.*), array (== 0.5.*), bytestring (== 0.10.*), definitive-parser (== 1.0.*), vector (== 0.10.*), primitive (== 0.5.*), cpu (== 0.1.*), utf8-string (== 0.3.*), JuicyPixels (== 3.1.*), binary (== 0.7.*), mtl (== 2.1.*), transformers (== 0.3.*), zlib (== 0.5.*), stb-truetype (== 0.1.*)+  default-extensions: RebindableSyntax NoMonomorphismRestriction TypeOperators ViewPatterns FlexibleInstances MultiParamTypeClasses+  ghc-options: -W -threaded+  default-language: Haskell2010