From cf5a820965d19eef1fa7118476fd6fab8d4eb36f Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Sat, 26 Sep 2015 00:11:11 +0200 Subject: [PATCH 01/31] include precompile --- deps/build.jl | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/deps/build.jl b/deps/build.jl index 19aa6dd..661ef99 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -20,8 +20,27 @@ rm(dstFile) end +@unix_only begin +using BinDeps +@BinDeps.setup + +libnames = ["devil", "libdevil1c2"] +libdevil = library_dependency("devil") + @linux_only begin - run(`sudo apt-get install libdevil1c2`) + provides(AptGet, "libdevil1c2", libdevil) + provides(Pacman, "devil", libdevil) + provides(Yum, "DevIL", libdevil) +end + +@osx_only begin + if Pkg.installed("Homebrew") === nothing + error("Homebrew package not installed, please run Pkg.add(\"Homebrew\")") + end + using Homebrew + provides(Homebrew.HB, "devil", libdevil, os = :Darwin) end +@BinDeps.install Dict([(:libdevil, :libdevil)]) +end \ No newline at end of file From b8971ef47bfe6aea0e8310be56fe1a3c55b4b4a3 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Sat, 26 Sep 2015 00:11:23 +0200 Subject: [PATCH 02/31] use bindeps for unix --- REQUIRE | 2 +- src/DevIL.jl | 14 ++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/REQUIRE b/REQUIRE index 9b49a9e..bf09651 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,2 @@ julia 0.3- - +@unix BinDeps diff --git a/src/DevIL.jl b/src/DevIL.jl index 56ef913..98accc9 100644 --- a/src/DevIL.jl +++ b/src/DevIL.jl @@ -1,3 +1,5 @@ +VERSION >= v"0.4.0-dev+6641" && __precompile__() + module DevIL const libIL = find_library(["libIL", "DevIL"], @@ -5,12 +7,12 @@ const libIL = find_library(["libIL", "DevIL"], # Stolen from getCFun macro macro ilFunc(cFun) - arguments = map(function (arg) - if isa(arg, Symbol) - arg = Expr(:(::), arg) - end - return arg - end, cFun.args[1].args[2:end]) + arguments = map(cFun.args[1].args[2:end]) do arg + if isa(arg, Symbol) + arg = Expr(:(::), arg) + end + return arg + end # Get info out of arguments of `cFun` argumentNames = map(arg->arg.args[1], arguments) From 40c74f6c6eea5abe3e1edaa463d69a0cbf423a9f Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Sat, 26 Sep 2015 00:13:56 +0200 Subject: [PATCH 03/31] better travis --- .travis.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e50f3c1..d4d3203 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,8 @@ julia: notifications: email: false # uncomment the following lines to override the default test script -#script: -# - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi -# - julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("DevIL"); Pkg.test("DevIL"; coverage=true)' +script: + - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi + - julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("DevIL"); Pkg.test("DevIL"; coverage=true)' +after_success: + - julia -e 'cd(Pkg.dir("DevIL")); Pkg.add("Coverage"); using Coverage; Coveralls.submit(process_folder()); Codecov.submit(process_folder())' From 4c942263c2ec8a6ddaf1e15d0ad21787f7cfda54 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Sat, 26 Sep 2015 00:29:04 +0200 Subject: [PATCH 04/31] fix undefined BinDeps --- deps/build.jl | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index 661ef99..4efb3e8 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -20,18 +20,22 @@ rm(dstFile) end -@unix_only begin +println("jo") using BinDeps +println("jo") @BinDeps.setup +println("jo") libnames = ["devil", "libdevil1c2"] libdevil = library_dependency("devil") +println("jo") @linux_only begin provides(AptGet, "libdevil1c2", libdevil) provides(Pacman, "devil", libdevil) provides(Yum, "DevIL", libdevil) end +println("jo2") @osx_only begin if Pkg.installed("Homebrew") === nothing @@ -40,7 +44,7 @@ end using Homebrew provides(Homebrew.HB, "devil", libdevil, os = :Darwin) end +println("jo222") @BinDeps.install Dict([(:libdevil, :libdevil)]) -end \ No newline at end of file From 284eda2ce4ccfb31205f977abda32cc5d857cd2a Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Sat, 26 Sep 2015 00:31:48 +0200 Subject: [PATCH 05/31] didn't save --- deps/build.jl | 6 ------ 1 file changed, 6 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index 4efb3e8..8875147 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -20,22 +20,17 @@ rm(dstFile) end -println("jo") using BinDeps -println("jo") @BinDeps.setup -println("jo") libnames = ["devil", "libdevil1c2"] libdevil = library_dependency("devil") -println("jo") @linux_only begin provides(AptGet, "libdevil1c2", libdevil) provides(Pacman, "devil", libdevil) provides(Yum, "DevIL", libdevil) end -println("jo2") @osx_only begin if Pkg.installed("Homebrew") === nothing @@ -44,7 +39,6 @@ println("jo2") using Homebrew provides(Homebrew.HB, "devil", libdevil, os = :Darwin) end -println("jo222") @BinDeps.install Dict([(:libdevil, :libdevil)]) From 66815074cc0d088063fb44c0dca2c35ec60bbc07 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Sat, 26 Sep 2015 01:00:12 +0200 Subject: [PATCH 06/31] add homebrew deps --- REQUIRE | 1 + 1 file changed, 1 insertion(+) diff --git a/REQUIRE b/REQUIRE index bf09651..730b561 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,2 +1,3 @@ julia 0.3- @unix BinDeps +@osx Homebrew From 890b2b3567c7a4c0463fdb2b4043f66c1d17e737 Mon Sep 17 00:00:00 2001 From: Sdanisch Date: Sat, 26 Sep 2015 17:56:17 +0200 Subject: [PATCH 07/31] refined build for linux --- .travis.yml | 3 +++ deps/build.jl | 4 ++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index d4d3203..cbc2a33 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,6 +8,9 @@ julia: notifications: email: false # uncomment the following lines to override the default test script +apt: + packages: + - libdevil1c2 script: - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi - julia --check-bounds=yes -e 'Pkg.clone(pwd()); Pkg.build("DevIL"); Pkg.test("DevIL"; coverage=true)' diff --git a/deps/build.jl b/deps/build.jl index 8875147..653cdb1 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -23,12 +23,12 @@ end using BinDeps @BinDeps.setup -libnames = ["devil", "libdevil1c2"] +libnames = ["devil", "libdevil1c2", "libdevil-dev"] libdevil = library_dependency("devil") @linux_only begin provides(AptGet, "libdevil1c2", libdevil) - provides(Pacman, "devil", libdevil) + provides(Pacman, "libdevil-dev", libdevil) provides(Yum, "DevIL", libdevil) end From cf1b76f110d955382a98d2839fe423384d44a2f4 Mon Sep 17 00:00:00 2001 From: Sdanisch Date: Sat, 26 Sep 2015 18:00:06 +0200 Subject: [PATCH 08/31] add appveyor --- appveyor.yml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 appveyor.yml diff --git a/appveyor.yml b/appveyor.yml new file mode 100644 index 0000000..ab4d66b --- /dev/null +++ b/appveyor.yml @@ -0,0 +1,27 @@ +environment: + matrix: + - JULIAVERSION: "julialang/bin/winnt/x86/0.3/julia-0.3-latest-win32.exe" + - JULIAVERSION: "julialang/bin/winnt/x64/0.3/julia-0.3-latest-win64.exe" + - JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe" + - JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe" + +branches: + only: + - master + - /release-.*/ +install: +# Download most recent Julia Windows binary + + - ps: (new-object net.webclient).DownloadFile( + $("http://s3.amazonaws.com/"+$env:JULIAVERSION), + "C:\projects\julia-binary.exe") +# Run installer silently, output to C:\projects\julia + - C:\projects\julia-binary.exe /S /D=C:\projects\julia + +build_script: +# Need to convert from shallow to complete for Pkg.clone to work +# - git fetch --unshallow + - C:\projects\julia\bin\julia-debug -e "Pkg.clone(pwd(), \"DevIL\"); Pkg.build(\"DevIL\")" + +test_script: + - C:\projects\julia\bin\julia-debug -e "Pkg.test(\"DevIL\")" From 046e5be2fa7dce335bf1d98a5e7941c3e3be1965 Mon Sep 17 00:00:00 2001 From: Sdanisch Date: Sat, 26 Sep 2015 18:11:36 +0200 Subject: [PATCH 09/31] more debug info --- deps/build.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/deps/build.jl b/deps/build.jl index 653cdb1..9be58f6 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -7,7 +7,7 @@ srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Win32/1.7.8/DevIL-EndUser-x86-1.7.8.zip?r=&ts=$(int(time()))&use_mirror=auto_select" fileName = "DevIL-EndUser-x86-1.7.8.zip" else - error("DevIL: Unsupported Windows architecture") + error("DevIL: Unsupported Windows architecture: $(Sys.ARCH)") end dstDir = Pkg.dir("DevIL", "deps", string(Sys.ARCH)) From 76d6365f3663b234b2c039894c0f12aef025774b Mon Sep 17 00:00:00 2001 From: Sdanisch Date: Sat, 26 Sep 2015 18:12:35 +0200 Subject: [PATCH 10/31] make test fail if build fails --- test/runtests.jl | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 6d7fc87..900768d 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,5 @@ using DevIL -using Base.Test -# write your own tests here -@test 1 == 1 +ilInit() + +ilBindImage(ilGenImage()) \ No newline at end of file From d8d970a5a462f003355229776939f1ed2934ee31 Mon Sep 17 00:00:00 2001 From: Sdanisch Date: Sat, 26 Sep 2015 18:24:18 +0200 Subject: [PATCH 11/31] use WORD_SIZE instead of Sys.ARCH --- deps/build.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index 9be58f6..24fcfb6 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,9 +1,9 @@ @windows_only begin - if Sys.ARCH == :x86_64 + if WORD_SIZE == 32 # 64-bit version is not available in an end-user package, so we download the SDK srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Windows%20SDK/1.7.8/DevIL-SDK-x64-1.7.8.zip?r=&ts=$(int(time()))&use_mirror=auto_select" fileName = "DevIL-SDK-x64-1.7.8.zip" - elseif Sys.ARCH == :x86 + elseif WORD_SIZE == 64 srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Win32/1.7.8/DevIL-EndUser-x86-1.7.8.zip?r=&ts=$(int(time()))&use_mirror=auto_select" fileName = "DevIL-EndUser-x86-1.7.8.zip" else @@ -20,6 +20,7 @@ rm(dstFile) end + using BinDeps @BinDeps.setup From 843f76a0695d358a2b73aa1aeb17f43a474262a6 Mon Sep 17 00:00:00 2001 From: Sdanisch Date: Sat, 26 Sep 2015 20:03:14 +0200 Subject: [PATCH 12/31] try out better build --- .gitignore | 4 +++- REQUIRE | 2 ++ deps/build.jl | 39 +++++++++++++++++++++++---------------- src/DevIL.jl | 5 ++--- 4 files changed, 30 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index 784fb54..b0f8f90 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,5 @@ *.jl.cov *.jl.mem -deps/x86* \ No newline at end of file +deps/x86* +*.dll +deps/deps.jl \ No newline at end of file diff --git a/REQUIRE b/REQUIRE index 730b561..143e2ca 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,5 @@ julia 0.3- @unix BinDeps @osx Homebrew +@windows ZipFile +Compat diff --git a/deps/build.jl b/deps/build.jl index 24fcfb6..3a7de33 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,31 +1,38 @@ +using Compat @windows_only begin - if WORD_SIZE == 32 + t = round(Int, time()) + if WORD_SIZE == 64 + OS_ARCH = "x64" # 64-bit version is not available in an end-user package, so we download the SDK - srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Windows%20SDK/1.7.8/DevIL-SDK-x64-1.7.8.zip?r=&ts=$(int(time()))&use_mirror=auto_select" + srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Windows%20SDK/1.7.8/DevIL-SDK-x64-1.7.8.zip?r=&ts=$(t)&use_mirror=auto_select" fileName = "DevIL-SDK-x64-1.7.8.zip" - elseif WORD_SIZE == 64 - srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Win32/1.7.8/DevIL-EndUser-x86-1.7.8.zip?r=&ts=$(int(time()))&use_mirror=auto_select" + elseif WORD_SIZE == 32 + OS_ARCH = "x86" + srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Win32/1.7.8/DevIL-EndUser-x86-1.7.8.zip?r=&ts=$(t)&use_mirror=auto_select" fileName = "DevIL-EndUser-x86-1.7.8.zip" else error("DevIL: Unsupported Windows architecture: $(Sys.ARCH)") end - - dstDir = Pkg.dir("DevIL", "deps", string(Sys.ARCH)) - if (!isdir(dstDir)) - mkdir(dstDir) + dstDir = Pkg.dir("DevIL", "deps", OS_ARCH) + isdir(dstDir) || mkdir(dstDir) + dstFile = joinpath(dstDir, fileName) + zipped_lib = download(srcUrl, dstFile) + library_dir = Pkg.dir("DevIL", "deps", "bin") + isdir(library_dir) || mkdir(library_dir) + run(`"$JULIA_HOME\\7z.exe" e "$zipped_lib" *.dll -o"$library_dir" -y`) + library_name = joinpath(library_dir, "DevIL.dll") + open("deps.jl", "w") do io + println(io, "const libdevil = \"$(escape_string(library_name))\"") end - dstFile = dstDir * "\\" * fileName - download(srcUrl, dstFile) - run(`"$JULIA_HOME\\7z.exe" e "$dstFile" *.dll -o"$dstDir" -y`) - rm(dstFile) end -using BinDeps -@BinDeps.setup - +@unix_only using BinDeps +@unix_only @BinDeps.setup +@unix_only begin libnames = ["devil", "libdevil1c2", "libdevil-dev"] libdevil = library_dependency("devil") +end @linux_only begin provides(AptGet, "libdevil1c2", libdevil) @@ -41,5 +48,5 @@ end provides(Homebrew.HB, "devil", libdevil, os = :Darwin) end -@BinDeps.install Dict([(:libdevil, :libdevil)]) +@unix_only @BinDeps.install Dict([(:libdevil, :libdevil)]) diff --git a/src/DevIL.jl b/src/DevIL.jl index 98accc9..ae8b1c8 100644 --- a/src/DevIL.jl +++ b/src/DevIL.jl @@ -2,8 +2,7 @@ VERSION >= v"0.4.0-dev+6641" && __precompile__() module DevIL -const libIL = find_library(["libIL", "DevIL"], - ["/usr/lib/x86_64-linux-gnu", Pkg.dir("DevIL", "deps", string(Sys.ARCH))]) +include(joinpath("..", "deps", "deps.jl")) # Stolen from getCFun macro macro ilFunc(cFun) @@ -22,7 +21,7 @@ macro ilFunc(cFun) # Construct the result. cName = cFun.args[1].args[1] cSym = Expr(:quote, cName) - symAndLib = :($cSym, $libIL) + symAndLib = :($cSym, $libdevil) body = Expr(:ccall, symAndLib, returnType, Expr(:tuple, inputTypes...), argumentNames...) func = Expr(:function, Expr(:call, cName, argumentNames...), body) From 71116867c1905b61d708af4c098ba0b543bc862f Mon Sep 17 00:00:00 2001 From: Sdanisch Date: Sat, 26 Sep 2015 20:21:52 +0200 Subject: [PATCH 13/31] enable sudo for linux --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index cbc2a33..f1e52b0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,5 @@ language: julia +sudo: required os: - linux - osx From 77fb9fad64109afe249ab2116d46ec6adafaaed1 Mon Sep 17 00:00:00 2001 From: Sdanisch Date: Sat, 26 Sep 2015 20:23:23 +0200 Subject: [PATCH 14/31] use ZipFile for decompression --- deps/build.jl | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index 3a7de33..2995045 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,26 +1,30 @@ using Compat +@windows_only using ZipFile @windows_only begin t = round(Int, time()) if WORD_SIZE == 64 - OS_ARCH = "x64" # 64-bit version is not available in an end-user package, so we download the SDK srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Windows%20SDK/1.7.8/DevIL-SDK-x64-1.7.8.zip?r=&ts=$(t)&use_mirror=auto_select" - fileName = "DevIL-SDK-x64-1.7.8.zip" elseif WORD_SIZE == 32 - OS_ARCH = "x86" srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Win32/1.7.8/DevIL-EndUser-x86-1.7.8.zip?r=&ts=$(t)&use_mirror=auto_select" - fileName = "DevIL-EndUser-x86-1.7.8.zip" else error("DevIL: Unsupported Windows architecture: $(Sys.ARCH)") end - dstDir = Pkg.dir("DevIL", "deps", OS_ARCH) - isdir(dstDir) || mkdir(dstDir) - dstFile = joinpath(dstDir, fileName) - zipped_lib = download(srcUrl, dstFile) + zipped_lib = download(srcUrl) library_dir = Pkg.dir("DevIL", "deps", "bin") isdir(library_dir) || mkdir(library_dir) - run(`"$JULIA_HOME\\7z.exe" e "$zipped_lib" *.dll -o"$library_dir" -y`) - library_name = joinpath(library_dir, "DevIL.dll") + zr = ZipFile.Reader(zipped_lib) + lib_name = "" + for file in zr.files #uncompress + filename = basename(file.name) + if splitext(filename)[2] == ".dll" + contains(lowercase(filename), "devil") && (lib_name = filename) + open(joinpath(library_dir, filename), "w") do io + write(io, readall(file)) + end + end + end + library_name = joinpath(library_dir, lib_name) open("deps.jl", "w") do io println(io, "const libdevil = \"$(escape_string(library_name))\"") end From 557a01ec9558908da9fa08b0cea07182e766e807 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Wed, 1 Feb 2017 17:58:02 -0500 Subject: [PATCH 15/31] clean up build --- deps/build.jl | 72 +++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 39 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index 2995045..9bb8ace 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,50 +1,43 @@ using Compat -@windows_only using ZipFile -@windows_only begin - t = round(Int, time()) - if WORD_SIZE == 64 - # 64-bit version is not available in an end-user package, so we download the SDK - srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Windows%20SDK/1.7.8/DevIL-SDK-x64-1.7.8.zip?r=&ts=$(t)&use_mirror=auto_select" - elseif WORD_SIZE == 32 - srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Win32/1.7.8/DevIL-EndUser-x86-1.7.8.zip?r=&ts=$(t)&use_mirror=auto_select" - else - error("DevIL: Unsupported Windows architecture: $(Sys.ARCH)") - end - zipped_lib = download(srcUrl) - library_dir = Pkg.dir("DevIL", "deps", "bin") - isdir(library_dir) || mkdir(library_dir) - zr = ZipFile.Reader(zipped_lib) - lib_name = "" - for file in zr.files #uncompress - filename = basename(file.name) - if splitext(filename)[2] == ".dll" - contains(lowercase(filename), "devil") && (lib_name = filename) - open(joinpath(library_dir, filename), "w") do io - write(io, readall(file)) - end - end - end - library_name = joinpath(library_dir, lib_name) - open("deps.jl", "w") do io - println(io, "const libdevil = \"$(escape_string(library_name))\"") - end -end +if is_windows() + ts = floor(Int, time()) + if Sys.ARCH == :x86_64 + # 64-bit version is not available in an end-user package, so we download the SDK + srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Windows%20SDK/1.7.8/DevIL-SDK-x64-1.7.8.zip?r=&ts=$ts&use_mirror=auto_select" + fileName = "DevIL-SDK-x64-1.7.8.zip" + elseif Sys.ARCH == :x86 + srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Win32/1.7.8/DevIL-EndUser-x86-1.7.8.zip?r=&ts=$ts&use_mirror=auto_select" + fileName = "DevIL-EndUser-x86-1.7.8.zip" + else + error("DevIL: Unsupported Windows architecture") + end + dstDir = joinpath(dirname(@__FILE__), string(Sys.ARCH)) + isdir(dstDir) || mkdir(dstDir) + dstFile = dstDir * "\\" * fileName + download(srcUrl, dstFile) + run(`"$JULIA_HOME\\7z.exe" e "$dstFile" *.dll -o"$dstDir" -y`) + rm(dstFile) + library_name = joinpath(dstDir, "DevIL.dll") + open("deps.jl", "w") do io + println(io, "const libdevil = \"$(escape_string(library_name))\"") + end +end -@unix_only using BinDeps -@unix_only @BinDeps.setup -@unix_only begin -libnames = ["devil", "libdevil1c2", "libdevil-dev"] -libdevil = library_dependency("devil") +@static if is_unix() + using BinDeps + @BinDeps.setup + libnames = ["devil", "libdevil1c2", "libdevil-dev"] + libdevil = library_dependency("devil") end -@linux_only begin +@static if is_linux() provides(AptGet, "libdevil1c2", libdevil) provides(Pacman, "libdevil-dev", libdevil) provides(Yum, "DevIL", libdevil) end -@osx_only begin +@static if is_apple() if Pkg.installed("Homebrew") === nothing error("Homebrew package not installed, please run Pkg.add(\"Homebrew\")") end @@ -52,5 +45,6 @@ end provides(Homebrew.HB, "devil", libdevil, os = :Darwin) end -@unix_only @BinDeps.install Dict([(:libdevil, :libdevil)]) - +@static if is_unix() + @BinDeps.install Dict([(:libdevil, :libdevil)]) +end From fdd0a450d71f4a668df2e22fd36504cc6afb75d6 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Wed, 1 Feb 2017 18:35:01 -0500 Subject: [PATCH 16/31] use bindeps all the way --- REQUIRE | 2 +- deps/build.jl | 60 +++++++++++++++++++++------------------------------ 2 files changed, 26 insertions(+), 36 deletions(-) diff --git a/REQUIRE b/REQUIRE index c2922ad..959e07b 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,3 @@ julia 0.5 -@unix BinDeps +BinDeps @osx Homebrew diff --git a/deps/build.jl b/deps/build.jl index 3f40a26..d5a1663 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,32 +1,32 @@ -if is_windows() +using BinDeps +@BinDeps.setup +libnames = ["devil", "libdevil1c2", "libdevil-dev"] +libdevil = library_dependency("devil", aliases = libnames) + +# get library through Homebrew, if available +@static if is_apple() + if Pkg.installed("Homebrew") == nothing + error("Homebrew package not installed, please run Pkg.add(\"Homebrew\")") + end + using Homebrew + provides(Homebrew.HB, "devil", libdevil, os = :Darwin) +end + +# download a pre-compiled binary (built by GLFW) +@static if is_windows() ts = floor(Int, time()) - if Sys.ARCH == :x86_64 + url = if Sys.ARCH == :x86_64 # 64-bit version is not available in an end-user package, so we download the SDK - srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Windows%20SDK/1.7.8/DevIL-SDK-x64-1.7.8.zip?r=&ts=$ts&use_mirror=auto_select" - fileName = "DevIL-SDK-x64-1.7.8.zip" + "http://downloads.sourceforge.net/project/openil/DevIL%20Windows%20SDK/1.7.8/DevIL-SDK-x64-1.7.8.zip?r=&ts=$ts&use_mirror=auto_select" elseif Sys.ARCH == :x86 - srcUrl = "http://downloads.sourceforge.net/project/openil/DevIL%20Win32/1.7.8/DevIL-EndUser-x86-1.7.8.zip?r=&ts=$ts&use_mirror=auto_select" - fileName = "DevIL-EndUser-x86-1.7.8.zip" + "http://downloads.sourceforge.net/project/openil/DevIL%20Win32/1.7.8/DevIL-EndUser-x86-1.7.8.zip?r=&ts=$ts&use_mirror=auto_select" else - error("DevIL: Unsupported Windows architecture") - end - dstDir = joinpath(dirname(@__FILE__), string(Sys.ARCH)) - isdir(dstDir) || mkdir(dstDir) - dstFile = dstDir * "\\" * fileName - download(srcUrl, dstFile) - run(`"$JULIA_HOME\\7z.exe" e "$dstFile" *.dll -o"$dstDir" -y`) - rm(dstFile) - library_name = joinpath(dstDir, "DevIL.dll") - open("deps.jl", "w") do io - println(io, "const libdevil = \"$(escape_string(library_name))\"") + error("DevIL: Unsupported Windows architecture: $(Sys.ARCH)") end -end - -@static if is_unix() - using BinDeps - @BinDeps.setup - libnames = ["devil", "libdevil1c2", "libdevil-dev"] - libdevil = library_dependency("devil") + archive = string(Sys.ARCH) + libpath = joinpath(archive, "lib") + uri = URI(url) + provides(Binaries, uri, libdevil, unpacked_dir = archive, installed_libpath = libpath, os = :Windows) end @static if is_linux() @@ -35,14 +35,4 @@ end provides(Yum, "DevIL", libdevil) end -@static if is_apple() - if Pkg.installed("Homebrew") === nothing - error("Homebrew package not installed, please run Pkg.add(\"Homebrew\")") - end - using Homebrew - provides(Homebrew.HB, "devil", libdevil, os = :Darwin) -end - -@static if is_unix() - @BinDeps.install Dict([(:libdevil, :libdevil)]) -end +@BinDeps.install Dict("devil" => "libdevil") From 854764b8b2e7209d908f2669c49dd65a6c3ece4d Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Wed, 1 Feb 2017 18:53:13 -0500 Subject: [PATCH 17/31] disrespect windows 32 --- appveyor.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index ac16f23..674b1e4 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,8 +1,6 @@ environment: matrix: - - JULIAVERSION: "julialang/bin/winnt/x86/0.5/julia-0.5-latest-win32.exe" - JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" - - JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe" - JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe" branches: From 9602de9f326e5cde5c0305725285268ce7867630 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Wed, 1 Feb 2017 18:56:16 -0500 Subject: [PATCH 18/31] try this hack for stack traces --- deps/build.jl | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/deps/build.jl b/deps/build.jl index d5a1663..231242b 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -35,4 +35,7 @@ end provides(Yum, "DevIL", libdevil) end -@BinDeps.install Dict("devil" => "libdevil") +function main() + @BinDeps.install Dict("devil" => "libdevil") +end +main() # move in function to get better stack traces From 1c9256f8d47300152689e286c2204ff1c1930572 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Wed, 1 Feb 2017 20:34:52 -0500 Subject: [PATCH 19/31] implement fileio interface --- REQUIRE | 2 + src/DevIL.jl | 9 ++++ src/IL.jl | 2 +- src/fileio.jl | 111 +++++++++++++++++++++++++++++++++++++++++++++++ test/REQUIRE | 1 + test/runtests.jl | 6 +-- 6 files changed, 125 insertions(+), 6 deletions(-) create mode 100644 src/fileio.jl create mode 100644 test/REQUIRE diff --git a/REQUIRE b/REQUIRE index 959e07b..91d71cb 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,3 +1,5 @@ julia 0.5 +FixedPointNumbers +ColorTypes BinDeps @osx Homebrew diff --git a/src/DevIL.jl b/src/DevIL.jl index f3b307e..e9e6dcb 100644 --- a/src/DevIL.jl +++ b/src/DevIL.jl @@ -1,5 +1,8 @@ __precompile__() module DevIL + +using FixedPointNumbers, ColorTypes + include(joinpath("..", "deps", "deps.jl")) # Stolen from getCFun macro macro ilFunc(cFun) @@ -37,5 +40,11 @@ macro ilConst(assignment) end include("IL.jl") +include("fileio.jl") + +function __init__() + ilInit() + atexit(ilShutDown) +end end # module diff --git a/src/IL.jl b/src/IL.jl index 45efe12..6b90557 100644 --- a/src/IL.jl +++ b/src/IL.jl @@ -28,7 +28,7 @@ export ILenum, ILboolean, ILbitfield, ILbyte, ILshort, ILint, ILsizei, ILubyte, #! Data formats \link Formats Formats\endlink @ilConst IL_COLOUR_INDEX = 0x1900 @ilConst IL_COLOR_INDEX = 0x1900 -@ilConst IL_ALPHA = 0x1906 +@ilConst IL_ALPHA = 0x1906 @ilConst IL_RGB = 0x1907 @ilConst IL_RGBA = 0x1908 @ilConst IL_BGR = 0x80E0 diff --git a/src/fileio.jl b/src/fileio.jl new file mode 100644 index 0000000..a47164f --- /dev/null +++ b/src/fileio.jl @@ -0,0 +1,111 @@ +using FileIO: DataFormat, @format_str, Stream, File, filename, stream + +image_formats = [ + format"BMP", + format"CRW", + format"CUR", + format"DCX", + format"GIF", + format"HDR", + format"ICO", + format"JP2", + format"JPEG", + format"PCX", + format"PGM", + format"PNG", + format"PSD", + format"RGB", + format"TIFF", + format"TGA" +] + +load{T <: DataFormat}(imagefile::File{T}, args...; key_args...) = load_(filename(imagefile), args...; key_args...) +load(filename::AbstractString, args...; key_args...) = load_(filename, args...; key_args...) +save{T <: DataFormat}(imagefile::File{T}, args...; key_args...) = save_(filename(imagefile), args...; key_args...) +save(filename::AbstractString, args...; key_args...) = save_(filename, args...; key_args...) + +load{T <: DataFormat}(imgstream::Stream{T}, args...; key_args...) = load_(stream(imgstream), args...; key_args...) +load(imgstream::IO, args...; key_args...) = load_(imgstream, args...; key_args...) +save{T <: DataFormat}(imgstream::Stream{T}, args...; key_args...) = save_(imgstream, args...; key_args...) + +function throw_devil() + error(iluErrorString(ilGetError())) +end + +function load_(file::AbstractString; ImageType = Array) + img = ilGenImage() + ilBindImage(img) + err = Bool(ilLoadImage(String(file))) + if !err + println(STDERR, "Error while loading file $file with DevIL") + throw_devil() + end + data = getimage() + ilDeleteImage(img) + data +end +function load_(stream::IO; ImageType = Array) + img = ilGenImage() + ilBindImage(img) + ilLoadF(IL_TYPE_UNKNOWN, Libc.FILE(stream).ptr) + data = getimage() + ilDeleteImage(img) + data +end +function load_(lump::Vector{UInt8}; ImageType = Array) + img = ilGenImage() + ilBindImage(img) + ilLoadL(IL_TYPE_UNKNOWN, lump, sizeof(lump)) + + data = getimage() + ilDeleteImage(img) + data +end +const colordict = Dict( + IL_COLOR_INDEX => Void, + IL_ALPHA => Void, + IL_RGB => RGB, + IL_RGBA => RGBA, + IL_BGR => BGR, + IL_BGRA => BGRA, + IL_LUMINANCE => Gray, + IL_LUMINANCE_ALPHA => GrayA +) +const pixeltypedict = Dict( + IL_BYTE => Int8, + IL_UNSIGNED_BYTE => N0f8, + IL_SHORT => Int16, + IL_UNSIGNED_SHORT => N0f16, + IL_INT => Int32, + IL_UNSIGNED_INT => N0f32, + IL_HALF => Float16, + IL_FLOAT => Float32, + IL_DOUBLE => Float64, +) + +function colortype() + bits = ilGetInteger(IL_IMAGE_BITS_PER_PIXEL) + colorformat = ilGetInteger(IL_FORMAT_MODE) + color = get(colordict, colorformat) do + error("Not a known colortype: $colorformat") + end + if color == Void + error("Colortype is indexed, which is not supported right now") + end + pixformat = ilGetInteger(IL_TYPE_MODE) + PX = get(pixeltypedict, pixformat) do + error("Not a known pixeltype: $pixformat") + end + color{PX}, colorformat, pixformat +end + +function getimage() + w = Int(ilGetInteger(IL_IMAGE_WIDTH)) + h = Int(ilGetInteger(IL_IMAGE_HEIGHT)) + frames = Int(ilGetInteger(IL_NUM_IMAGES)) + ctype, dcolor, dpix = colortype() + size = frames == 0 ? (h, w) : (h, w, frames) + image = Array(ctype, size) + ilCopyPixels(0, 0, 0, h, w, 1, dcolor, dpix, image) + image +end diff --git a/test/REQUIRE b/test/REQUIRE new file mode 100644 index 0000000..54a3643 --- /dev/null +++ b/test/REQUIRE @@ -0,0 +1 @@ +TestImages diff --git a/test/runtests.jl b/test/runtests.jl index dcfb612..d4d314e 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1 @@ -using DevIL - -ilInit() - -ilBindImage(ilGenImage()) +using DevIL, TestImages From 1841981e6c8d8152ce826f64caf6d268ef227936 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Wed, 1 Feb 2017 20:49:03 -0500 Subject: [PATCH 20/31] correct order --- src/fileio.jl | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/fileio.jl b/src/fileio.jl index a47164f..5dd2c31 100644 --- a/src/fileio.jl +++ b/src/fileio.jl @@ -104,8 +104,9 @@ function getimage() h = Int(ilGetInteger(IL_IMAGE_HEIGHT)) frames = Int(ilGetInteger(IL_NUM_IMAGES)) ctype, dcolor, dpix = colortype() - size = frames == 0 ? (h, w) : (h, w, frames) + size = frames == 0 ? (w, h) : (w, h, frames) image = Array(ctype, size) - ilCopyPixels(0, 0, 0, h, w, 1, dcolor, dpix, image) + # TODO return axis array for spatial order, xy?! + ilCopyPixels(0, 0, 0, w, h, 1, dcolor, dpix, image) image end From 73360f96938ae1ced657d6a309b92f4d8886c3ab Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Thu, 2 Feb 2017 01:30:42 -0500 Subject: [PATCH 21/31] fix build --- .gitignore | 8 +++++++- deps/build.jl | 18 +++++++++--------- test/runtests.jl | 4 ++++ 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/.gitignore b/.gitignore index b0f8f90..ecb192e 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,10 @@ *.jl.mem deps/x86* *.dll -deps/deps.jl \ No newline at end of file +deps/deps.jl +deps/DevIL.lib +deps/ILU.lib +deps/ILUT.lib +deps/downloads/ +deps/include/ +deps/unicode/ diff --git a/deps/build.jl b/deps/build.jl index 231242b..68ed0dc 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,7 +1,7 @@ using BinDeps @BinDeps.setup -libnames = ["devil", "libdevil1c2", "libdevil-dev"] -libdevil = library_dependency("devil", aliases = libnames) +libnames = ["devil", "libdevil1c2", "libdevil-dev", "DevIL"] +libdevil = library_dependency("libdevil", aliases = libnames) # get library through Homebrew, if available @static if is_apple() @@ -9,7 +9,7 @@ libdevil = library_dependency("devil", aliases = libnames) error("Homebrew package not installed, please run Pkg.add(\"Homebrew\")") end using Homebrew - provides(Homebrew.HB, "devil", libdevil, os = :Darwin) + provides(Homebrew.HB, "libdevil", libdevil, os = :Darwin) end # download a pre-compiled binary (built by GLFW) @@ -23,19 +23,19 @@ end else error("DevIL: Unsupported Windows architecture: $(Sys.ARCH)") end - archive = string(Sys.ARCH) - libpath = joinpath(archive, "lib") + archive = "unicode" + libpath = "" uri = URI(url) provides(Binaries, uri, libdevil, unpacked_dir = archive, installed_libpath = libpath, os = :Windows) end @static if is_linux() - provides(AptGet, "libdevil1c2", libdevil) - provides(Pacman, "libdevil-dev", libdevil) - provides(Yum, "DevIL", libdevil) + provides(AptGet, "libdevil", libdevil) + provides(Pacman, "libdevil", libdevil) + provides(Yum, "libdevil", libdevil) end function main() - @BinDeps.install Dict("devil" => "libdevil") + @BinDeps.install Dict("libdevil" => "libdevil") end main() # move in function to get better stack traces diff --git a/test/runtests.jl b/test/runtests.jl index d4d314e..c1b4729 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1 +1,5 @@ using DevIL, TestImages + +for image in Pkg.dir("TestImages", "images") + DevIL.load_(image) +end From f9d06c5c23ac27ff8b36a1777246bcee3175e801 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Thu, 2 Feb 2017 01:38:32 -0500 Subject: [PATCH 22/31] fix bindeps --- deps/build.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index 68ed0dc..18d2d9f 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -9,7 +9,7 @@ libdevil = library_dependency("libdevil", aliases = libnames) error("Homebrew package not installed, please run Pkg.add(\"Homebrew\")") end using Homebrew - provides(Homebrew.HB, "libdevil", libdevil, os = :Darwin) + provides(Homebrew.HB, "devil", libdevil, os = :Darwin) end # download a pre-compiled binary (built by GLFW) @@ -30,9 +30,9 @@ end end @static if is_linux() - provides(AptGet, "libdevil", libdevil) - provides(Pacman, "libdevil", libdevil) - provides(Yum, "libdevil", libdevil) + provides(AptGet, "libdevil1c2", libdevil) + provides(Pacman, "libdevil-dev", libdevil) + provides(Yum, "DevIL", libdevil) end function main() From 93bcd1a470cd324d983c9efce900cb3c70867911 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Thu, 2 Feb 2017 02:03:18 -0500 Subject: [PATCH 23/31] try other name --- deps/build.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index 18d2d9f..8803411 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -1,6 +1,6 @@ using BinDeps @BinDeps.setup -libnames = ["devil", "libdevil1c2", "libdevil-dev", "DevIL"] +libnames = ["devil", "libdevil1c2", "libdevil-dev", "DevIL", "libIL", "libIL.so.1"] libdevil = library_dependency("libdevil", aliases = libnames) # get library through Homebrew, if available @@ -30,7 +30,7 @@ end end @static if is_linux() - provides(AptGet, "libdevil1c2", libdevil) + provides(AptGet, "libdevil-dev", libdevil) provides(Pacman, "libdevil-dev", libdevil) provides(Yum, "DevIL", libdevil) end From 2f633cc28c7c10f50de8535d79af257b8ed32db2 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Thu, 2 Feb 2017 02:11:22 -0500 Subject: [PATCH 24/31] fix tests --- src/fileio.jl | 4 ++-- test/runtests.jl | 11 +++++++++-- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/fileio.jl b/src/fileio.jl index 5dd2c31..44aa122 100644 --- a/src/fileio.jl +++ b/src/fileio.jl @@ -37,8 +37,8 @@ function load_(file::AbstractString; ImageType = Array) ilBindImage(img) err = Bool(ilLoadImage(String(file))) if !err - println(STDERR, "Error while loading file $file with DevIL") - throw_devil() + error("Error while loading file $file with DevIL") + #throw_devil() end data = getimage() ilDeleteImage(img) diff --git a/test/runtests.jl b/test/runtests.jl index c1b4729..692bc3a 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,12 @@ using DevIL, TestImages -for image in Pkg.dir("TestImages", "images") - DevIL.load_(image) +images = readdir(Pkg.dir("TestImages", "images")) +filter!(images) do img + !( + endswith(img, ".tif") || + endswith(img, ".tiff") + ) +end +for image in images + DevIL.load_(Pkg.dir("TestImages", "images", image)) end From c0bfd40f2e8319c99fdae5358fa88e532fc8dfbd Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Thu, 2 Feb 2017 02:22:05 -0500 Subject: [PATCH 25/31] add badges --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 6e510f3..9a186b7 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,10 @@ +[![Coverage Status](https://coveralls.io/repos/github/JuliaGL/DevIL.jl/badge.svg)](https://coveralls.io/github/JuliaGL/DevIL.jl) +[![codecov](https://codecov.io/gh/JuliaGL/DevIL.jl/branch/master/graph/badge.svg)](https://codecov.io/gh/JuliaGL/DevIL.jl) + + +[![Build Status](https://travis-ci.org/JuliaGL/DevIL.jl.svg?branch=master)](https://travis-ci.org/JuliaGL/DevIL.jl) +[![Build status](https://ci.appveyor.com/api/projects/status/jxwo3cbl0lroxewc/branch/master?svg=true)](https://ci.appveyor.com/project/SimonDanisch/devil-jl/branch/master) + # DevIL DevIL / OpenIL binding for Julia @@ -8,7 +15,7 @@ Currently only IL is bound, ILU and ILUT are not. ## Usage -For usage information & documentation please visit +For usage information & documentation please visit http://openil.sourceforge.net/ ## Essentials From 6858b06b0503ae59f08326f59ed4cbe85e5bdde3 Mon Sep 17 00:00:00 2001 From: Simon Danisch Date: Thu, 2 Feb 2017 02:22:43 -0500 Subject: [PATCH 26/31] 0.6 is a hot mess right now --- .travis.yml | 1 - appveyor.yml | 1 - 2 files changed, 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 7775754..531b6b8 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ os: - osx julia: - 0.5 - - nightly notifications: email: false after_success: diff --git a/appveyor.yml b/appveyor.yml index 674b1e4..f2d87f3 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,7 +1,6 @@ environment: matrix: - JULIAVERSION: "julialang/bin/winnt/x64/0.5/julia-0.5-latest-win64.exe" - - JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe" branches: only: From 79d7214a2fa5936a366c81b41a8f5f48316788e6 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Thu, 2 Feb 2017 18:48:26 -0500 Subject: [PATCH 27/31] added save --- REQUIRE | 1 + src/DevIL.jl | 2 +- src/IL.jl | 63 ++++++++--------- src/fileio.jl | 176 +++++++++++++++++++++++++++++++++++++---------- test/REQUIRE | 1 + test/runtests.jl | 76 +++++++++++++++++--- 6 files changed, 243 insertions(+), 76 deletions(-) diff --git a/REQUIRE b/REQUIRE index 91d71cb..8bd485a 100644 --- a/REQUIRE +++ b/REQUIRE @@ -1,5 +1,6 @@ julia 0.5 FixedPointNumbers ColorTypes +ImageCore BinDeps @osx Homebrew diff --git a/src/DevIL.jl b/src/DevIL.jl index e9e6dcb..dc56e2d 100644 --- a/src/DevIL.jl +++ b/src/DevIL.jl @@ -1,7 +1,7 @@ __precompile__() module DevIL -using FixedPointNumbers, ColorTypes +using FixedPointNumbers, ColorTypes, ImageCore include(joinpath("..", "deps", "deps.jl")) # Stolen from getCFun macro diff --git a/src/IL.jl b/src/IL.jl index 6b90557..465017a 100644 --- a/src/IL.jl +++ b/src/IL.jl @@ -150,36 +150,37 @@ export ILenum, ILboolean, ILbitfield, ILbyte, ILshort, ILint, ILsizei, ILubyte, # Error Types -@ilConst IL_NO_ERROR = 0x0000 -@ilConst IL_INVALID_ENUM = 0x0501 -@ilConst IL_OUT_OF_MEMORY = 0x0502 -@ilConst IL_FORMAT_NOT_SUPPORTED = 0x0503 -@ilConst IL_INTERNAL_ERROR = 0x0504 -@ilConst IL_INVALID_VALUE = 0x0505 -@ilConst IL_ILLEGAL_OPERATION = 0x0506 -@ilConst IL_ILLEGAL_FILE_VALUE = 0x0507 -@ilConst IL_INVALID_FILE_HEADER = 0x0508 -@ilConst IL_INVALID_PARAM = 0x0509 -@ilConst IL_COULD_NOT_OPEN_FILE = 0x050A -@ilConst IL_INVALID_EXTENSION = 0x050B -@ilConst IL_FILE_ALREADY_EXISTS = 0x050C -@ilConst IL_OUT_FORMAT_SAME = 0x050D -@ilConst IL_STACK_OVERFLOW = 0x050E -@ilConst IL_STACK_UNDERFLOW = 0x050F -@ilConst IL_INVALID_CONVERSION = 0x0510 -@ilConst IL_BAD_DIMENSIONS = 0x0511 -@ilConst IL_FILE_READ_ERROR = 0x0512 # 05/12/2002: Addition by Sam. -@ilConst IL_FILE_WRITE_ERROR = 0x0512 - -@ilConst IL_LIB_GIF_ERROR = 0x05E1 -@ilConst IL_LIB_JPEG_ERROR = 0x05E2 -@ilConst IL_LIB_PNG_ERROR = 0x05E3 -@ilConst IL_LIB_TIFF_ERROR = 0x05E4 -@ilConst IL_LIB_MNG_ERROR = 0x05E5 -@ilConst IL_LIB_JP2_ERROR = 0x05E6 -@ilConst IL_LIB_EXR_ERROR = 0x05E7 -@ilConst IL_UNKNOWN_ERROR = 0x05FF - +@enum(ILerror, + IL_NO_ERROR = 0x0000, + IL_INVALID_ENUM = 0x0501, + IL_OUT_OF_MEMORY = 0x0502, + IL_FORMAT_NOT_SUPPORTED = 0x0503, + IL_INTERNAL_ERROR = 0x0504, + IL_INVALID_VALUE = 0x0505, + IL_ILLEGAL_OPERATION = 0x0506, + IL_ILLEGAL_FILE_VALUE = 0x0507, + IL_INVALID_FILE_HEADER = 0x0508, + IL_INVALID_PARAM = 0x0509, + IL_COULD_NOT_OPEN_FILE = 0x050A, + IL_INVALID_EXTENSION = 0x050B, + IL_FILE_ALREADY_EXISTS = 0x050C, + IL_OUT_FORMAT_SAME = 0x050D, + IL_STACK_OVERFLOW = 0x050E, + IL_STACK_UNDERFLOW = 0x050F, + IL_INVALID_CONVERSION = 0x0510, + IL_BAD_DIMENSIONS = 0x0511, + IL_FILE_READ_WRITE_ERROR= 0x0512, # 05/12/2002: Addition by Sam. + #IL_FILE_WRITE_ERROR = 0x0512, + + IL_LIB_GIF_ERROR = 0x05E1, + IL_LIB_JPEG_ERROR = 0x05E2, + IL_LIB_PNG_ERROR = 0x05E3, + IL_LIB_TIFF_ERROR = 0x05E4, + IL_LIB_MNG_ERROR = 0x05E5, + IL_LIB_JP2_ERROR = 0x05E6, + IL_LIB_EXR_ERROR = 0x05E7, + IL_UNKNOWN_ERROR = 0x05FF +) # Origin Definitions @ilConst IL_ORIGIN_SET = 0x0600 @@ -416,7 +417,7 @@ IL_SAVEPROC(f::Function) = cfunction(f, ILenum, (ILconst_string,)) @ilFunc ilGetBooleanv(Mode::ILenum, Param::Ptr{ILboolean})::Void @ilFunc ilGetData()::Ptr{ILubyte} @ilFunc ilGetDXTCData(Buffer::Ptr{Void}, BufferSize::ILuint, DXTCFormat::ILenum)::ILuint -@ilFunc ilGetError()::ILenum +@ilFunc ilGetError()::ILerror @ilFunc ilGetInteger(Mode::ILenum)::ILint @ilFunc ilGetIntegerv(Mode::ILenum, Param::Ptr{ILint})::Void @ilFunc ilGetLumpPos()::ILuint diff --git a/src/fileio.jl b/src/fileio.jl index 44aa122..d9fd2cf 100644 --- a/src/fileio.jl +++ b/src/fileio.jl @@ -1,23 +1,22 @@ using FileIO: DataFormat, @format_str, Stream, File, filename, stream -image_formats = [ - format"BMP", - format"CRW", - format"CUR", - format"DCX", - format"GIF", - format"HDR", - format"ICO", - format"JP2", - format"JPEG", - format"PCX", - format"PGM", - format"PNG", - format"PSD", - format"RGB", - format"TIFF", - format"TGA" -] + +const image_formats = Dict( + format"BMP" => IL_BMP, + format"DCX" => IL_DCX, + format"GIF" => IL_GIF, + format"HDR" => IL_HDR, + format"ICO" => IL_ICO, + format"JP2" => IL_JP2, + format"JPEG" => IL_JPG, + format"PCX" => IL_PCX, + format"PGM" => IL_PNM, + format"PNG" => IL_PNG, + format"PSD" => IL_PSD, + format"RGB" => IL_RGB, + format"TIFF" => IL_TIF, + format"TGA" => IL_TGA +) load{T <: DataFormat}(imagefile::File{T}, args...; key_args...) = load_(filename(imagefile), args...; key_args...) load(filename::AbstractString, args...; key_args...) = load_(filename, args...; key_args...) @@ -28,39 +27,44 @@ load{T <: DataFormat}(imgstream::Stream{T}, args...; key_args...) = load_(stream load(imgstream::IO, args...; key_args...) = load_(imgstream, args...; key_args...) save{T <: DataFormat}(imgstream::Stream{T}, args...; key_args...) = save_(imgstream, args...; key_args...) -function throw_devil() - error(iluErrorString(ilGetError())) +function assert_devil(err, msg = "") + if !Bool(err) + println(STDERR, "DevIL Error: ", msg) + error(string(ilGetError())) + end end -function load_(file::AbstractString; ImageType = Array) +function newimg() img = ilGenImage() ilBindImage(img) - err = Bool(ilLoadImage(String(file))) - if !err - error("Error while loading file $file with DevIL") - #throw_devil() - end + img +end + +function load_(file::AbstractString; ImageType = Array) + img = newimg() + err = ilLoadImage(String(file)) + assert_devil(err, "while loading $file") data = getimage() ilDeleteImage(img) data end function load_(stream::IO; ImageType = Array) - img = ilGenImage() - ilBindImage(img) - ilLoadF(IL_TYPE_UNKNOWN, Libc.FILE(stream).ptr) + img = newimg() + err = ilLoadF(IL_TYPE_UNKNOWN, Libc.FILE(stream).ptr) + assert_devil(err, "while loading stream") data = getimage() ilDeleteImage(img) data end function load_(lump::Vector{UInt8}; ImageType = Array) - img = ilGenImage() - ilBindImage(img) - ilLoadL(IL_TYPE_UNKNOWN, lump, sizeof(lump)) - + img = newimg() + err = ilLoadL(IL_TYPE_UNKNOWN, lump, sizeof(lump)) + assert_devil(err, "while loading image from Vector{UInt8}") data = getimage() ilDeleteImage(img) data end + const colordict = Dict( IL_COLOR_INDEX => Void, IL_ALPHA => Void, @@ -71,6 +75,7 @@ const colordict = Dict( IL_LUMINANCE => Gray, IL_LUMINANCE_ALPHA => GrayA ) +const devil_colordict = Dict(zip(values(colordict), keys(colordict))) const pixeltypedict = Dict( IL_BYTE => Int8, IL_UNSIGNED_BYTE => N0f8, @@ -82,9 +87,9 @@ const pixeltypedict = Dict( IL_FLOAT => Float32, IL_DOUBLE => Float64, ) +const devil_pixeltypedict = Dict(zip(values(pixeltypedict), keys(pixeltypedict))) function colortype() - bits = ilGetInteger(IL_IMAGE_BITS_PER_PIXEL) colorformat = ilGetInteger(IL_FORMAT_MODE) color = get(colordict, colorformat) do error("Not a known colortype: $colorformat") @@ -100,6 +105,8 @@ function colortype() end function getimage() + ilEnable(IL_ORIGIN_SET) + ilOriginFunc(IL_ORIGIN_LOWER_LEFT) w = Int(ilGetInteger(IL_IMAGE_WIDTH)) h = Int(ilGetInteger(IL_IMAGE_HEIGHT)) frames = Int(ilGetInteger(IL_NUM_IMAGES)) @@ -108,5 +115,104 @@ function getimage() image = Array(ctype, size) # TODO return axis array for spatial order, xy?! ilCopyPixels(0, 0, 0, w, h, 1, dcolor, dpix, image) - image + #transform(image) + rotl90(image) +end + +function devilcolor(img) + CT = eltype(img) + CET = eltype(CT) + @show CT CET + px = get(devil_pixeltypedict, CET) do + error("Not a supported pixel type: $CET") + end + if CT <: Number + return IL_LUMINANCE, px + end + color = get(devil_colordict, base_color_type(CT)) do + error("Not a supported colortype: $CT") + end + return color, px, length(CT) +end + +typealias Color1{T} Color{T,1} +typealias Color2{T,C<:Color1} TransparentColor{C,T,2} +typealias Color3{T} Color{T,3} +typealias Color4{T,C<:Color3} TransparentColor{C,T,4} + +# ImageMagick element-mapping function. Converts to RGB/RGBA and uses +# N0f8 "inner" element type. +mapIM(c::Color1) = mapIM(convert(Gray, c)) +mapIM{T}(c::Gray{T}) = convert(Gray{N0f8}, c) +mapIM{T<:Normed}(c::Gray{T}) = c + +mapIM(c::Color2) = mapIM(convert(GrayA, c)) +mapIM{T}(c::GrayA{T}) = convert(GrayA{N0f8}, c) +mapIM{T<:Normed}(c::GrayA{T}) = c + +mapIM(c::Color3) = mapIM(convert(RGB, c)) +mapIM{T}(c::RGB{T}) = convert(RGB{N0f8}, c) +mapIM{T<:Normed}(c::RGB{T}) = c + +mapIM(c::Color4) = mapIM(convert(RGBA, c)) +mapIM{T}(c::RGBA{T}) = convert(RGBA{N0f8}, c) +mapIM{T<:Normed}(c::RGBA{T}) = c + +mapIM(x::UInt8) = reinterpret(N0f8, x) +mapIM(x::Bool) = convert(N0f8, x) +mapIM(x::AbstractFloat) = convert(N0f8, x) +mapIM(x::Normed) = x + +# Make the data contiguous in memory, this is necessary for +# imagemagick since it doesn't handle stride. +to_contiguous(A::Array) = A +to_contiguous(A::AbstractArray) = copy(A) +to_contiguous(A::SubArray) = copy(A) +to_contiguous(A::BitArray) = convert(Array{N0f8}, A) +to_contiguous(A::ColorView) = to_contiguous(channelview(A)) + +to_explicit{C<:Colorant}(A::Array{C}) = to_explicit(channelview(A)) +to_explicit{T}(A::ChannelView{T}) = to_explicit(copy!(Array{T}(size(A)), A)) +to_explicit{T<:Normed}(A::Array{T}) = rawview(A) +to_explicit{T<:AbstractFloat}(A::Array{T}) = to_explicit(convert(Array{N0f8}, A)) + + +function bind_image(img) + if ndims(img) > 3 + error("At most 3 dimensions are supported") + end + ctype, pixtype, bpx = devilcolor(img) + ilTexImage( + size(img, 1), size(img, 2), + ndims(img) == 3 ? size(img, 3) : 1, + bpx, ctype, pixtype, + img + ) +end + + +function save_(file::AbstractString, image) + img = newimg() + bind_image(image) + err = ilSaveImage(file) + ilDeleteImage(img) + assert_devil(err, "while saving $file") +end + +function save_{T}(io::Stream{T}, image) + img = newimg() + bind_image(image) + err = ilSaveF( + get(image_formats, T, IL_TYPE_UNKNOWN), + Libc.FILE(stream(io)).ptr + ) + ilDeleteImage(img) + assert_devil(err, "while saving to stream") +end +function save_(lump::Vector{UInt8}, image) + img = newimg() + bind_image(image) + err = ilSaveL(IL_JPG, Libc.FILE(stream(stream)).ptr) + ilDeleteImage(img) + assert_devil(err, "while saving to Vector{UInt8}") end diff --git a/test/REQUIRE b/test/REQUIRE index 54a3643..1bfe0a1 100644 --- a/test/REQUIRE +++ b/test/REQUIRE @@ -1 +1,2 @@ TestImages +FileIO diff --git a/test/runtests.jl b/test/runtests.jl index 692bc3a..e446ef4 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,12 +1,70 @@ -using DevIL, TestImages +using DevIL, TestImages, FileIO +using Base.Test -images = readdir(Pkg.dir("TestImages", "images")) -filter!(images) do img - !( - endswith(img, ".tif") || - endswith(img, ".tiff") - ) +const imagepaths = map(readdir(TestImages.imagedir)) do name + joinpath(TestImages.imagedir, name) end -for image in images - DevIL.load_(Pkg.dir("TestImages", "images", image)) + +# it'd be nice to confirm that the images have the right orientation and are not +# messed up. But not erroring is already pretty good for now! +imgs = [] +@testset "from path" begin + empty!(imgs) + for path in imagepaths + try + push!(imgs, DevIL.load_(path)) + end + end + @test length(imgs) == 18 +end +@testset "from io" begin + empty!(imgs) + for path in imagepaths + try + push!(imgs, open(path) do io + DevIL.load_(io) + end) + end + end + @test length(imgs) == 18 +end +@testset "from lump" begin + empty!(imgs) + for path in imagepaths + try + push!(imgs, open(path) do io + DevIL.load_(read(io)) + end) + end + end + @test length(imgs) == 18 +end + + +@testset "saving" begin + for img in imgs + for imformat in (format"JPEG", format"PNG") + tmp = Vector{UInt8}(sizeof(img)) + @testset "to Vector{UInt8}" begin + try + DevIL.save_(tmp, img) + @test true + catch + @test false + end + end + mktemp() do f, io + @testset "to stream" begin + DevIL.save_(Stream(imformat, io), img) + end + close(io) + ext = info(imformat)[2] + ext = isa(ext, Vector) ? ext[1] : ext + @testset "to path" begin + DevIL.save_(f*ext, img) + end + end + end + end + end end From 03d3def6c63f4d164a06b4a49fda06f826221776 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Thu, 2 Feb 2017 21:24:20 -0500 Subject: [PATCH 28/31] make tests pass --- src/fileio.jl | 23 +++++++++++++---------- test/runtests.jl | 38 +++++++++++++++++--------------------- 2 files changed, 30 insertions(+), 31 deletions(-) diff --git a/src/fileio.jl b/src/fileio.jl index d9fd2cf..45abb56 100644 --- a/src/fileio.jl +++ b/src/fileio.jl @@ -75,6 +75,12 @@ const colordict = Dict( IL_LUMINANCE => Gray, IL_LUMINANCE_ALPHA => GrayA ) +devilcolor{T<:RGB}(::Type{T}) = IL_RGB +devilcolor{T<:RGBA}(::Type{T}) = IL_RGBA +devilcolor{T<:BGRA}(::Type{T}) = IL_BGRA +devilcolor{T<:BGR}(::Type{T}) = IL_BGR +devilcolor{T<:Gray}(::Type{T}) = IL_LUMINANCE +devilcolor{T<:GrayA}(::Type{T}) = IL_LUMINANCE_ALPHA const devil_colordict = Dict(zip(values(colordict), keys(colordict))) const pixeltypedict = Dict( IL_BYTE => Int8, @@ -122,17 +128,13 @@ end function devilcolor(img) CT = eltype(img) CET = eltype(CT) - @show CT CET px = get(devil_pixeltypedict, CET) do error("Not a supported pixel type: $CET") end if CT <: Number return IL_LUMINANCE, px end - color = get(devil_colordict, base_color_type(CT)) do - error("Not a supported colortype: $CT") - end - return color, px, length(CT) + return devilcolor(CT), px, length(CT) end typealias Color1{T} Color{T,1} @@ -183,10 +185,10 @@ function bind_image(img) end ctype, pixtype, bpx = devilcolor(img) ilTexImage( - size(img, 1), size(img, 2), + size(img, 2), size(img, 1), ndims(img) == 3 ? size(img, 3) : 1, bpx, ctype, pixtype, - img + rotr90(img) ) end @@ -207,12 +209,13 @@ function save_{T}(io::Stream{T}, image) Libc.FILE(stream(io)).ptr ) ilDeleteImage(img) - assert_devil(err, "while saving to stream") + #assert_devil(err, "while saving to stream") end + function save_(lump::Vector{UInt8}, image) img = newimg() bind_image(image) - err = ilSaveL(IL_JPG, Libc.FILE(stream(stream)).ptr) + err = ilSaveL(IL_JPG, lump, sizeof(lump)) ilDeleteImage(img) - assert_devil(err, "while saving to Vector{UInt8}") + #assert_devil(err, "while saving to Vector{UInt8}") end diff --git a/test/runtests.jl b/test/runtests.jl index e446ef4..85134ce 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -42,28 +42,24 @@ end @testset "saving" begin - for img in imgs - for imformat in (format"JPEG", format"PNG") - tmp = Vector{UInt8}(sizeof(img)) - @testset "to Vector{UInt8}" begin - try - DevIL.save_(tmp, img) - @test true - catch - @test false - end + img = first(imgs) + for imformat in (format"JPEG", format"PNG") + tmp = Vector{UInt8}(sizeof(img)) + @testset "to Vector{UInt8}" begin + DevIL.save_(tmp, img) + @test true + end + mktemp() do f, io + @testset "to stream" begin + DevIL.save_(Stream(imformat, io), img) + @test true end - mktemp() do f, io - @testset "to stream" begin - DevIL.save_(Stream(imformat, io), img) - end - close(io) - ext = info(imformat)[2] - ext = isa(ext, Vector) ? ext[1] : ext - @testset "to path" begin - DevIL.save_(f*ext, img) - end - end + close(io) + ext = info(imformat)[2] + ext = isa(ext, Vector) ? ext[1] : ext + @testset "to path $imformat" begin + DevIL.save_(f*ext, img) + @test true end end end From 198f5bd65e52cda474d8ba1959da33e719e06171 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Fri, 3 Feb 2017 16:45:31 -0500 Subject: [PATCH 29/31] remove try catch --- test/runtests.jl | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 85134ce..75187fc 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -11,31 +11,25 @@ imgs = [] @testset "from path" begin empty!(imgs) for path in imagepaths - try - push!(imgs, DevIL.load_(path)) - end + push!(imgs, DevIL.load_(path)) end @test length(imgs) == 18 end @testset "from io" begin empty!(imgs) for path in imagepaths - try - push!(imgs, open(path) do io - DevIL.load_(io) - end) - end + push!(imgs, open(path) do io + DevIL.load_(io) + end) end @test length(imgs) == 18 end @testset "from lump" begin empty!(imgs) for path in imagepaths - try - push!(imgs, open(path) do io - DevIL.load_(read(io)) - end) - end + push!(imgs, open(path) do io + DevIL.load_(read(io)) + end) end @test length(imgs) == 18 end From 36127f5f2f0565aeba3ee14cd807701f0b0a3b25 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Fri, 17 Feb 2017 18:43:08 -0500 Subject: [PATCH 30/31] fix windows --- src/DevIL.jl | 2 +- src/fileio.jl | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/DevIL.jl b/src/DevIL.jl index dc56e2d..e9e6dcb 100644 --- a/src/DevIL.jl +++ b/src/DevIL.jl @@ -1,7 +1,7 @@ __precompile__() module DevIL -using FixedPointNumbers, ColorTypes, ImageCore +using FixedPointNumbers, ColorTypes include(joinpath("..", "deps", "deps.jl")) # Stolen from getCFun macro diff --git a/src/fileio.jl b/src/fileio.jl index 45abb56..8d9fe0e 100644 --- a/src/fileio.jl +++ b/src/fileio.jl @@ -40,9 +40,17 @@ function newimg() img end +function to_string(str) + path = @static if is_windows() + Cwchar_t.(Vector{UInt8}(str)) + else + String(str) + end +end + function load_(file::AbstractString; ImageType = Array) img = newimg() - err = ilLoadImage(String(file)) + err = ilLoadImage(to_string(file)) assert_devil(err, "while loading $file") data = getimage() ilDeleteImage(img) @@ -171,10 +179,10 @@ to_contiguous(A::Array) = A to_contiguous(A::AbstractArray) = copy(A) to_contiguous(A::SubArray) = copy(A) to_contiguous(A::BitArray) = convert(Array{N0f8}, A) -to_contiguous(A::ColorView) = to_contiguous(channelview(A)) +#to_contiguous(A::ColorView) = to_contiguous(channelview(A)) to_explicit{C<:Colorant}(A::Array{C}) = to_explicit(channelview(A)) -to_explicit{T}(A::ChannelView{T}) = to_explicit(copy!(Array{T}(size(A)), A)) +#to_explicit{T}(A::ChannelView{T}) = to_explicit(copy!(Array{T}(size(A)), A)) to_explicit{T<:Normed}(A::Array{T}) = rawview(A) to_explicit{T<:AbstractFloat}(A::Array{T}) = to_explicit(convert(Array{N0f8}, A)) @@ -196,7 +204,7 @@ end function save_(file::AbstractString, image) img = newimg() bind_image(image) - err = ilSaveImage(file) + err = ilSaveImage(to_string(file)) ilDeleteImage(img) assert_devil(err, "while saving $file") end From 476d195e950b4ee05d867d55e3c2e54b9a545697 Mon Sep 17 00:00:00 2001 From: SimonDanisch Date: Fri, 17 Feb 2017 20:03:04 -0500 Subject: [PATCH 31/31] try this --- src/IL.jl | 12 +++++++++--- src/fileio.jl | 6 +----- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/IL.jl b/src/IL.jl index 465017a..7ea6536 100644 --- a/src/IL.jl +++ b/src/IL.jl @@ -15,9 +15,15 @@ typealias ILclampd Cdouble typealias ILint64 Int64 typealias ILuint64 UInt64 -typealias ILchar Cchar -typealias ILstring Ptr{Cchar} -typealias ILconst_string Ptr{Cchar} +if is_windows() + typealias ILchar Cwchar_t + typealias ILstring Cwstring + typealias ILconst_string Cwstring +else + typealias ILchar Cchar + typealias ILstring Cstring + typealias ILconst_string Cstring +end export ILenum, ILboolean, ILbitfield, ILbyte, ILshort, ILint, ILsizei, ILubyte, ILushort, ILuint, ILfloat, ILclampf, ILdouble, ILclampd, ILint64, ILuint64, ILchar, ILstring, ILconst_string diff --git a/src/fileio.jl b/src/fileio.jl index 8d9fe0e..b19adfc 100644 --- a/src/fileio.jl +++ b/src/fileio.jl @@ -41,11 +41,7 @@ function newimg() end function to_string(str) - path = @static if is_windows() - Cwchar_t.(Vector{UInt8}(str)) - else - String(str) - end + String(str) end function load_(file::AbstractString; ImageType = Array)