You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hoping you can help me work out how to use Cairo.jl to get better code for this. I'm trying to extract the data from a copied image surface. The values match if alpha is 1, but not if alpha is less than 1.0.
Here's the MWE:
using Cairo
alpha = 0.5
rgba(k) = reinterpret(UInt8,[k]) ./ 0xFF
############### source image
surface = CairoARGBSurface(256, 256)
cr = CairoContext(surface)
save(cr)
set_source_rgba(cr, 0.8, 0.8, 0.8, alpha)
rectangle(cr, 0.0, 0.0, 256.0, 256.0)
fill(cr)
restore(cr)
save(cr)
set_source_rgba(cr, 1.0, 0.5, 0.0, alpha)
rectangle(cr, 64.0, 64.0, 64.0, 64.0)
fill(cr)
restore(cr)
save(cr)
set_source_rgba(cr, 0.0, 1.0, 1.0, alpha)
rectangle(cr, 100.0, 100.0, 64.0, 64.0)
fill(cr)
restore(cr)
Cairo.write_to_png(surface,"/tmp/image1.png")
############## make a copy
z = zeros(UInt32, 256, 256)
imagesurface = CairoImageSurface(z, Cairo.FORMAT_ARGB32)
crdest = CairoContext(imagesurface)
set_source_surface(crdest, surface, 0, 0)
set_operator(crdest, Cairo.OPERATOR_SOURCE)
paint(crdest)
data = imagesurface.data # this works
println(rgba(data[1])) # but values are different
Cairo.write_to_png(imagesurface,"/tmp/image2.png")
If alpha is 1.0, the value printed is [0.8, 0.8, 0.8, 1.0], matching the first pixel's value, but if alpha is 0.5, the printed value is [0.4, 0.4, 0.4, 0.5019607843137255].
What I want to do is copy an RGB image to a matrix with accurate values. I think I'm missing some information about copying alpha color values...
The text was updated successfully, but these errors were encountered:
Hoping you can help me work out how to use Cairo.jl to get better code for this. I'm trying to extract the data from a copied image surface. The values match if
alpha
is 1, but not ifalpha
is less than 1.0.Here's the MWE:
If
alpha
is 1.0, the value printed is[0.8, 0.8, 0.8, 1.0]
, matching the first pixel's value, but ifalpha
is 0.5, the printed value is[0.4, 0.4, 0.4, 0.5019607843137255]
.What I want to do is copy an RGB image to a matrix with accurate values. I think I'm missing some information about copying alpha color values...
The text was updated successfully, but these errors were encountered: