Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Implement the remaining methods as follows: Calling decode restores an image in which each pixel has had the upper four bits negated. To unscramble the

Implement the remaining methods as follows:

Calling decode restores an image in which each pixel has had the upper four bits negated. To unscramble the image, your code should negate them again. You can use bitwise operators or the following algorithm: To get the upper bits, divide the pixel by 16. To get the lower bits, modulo the pixel by 16. The resulting upper and lower values should be in the range 0..15. Negate the upper bits as follows: upper = 15 - upper; Then put the bits back together by multiplying the upper bits by 16 and adding the result to lower. Here's an example for your testing:

original pixel = 115 = 0b01110011

upper value = 115 / 16 = 7 = 0b0111 (upper four bits of original)

lower value = 115 % 16 = 3 = 0b0011 (lower four bits of original)

negate upper value = 15 - 7 = 8 = 0b1000

new pixel = (upper * 16) + lower = (8 * 16) + 3 = 131 = 0b10000011

Calling swap restores an image in which each pixel has been scrambled by exhanging the lower 2 bits with the upper 2 bits. To do this requires that your code do the same exchange to restore the original pixel. Don't modify the middle four bits. By far the easiest way to do this is to use the bitwise operators. Here's an example for your testing:

original pixel = 114 = 0b01110010

upper two bits of original = 0b01110010 & 0b11000000 = 0b01000000

middle four bits of original = 0b01110010 & 0b00111100 = 0b00110000

lower two bits of original = 0b01110010 & 0b00000011 = 0b00000010

new pixel = (lower << 6) | middle | (upper >> 6)

Calling mirror reverses the image top to bottom. To reverse top to bottom, exchange the first row for the last row, the second row for the second to last row, and so on until the entire image is reversed.

Calling exchange swaps the image area defined by a rectangle with width 150 and height 300 starting at row index 10 and column index 10 for a rectangle of the same size starting at row index 10, and column index 310.

NOTE: The maximum value of a pixel (PictureLibrary.MAXVAL) is 255, so only 8 bits are valid for each pixel. These are numbered bits 0-7, where bit 0 is equal to 1 and bit 7 is equal to 128. There are no negative values allowed.

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions