Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions reference/Project.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[deps]
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Colors = "5ae59095-9a9b-59fe-a467-6f913c188581"
FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549"
LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f"
MathTeXEngine = "0a4f8689-d25c-4efe-a92b-7142dfc1aa53"
Expand Down
49 changes: 34 additions & 15 deletions reference/compare.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using CairoMakie
using Colors
using FileIO
using MathTeXEngine
using Tar
Expand All @@ -7,7 +8,7 @@ using TOML

include("references.jl")

function download_refimages(tag = "refimages-v2")
function download_refimages(tag = "refimages-v3")
url = "https://github.com/Kolaru/MathTeXEngine.jl/releases/download/$tag/reference_images.tar"
images_tar = joinpath(@__DIR__, "reference_images.tar")
images = joinpath(@__DIR__, "reference_images")
Expand Down Expand Up @@ -37,12 +38,15 @@ function image_paths(references)
return paths
end

n_bad_pixels(img1, img2) = count(>(0.5), image_difference(img1, img2))
image_difference(img1, img2) = colordiff.(img1, img2) ./ 100

@testset "Reference images" begin
@info "Reference test started"

@info "Downloading reference images"
reference_images = download_refimages()
@inof "Reference images downloaded in $reference_images"
@info "Reference images downloaded in $reference_images"

@info "Generating comparison images"
comparison_images = joinpath(@__DIR__, "comparison_images")
Expand All @@ -59,22 +63,37 @@ end
for image_path in image_paths(REFERENCES)
@info "Comparing $image_path"

refimg = load(joinpath(reference_images, image_path))
img = load(joinpath(comparison_images, image_path))
refimg = rotr90(load(joinpath(reference_images, image_path)))
img = rotr90(load(joinpath(comparison_images, image_path)))

if (failed = n_bad_pixels(img, refimg) >= 10)
@info "Saving the reference comparison for '$image_path' (image difference $(n_bad_pixels(img, refimg)))"
fig = Figure(size = (3*size(img, 1), size(img, 2)))
Label(fig[1, 1], "Reference $(size(refimg))", tellwidth=false)
axref = Axis(fig[2, 1], aspect = DataAspect())
hidedecorations!(axref)
image!(axref, refimg)

Label(fig[1, 2], "Current $(size(img))", tellwidth=false)
axcurrent = Axis(fig[2, 2], aspect = DataAspect())
hidedecorations!(axcurrent)
image!(axcurrent, img)

if img != refimg
@info "Saving the reference comparison for '$image_path'."
fig = Figure()
fig[1, 1] = Label(fig, "Reference", tellwidth=false)
axref = fig[2, 1] = Axis(fig, aspect=DataAspect())
image!(axref, rotr90(refimg))
if size(img) == size(refimg)
Label(fig[1, 3], "Difference ($(n_bad_pixels(img, refimg)) bad pixels). Blue: reference. Orange: current.", tellwidth=false)
axdiff = Axis(fig[2, 3], aspect = DataAspect())
hidedecorations!(axdiff)
diff = Gray.(img) - Gray.(refimg)
overlay = RGB.(Gray.(refimg), Gray.(img)./2 .+ Gray.(refimg)./2, Gray.(img))

fig[1, 2] = Label(fig, "Current", tellwidth=false)
axcurrent = fig[2, 2] = Axis(fig, aspect=DataAspect())
image!(axcurrent, rotr90(img))
image!(axdiff, overlay)
end

save(joinpath(path, image_path), fig)
comparison_path = joinpath(path, image_path)
mkpath(dirname(comparison_path))
@info "Saving the reference plot at $comparison_path"
save(comparison_path, fig)
end
@test img == refimg
@test !failed
end
end
2 changes: 1 addition & 1 deletion reference/references.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const SUPPORTED_FONTS = [
]

function generate(destination_folder, references = REFERENCES, fonts = SUPPORTED_FONTS)
@info "Generating reference images in folder $destination_folder"
@info "Generating images in folder $destination_folder"

path = mkpath(destination_folder)
failures = Dict()
Expand Down
Loading