Question
Your task in this function is to modify the image you are given, converting any green pixels into transparent ones, with no color information, such
Your task in this function is to modify the image you are given, converting any green pixels into transparent ones, with no color information, such as the image below.
void greenScreen(unsigned char * const img, int width, int height){
const int BPP = 4; unsigned char * p = img; const auto * const end = img + (width * height * BPP); unsigned char maxValue; while(p != end) { if(*(p) > *(p+2)) { maxValue = *(p); } else { maxValue = *(p + 2); } if(*(p+1) >= (2 * maxValue)) { *p = 0; //modify red p++; //move to green component *p = 0; //modify green p++; //move to blue component *p = 0; //modify blue p++; //move to alpha component p= 0; //modify alpha } *p += 4; } }
It is unlikely that any pixels will have pure green pixels (no red or blue with a green component of 255), so you should treat a pixel as green if its green component is at least twice as large as the larger of its red and blue component. When you find a green pixels that meets these requirements, set all of its components-red, green, blue and alpha to 0. If a pixel is not green, just skip it This sounds fairly easy. We can follow the pseudocode here: Let p point the beginning of the image Set end to point just past the end While p !-end If *(p 1) is twice as Large as max(red, blue) Clear alL of the fields Increment p by 4Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started