Skip to content

Commit

Permalink
Merge pull request #21 from JuliaImages/ash/encode+perf
Browse files Browse the repository at this point in the history
Extending encode operation to handle all formats
  • Loading branch information
ashwanirathee authored Apr 19, 2023
2 parents 55077d7 + a7c5b44 commit 0ea0e03
Show file tree
Hide file tree
Showing 10 changed files with 155 additions and 112 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/UnitTest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ jobs:
- os: macOS-latest
version: '1'
arch: x64
- os: ubuntu-latest
version: '1'
arch: x86
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name = "ExifViewer"
uuid = "81511e1f-44aa-483a-b228-c9d3a109f0d4"
version = "0.1.1"
version = "0.1.2"

[deps]
ColorTypes = "3da002f7-5984-5a60-b8a6-cbb66c0b333f"
Expand Down
38 changes: 29 additions & 9 deletions gen/Manifest.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
# This file is machine-generated - editing it directly is not advised

julia_version = "1.7.2"
julia_version = "1.8.5"
manifest_format = "2.0"
project_hash = "3951e233404121cfddbc73ed9012023b05cf9186"

[[deps.ArgTools]]
uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f"
version = "1.1.1"

[[deps.Artifacts]]
uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand All @@ -19,23 +21,27 @@ version = "0.4.2"

[[deps.Clang]]
deps = ["CEnum", "Clang_jll", "Downloads", "Pkg", "TOML"]
git-tree-sha1 = "b6998b85ea2abbc8a02ca1ccca9438338ed5f8e5"
git-tree-sha1 = "9c5e5bf14878315b43ae322fe2f2a5080c827a27"
uuid = "40e3b903-d033-50b4-a0cc-940c62c95e31"
version = "0.15.8"
version = "0.17.2"

[[deps.Clang_jll]]
deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg", "Zlib_jll", "libLLVM_jll"]
git-tree-sha1 = "8cf7e67e264dedc5d321ec87e78525e958aea057"
git-tree-sha1 = "0dfffba1b32bb3e30cb0372bfe666a5ddffe37fb"
uuid = "0ee61d77-7f21-5576-8119-9fcc46b10100"
version = "12.0.1+3"
version = "13.0.1+3"

[[deps.Dates]]
deps = ["Printf"]
uuid = "ade2ca70-3891-5945-98fb-dc099432e06a"

[[deps.Downloads]]
deps = ["ArgTools", "LibCURL", "NetworkOptions"]
deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"]
uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6"
version = "1.6.0"

[[deps.FileWatching]]
uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee"

[[deps.InteractiveUtils]]
deps = ["Markdown"]
Expand All @@ -50,10 +56,12 @@ version = "1.4.1"
[[deps.LibCURL]]
deps = ["LibCURL_jll", "MozillaCACerts_jll"]
uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21"
version = "0.6.3"

[[deps.LibCURL_jll]]
deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"]
uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0"
version = "7.84.0+0"

[[deps.LibGit2]]
deps = ["Base64", "NetworkOptions", "Printf", "SHA"]
Expand All @@ -62,6 +70,7 @@ uuid = "76f85450-5226-5b5a-8eaa-529ad045b433"
[[deps.LibSSH2_jll]]
deps = ["Artifacts", "Libdl", "MbedTLS_jll"]
uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8"
version = "1.10.2+0"

[[deps.Libdl]]
uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
Expand All @@ -76,16 +85,20 @@ uuid = "d6f4376e-aef5-505a-96c1-9c027394607a"
[[deps.MbedTLS_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1"
version = "2.28.0+0"

[[deps.MozillaCACerts_jll]]
uuid = "14a3606d-f60d-562e-9121-12d972cd8159"
version = "2022.2.1"

[[deps.NetworkOptions]]
uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908"
version = "1.2.0"

[[deps.Pkg]]
deps = ["Artifacts", "Dates", "Downloads", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"]
uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
version = "1.8.0"

[[deps.Preferences]]
deps = ["TOML"]
Expand All @@ -107,6 +120,7 @@ uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"

[[deps.SHA]]
uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce"
version = "0.7.0"

[[deps.Serialization]]
uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
Expand All @@ -117,10 +131,12 @@ uuid = "6462fe0b-24de-5631-8697-dd941f90decc"
[[deps.TOML]]
deps = ["Dates"]
uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76"
version = "1.0.0"

[[deps.Tar]]
deps = ["ArgTools", "SHA"]
uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e"
version = "1.10.1"

[[deps.UUIDs]]
deps = ["Random", "SHA"]
Expand All @@ -132,21 +148,25 @@ uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5"
[[deps.Zlib_jll]]
deps = ["Libdl"]
uuid = "83775a58-1f1d-513f-b197-d71354ab007a"
version = "1.2.12+3"

[[deps.libLLVM_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8f36deef-c2a5-5394-99ed-8e07531fb29a"
version = "13.0.1+3"

[[deps.libexif_jll]]
deps = ["Libdl", "Pkg"]
git-tree-sha1 = "a4df42e744b7ca582639e3c0573d4fb55f8cb9a3"
deps = ["Artifacts", "JLLWrappers", "Libdl"]
git-tree-sha1 = "3eecc367591234ba02d4cc48b3dd80344b941b26"
uuid = "cdeeb48b-bcdf-5b3f-98c4-7a29487f695f"
version = "0.6.21+0"
version = "0.6.24+0"

[[deps.nghttp2_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d"
version = "1.48.0+0"

[[deps.p7zip_jll]]
deps = ["Artifacts", "Libdl"]
uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0"
version = "17.4.0+0"
2 changes: 1 addition & 1 deletion lib/LibExif.jl
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ function exif_mem_unref(arg1)
end

function exif_mem_alloc(m, s)
ccall((:exif_mem_alloc, libexif), Ptr{Cvoid}, (Ptr{ExifMem}, ExifLong), m, s)
ccall((:exif_mem_alloc, libexif), Ptr{UInt8}, (Ptr{ExifMem}, ExifLong), m, s)
end

function exif_mem_realloc(m, p, s)
Expand Down
2 changes: 1 addition & 1 deletion src/precompile.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ using SnoopPrecompile

write(path, file)

tags = Dict{String,Any}(
tags = Dict{String, String}(
"EXIF_TAG_MAKE" => "test",
"EXIF_TAG_ORIENTATION" => "Top-left",
"EXIF_TAG_X_RESOLUTION" => "300",
Expand Down
22 changes: 13 additions & 9 deletions src/read.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ Dict{Any, Any} with 2 entries:
function read_tags(
data::Vector{UInt8};
ifds::Union{Int,NTuple,UnitRange} = IFDS_ALL_FIELDS,
read_all = true,
read_all::Bool = true,
tags::Union{AbstractVector,Tuple} = Vector{LibExif.ExifTag}([]),
extract_thumbnail = false,
read_mnote = false,
)
extract_thumbnail::Bool = false,
read_mnote::Bool = false,
)
ed_ptr = LibExif.exif_data_new_from_data(data, length(data))
if (ed_ptr == C_NULL)
return error("Unable to read EXIF data: invalid pointer")
Expand All @@ -57,7 +57,9 @@ function read_tags(
tags = normalize_exif_flag(tags)
typeassert(tags, Vector{LibExif.ExifTag})

result = Dict{String,Any}()
result = Dict{String,String}()
thumbnail_data = UInt8[]

try
ed = unsafe_load(ed_ptr)
ifds = collect(ifds)
Expand All @@ -69,7 +71,7 @@ function read_tags(
str = Vector{Cuchar}(undef, 1024)

for i in ifds
content_ptr = ed.ifd[i] # ques: do we need to unref these too?
content_ptr = ed.ifd[i]
if (content_ptr == C_NULL)
return error("Unable to read IFD:", i)
end
Expand All @@ -84,6 +86,7 @@ function read_tags(
if condition
LibExif.exif_entry_get_value(Ref(entry), str, length(str))
tag = String(copy(str))[1:max(findfirst(iszero, str) - 1, 1)]
# @info entry.tag entry.format
if string(entry.tag) keys(result)
tagname = string(entry.tag)
# to update name if its gps ifd
Expand Down Expand Up @@ -133,18 +136,19 @@ function read_tags(
if (extract_thumbnail == true)
thumbnail_size = Int(ed.size)
thumbnail_data = unsafe_wrap(Array, ed.data, thumbnail_size)
result["EXIF_TAG_THUMBNAIL_DATA"] = thumbnail_data
end

finally
LibExif.exif_data_unref(ed_ptr)
end

return result
if (extract_thumbnail) return result, thumbnail_data
else return result end
end

function read_tags(filepath::AbstractString; kwargs...)
open(filepath, "r") do io
read_tags(io; kwargs...)
read_tags(read(io); kwargs...)
end
end

Expand Down
43 changes: 36 additions & 7 deletions src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,26 +1,37 @@
"""
numifds(ed::LibExif._ExifData)
Returns the number of IFDs in the EXIF data.
"""
function numifds(ed::LibExif._ExifData)
return length(ed.ifd)
end


"""
numentriesinifd(data::LibExif._ExifContent)
Returns the number of entries in the IFD.
"""
function numentriesinifd(data::LibExif._ExifContent)
return Int(data.count)
end

"""
normalize_exif_flag(flags::Union{AbstractVector,Tuple}) = map(normalize_exif_flag, flags)
normalize_exif_flag(flag::AbstractString) = normalize_exif_flag(Symbol(flag))
normalize_exif_flag(flag::Symbol) = getfield(LibExif, flag)
normalize_exif_flag(flag::LibExif.ExifTag) = flag
normalize_exif_flag(flag::Int) = LibExif.ExifTag(flag)
Converts the input to `LibExif.ExifTag` type if possible.
"""
normalize_exif_flag(flags::Union{AbstractVector,Tuple}) = map(normalize_exif_flag, flags)
normalize_exif_flag(flag::AbstractString) = normalize_exif_flag(Symbol(flag))
normalize_exif_flag(flag::Symbol) = getfield(LibExif, flag)
normalize_exif_flag(flag::LibExif.ExifTag) = flag
normalize_exif_flag(flag::Int) = LibExif.ExifTag(flag)

function issupported(tag)
if tag in ["EXIF_TAG_MAKE", "EXIF_TAG_ARTIST", "EXIF_TAG_MODEL", "EXIF_TAG_ORIENTATION", "EXIF_TAG_X_RESOLUTION", "EXIF_TAG_Y_RESOLUTION", "EXIF_TAG_RESOLUTION_UNIT", "EXIF_TAG_FOCAL_PLANE_RESOLUTION_UNIT", "EXIF_TAG_YCBCR_POSITIONING", "EXIF_TAG_COMPRESSION", "EXIF_TAG_FNUMBER", "EXIF_TAG_COMPRESSED_BITS_PER_PIXEL", "EXIF_TAG_METERING_MODE", "EXIF_TAG_FLASH", "EXIF_TAG_FLASH_PIX_VERSION", "EXIF_TAG_PIXEL_Y_DIMENSION", "EXIF_TAG_PIXEL_X_DIMENSION", "EXIF_TAG_IMAGE_WIDTH", "EXIF_TAG_IMAGE_LENGTH", "EXIF_TAG_COLOR_SPACE", "EXIF_TAG_FOCAL_PLANE_X_RESOLUTION", "EXIF_TAG_FOCAL_PLANE_Y_RESOLUTION", "EXIF_TAG_SENSING_METHOD", "EXIF_TAG_SUBJECT_DISTANCE_RANGE", "EXIF_TAG_PLANAR_CONFIGURATION", "EXIF_TAG_PHOTOMETRIC_INTERPRETATION", "EXIF_TAG_CUSTOM_RENDERED", "EXIF_TAG_EXPOSURE_MODE", "EXIF_TAG_WHITE_BALANCE", "EXIF_TAG_SCENE_CAPTURE_TYPE", "EXIF_TAG_GAIN_CONTROL", "EXIF_TAG_SATURATION", "EXIF_TAG_SHARPNESS", "EXIF_TAG_CONTRAST"]
return true
else
return false
end
end



Expand Down Expand Up @@ -183,5 +194,23 @@ TagsDict = Dict(
"Soft" => 1,
"Hard" => 2
),
LibExif.EXIF_TAG_EXPOSURE_PROGRAM => Dict{String,UInt16}(
"Not defined" => 0,
"Manual" => 1,
"Normal program" => 2,
"Normal" => 2,
"Aperture priority" => 3,
"Aperture" => 3,
"Shutter priority" => 4,
"Shutter" => 4,
"Creative program (biased toward depth of field)" => 5,
"Creative" => 5,
"Creative program (biased toward fast shutter speed)" => 6,
"Action" => 6,
"Portrait mode (for closeup photos with the background out of focus" => 7,
"Portrait" => 7,
"Landscape mode (for landscape photos with the background in focus)" => 8,
"Landscape" => 8,
)
)

Loading

0 comments on commit 0ea0e03

Please sign in to comment.