1) first allocate a C-side buffer in memory and stores the encoded bytes, and
2) unsafe_wrap the buffer in Julia side and use Julia’s IO operation to write to the output file
function jpeg_encode(filename::AbstractString, img; kwargs...)
open(filename, "w") do io
jpeg_encode(io, img; kwargs...)
end
end
jpeg_encode(io::IO, img; kwargs...) = write(io, jpeg_encode(img; kwargs...))
If we can fuse two stages, then we can get a faster version.
For jpeg_encode(filename, img) specifically, it's also possible to wrap the C stdio Libc.FILE version.
The current pipeline consists of two stages:
1) first allocate a C-side buffer in memory and stores the encoded bytes, and 2) unsafe_wrap the buffer in Julia side and use Julia’s IO operation to write to the output file
If we can fuse two stages, then we can get a faster version.
For
jpeg_encode(filename, img)
specifically, it's also possible to wrap the C stdioLibc.FILE
version.