Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

P2 (15pt): Most graphics hardware includes support for a low-level operation called blit, or block transfer, which quickly copies a rectangular chunk of a pixel

image text in transcribed

P2 (15pt): Most graphics hardware includes support for a low-level operation called blit, or block transfer, which quickly copies a rectangular chunk of a pixel map (a two-dimensional array of pixel values) from one location to another. This is a two-dimensional version of the standard C library function memcpy(). Suppose we want to rotate an n xn pixel map 90 clockwise. One way to do this, at least when n is a power of two, is to split the pixel map into four xblocks, move each block to its proper position using a sequence of five blits, and then recursively rotate each block. (Why five? For the same reason the Tower of Hanoi puzzle needs a third peg.) Alternately, we could first recursive rotate the blocks and then blit them into place. 1 AB CD 5 blits | CA DB recurse CD recurse 5 blits Figure 1. Two algorithms to rotate pixel map. (a) Prove that both versions of the algorithm are correct when n is a power of 2. (b) Exactly how many blits does the algorithm perform when n is a power of 2? (c) Describe how to modify the algorithm so that it works for arbitrary n, not just powers of 2. How many blits does your modified algorithm perform? (d) What is your algorithm's running time if a k x k blit takes (k)time? (e) What if a k xk blit takes only (k) time? P2 (15pt): Most graphics hardware includes support for a low-level operation called blit, or block transfer, which quickly copies a rectangular chunk of a pixel map (a two-dimensional array of pixel values) from one location to another. This is a two-dimensional version of the standard C library function memcpy(). Suppose we want to rotate an n xn pixel map 90 clockwise. One way to do this, at least when n is a power of two, is to split the pixel map into four xblocks, move each block to its proper position using a sequence of five blits, and then recursively rotate each block. (Why five? For the same reason the Tower of Hanoi puzzle needs a third peg.) Alternately, we could first recursive rotate the blocks and then blit them into place. 1 AB CD 5 blits | CA DB recurse CD recurse 5 blits Figure 1. Two algorithms to rotate pixel map. (a) Prove that both versions of the algorithm are correct when n is a power of 2. (b) Exactly how many blits does the algorithm perform when n is a power of 2? (c) Describe how to modify the algorithm so that it works for arbitrary n, not just powers of 2. How many blits does your modified algorithm perform? (d) What is your algorithm's running time if a k x k blit takes (k)time? (e) What if a k xk blit takes only (k) time

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

Databases Illuminated

Authors: Catherine M. Ricardo, Susan D. Urban, Karen C. Davis

4th Edition

1284231585, 978-1284231588

More Books

Students also viewed these Databases questions

Question

When is the appropriate time to write a business plan?

Answered: 1 week ago