-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibjpeg2ktest.jl
37 lines (31 loc) · 1.07 KB
/
libjpeg2ktest.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
##
# Run this file as: julia --project=. libjpeg2ktest.jl inside (base) ashwani@user:~/Desktop/GSOC/io-project/jpeg2000wrapper$
##
## imports
using Libdl
using FileIO
using ColorTypes
using ColorVectorSpace
using FixedPointNumbers
include("lib/LibOpenJpeg.jl")
push!(DL_LOAD_PATH, "./libopenjpegextra")
# load a image from filename:
# support different versions of colorspaces
# save in different versions
RGB = 1
GRAY = 0
# btw this works currently
function load(filename::AbstractString;)
n = ccall((:decode, :libopenjpegextra), Ptr{LibOpenJpeg.opj_image_t}, (Ptr{Cchar},), filename)
N = unsafe_load(n)
components = unsafe_wrap(Array, N.comps, N.numcomps)
println("Width:", N.x1,", Height:", N.y1)
data = convert(Array{UInt8}, (unsafe_wrap(Array, components[1].data, N.x1 * N.y1)))
res = reinterpret(Gray{N0f8}, data)
res = reshape(res, Int64(N.x1), Int64(N.y1))
res = res'
# save("./test.jpg",res) # this works too and saved images is test.jpeg after this test was
return res
end
filename = "./libopenjpegextra/notes/sample1.jp2"
load(filename)