Runar Jordhal did a post the other day about how Display Alpha Channel PNG Images in VisualWorks. He used as his example a PNG from the png test suite, where the vertical gradient is based on hue and the horizontal gradient is alpha channel.
I thought it would be fun to generate that swatch pragmatically from within VisualWorks. Using my newest toy of course: Cairo. The fun thing about generating it yourself is that you can vary it. Like... make the size bigger.
It also gave me a chance to begin to flesh out the Smalltalk language binding to the Cairo library. I chose to reify the "pattern" interfaces. So patterns have now been fleshed out. They look like normal Smalltalk objects and hide the C'ish patterns. Next, I need to work on the actual "context" itself. Here's the Smalltalk code used to generate that image:
lib := LibCairo new.
size := 128.
data := CIntegerType unsignedChar gcCalloc: size squared * 4.
surface := lib
cairo_image_surface_create_for_data: data
with: (lib _cairo_format memberNamed: #CAIRO_FORMAT_ARGB32)
with: size
with: size
with: size * 4.
cr := lib cairo_create: surface.
colorPattern := LinearGradient from: 0 @ 0 to: 0 @ image height.
0 to: image height - 1
do: [:n | colorPattern addStopAt: n / size colorValue: (ColorValue hue: n / size)].
alphaPattern := LinearGradient from: 0 @ 0 to: image width @ 0.
alphaPattern addStopAt: 0.0 red: 0 green: 0 blue: 0 alpha: 0.
alphaPattern addStopAt: 1.0 red: 0 green: 0 blue: 0 alpha: 1.0.
lib cairo_set_source: cr with: colorPattern handle.
lib cairo_mask: cr with: alphaPattern handle.
lib cairo_surface_write_to_png: surface with: '/home/travis/cairo_runar.png'.