accelerate-io-bmp (empty) → 0.1.0.0
raw patch · 6 files changed
+196/−0 lines, 6 filesdep +acceleratedep +accelerate-io-bytestringdep +basesetup-changed
Dependencies added: accelerate, accelerate-io-bytestring, base, bmp
Files
- CHANGELOG.md +12/−0
- LICENSE +23/−0
- README.md +25/−0
- Setup.hs +2/−0
- accelerate-io-bmp.cabal +51/−0
- src/Data/Array/Accelerate/IO/Codec/BMP.hs +83/−0
+ CHANGELOG.md view
@@ -0,0 +1,12 @@+# Change Log++Notable changes to the project will be documented in this file.++The format is based on [Keep a Changelog](http://keepachangelog.com/) and the+project adheres to the [Haskell Package Versioning+Policy (PVP)](https://pvp.haskell.org)++## [0.1.0.0] - 2020-08-26+### Changed+ * Split from the `accelerate-io` package+
+ LICENSE view
@@ -0,0 +1,23 @@+Copyright (c) [2007..2012] The Accelerate Team. All rights reserved.++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are met:+ * Redistributions of source code must retain the above copyright+ notice, this list of conditions and the following disclaimer.+ * Redistributions in binary form must reproduce the above copyright+ notice, this list of conditions and the following disclaimer in the+ documentation and/or other materials provided with the distribution.+ * Neither the names of the contributors nor of their affiliations may+ be used to endorse or promote products derived from this software+ without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY+EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE+DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDERS BE LIABLE FOR ANY+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES+(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;+LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND+ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS+SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ README.md view
@@ -0,0 +1,25 @@+<div align="center">+<img width="450" src="https://github.com/AccelerateHS/accelerate/raw/master/images/accelerate-logo-text-v.png?raw=true" alt="henlo, my name is Theia"/>++# Array conversion components for the Accelerate language++[](https://github.com/tmcdonell/accelerate-io/actions)+[](https://gitter.im/AccelerateHS/Lobby)+<br>+[](https://stackage.org/lts/package/accelerate-io)+[](https://stackage.org/nightly/package/accelerate-io)+[](https://hackage.haskell.org/package/accelerate-io)++</div>++Efficient conversion routines between Accelerate arrays and a range of data+formats.++For details on Accelerate, refer to the [main repository][GitHub].++Contributions and bug reports are welcome!<br>+Please feel free to contact me through [GitHub][GitHub] or [gitter.im][gitter.im].++ [GitHub]: https://github.com/AccelerateHS/accelerate+ [gitter.im]: https://gitter.im/AccelerateHS/Lobby+
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ accelerate-io-bmp.cabal view
@@ -0,0 +1,51 @@+name: accelerate-io-bmp+version: 0.1.0.0+cabal-version: >= 1.10+build-type: Simple++synopsis: Convert between Accelerate arrays and BMP images+Description:+ This package provides efficient conversion routines between Accelerate arrays+ and BMP images.+ .+ Refer to the main /Accelerate/ package for more information:+ <http://hackage.haskell.org/package/accelerate>++license: BSD3+license-file: LICENSE+author: The Accelerate Team+maintainer: Trevor L. McDonell <trevor.mcdonell@gmail.com>+homepage: https://github.com/AccelerateHS/accelerate-io#readme+bug-reports: https://github.com/AccelerateHS/accelerate-io/issues+category: Accelerate, Data++extra-source-files:+ README.md+ CHANGELOG.md++library+ build-depends:+ base >= 4.8 && < 5+ , accelerate >= 1.3+ , accelerate-io-bytestring >= 0.1+ , bmp >= 1.2++ exposed-modules:+ Data.Array.Accelerate.IO.Codec.BMP++ ghc-options:+ -O2+ -Wall+ -funbox-strict-fields++ ghc-prof-options:+ -fprof-auto++ hs-source-dirs: src+ default-language: Haskell2010++source-repository head+ type: git+ location: https://github.com/AccelerateHS/accelerate-io++-- vim: nospell
+ src/Data/Array/Accelerate/IO/Codec/BMP.hs view
@@ -0,0 +1,83 @@+{-# LANGUAGE CPP #-}+{-# LANGUAGE RecordWildCards #-}+{-# LANGUAGE TemplateHaskell #-}+-- |+-- Module : Data.Array.Accelerate.IO.Codec.BMP+-- Copyright : [2012..2020] The Accelerate Team+-- License : BSD3+--+-- Maintainer : Trevor L. McDonell <trevor.mcdonell@gmail.com>+-- Stability : experimental+-- Portability : non-portable (GHC extensions)+--+-- Read and write uncompressed 24 or 32-bit Windows BMP images into+-- a packed-word RGBA format. See the /colour-accelerate/ package for colour+-- representations and utilities such as packing and unpacking.+--++module Data.Array.Accelerate.IO.Codec.BMP (++ RGBA32,+ readImageFromBMP, writeImageToBMP,++) where++import Data.Word+import Codec.BMP++import Data.Array.Accelerate.IO.Data.ByteString+import Data.Array.Accelerate.Sugar.Array+import Data.Array.Accelerate.Sugar.Shape+++-- | Packed RGBA pixel data+--+type RGBA32 = Word32+++-- File IO ---------------------------------------------------------------------++-- | Read RGBA components from a BMP file.+--+readImageFromBMP :: FilePath -> IO (Either Error (Array DIM2 RGBA32))+readImageFromBMP file = do+ ebmp <- readBMP file+ case ebmp of+ Left err -> return $ Left err+ Right bmp -> do+ let (w,h) = bmpDimensions bmp+ bs = unpackBMPToRGBA32 bmp'+ arr = fromByteStrings (Z :. h :. w) bs+ --+ bmp' = bmp { bmpBitmapInfo = info' }+ info' = case bmpBitmapInfo bmp of+ InfoV3 i -> InfoV3 (info3 i)+ InfoV4 i -> InfoV4 (info4 i)+ InfoV5 i -> InfoV5 (info5 i)++ info3 BitmapInfoV3{..} = BitmapInfoV3 { dib3HeightFlipped = not dib3HeightFlipped, .. }+ info4 BitmapInfoV4{..} = BitmapInfoV4 { dib4InfoV3 = info3 dib4InfoV3, .. }+ info5 BitmapInfoV5{..} = BitmapInfoV5 { dib5InfoV4 = info4 dib5InfoV4, .. }+ --+ return $ Right arr+++-- | Write the image data to a file.+--+writeImageToBMP :: FilePath -> Array DIM2 RGBA32 -> IO ()+writeImageToBMP file rgba = writeBMP file bmp'+ where+ Z :. h :. w = shape rgba+ bs = toByteStrings rgba+ bmp = packRGBA32ToBMP w h bs+ --+ bmp' = bmp { bmpBitmapInfo = info' }+ info' = case bmpBitmapInfo bmp of+ InfoV3 i -> InfoV3 (info3 i)+ InfoV4 i -> InfoV4 (info4 i)+ InfoV5 i -> InfoV5 (info5 i)++ info3 BitmapInfoV3{..} = BitmapInfoV3 { dib3Height = -dib3Height, dib3HeightFlipped = True, .. }+ info4 BitmapInfoV4{..} = BitmapInfoV4 { dib4InfoV3 = info3 dib4InfoV3, .. }+ info5 BitmapInfoV5{..} = BitmapInfoV5 { dib5InfoV4 = info4 dib5InfoV4, .. }+