Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
gargantext-ihaskell
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gargantext
gargantext-ihaskell
Commits
89c52019
Commit
89c52019
authored
9 years ago
by
Andrew Gibiansky
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' of github.com:gibiansky/IHaskell
parents
823bbac9
0717983b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
85 deletions
+32
-85
Juicypixels.hs
...play/ihaskell-juicypixels/IHaskell/Display/Juicypixels.hs
+27
-82
ihaskell-juicypixels.cabal
...l-display/ihaskell-juicypixels/ihaskell-juicypixels.cabal
+5
-3
No files found.
ihaskell-display/ihaskell-juicypixels/IHaskell/Display/Juicypixels.hs
View file @
89c52019
{-# LANGUAGE TypeSynonymInstances, FlexibleInstances #-}
module
IHaskell.Display.Juicypixels
(
module
IHaskell
.
Display
,
module
Codec
.
Picture
)
where
module
IHaskell.Display.Juicypixels
(
module
IHaskell
.
Display
,
module
Codec
.
Picture
)
where
import
Codec.Picture
import
IHaskell.Display
import
System.Directory
import
System.IO.Unsafe
import
qualified
Data.ByteString.Char8
as
CBS
import
qualified
Codec.Picture
as
P
import
Codec.Picture
(
Image
(
..
))
import
Codec.Picture.Png
(
PngSavable
,
encodePng
)
import
IHaskell.Display
(
IHaskellDisplay
,
Display
(
..
),
display
,
png
,
base64
)
import
Data.ByteString.Lazy
(
ByteString
,
toStrict
)
-- instances
instance
IHaskellDisplay
DynamicImage
where
display
=
displayImageAsJpg
instance
IHaskellDisplay
(
Image
P
.
Pixel8
)
where
display
=
return
.
format
instance
IHaskellDisplay
(
Image
P
ixel8
)
where
display
=
displayImageAsJpg
.
ImageY8
instance
IHaskellDisplay
(
Image
P
.
Pixel16
)
where
display
=
return
.
format
instance
IHaskellDisplay
(
Image
P
ixel16
)
where
display
=
displayImageAsJpg
.
ImageY16
instance
IHaskellDisplay
(
Image
P
.
PixelYA8
)
where
display
=
return
.
format
instance
IHaskellDisplay
(
Image
P
ixelF
)
where
display
=
displayImageAsJpg
.
ImageYF
instance
IHaskellDisplay
(
Image
P
.
PixelYA16
)
where
display
=
return
.
format
instance
IHaskellDisplay
(
Image
P
ixelYA
8
)
where
display
=
displayImageAsJpg
.
ImageYA8
instance
IHaskellDisplay
(
Image
P
.
PixelRGB
8
)
where
display
=
return
.
format
instance
IHaskellDisplay
(
Image
P
ixelYA
16
)
where
display
=
displayImageAsJpg
.
ImageYA16
instance
IHaskellDisplay
(
Image
P
.
PixelRGB
16
)
where
display
=
return
.
format
instance
IHaskellDisplay
(
Image
P
ixelRGB
8
)
where
display
=
displayImageAsJpg
.
ImageRGB8
instance
IHaskellDisplay
(
Image
P
.
PixelRGBA
8
)
where
display
=
return
.
format
instance
IHaskellDisplay
(
Image
P
ixelRGB
16
)
where
display
=
displayImageAsJpg
.
ImageRGB16
instance
IHaskellDisplay
(
Image
P
.
PixelRGBA
16
)
where
display
=
return
.
format
instance
IHaskellDisplay
(
Image
PixelRGBF
)
where
display
=
displayImageAsJpg
.
ImageRGBF
instance
IHaskellDisplay
(
Image
PixelRGBA8
)
where
display
=
displayImageAsJpg
.
ImageRGBA8
instance
IHaskellDisplay
(
Image
PixelRGBA16
)
where
display
=
displayImageAsJpg
.
ImageRGBA16
instance
IHaskellDisplay
(
Image
PixelYCbCr8
)
where
display
=
displayImageAsJpg
.
ImageYCbCr8
instance
IHaskellDisplay
(
Image
PixelCMYK8
)
where
display
=
displayImageAsJpg
.
ImageCMYK8
instance
IHaskellDisplay
(
Image
PixelCMYK16
)
where
display
=
displayImageAsJpg
.
ImageCMYK16
-- main rendering function
displayImageAsJpg
::
DynamicImage
->
IO
Display
displayImageAsJpg
renderable
=
do
switchToTmpDir
let
filename
=
".ihaskell.juicypixels.jpg"
-- Write the image
saveJpgImage
95
filename
renderable
-- Convert to base64.
imgData
<-
CBS
.
readFile
filename
return
$
Display
[
jpg
(
imWidth
renderable
)
(
imHeight
renderable
)
$
base64
imgData
]
-- The type DynamicImage does not have a function to extract width and height
imWidth
::
DynamicImage
->
Int
imWidth
img
=
w
where
(
w
,
h
)
=
imWidthHeight
img
imHeight
::
DynamicImage
->
Int
imHeight
img
=
h
where
(
w
,
h
)
=
imWidthHeight
img
-- Helper functions to pattern match on the DynamicImage Constructors
imWidthHeight
::
DynamicImage
->
(
Int
,
Int
)
imWidthHeight
(
ImageY8
im
)
=
imWH
im
imWidthHeight
(
ImageY16
im
)
=
imWH
im
imWidthHeight
(
ImageYF
im
)
=
imWH
im
imWidthHeight
(
ImageYA8
im
)
=
imWH
im
imWidthHeight
(
ImageYA16
im
)
=
imWH
im
imWidthHeight
(
ImageRGB8
im
)
=
imWH
im
imWidthHeight
(
ImageRGB16
im
)
=
imWH
im
imWidthHeight
(
ImageRGBF
im
)
=
imWH
im
imWidthHeight
(
ImageRGBA8
im
)
=
imWH
im
imWidthHeight
(
ImageRGBA16
im
)
=
imWH
im
imWidthHeight
(
ImageYCbCr8
im
)
=
imWH
im
imWidthHeight
(
ImageCMYK8
im
)
=
imWH
im
imWidthHeight
(
ImageCMYK16
im
)
=
imWH
im
imWH
::
Image
a
->
(
Int
,
Int
)
imWH
im
=
(
imageWidth
im
,
imageHeight
im
)
format
::
PngSavable
a
=>
Image
a
->
Display
format
im
@
(
Image
w
h
_
)
=
Display
[
png
w
h
.
base64
.
toStrict
.
encodePng
$
im
]
\ No newline at end of file
This diff is collapsed.
Click to expand it.
ihaskell-display/ihaskell-juicypixels/ihaskell-juicypixels.cabal
View file @
89c52019
...
...
@@ -7,7 +7,7 @@ name: ihaskell-juicypixels
-- PVP summary: +-+------- breaking API changes
-- | | +----- non-breaking API additions
-- | | | +--- code changes with no API change
version:
0.3
.0.0
version:
1.1
.0.0
-- A short (one-line) description of the package.
synopsis: IHaskell - IHaskellDisplay instances of the image types of the JuicyPixels package.
...
...
@@ -29,11 +29,13 @@ license: MIT
license-file: LICENSE
-- The package author(s).
author: Roland Senn
author: Roland Senn,
Will Yager
-- An email address to which users can send suggestions, bug reports, and
-- patches.
maintainer: rsx@bluewin.ch
maintainer: rsx@bluewin.ch,
will.yager@gmail.com
-- A copyright notice.
-- copyright:
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment