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; } }

Your task in this function is to modify the image you are

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 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!