-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
302 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.stack-work* | ||
*~ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog for ihaskell-hip | ||
|
||
## 0.1.0.0 | ||
|
||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
Copyright Alexey Kuleshevich (c) 2020 | ||
|
||
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 name of Alexey Kuleshevich nor the names of other | ||
contributors 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 AND CONTRIBUTORS | ||
"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 THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# ihaskell-hip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
{-# LANGUAGE CPP #-} | ||
{-# OPTIONS_GHC -Wall #-} | ||
module Main (main) where | ||
|
||
#ifndef MIN_VERSION_cabal_doctest | ||
#define MIN_VERSION_cabal_doctest(x,y,z) 0 | ||
#endif | ||
|
||
#if MIN_VERSION_cabal_doctest(1,0,0) | ||
|
||
import Distribution.Extra.Doctest ( defaultMainWithDoctests ) | ||
main :: IO () | ||
main = defaultMainWithDoctests "doctests" | ||
|
||
#else | ||
|
||
#ifdef MIN_VERSION_Cabal | ||
-- If the macro is defined, we have new cabal-install, | ||
-- but for some reason we don't have cabal-doctest in package-db | ||
-- | ||
-- Probably we are running cabal sdist, when otherwise using new-build | ||
-- workflow | ||
#warning You are configuring this package without cabal-doctest installed. \ | ||
The doctests test-suite will not work as a result. \ | ||
To fix this, install cabal-doctest before configuring. | ||
#endif | ||
|
||
import Distribution.Simple | ||
|
||
main :: IO () | ||
main = defaultMain | ||
|
||
#endif | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
name: ihaskell-hip | ||
version: 0.1.0.0 | ||
synopsis: Short description | ||
description: Please see the README on GitHub at <https://github.com/lehins/ihaskell-hip#readme> | ||
homepage: https://github.com/lehins/ihaskell-hip | ||
license: BSD3 | ||
license-file: LICENSE | ||
author: Alexey Kuleshevich | ||
maintainer: [email protected] | ||
copyright: 2020 Alexey Kuleshevich | ||
category: Algorithms | ||
build-type: Custom | ||
extra-source-files: README.md | ||
, CHANGELOG.md | ||
cabal-version: 1.18 | ||
tested-with: GHC == 8.4.3 | ||
, GHC == 8.4.4 | ||
, GHC == 8.6.3 | ||
, GHC == 8.6.4 | ||
, GHC == 8.6.5 | ||
, GHC == 8.8.1 | ||
, GHC == 8.8.2 | ||
, GHC == 8.10.1 | ||
custom-setup | ||
setup-depends: | ||
base | ||
, Cabal | ||
, cabal-doctest >=1.0.6 | ||
|
||
library | ||
hs-source-dirs: src | ||
exposed-modules: IHaskell.Display.Image | ||
|
||
other-modules: | ||
build-depends: base >= 4.11 && < 5 | ||
, bytestring | ||
, data-default-class | ||
, hip >= 2.0 | ||
, ihaskell | ||
, massiv-io | ||
|
||
default-language: Haskell2010 | ||
ghc-options: -Wall | ||
-Wincomplete-record-updates | ||
-Wincomplete-uni-patterns | ||
-Wredundant-constraints | ||
|
||
source-repository head | ||
type: git | ||
location: https://github.com/lehins/hip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
{-# LANGUAGE DataKinds #-} | ||
{-# LANGUAGE FlexibleContexts #-} | ||
{-# LANGUAGE FlexibleInstances #-} | ||
{-# LANGUAGE UndecidableInstances #-} | ||
{-# OPTIONS_GHC -fno-warn-orphans #-} | ||
-- | | ||
-- Module : IHaskell.Display.Image | ||
-- Copyright : (c) Alexey Kuleshevich 2020 | ||
-- License : BSD3 | ||
-- Maintainer : Alexey Kuleshevich <[email protected]> | ||
-- Stability : experimental | ||
-- Portability : non-portable | ||
-- | ||
module IHaskell.Display.Image | ||
( module IHaskell.Display | ||
, module I | ||
) where | ||
|
||
import Data.List.NonEmpty | ||
import Data.Default.Class (def) | ||
import qualified Data.Massiv.Array.IO as M | ||
import Data.Word | ||
import qualified Graphics.Image as I | ||
|
||
import Data.ByteString.Lazy (toStrict) | ||
import IHaskell.Display (Base64, Display(..), DisplayData, Height, | ||
IHaskellDisplay(display), Width, base64, gif, jpg, png) | ||
|
||
instance IHaskellDisplay (I.Image (M.SRGB 'I.NonLinear) Word8) where | ||
display = base64encode png M.PNG | ||
|
||
instance IHaskellDisplay (I.Image (M.SRGB 'I.NonLinear) Word16) where | ||
display = base64encode png M.PNG | ||
|
||
instance IHaskellDisplay (I.Image (M.YCbCr (M.SRGB 'I.NonLinear)) Word8) where | ||
display = base64encode jpg M.JPG | ||
|
||
instance IHaskellDisplay (I.Image (M.CMYK (M.SRGB 'I.NonLinear)) Word8) where | ||
display = base64encode jpg M.JPG | ||
|
||
instance IHaskellDisplay (I.Image M.Y' Word8) where | ||
display = base64encode png M.PNG | ||
|
||
instance IHaskellDisplay (I.Image M.Y' Word16) where | ||
display = base64encode png M.PNG | ||
|
||
instance IHaskellDisplay (I.Image (I.Alpha M.Y') Word8) where | ||
display = base64encode png M.PNG | ||
|
||
instance IHaskellDisplay (I.Image (I.Alpha M.Y') Word16) where | ||
display = base64encode png M.PNG | ||
|
||
instance {-# OVERLAPPABLE #-} (M.ColorSpace cs i e, M.ColorSpace (M.BaseSpace cs) i e) => | ||
IHaskellDisplay (I.Image cs e) where | ||
display = base64encode png (M.Auto M.PNG) | ||
|
||
|
||
|
||
base64encode :: | ||
(M.Writable f (M.Image I.S cs e), M.ColorModel cs e) | ||
=> (Width -> Height -> Base64 -> DisplayData) | ||
-> f | ||
-> I.Image cs e | ||
-> IO Display | ||
base64encode toDisplayData format img@(I.Image arr) = do | ||
let I.Sz2 m n = I.dims img | ||
bs <- M.encodeM format def arr | ||
pure $ Display [toDisplayData n m $ base64 $ toStrict bs] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# This file was automatically generated by 'stack init' | ||
# | ||
# Some commonly used options have been documented as comments in this file. | ||
# For advanced use and comprehensive documentation of the format, please see: | ||
# https://docs.haskellstack.org/en/stable/yaml_configuration/ | ||
|
||
# Resolver to choose a 'specific' stackage snapshot or a compiler version. | ||
# A snapshot resolver dictates the compiler version and the set of packages | ||
# to be used for project dependencies. For example: | ||
# | ||
# resolver: lts-3.5 | ||
# resolver: nightly-2015-09-21 | ||
# resolver: ghc-7.10.2 | ||
# | ||
# The location of a snapshot can be provided as a file or url. Stack assumes | ||
# a snapshot provided as a file might change, whereas a url resource does not. | ||
# | ||
# resolver: ./custom-snapshot.yaml | ||
# resolver: https://example.com/snapshots/2018-01-01.yaml | ||
resolver: lts-16.1 | ||
|
||
# User packages to be built. | ||
# Various formats can be used as shown in the example below. | ||
# | ||
# packages: | ||
# - some-directory | ||
# - https://example.com/foo/bar/baz-0.0.2.tar.gz | ||
# subdirs: | ||
# - auto-update | ||
# - wai | ||
packages: | ||
- . | ||
- ../hip | ||
extra-deps: #for now, since we might need to add changes to upstream deps | ||
- github: lehins/massiv | ||
commit: 4fdc959542193f95b9a5da7f44b7cc90868b68be | ||
subdirs: | ||
- massiv | ||
- github: lehins/massiv-io | ||
commit: 3501c8930179345a634e1ad66ea7f746ba599986 | ||
subdirs: | ||
- massiv-io | ||
- github: lehins/Color | ||
commit: c566a3083a238eba70e61ba0e261f9dacb8481bb | ||
subdirs: | ||
- Color | ||
# Dependency packages to be pulled from upstream that are not in the resolver. | ||
# These entries can reference officially published versions as well as | ||
# forks / in-progress versions pinned to a git hash. For example: | ||
# | ||
# extra-deps: | ||
# - acme-missiles-0.3 | ||
# - git: https://github.com/commercialhaskell/stack.git | ||
# commit: e7b331f14bcffb8367cd58fbfc8b40ec7642100a | ||
# | ||
# extra-deps: [] | ||
|
||
# Override default flag values for local packages and extra-deps | ||
# flags: {} | ||
|
||
# Extra package databases containing global packages | ||
# extra-package-dbs: [] | ||
|
||
# Control whether we use the GHC we find on the path | ||
# system-ghc: true | ||
# | ||
# Require a specific version of stack, using version ranges | ||
# require-stack-version: -any # Default | ||
# require-stack-version: ">=2.3" | ||
# | ||
# Override the architecture used by stack, especially useful on Windows | ||
# arch: i386 | ||
# arch: x86_64 | ||
# | ||
# Extra directories used by stack for building | ||
# extra-include-dirs: [/path/to/dir] | ||
# extra-lib-dirs: [/path/to/dir] | ||
# | ||
# Allow a newer minor version of GHC than the snapshot specifies | ||
# compiler-check: newer-minor |