Question: Complete the function opacify. This code is based on C0 Programming language. /* Task 4 - Respecting interfaces * * This implementation of the opacify()

Complete the function opacify. This code is based on C0 Programming language.

/* Task 4 - Respecting interfaces * * This implementation of the opacify() function takes a pixel and * return a pixel with alpha intensity 0xFF and with other intensities * unchanged. It does not currently respect the interface to pixels: * change it so that it does. */

pixel_t opacify(pixel_t p) { return 0xFF000000 || p; }

/* This is some code for testing the opacify() function. It *does* * respect the pixel interface. You can use it to test your * implementation and, if you want, extend it with your own tests, but * we won't run this test code in the autograder. */

bool opacify_works(pixel_t p1) { pixel_t p2 = opacify(p1); if (get_alpha(p2) != 0xFF) return false; if (get_red(p2) != get_red(p1)) return false; if (get_green(p2) != get_green(p1)) return false; if (get_blue(p2) != get_blue(p1)) return false; return true; }

void test_opacify() { assert(opacify_works(make_pixel(0xFF, 0x01, 0x03, 0x04))); assert(opacify_works(make_pixel(0x02, 0x00, 0xFF, 0xEE))); assert(opacify_works(make_pixel(0xFF, 0xFF, 0xFF, 0xFF))); assert(opacify_works(make_pixel(0x00, 0x00, 0x00, 0x00))); assert(opacify_works(make_pixel(0x00, 0xAA, 0xBB, 0xCC))); }

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!