User Tag List

Results 1 to 5 of 5

Thread: Extracting the RGB components from an RGB value?

  1. #1
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Paul_Boland's Avatar
    Join Date
    Jun 2006
    Location
    Waterford, Ireland.
    Posts
    2,739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Extracting the RGB components from an RGB value?

    Hi Folks.

    I'm trying to back-engineer the maths behind RGB_Values. Here is what it says in the MMF help file:

    "Replace Color
    Allows you to replace a color by another one in the current image of the object. Select the color to replace in the color selector, or via the Calculation button, and then the new color. The Calculation button in the Color selector allows you to enter a RGB value. A RGB value can be calculated from its Red, Green, and Blue components by the following formula:
    RGB_Value = B*65536 + G*256 + R.
    To extract the R, B and B components from a RGB value, use:
    R = RGB_Value AND 255
    G = (RGB_Value / 256) AND 255
    B = (RGB_Value / 65536) AND 255
    "

    I can create the RGB_Value without issue given the three R, G and B numbers between 0 and 255. But what if I want to back-engineer an RGB_Value to get the individual RGB components? I can't understand the maths listed in the help file to do this above?!? So if I have an RGB_Value of 16777215, which is pure white, how do I back-engineer this number to get 255, 255, 255?
    KnightTrek Productions
    http://www.knighttrek.com

  2. #2
    Clicker Fusion 2.5 Developer

    Join Date
    Jul 2008
    Location
    UK
    Posts
    1,398
    Mentioned
    16 Post(s)
    Tagged
    0 Thread(s)
    just use the built-in expressions (they're not hidden)

  3. #3
    Clicker Multimedia Fusion 2SWF Export Module
    Jacob's Avatar
    Join Date
    Jul 2007
    Location
    Second pixel to the right
    Posts
    3,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It shows you right there how to do it, use the AND operator with 255 to isolate Red, but divide first by 256 to isolate green, or divide by 256▓ to get blue. This is easier to see if you look at the numbers in hex.

    0x000000 is black. Red, green, and blue all have values of 0.
    0xFFFFFF is white. Red, green, and blue all have values of 255 (0xFF)

    00 in binary is 00000000, where FF in binary is 11111111
    The AND operator (usually denoted as &) returns 1 if both the input values are 1

    011 & 110 = 010, because only the second bit had 1 for both input values.

    When you do RGB AND 255, you can represent this in hex as (value) & FF. Using a random colour as an example
    76FC8B & FF is the same as
    76FC8B & 0000FF. Knowing that FF is all 1s and 00 is all 0s, the result would have to be
    00008B, isolating the blue value.

    Hexadecimal is base 16, so each digit has a value from 0 to 9 and then A to F.
    10 in base 10 is just 10╣, where in hex it's 16╣
    100 in base 10 is 10▓, where in hex it's 16▓ (256)
    This is why dividing the number by 256 moves it two hexadecimal places to the right, in the same way dividing a number by 100 would do that in decimal.
    78FC8B / 100 = 78FC.8B which truncates to 78FC
    78FC & 00FF = FC, isolating green.

    Hopefully this explains it well enough. That help file says you just & 255 to isolate red, which is either wrong or MMF stores values in BGR format instead of industry standard RGB.

  4. #4
    Forum Moderator Fusion 2.5 DeveloperHTML5 Export ModuleiOS Export ModuleSWF Export ModuleInstall Creator Pro
    Paul_Boland's Avatar
    Join Date
    Jun 2006
    Location
    Waterford, Ireland.
    Posts
    2,739
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    After a battle with Excel, I managed to work out the maths but it's interesting to see the hexdecimal way (though it melts my brain! LOL!!). I didn't know about the built in MMF functions to do this, thanks for the heads up.
    KnightTrek Productions
    http://www.knighttrek.com

  5. #5
    Clicker Multimedia Fusion 2SWF Export Module
    Jacob's Avatar
    Join Date
    Jul 2007
    Location
    Second pixel to the right
    Posts
    3,208
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, you can use getRed() getGreen() and getBlue(). If you want to make yourself look like an awesome coder to anyone that looks, just use

    blue = RGB and 0x0000FF
    green = RGB and 0x00FF00
    red = RGB and 0xFF0000

    remembering 0xRRGGBB for where the Fs go

Similar Threads

  1. List and Edit Box with real Flex components
    By Looki in forum Beta Flash Extensions
    Replies: 17
    Last Post: 4th April 2012, 07:30 PM
  2. Some basic components
    By Ham in forum dotNet Scripting
    Replies: 2
    Last Post: 3rd December 2010, 09:17 PM
  3. Flash components
    By Ham in forum SWF/Flash Export Module Version 2.0
    Replies: 2
    Last Post: 3rd April 2010, 08:09 AM
  4. [BUG] Windows components objects and Layers
    By Sphax in forum Multimedia Fusion 2 - Technical Support
    Replies: 3
    Last Post: 9th May 2009, 06:41 AM
  5. Extracting an MFA?
    By Eutherin in forum Multimedia Fusion 2 - Technical Support
    Replies: 7
    Last Post: 2nd February 2009, 05:27 AM

Posting Permissions

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