Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Contemporary Issues In Database Design And Information Systems Development

Authors: Keng Siau

1st Edition

1599042894, 978-1599042893

More Books

Students also viewed these Databases questions

Question

identify the main ways in which you learn

Answered: 1 week ago