The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Making Alpha Channel PNG Images In VisualWorks

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
James Robertson

Posts: 29924
Nickname: jarober61
Registered: Jun, 2003

David Buck, Smalltalker at large
Making Alpha Channel PNG Images In VisualWorks Posted: Jun 26, 2006 3:45 PM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Making Alpha Channel PNG Images In VisualWorks
Feed Title: Travis Griggs - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/travis-rss.xml
Feed Description: This TAG Line is Extra
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From Travis Griggs - Blog

Advertisement

Alpha-Hue Gradient 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'.

Read: Making Alpha Channel PNG Images In VisualWorks

Topic: Why Refactoring Isn't Popular Previous Topic   Next Topic Topic: Wednesday Morning Beach

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use