C481 B581 Computer Graphics
Dana Vrajitoru
Homework 1

Due date: Thursday, January 20.

Ex. 1 Here is a table of correspondence between the RGB, HSV, and HTML color representation systems.
 
Color Aspect RGB HSV HTML
black   0, 0, 0 0, 0, 0 "#000000" = 0, 0, 0
white   1, 1, 1 0, 0, 1 "#FFFFFF" = 255, 255, 255
gray   0.3, 0.3, 0.3 0, 0, 0.3 "#555555" = 85, 85, 85
red   1, 0, 0 0, 1, 1 "#FF0000" = 255, 0, 0
yellow   1, 1, 0 60, 1, 1 "#FFFF00" = 255, 255, 0
green   0, 1, 0 120, 1, 1 "#00FF00" = 0, 255, 0
cyan   0, 1, 1 180, 1, 1 "#00FFFF" = 0, 255, 255
blue   0, 0, 1 240, 1, 1 "#0000FF" = 0, 0, 255
magenta   1, 0, 1 300, 1, 1 "#FF00FF" = 255, 0, 255
light blue   0.6, 0.6, 1 240, 0.4, 1 "#9999FF" = 153, 153, 255
light orange   0.9, 0.5, 0.3 20, 0.67, 0.9 "#E68055" = 230, 128, 80

Complete the following c++ file performing a conversion between these 3 formats.
convertrgb.cc
This file does not require any special library and should compile with a simple g++ command.

Hint:
0.67 = 1 - (0.3 / 0.9)
20 = 0 + (0.5 - 0.3) * 60 / (0.9 - 0.3)

Hint
For the transformation from HSV to RGB, you can find the maximum of the r, g, b values directly from the v value. The formula
c.s = 1-mn/c.v;
can be reversed to compute the minimum of the three values, mn. The offset can be computed as the difference between the angle h and the dominant component, based on the quadrant. For example, if the angle h is between 120 and 180, then the offset if h-120, while if it is between 180 and 240, then it is 240-h.

Then the formula
offset = (md - mn) * 60 /(c.v - mn);
can be reversed to compute the median of the 3 values, md.

Last, suppose that we have mx, md, and mn, the three values in this order. The way they are assigned to the rgb values also depends on the quadrant. For example, if the angle h is between 60 and 120, then mx will be assigned to g, the median value will be assigned to r, and the smalled value will be assigned to b.

In addition, you will probably need to consider the special cases that result in the denominator in any of the formulas you have to be 0. Those need to be considered separately before.

Ex. 2 In this exercise you will experiment with image representation and color

Turn in: the modified file for ex. 1, one image file for ex. 2, and the file comparison by email.