diff --git a/CHANGELOG.md b/CHANGELOG.md index 27b244bd1b0..e4596871baf 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ - Changed `inspectable` to be inherited from the parent scenes theme. [#4739](https://github.com/MakieOrg/Makie.jl/pull/4739) - Reverted change to `poly` which disallowed 3D geometries from being plotted [#4738](https://github.com/MakieOrg/Makie.jl/pull/4738) - Enabled autocompletion on Block types, e.g. `?Axis.xti...` [#4786](https://github.com/MakieOrg/Makie.jl/pull/4786) +- Added `dpi` metadata to all rendered png files, where `px_per_unit = 1` means 96dpi, `px_per_unit = 2` means 192dpi, and so on. This gives frontends a chance to show plain Makie png images with the correct scaling [#4812](https://github.com/MakieOrg/Makie.jl/pull/4812). ## [0.22.1] - 2025-01-17 diff --git a/CairoMakie/src/display.jl b/CairoMakie/src/display.jl index 813b53b7b10..ac87b0a9358 100644 --- a/CairoMakie/src/display.jl +++ b/CairoMakie/src/display.jl @@ -101,13 +101,6 @@ function Makie.backend_show(screen::Screen{EPS}, io::IO, ::MIME"application/post return screen end -function Makie.backend_show(screen::Screen{IMAGE}, io::IO, ::MIME"image/png", scene::Scene) - Makie.push_screen!(scene, screen) - cairo_draw(screen, scene) - Cairo.write_to_png(screen.surface, io) - return screen -end - # Disabling mimes and showable const DISABLED_MIMES = Set{String}() diff --git a/CairoMakie/src/screen.jl b/CairoMakie/src/screen.jl index b6759fee88d..499afa18709 100644 --- a/CairoMakie/src/screen.jl +++ b/CairoMakie/src/screen.jl @@ -305,6 +305,9 @@ function Makie.apply_screen_config!(screen::Screen, config::ScreenConfig, scene: Makie.apply_screen_config!(screen, config, scene, nothing, MIME"image/png"()) end +function Makie.px_per_unit(s::Screen)::Float64 + return s.config.px_per_unit +end function Screen(scene::Scene; screen_config...) config = Makie.merge_screen_config(ScreenConfig, Dict{Symbol, Any}(screen_config)) diff --git a/GLMakie/src/screen.jl b/GLMakie/src/screen.jl index 92270e68938..eee1b25f9ec 100644 --- a/GLMakie/src/screen.jl +++ b/GLMakie/src/screen.jl @@ -463,6 +463,12 @@ function Screen(; return screen end +function Makie.px_per_unit(s::Screen)::Float64 + config = s.config + config === nothing && return 1.0 + return something(config.px_per_unit, 1.0) +end + function set_screen_visibility!(screen::Screen, visible::Bool) if !screen.owns_glscreen error(unimplemented_error) diff --git a/Project.toml b/Project.toml index 39fc4abdc40..2f81a0c653a 100644 --- a/Project.toml +++ b/Project.toml @@ -102,7 +102,7 @@ Markdown = "1.0, 1.6" MathTeXEngine = "0.5, 0.6" Observables = "0.5.5" OffsetArrays = "1" -PNGFiles = "0.4.3" +PNGFiles = "0.4.4" Packing = "0.5" PlotUtils = "1.4.2" PolygonOps = "0.1.1" diff --git a/ReferenceTests/src/runtests.jl b/ReferenceTests/src/runtests.jl index 52a689289d0..9fb54e76524 100644 --- a/ReferenceTests/src/runtests.jl +++ b/ReferenceTests/src/runtests.jl @@ -2,8 +2,7 @@ function get_frames(a, b) return (get_frames(a), get_frames(b)) end -rgbf_convert(x::AbstractMatrix{<:RGB}) = convert(Matrix{RGBf}, x) -rgbf_convert(x::AbstractMatrix{<:RGBA}) = convert(Matrix{RGBAf}, x) +rgbaf_convert(x::AbstractMatrix{<:Union{RGB,RGBA}}) = convert(Matrix{RGBAf}, x) function get_frames(video::AbstractString) mktempdir() do folder @@ -25,8 +24,8 @@ end function compare_images(a::AbstractMatrix{<:Union{RGB,RGBA}}, b::AbstractMatrix{<:Union{RGB,RGBA}}) - a = rgbf_convert(a) - b = rgbf_convert(b) + a = rgbaf_convert(a) + b = rgbaf_convert(b) if size(a) != size(b) @warn "images don't have the same size, difference will be Inf" diff --git a/WGLMakie/src/display.jl b/WGLMakie/src/display.jl index 52e29b8998c..d5d42cc7f82 100644 --- a/WGLMakie/src/display.jl +++ b/WGLMakie/src/display.jl @@ -66,6 +66,10 @@ mutable struct Screen <: Makie.MakieScreen end end +function Makie.px_per_unit(s::Screen)::Float64 + return something(s.config.px_per_unit, 1.0) +end + function Screen(; config...) config = Makie.merge_screen_config(ScreenConfig, Dict{Symbol,Any}(config)) return Screen(nothing, config) diff --git a/src/display.jl b/src/display.jl index 336c6028922..58459a54d4e 100644 --- a/src/display.jl +++ b/src/display.jl @@ -480,10 +480,14 @@ function colorbuffer(fig::FigureLike, format::ImageStorageFormat = JuliaNative; end end +px_per_unit(screen::MakieScreen)::Float64 = 1.0 # fallback for backends who don't have upscaling + # Fallback for any backend that will just use colorbuffer to write out an image function backend_show(screen::MakieScreen, io::IO, ::MIME"image/png", scene::Scene) img = colorbuffer(screen) - FileIO.save(FileIO.Stream{FileIO.format"PNG"}(Makie.raw_io(io)), img) + px_per_unit = Makie.px_per_unit(screen)::Float64 + dpi = px_per_unit * 96 # attach dpi metadata corresponding to 1 unit == 1 CSS pixel + FileIO.save(FileIO.Stream{FileIO.format"PNG"}(Makie.raw_io(io)), img; dpi) return end