Results 1 to 15 of 15

Thread: alphablending?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    112

    alphablending?

    hey guys
    i am sure some of you guys have used sonique or the new opera 7..have you noticed (especially in sonique) how pressing a button results in a nice effect?it looks lke it is being pressed slowlly (sortof)..is that called alphablending?
    anyways, does anyone know of a tutorial or the like where i could learn the basics of those effects? thanks in advance (all i have found oin the web is for directX)

  2. #2

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    112
    btw, i wouldn't be using any actual buttons..just images (png)..

  3. #3
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Search the MSDN for Alphablend, there is a API for it.(win98 and above)

    [Edited: I think the API is for BMP only]

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    112
    is it hard to implement? because i am not on windows..

  5. #5
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Err... shouldn't be hard for me. The formula is given in the MSDN. You have to do it pixel by pixel

    You have to make sure the results are within 0-255.

    Eg,After calculation, red component is the biggest number of the 3 components and is more than 255, you have to set it to 255. If you scale down red by 20%, green and blue have to be scaled down by 20% too, no matter whether they are bigger than 255 in the first place. The same thing applies to results less than 0.

  6. #6

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    112
    cool thanks i'll look at that

  7. #7
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    if any color component is more than 255.0, use the code below to make it positive.


    FinalRed, FinalGreen and FinalBlue are floats.
    nFinalRed, nFinalGreen and nFinalBlue are integers.

    Code:
    	if(FinalRed>=FinalGreen && FinalRed>=FinalBlue)
    	{
    		if(FinalRed>255.0f)
    		{
    			nFinalRed=255;
    			nFinalGreen=(int)(FinalGreen/FinalRed*255.0f);
    			nFinalBlue =(int)(FinalBlue/FinalRed*255.0f);
    		}
    		else
    		{
    			nFinalRed  =(int)(FinalRed);
    			nFinalGreen=(int)(FinalGreen);
    			nFinalBlue =(int)(FinalBlue);
    		}
    	}
    	else if(FinalGreen>=FinalRed && FinalGreen>=FinalBlue)
    	{
    		if(FinalGreen>255.0f)
    		{
    			nFinalRed  =(int)(FinalRed/FinalGreen*255.0f);
    			nFinalGreen=255;
    			nFinalBlue =(int)(FinalBlue/FinalGreen*255.0f);
    		}
    		else
    		{
    			nFinalRed  =(int)(FinalRed);
    			nFinalGreen=(int)(FinalGreen);
    			nFinalBlue =(int)(FinalBlue);
    		}
    	}
    	else if(FinalBlue>=FinalRed && FinalBlue>=FinalGreen)
    	{
    		if(FinalBlue>255.0f)
    		{
    			nFinalRed  =(int)(FinalRed/FinalBlue*255.0f);
    			nFinalGreen=(int)(FinalGreen/FinalBlue*255.0f);
    			nFinalBlue=255;
    		}
    		else
    		{
    			nFinalRed  =(int)(FinalRed);
    			nFinalGreen=(int)(FinalGreen);
    			nFinalBlue =(int)(FinalBlue);
    		}
    	}
    Last edited by transcendental; Feb 26th, 2003 at 04:40 AM.

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    112
    thanks a lot..one thing though: is this the formula(s) you were talking about?
    http://msdn.microsoft.com/library/de...tmaps_3b3m.asp
    thanks again

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    112
    i think this is what you meant:

    Blend = Alpha * Source + (1 - Alpha) * Destination

    what exactly do the variables stand for? i dont understand what they represent.
    basically i would have to do this for every pixel, and for all 3 chanels?

  10. #10
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    Originally posted by paneb
    i think this is what you meant:

    Blend = Alpha * Source + (1 - Alpha) * Destination

    what exactly do the variables stand for? i dont understand what they represent.
    Yes, that is the formula I meant. Alpha is from 0 to 255, Alpha means (degree of) transparency(0 is transparent and 255 is opaque.)

    Source means the source pixel and destination means the destination pixel; Basically they are the 2 you want to mix together to form the effect.

    Blend is the result.

    Originally posted by paneb
    basically i would have to do this for every pixel, and for all 3 chanels?
    Yes, you have to do it for all the 3 primary colors of every pixel.

  11. #11
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    What system are you on? Linux?
    You might want to use libart, it supports alpha blending.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2003
    Posts
    112
    yea i know about libart..but i wanna try writing the function though..
    i have one question: i havent' done much gfx stuff..how would go about calculating the Blend for each pixel? i mean how would i sotre the pixels i have worked on, and how would i move on to the next one? would i need to create an arrya or something?

  13. #13
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Depends on what you want to do. Basically you're drawing to a target. The target might be the screen or a memory buffer. So for each pixel you get the two source pixels, blend them together and store the result at the output location. For efficiency this should be a memory location which you then blit to the screen all at once.

    transcendental:
    Given the formula here Alpha ranges from 0.0 to 1.0. If it was from 0 to 255 then the formula would be
    Blend = Alpha * Source + (255 - Alpha) * Destination

    or in general
    Blend = Alpha * Source + (AlphaRange - Alpha) * Destination
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  14. #14
    Hyperactive Member
    Join Date
    Sep 2001
    Posts
    396
    If it was from 0 to 255 then the formula would be
    Blend = Alpha/255.0 * Source + (1.0 - Alpha/255.0) * Destination

  15. #15
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    *selfslap*

    Yeah, right.
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width