Indigo Rose Software

Professional Software Development Tools

 
Results 1 to 12 of 12

Thread: RGB Maths

  1. #1
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420

    RGB Maths

    Ive been trying to work out how to merge to bitmaps with added fade. If i want an even fade between the two pictures the process is quite simple, I can go though the pictures pixel by pixel ,Split the matching pixels into RGB values, add them together

    Red =(RedA + RedB) / 2
    Green = (GreenA + GreenB) / 2
    Blue = (BlueA + BlueB) / 2

    This is the average color of the 2 combined.

    Now i want to be able to set the level of fade on one PicB as its merged onto pic A (which has no fade).
    I tried the same calculation as before but halved (50%) of the color channels for picB


    Red = (RedA + (50% of RedB)) / 2
    Green = (GreenA + (50% of GreenB)) / 2
    Blue = (BlueA + (50% of BlueB)) / 2

    but instead of getting a weaker image of picB on top of PicA i just get a darker one.
    Does anyone know how i can merge the two pics correctly?
    thanks.
    Last edited by clueless; 05-12-2008 at 08:11 PM.

  2. #2
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420
    I tried a weighted average
    weighted average = the sum of the values + the weights assigned to [each value] divided by the sum of the weights
    or
    x=Exw/Ew
    so If picA Red channel was 120 and PicB channel was (50 % of 80) the calculation would be;
    ((120*1)+(80*0.5))/(1+0.5)
    This is slightly better but still to dark.

  3. #3
    Join Date
    Oct 2007
    Location
    Gensokyo
    Posts
    1,324
    Code:
    function Create(Red,Green,Blue)
    	return ((Red) + (Green*256) + (Blue*256*256));
    end
    rgb.lua, Gallery\Scripts\

    Dunno if that's what your looking for or not. Don't really understand what you're looking for.

  4. #4
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420
    Thanks, Ive been advised to try this method;-
    * Find the average R/G/B values for image B.
    * Create a "virtual image" with differential RGB-values, i.e. the values for each pixel will be the differences of the original values for that pixel from the average values for the image. This will produce negative as well as positive values, so this is not an image you can display, of course.
    * Now apply this virtual image to image A, multiplying by a fade factor, i.e.

    Red = RedA + f*RedV

    This will produce a result that has the same brightness as the original A, since you're adding an image with brightness 0, but exhibiting the brightness and colour variations of B superimposed on those of A. This would be called a "Hue/Saturation" blend in Photoshop, I think.
    looks promising..

  5. #5
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420
    Ive had an idea,Sside has made 2 dll's that can Read/Write pixels and convert color values between win32 and .net. The .net color values have an extra color channel for opacity so It would just be a case of scanning though picB pixel by pixel converting all the colors first to RGB then adding a value for opacity and converting it back to .Net. Then just write the .net value to picA. I think the mixing of the final colors should be automatic.
    Its a shame i haven't got the Declarations and function calls for the dll's in VB, then i could just make a commandline prog to do the job and benefit from the extra speed. I'm going to have a go at guessing them but i haven't had much luck at doing this in the past.lol
    Last edited by clueless; 05-13-2008 at 04:46 AM.

  6. #6
    Join Date
    Feb 2001
    Location
    Indigo Rose Software
    Posts
    2,728
    Look up "alpha blending" on google. The traditional formula is:

    result = ( ALPHA * ( srcPixel - destPixel ) ) / 256 + destPixel

    ...where ALPHA is a value from 0 to 255.

    For RGB color modes, you need to do that for each channel (red, green, and blue).

    There are various ways to optimize it further, but that basic formula should get you on the right track.

    I wouldn't expect your approach to be fast in any case, since your overhead will be way too high doing it one pixel at a time. But it would be a good learning exercise!
    --[[ Indigo Rose Software Developer ]]

  7. #7
    Join Date
    Dec 2003
    Location
    The Netherlands
    Posts
    475
    clueless

    Can you post here an manipulated image to show me what you're trying to accomplish?

    Quote Originally Posted by clueless View Post
    Its a shame i haven't got the Declarations and function calls for the dll's in VB, then i could just make a commandline prog to do the job and benefit from the extra speed. I'm going to have a go at guessing them but i haven't had much luck at doing this in the past.lol
    I thought forum member Rizla did post you the vb declarations? Have you tried it and it didn't work out?

    With Kind Regards
    sside

  8. #8
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420
    Lorne: thanks ill give that a try.

    Sside: Sure, this is the effect im trying to achieve:

    I used paintshop pro with blending on normal.Picture A is at full opacity. Pic B is placed into an empty layer which then has its opacity altered in percentage increments of 10.

    I had a problem with one or two of the declarations.
    Attached Images

  9. #9
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420
    I dont think its possible to use the dll's as they are now with Visual basic. Every time ive attempted to use them i get
    Error 49: Bad Dll calling convention
    I asked around at few other forums and have been told
    A calling convention error most likely means the DLL uses the cdecl convention. You'll would need to add _stdcall to the function signatures and recompile. Alternatively, write a TLB with the _cdecl convention.

  10. #10
    Join Date
    May 2006
    Posts
    5,380
    A calling convention error most likely means the DLL uses the cdecl convention. You'll would need to add _stdcall to the function signatures and recompile. Alternatively, write a TLB with the _cdecl convention.
    or call the dll with the "DLL_CALL_CDECL" flag.
    Open your eyes to Narcissism, Don't let her destroy your life!!

  11. #11
    Join Date
    Apr 2007
    Location
    Raalte, OV, Netherlands
    Posts
    3,287
    haha xD nice...
    Bas Groothedde
    Imagine Programming :: Blog :: Familiar people here

    My AMS Plugins:

  12. #12
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420
    That sounds very promising , could you show me how thats done?

  13. #13
    Join Date
    Jun 2006
    Location
    UK SouthWest
    Posts
    420
    Im realy not sure what you mean , i put "visual basic dll DLL_CALL_CDECL" into google and got nothing.

Similar Threads

  1. RGB to HEX
    By jwarrent in forum AutoPlay Media Studio 5.0
    Replies: 13
    Last Post: 08-25-2004, 04:49 PM

Posting Permissions

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