Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make VideoStream aware of px_per_unit #4466

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
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 CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## [Unreleased]

- Fix relocatability of GLMakie [#4461](https://github.com/MakieOrg/Makie.jl/pull/4461).
- Fix `px_per_unit` not being recognized in `record` and `VideoStream`, leading to errors [#4466](https://github.com/MakieOrg/Makie.jl/pull/4466).

## [0.21.13] - 2024-10-07

Expand Down
8 changes: 7 additions & 1 deletion src/ffmpeg-util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,13 @@ function VideoStream(fig::FigureLike;
get!(config, :visible, visible)
get!(config, :start_renderloop, false)
screen = getscreen(backend, scene, config, GLNative)
_xdim, _ydim = size(screen)
# We extract `px_per_unit` from the screen in order to get the ground truth.
px_per_unit = if hasproperty(screen, :config) && hasproperty(screen.config, :px_per_unit)
screen.config.px_per_unit
else # backend has no screen config, or config has no px_per_unit, so assume 1 px per dip
1
end
_xdim, _ydim = ceil.(Int, size(screen) .* px_per_unit)
xdim = iseven(_xdim) ? _xdim : _xdim + 1
ydim = iseven(_ydim) ? _ydim : _ydim + 1
buffer = Matrix{RGB{N0f8}}(undef, xdim, ydim)
Expand Down
24 changes: 20 additions & 4 deletions test/record.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@ using Logging

module VideoBackend
using Makie
Base.@kwdef struct ScreenConfig
px_per_unit = 1
end
struct Screen <: MakieScreen
size::Tuple{Int, Int}
end
struct ScreenConfig
config::ScreenConfig
end
Base.size(screen::Screen) = screen.size
Screen(scene::Scene, config::ScreenConfig, ::Makie.ImageStorageFormat) = Screen(size(scene))
Screen(scene::Scene, config::ScreenConfig, ::Makie.ImageStorageFormat) = Screen(size(scene), config)
Makie.backend_showable(::Type{Screen}, ::MIME"text/html") = true
Makie.backend_showable(::Type{Screen}, ::MIME"image/png") = true
Makie.colorbuffer(screen::Screen) = zeros(RGBf, reverse(screen.size)...)
Makie.colorbuffer(screen::Screen) = zeros(RGBf, ceil.(Int, reverse(screen.size) .* screen.config.px_per_unit)...)
Base.display(::Screen, ::Scene; kw...) = nothing
end

Expand Down Expand Up @@ -39,6 +41,20 @@ mktempdir() do tempdir
end
end

@testset "px_per_unit" begin
for fmt in ("mp4", "gif"), px_per_unit in (1, 2)
dst = joinpath(tempdir, "out_$px_per_unit.$fmt")
@test begin
record(fig, dst, 1:n; px_per_unit) do i
lines!(ax, sin.(i .* x))
return nothing
end
true
end
end
end


# test that the proper warnings are thrown
@testset "Warnings" begin
function run_record(dst; kwargs...)
Expand Down