gloss-devil 0.1 → 0.2
raw patch · 2 files changed
+36/−52 lines, 2 filesdep −repa-bytestringdep ~repa
Dependencies removed: repa-bytestring
Dependency ranges changed: repa
Files
- Graphics/Gloss/DevIL.hs +33/−11
- gloss-devil.cabal +3/−41
Graphics/Gloss/DevIL.hs view
@@ -1,30 +1,52 @@ module Graphics.Gloss.DevIL ( loadDevILPicture- , repaToPicture+ , imageToPicture , readRepaImage ) where import Data.Array.Repa as R import Graphics.Gloss-import qualified Data.Array.Repa.ByteString as RB+import qualified Data.Array.Repa.Repr.ByteString as RB+import qualified Data.Array.Repa.Repr.ForeignPtr as RF import qualified Data.Array.Repa.IO.DevIL as RD import qualified Data.ByteString as B import Data.Word import Control.Monad+import Data.ByteString.Internal as BI -- |Load picture using 'Codec-Image-DevIL' and convert it a bitmap for display by 'Gloss' loadDevILPicture :: FilePath -> IO (Int, Int, Picture)-loadDevILPicture = liftM (repaToPicture False) . readRepaImage+loadDevILPicture = liftM (imageToPicture False) . readRepaImage --- |@repaToPicture cacheMeFlag array@ will convert a 'Repa' RGBA array to a tuple of--- the number of columns, rows and a bitmap for use with 'Gloss'.-repaToPicture :: Bool -> Array DIM3 Word8 -> (Int, Int, Picture)-repaToPicture b arr = (col, row, bitmapOfByteString row col (toBS arr) b)+-- |@repaToPicture cacheMeFlag array@ will convert a 'Repa' RGBA array to a+-- tuple of the number of columns, rows and a bitmap for use with 'Gloss'.+imageToPicture :: Bool -> RD.Image -> (Int, Int, Picture)+imageToPicture b (RD.Grey arr) = img2d b arr+imageToPicture b (RD.RGBA arr) = img3d b arr+imageToPicture b (RD.RGB arr) = img3d b arr++img2d :: Bool -> Array RF.F DIM2 Word8 -> (Int, Int, Picture)+img2d b arr0 = (oldCol, oldRow, bitmapOfByteString oldRow oldCol (toBS arr0) b) where- e@(Z :. col :. row :. chan) = extent arr- order (Z :. oldCol :. oldRow :. oldChan) = Z :. oldCol :. oldRow :. chan - oldChan - 1- toBS = RB.toByteString . backpermute e order+ e@(Z :. oldCol :. oldRow) = extent arr0+ toBS arr =+ let arr2 = backpermute e order arr+ order (Z :. col :. row) =+ Z :. col :. row+ fp = RF.toForeignPtr (R.computeS arr2)+ in BI.fromForeignPtr fp 0 (oldCol * oldRow) +img3d :: Bool -> Array RF.F DIM3 Word8 -> (Int, Int, Picture)+img3d b arr0 = (oldCol, oldRow, bitmapOfByteString oldRow oldCol (toBS arr0) b)+ where+ e@(Z :. oldCol :. oldRow :. oldChan) = extent arr0+ toBS arr =+ let arr2 = backpermute e order arr+ order (Z :. col :. row :. chan) =+ Z :. col :. row :. oldChan - chan - 1+ fp = RF.toForeignPtr (R.computeS arr2)+ in BI.fromForeignPtr fp 0 (oldCol * oldRow * oldChan)+ -- |Read in a file into a repa array (using the 'repa-devil' package)-readRepaImage :: FilePath -> IO (Array DIM3 Word8)+readRepaImage :: FilePath -> IO RD.Image readRepaImage = RD.runIL . RD.readImage
gloss-devil.cabal view
@@ -1,59 +1,21 @@--- gloss-png.cabal auto-generated by cabal init. For additional--- options, see--- http://www.haskell.org/cabal/release/cabal-latest/doc/users-guide/authors.html#pkg-descr.--- The name of the package. Name: gloss-devil---- The package version. See the Haskell package versioning policy--- (http://www.haskell.org/haskellwiki/Package_versioning_policy) for--- standards guiding when and how versions should be incremented.-Version: 0.1---- A short (one-line) description of the package.+Version: 0.2 Synopsis: Display images in Gloss using libdevil for decoding---- A longer description of the package. -- Description: ---- The license under which the package is released. License: BSD3---- The file containing the license text. License-file: LICENSE---- The package author(s). Author: Thomas M. DuBuisson---- An email address to which users can send suggestions, bug reports,--- and patches. Maintainer: Thomas.DuBuisson@gmail.com---- A copyright notice. -- Copyright: - Category: Graphics- Build-type: Simple---- Extra files to be distributed with the package, such as examples or--- a README. -- Extra-source-files: ---- Constraint on the version of Cabal needed to build this package. Cabal-version: >=1.6 - Library- -- Modules exported by the library. Exposed-modules: Graphics.Gloss.DevIL- - -- Packages needed in order to build this package.- Build-depends: base >= 4 && < 5, gloss >= 1.6, repa == 2.2.*- , repa-bytestring, repa-devil, bytestring- - -- Modules not exported by this package.+ Build-depends: base >= 4 && < 5, gloss >= 1.6, repa >= 3.0+ , repa-devil, bytestring -- Other-modules: - - -- Extra tools (e.g. alex, hsc2hs, ...) needed to build the source. -- Build-tools: