This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Alpha Blending (Transparency) Examples.


Alpha Blending (Transparency) Examples.

Postby brendan » Oct 3, 2007 @ 12:19am

Hi Everyone,

I've been using a "hacked up" EasyCE library for all my games up until now, and it's still doing what I want, so I don't really want to have to jump to another library. I've effectivly build my own library from Jackos old one.

Anyone, the one thing that the library does not support is good alpha channel transparency. Up until now, I've just been using a transparency color, but this tends to give quite a harsh look.

Are there any really good examples anywhere on how to implement transparency? could someone share a TGA file example. I have alomost no idea, if someone would like to spend a little time explaining the process from Photoshop to code to get the final product I'd be very thankful.

I'm happy to share what my library currently has, in order to support it etc. I'm all for educationing the PDA Dev community.

-thanks.
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby j.edwards » Oct 3, 2007 @ 1:06am

For the blending of pixels I used Tala's suggestion from this thread:

http://www.pocketmatrix.com/forums/view ... tala+alpha

I prefer to work with PNG files because Photoshop and Inkscape support them and they have the 8bit alpha. Because I use PocketHAL which abstracts the display always as 16bit 565 I make sure all images are stored in that format and have built a little cmd line utility that converts PNG files into a custom format which is in 16-565 format and includes the alpha channel as a 5 bit value (see post above). By doing this there is no need to convert anything at runtime on the ppc - it's just straight blit to surface from there.
User avatar
j.edwards
pm Member
 
Posts: 240
Joined: Oct 29, 2003 @ 11:09am
Location: Australia


Postby brendan » Oct 3, 2007 @ 9:08am

User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby Dan East » Oct 3, 2007 @ 11:57am

User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Postby brendan » Oct 3, 2007 @ 12:17pm

Yer, I figured since it was greyscale I could use one, but decided to use the KISS principle until I got it working.

Hopefully this will work... :)

OK, almost...

just a few variable conflicts and pumping the result back to dest[calcd]

:)
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby brendan » Oct 3, 2007 @ 1:32pm

Ok, All working, sweet as. Next issue.

I've been playing around with photoshop for quite a while, I can create the alpha channel, it all looks sweet etc, but I can't save only the alpha channel as a tga.... talk about frustrating.....

how do you guys do it, just save the alpha as part of the tga, and recode the tga load algo?

-B
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby Dan East » Oct 4, 2007 @ 12:34am

For some reason, saving alpha channels in TGA files is really tough. Randall and I worked on this for a few hours to get a technique in place. We ended up using Paint Shop Pro (version 6 at that time) to save the alpha channel to TGA. It was a fairly convoluted process that I can't really remember the specifics of. He never could get a method worked out with Photoshop. I guess saving alpha channel to TGA isn't a very important feature, so it is pretty much an implementation afterthought.

Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Postby brendan » Oct 4, 2007 @ 2:09am

I've been having some success by going to channels, only displaying the alpha, selecting all, then copying it, then pasting that into a new layer. It seems to work ok, bit of a long process, particually if your trying to tweek the image. I mite try to "automate" it.

-B
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby j.edwards » Oct 4, 2007 @ 2:21am

Is there any reason why you have to use TGA's? I would recommend using PNGs.
User avatar
j.edwards
pm Member
 
Posts: 240
Joined: Oct 29, 2003 @ 11:09am
Location: Australia


Postby brendan » Oct 4, 2007 @ 11:46pm

User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby j.edwards » Oct 5, 2007 @ 12:59am

In my code I check for alpha == 0 (ignore that pixel and move to next), and alpha == 31 - just copy src pixel directly as no alpha necessary. Haven't done any performance tests, but am assuming it's quicker because most images I use have a large chunk of alpha=31 but with edge transparency.

Png can store a variety of pixel formats but I just use the simple 32bit - 8r, 8g, 8b, 8a - because it's easy to convert. Wouldn't be surprised if you can store in a 16bit 565 format and have an alpha channel as well though.

For png I used libpng (which also required zlib), which took a bit to get building, and I could never get it to build for ppc, which wasn't a big problem for my purposes because most of my images are icons so I convert them on desktop to a simple run-length encoding that isn't as well compressed as png obviously. if you need large images then you will need to spend the time to get it building for ppc so you can store them as png on the client. There are posts in this forum about using jpegs as well which compress better than pngs because png are lossless.

Depending on how each image is used I choose to keep it as run-length encoded in memory or expanded out to a full surface - if it can be drawn without dropping framerate as runlength then that is done to reduce memory, but if there are clipping issues or need maximum performance then expand them out.

It was a bit of work to get it all working, but has made life so much easier since. Now I can just work with the graphics tools like photoshop or inkscape, save as png, double click a batch file that converts all png images in the folder, package them as part of that process, F5 and go. If you are going to get back into ppc development seriously, it's probably worth your while getting it sorted out to start with.
User avatar
j.edwards
pm Member
 
Posts: 240
Joined: Oct 29, 2003 @ 11:09am
Location: Australia


Postby Dan East » Oct 5, 2007 @ 3:30am

TGA supports RLE compression.

Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Postby brendan » Oct 5, 2007 @ 6:31am

yep, but the way my app is coded it's not much use, because I just unzip the tga directly into a buffer. It may be useful if you unpack it in RLE, but then it would make mem allocation a nightmare.

-B
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Postby Cardinal » Oct 5, 2007 @ 7:38pm

I just got my image loader up and running using the IImagingFactory thats part of WindowsCE. It's quite nice as it loads PNG, JPG, GIF and BMP. It isn't done yet as it only loads from file but once I get it working so that it also loads a BMP from the resources and image decoding from memory, I'll post the code here.

If your just after PNG loading, I found this library which could be adapted in all sorts of ways:

http://homepage3.nifty.com/ysflight/png ... odere.html

As for alpha channels, I stick to PNG's for the compression. Photoshop will allow you to create and save images with alpha channel in TGA and PNG format. While in Photoshop, go to the Windows menu and select layers or hit F7. IN that new window you'll select the channels tab, from there you'll see the RGB channel layout.

If there is great demand for how alpha channels are created and saved in photoshop, I can post a tutorial.
Cardinal
pm Member
 
Posts: 53
Joined: Feb 6, 2006 @ 5:39am
Location: Ottawa, Ontario


Postby brendan » Oct 16, 2007 @ 6:41am

I'm getting some very random results....

1/2 the time it works, the other 1/2 it does not. I can't seem to consistantly create a system to produce an alpha channel with anything other than either black or white..

Maybe it would be easier to get a png library to load a png into a 565 buffer with an 8bit transparency buffer or 565(8) format.

Has anyone does this, feel like sharing?

-B
User avatar
brendan
pm Insider
 
Posts: 451
Joined: Oct 23, 2001 @ 2:51am
Location: Hobart, Australia


Next

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron