The Artima Developer Community
Sponsored Link

Agile Buzz Forum
Alpha Blending 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
Alpha Blending in VisualWorks Posted: Nov 7, 2007 4:54 AM
Reply to this message Reply

This post originated from an RSS feed registered with Agile Buzz by James Robertson.
Original Post: Alpha Blending in VisualWorks
Feed Title: David Buck - Blog
Feed URL: http://www.cincomsmalltalk.com/rssBlog/buck-rss.xml
Feed Description: Smalltalk can do that
Latest Agile Buzz Posts
Latest Agile Buzz Posts by James Robertson
Latest Posts From David Buck - Blog

Advertisement

A while back, Runar Jordahl wrote an article on how to do alpha blending in Smalltalk. He found that it was fast enough for standard applications.

Just for fun, I thought I'd try to approach the problem a different way. Runar's implementation plays nice with Images, uses proper encapsulation and does the alpha blending in floating point numbers. I took the "D*** the torpedoes" approach and went for put raw speed. I broke all the encapsulation rules and did the operation as fast as I could using Integer arithmetic in Smalltalk. The result is over 6 times faster than Runar's optimized approach.

Using this technique, I can alpha blend two images of size 1128x680 within about 200mS on my system. Not bad for being pure Smalltalk code. With a primitive, I'm sure I can go much faster.

The following method for Depth32Image does the work. It assumes that the palette is ABGR.

alphaBlendWith: aDepth32Image
  | otherBits bitsSize | 	
	aDepth32Image width = self width
		ifFalse: [^self error: 'Not the same size'].
	aDepth32Image height = self height
		ifFalse: [^self error: 'Not the same size'].
	aDepth32Image bitsPerPixel = 32
		ifFalse: [^self error: 'Wrong pixel depth'].
	otherBits := aDepth32Image bits.
	bitsSize := bits size.
	1 to: bitsSize by: 4 do: [:i |
		| j a ra |
		a := otherBits at: i.
		ra := 255 - a.
		j := i + 1.
		bits at: j put: (((bits at: j) * ra)
			+ ((otherBits at: j) * a) bitShift: -8).
		j := j + 1.
		bits at: j put: (((bits at: j) * ra)
			+ ((otherBits at: j) * a) bitShift: -8).
		j := j + 1.
		bits at: j put: (((bits at: j) * ra)
			+ ((otherBits at: j) * a) bitShift: -8)]

Read: Alpha Blending in VisualWorks

Topic: Strike Pain Previous Topic   Next Topic Topic: Industry Misinterpretations 60: Big Dave

Sponsored Links



Google
  Web Artima.com   

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