Skip to content

Commit

Permalink
Support for cairo_image_surface_get_data (#342) (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
luchr authored Apr 5, 2021
1 parent 80f9ea6 commit 2b7185c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/Cairo.jl
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,12 @@ for name in (:finish,:flush,:mark_dirty)
end
end

function image_surface_get_data(surface::CairoSurface{T}) where {T}
return ccall(
(:cairo_image_surface_get_data, libcairo),
Ptr{T}, (Ptr{Nothing},), surface.ptr)
end

function status(surface::CairoSurface)
ccall((:cairo_surface_status,libcairo),
Int32, (Ptr{Nothing},), surface.ptr)
Expand Down
10 changes: 10 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,16 @@ end
d = simple_hist(d1)

@test length(d) == 512 # black is included

# width: 5, height: 3; Test-Image
mat = [ 0x80800000 0x00000000 0x00000000
0x80800000 0x00000000 0x00000000
0x80800000 0x33000033 0x33000033
0x80800000 0x33000033 0x33000033
0xff00ff00 0xff00ff00 0x00000000 ]
surf = CairoImageSurface(mat, Cairo.FORMAT_ARGB32; flipxy=false)
data_arr = unsafe_wrap(Array, Cairo.image_surface_get_data(surf), (5, 3))
@test (mat == data_arr) && (mat == surf.data)
end

@testset "Assert/Status " begin
Expand Down

0 comments on commit 2b7185c

Please sign in to comment.