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

Help for OPACITY effect algorithm ?


Help for OPACITY effect algorithm ?

Postby denthorq » Apr 20, 2004 @ 5:25pm

Given :

PIXEL* frontbuffer = new PIXEL[240 * 320];

PIXEL* backbuffer = new PIXEL[240 * 320];

And assuming that PIXEL is 'unsigned short', how would I implement an OPACITY effect?

Any algo, code or help are welcome. Thanks in advance.
It's worth the wait...
User avatar
denthorq
pm Insider
 
Posts: 447
Joined: Apr 18, 2003 @ 9:15pm
Location: USA-PHILIPPINES


Postby Jinks » Apr 20, 2004 @ 6:10pm

I'm unsure about your all in one approach as it implies a fixed opacity.

My code for blend of two pixels is based on a 32 levels of mix and 565 RGB which is very common.

int mask=0x07e0f81f; // This is My favorite number. :-)
int c1=*frontbuffer++; // you need 32 bits it's a conversion anyway
int c2=*backbuffer++; // Don't know if it complains without (int)
int opacity=13; // whatever 0-32

c1|=c1<<16;
c1 =c1&mask;
c2|=c2<<16;
c2 =c2&mask;
c1 =c1*opacity;
c1+=c2*(32-opacity);
c1=(c1>>5)&mask;
c1|=c1>>16;
*anotherbuffer++=c1; // Don't know if they are both created each frame
// Can't just keep adding to one or it'll white out
Do above (320*240) times in a loop.

Im sure it's signed - unsigned has hick ups, but its the rough version.
First optimisation would be to try to write in words, so pairs of above and in sequential memories. And with so much effort do some tricks with the opacity level. Thiner at the edges to make beveled glass make it earn that many CPU cycles. Don't allow the opacity to <0 or >32
The stylus is mightier than the pen!
jinks
User avatar
Jinks
pm Member
 
Posts: 281
Joined: Feb 21, 2004 @ 1:57am
Location: Croydon, UK


Postby denthorq » Apr 20, 2004 @ 10:28pm

Basically I want to implement a fade out/ fade in effect and fixed opacity.

Thanks Jinks.
It's worth the wait...
User avatar
denthorq
pm Insider
 
Posts: 447
Joined: Apr 18, 2003 @ 9:15pm
Location: USA-PHILIPPINES


Postby j.edwards » Apr 21, 2004 @ 12:07am

User avatar
j.edwards
pm Member
 
Posts: 240
Joined: Oct 29, 2003 @ 11:09am
Location: Australia


Postby Jinks » Apr 21, 2004 @ 12:11am

The stylus is mightier than the pen!
jinks
User avatar
Jinks
pm Member
 
Posts: 281
Joined: Feb 21, 2004 @ 1:57am
Location: Croydon, UK


Postby Tala » Apr 22, 2004 @ 4:14pm

Tala
pm Member
 
Posts: 125
Joined: Feb 6, 2004 @ 4:32pm


Postby j.edwards » Apr 23, 2004 @ 12:43am

User avatar
j.edwards
pm Member
 
Posts: 240
Joined: Oct 29, 2003 @ 11:09am
Location: Australia


Postby rcp » Apr 23, 2004 @ 4:33am

User avatar
rcp
pm Member
 
Posts: 184
Joined: Jul 18, 2003 @ 2:12am
Location: Duluth, GA. (Southeast US)


Postby Sparkie » Apr 23, 2004 @ 12:35pm

Tala: it's a very neat algorythm. I did not imagine that it could be done with one multiply. Thanks for posting it.
Sparkie
pm Member
 
Posts: 35
Joined: May 7, 2003 @ 2:05pm
Location: Budapest/Hungary


Postby Johan » Apr 23, 2004 @ 1:13pm

Tala: You will get overflow using your algorithm (e.g. if R and B are shifted to the high bit and R is 31 the multiplication will not fit into 32 bits). The only way I know that you can reach one multiplication per pixel is to operate on two pixels simultaneously and use two multiplications for these. And achieving that is not trivial.
Johan Sanneblad, M.Sc, Ph.D
GapiDraw Systems Architect
[]
User avatar
Johan
pm Member
 
Posts: 1843
Joined: Jan 12, 2002 @ 12:38pm
Location: Sweden


Postby refractor » Apr 23, 2004 @ 2:01pm

User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby Jinks » Apr 23, 2004 @ 2:18pm

The stylus is mightier than the pen!
jinks
User avatar
Jinks
pm Member
 
Posts: 281
Joined: Feb 21, 2004 @ 1:57am
Location: Croydon, UK


Postby refractor » Apr 23, 2004 @ 2:24pm

User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby refractor » Apr 23, 2004 @ 2:30pm

User avatar
refractor
pm Insider
 
Posts: 2304
Joined: Feb 5, 2002 @ 1:12pm
Location: Luxembourg


Postby Jinks » Apr 23, 2004 @ 3:15pm

The stylus is mightier than the pen!
jinks
User avatar
Jinks
pm Member
 
Posts: 281
Joined: Feb 21, 2004 @ 1:57am
Location: Croydon, UK


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