Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

somebody can help me with this c++ program (win32 console application) Within a computer, color is often maintained as an object with three components, a

somebody can help me with this c++ program (win32 console application)

Within a computer, color is often maintained as an object with three components, a red channel, a green channel, and a blue channel, each with values between 0-255. The attached file has four fields per line to represent a color. The first three fields are integers from 0 to 255 representing the red, green, and blue channels of the color, and the fourth field is the standard name of the color.

RGB colors are difficult to interpret, in that it is not easy for a person to imagine the color that results from various levels of red, green, and blue. This has given rise to other color descriptions (color spaces). One of the most common is hue, saturation, and luminance or HSL.

The RGB color space can be converted to the HSL color space using the following algorithm.

Convert the RGB levels to values between 0.0 and 1.0.

Find the maximum and minimum values of the three (red, green, and blue).

Compute the sum S and the difference D of the maximum and minimum values.

The luminance value is the average of the min and max (ie. (min + max) / 2).

If the min and max are equal, hue and saturation are both 0.0, and the conversion is complete

if luminance is less than 0.5, saturation is D / S, otherwise saturation is D / (2.0 - S).

if red was the maximum, hue is (green - blue) / D

if green was the maximum, hue is 2.0 + (blue - red) / D

if blue was the maximum, hue is 4.0 + (red - green) / D

Multiple hue by 60.0 to convert it to degrees.

If hue is negative, add 360.0 degrees.

This produces the HSL values from RGB values.

For this assignment, write two classes

 class RGBColor { short red; short green; short blue; std::string name; public: RGBColor(std::string n, int r, int g, int b); short getRed() const; short getGreen() const; short getBlue() const; std::string getName(); std::string toString(); }; 

and

 class HSLColor { float hue; float sat; float light; std::string name; void rgb2hsl(RGBColor& clr); public: HSLColor(RGBColor& clr); float getHue(); float getSaturation(); float getLuminance(); std::string getName(); std::string toString(); }; 

The main loop of the assign_colors() test driver should look like:

 ifs >> red; while (!ifs.eof()) { ++rcd; ifs >> green >> blue >> name; rgb = new RGBColor(name, red, green, blue); hsl = new HSLColor(*rgb); cout << rgb->toString() << " = " << hsl->toString() << " " << rgb->getName() << endl; ifs >> red; } 

testcolors.txt is :

000 206 209 darkturquoise 047 079 079 darkslategrey 100 149 237 cornflowerblue 124 252 000 lawngreen 139 000 000 darkred 165 042 042 brown 188 143 143 rosybrown 218 112 214 orchid 238 232 170 palegoldenrod 248 248 255 ghostwhite 255 099 071 tomato 255 228 181 moccasin 255 255 000 yellow 

Code the test function assign_colors() to read the color data, one color per line, and create an RCGColor object from the data. The RGBColor object should then be used to create an HSLCoilor object which will convert the RGB to HSL according to the given algorithm. The HSL object should then be dispayed using its toString() method. The output should look like:

RGB=( 0, 206, 209) = HSL=( 180.9, 1.000, 0.410) darkturquoise RGB=( 47, 79, 79) = HSL=( 180.0, 0.254, 0.247) darkslategrey RGB=( 100, 149, 237) = HSL=( 218.5, 0.792, 0.661) cornflowerblue RGB=( 124, 252, 0) = HSL=( 90.5, 1.000, 0.494) lawngreen RGB=( 139, 0, 0) = HSL=( 0.0, 1.000, 0.273) darkred RGB=( 165, 42, 42) = HSL=( 0.0, 0.594, 0.406) brown RGB=( 188, 143, 143) = HSL=( 0.0, 0.251, 0.649) rosybrown RGB=( 218, 112, 214) = HSL=( 302.3, 0.589, 0.647) orchid RGB=( 238, 232, 170) = HSL=( 54.7, 0.667, 0.800) palegoldenrod RGB=( 248, 248, 255) = HSL=( 240.0, 1.000, 0.986) ghostwhite RGB=( 255, 99, 71) = HSL=( 9.1, 1.000, 0.639) tomato RGB=( 255, 228, 181) = HSL=( 38.1, 1.000, 0.855) moccasin RGB=( 255, 255, 0) = HSL=( 60.0, 1.000, 0.500) yellow 

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

Pro PowerShell For Database Developers

Authors: Bryan P Cafferky

1st Edition

1484205413, 9781484205419

More Books

Students also viewed these Databases questions

Question

How do modern Dashboards differ from earlier implementations?

Answered: 1 week ago