Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8669287
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T18:26:13+00:00 2026-06-12T18:26:13+00:00

All, I have a basic question that I am struggling with here. When you

  • 0

All,

I have a basic question that I am struggling with here. When you look at the findmyicone sample code from WWDC 2010, you will see this:

static const uint8_t orangeColor[] = {255, 127, 0};
uint8_t referenceColor[3];

// Remove luminance
static inline void normalize( const uint8_t colorIn[], uint8_t colorOut[] ) {

// Dot product
int sum = 0;
for (int i = 0; i < 3; i++)
sum += colorIn[i] / 3;

for (int j = 0; j < 3; j++)
colorOut[j] = (float) ((colorIn[j] / (float) sum) * 255);
}

And then it is called:

normalize(orangeColor, referenceColor);

Running the debugger, it is converting BGRA: (Red 255, Green 127, Blue 0) to (Red 0, Green 255, Blue 0). I have looked on the web and SO to find details on luminance and dot product and there is really no information.

1- Can someone guide me on what this function is doing?

2- Can you guide me to some helpful topics/primer online as well?

Thanks again
KMB

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T18:26:15+00:00Added an answer on June 12, 2026 at 6:26 pm

    What they’re trying to do is track a particular color across variations in brightness, so they’re normalizing for the luminance of the color. I do something similar in the fragment shader I use in a color tracking example based on a GPU Gems paper from Apple, as well as the ColorObjectTracking sample application in my GPUImage framework:

    vec3 normalizeColor(vec3 color)
    {
        return color / max(dot(color, vec3(1.0/3.0)), 0.3);
    }
    
    vec4 maskPixel(vec3 pixelColor, vec3 maskColor)
    {
        float  d;
        vec4   calculatedColor;
    
        // Compute distance between current pixel color and reference color
        d = distance(normalizeColor(pixelColor), normalizeColor(maskColor));
    
        // If color difference is larger than threshold, return black.
        calculatedColor =  (d > threshold)  ?  vec4(0.0)  :  vec4(1.0);
    
        //Multiply color by texture
        return calculatedColor;
    }
    

    The above calculation takes the average of the three color components by multiplying each channel by 1/3 and then summing them (that’s what the dot product does here). It then divides each color channel by this average to arrive at a normalized color.

    The distance between this normalized color and the target one is calculated, and if it is within a certain threshold the pixel is marked as being of that color.

    This is just one way of determining proximity of one color to another. Another way is to convert the RGB values into Y, Cr, and Cb (Y, U, and V) components and then take the distance between just the chrominance portions (Cr and Cb):

     vec4 textureColor = texture2D(inputImageTexture, textureCoordinate);
     vec4 textureColor2 = texture2D(inputImageTexture2, textureCoordinate2);
    
     float maskY = 0.2989 * colorToReplace.r + 0.5866 * colorToReplace.g + 0.1145 * colorToReplace.b;
     float maskCr = 0.7132 * (colorToReplace.r - maskY);
     float maskCb = 0.5647 * (colorToReplace.b - maskY);
    
     float Y = 0.2989 * textureColor.r + 0.5866 * textureColor.g + 0.1145 * textureColor.b;
     float Cr = 0.7132 * (textureColor.r - Y);
     float Cb = 0.5647 * (textureColor.b - Y);
    
     float blendValue = 1.0 - smoothstep(thresholdSensitivity, thresholdSensitivity + smoothing, distance(vec2(Cr, Cb), vec2(maskCr, maskCb)));
    

    This code is what I use in a chroma keying shader, and it’s based on a similar calculation that Apple uses in one of their sample applications. Which one is best can depend on the particular situation you’re facing.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a basic question here. I know that dealloc will be called when
I have a basic Android question here: I have a main.xml layout that loads
I have a basic question: how to make a mysql query that query all
This has to be a common question that all programmers have from time to
I have a pretty basic question that confuses me for some strange reason. I
enter code hereI have a basic question regarding an implementation using a Axis2 web
I have a pretty basic question that I imagine would require a join to
I have a basic partitioning question. I have a table that looks like this:
A question has many answers. It is easy to find all questions that have
I have a very basic question about SQL server and Visual Studio 2010. I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.