Skip to content

Commit

Permalink
Fix reading images that have more than 8bit per channel. Fixes #85
Browse files Browse the repository at this point in the history
  • Loading branch information
lehins committed Nov 14, 2019
1 parent bb8f817 commit 82e0de0
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions massiv-io/CHANGELOG.md
@@ -1,3 +1,8 @@
# 0.1.8

* Fix reading images that have more than 8bit per channel:
[#85](https://github.com/lehins/massiv/issues/85)

# 0.1.7

* Fix compatibility with `JuicyPixels >= 3.3.0`
Expand Down
2 changes: 1 addition & 1 deletion massiv-io/massiv-io.cabal
@@ -1,5 +1,5 @@
name: massiv-io
version: 0.1.7.0
version: 0.1.8.0
synopsis: Import/export of Image files into massiv Arrays
description: This package contains functionality for import/export of arrays
into the real world. For now it only has the ability to read/write
Expand Down
16 changes: 13 additions & 3 deletions massiv-io/src/Data/Massiv/Array/IO/Image/JuicyPixels.hs
Expand Up @@ -79,7 +79,7 @@ import qualified Codec.Picture.Gif as JP
import qualified Codec.Picture.Jpg as JP
import qualified Codec.Picture.Types as TypesJP
import Control.Exception
import Control.Monad (guard, msum)
import Control.Monad (guard, msum, unless)
import Data.Bifunctor
import qualified Data.ByteString as B
import qualified Data.ByteString.Lazy as BL (ByteString)
Expand Down Expand Up @@ -1004,10 +1004,20 @@ toJPImageCMYK16 = toJPImageUnsafe

-- General decoding and helper functions

fromJPImageUnsafe :: forall jpx cs e . (Storable (Pixel cs e), JP.Pixel jpx) =>
fromJPImageUnsafe :: forall jpx cs e . (Storable (Pixel cs e), Storable e, JP.Pixel jpx) =>
JP.Image jpx -> Maybe (Image S cs e)
fromJPImageUnsafe (JP.Image n m !v) = do
guard (n * m * sizeOf (undefined :: Pixel cs e) == V.length v)
let numberOfComponentsFromSize = sizeOf (undefined :: Pixel cs e) `div` sizeOf (undefined :: e)
numComponentsPerPixel = JP.componentCount (undefined :: jpx)
unless (numComponentsPerPixel == numberOfComponentsFromSize) $
error $
concat
[ "Mismatched sizes beteen JuicyPixels: "
, show numComponentsPerPixel
, " and massiv: "
, show numberOfComponentsFromSize
]
guard (n * m * numComponentsPerPixel == V.length v)
fromVectorM Par (Sz (m :. n)) $ V.unsafeCast v
{-# INLINE fromJPImageUnsafe #-}

0 comments on commit 82e0de0

Please sign in to comment.