Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

colorUtils.h file: #ifndef MODE_H #define MODE_H typedef enum { AVERAGE , LIGHTNESS , LUMINOSITY } Mode ; #endif /* MODE_H */ /** * Returns the

image text in transcribed
image text in transcribed
colorUtils.h file:
#ifndef MODE_H
#define MODE_H

typedef enum {
AVERAGE,
LIGHTNESS,
LUMINOSITY
} Mode;

#endif /* MODE_H */

/**
* Returns the maximum value among the three given values
*/
int max(int a, int b, int c);

/**
* Returns the minimum value among the three given values
*/
int min(int a, int b, int c);

/**
* TODO: add documentation here
*/
int toGrayScale(int *r, int *g, int *b, Mode mode);

/**
* TODO: add documentation here
*/
int toSepia(int *r, int *g, int *b);
colorUtils.c file:
#include
#include

#include "colorUtils.h"

int max(int a, int b, int c) {
return (a > b) ? (a > c ? a : c) : (b > c ? b: c);
}

int min(int a, int b, int c) {
return (a b) ? (a c ? a : c) : (b c ? b : c);
}

int toGrayScale(int *r, int *g, int *b, Mode mode) {
//TODO: implement
}

int toSepia(int *r, int *g, int *b) {
//TODO: implement
}
(Re)designing Your Functions In the previous lab you designed several functions to convert RGB values to gray-seale (using one of three techniques) and to sepia. The details of how to do this available in the previous lab and are repeated for your convenience below. The design of those functions was less than ideal. For the gray seale functions, there was a function for each of the three techniques. For the sepia conversion, we had to have three separate functions (one for each component, red, green, blue). This was necessary because functions can only retum one value. We can't have a function compute and "retum" all three RGB values. However, if we use pass-by-reference variables, we can compute and "return" multiple values with a single function! Moreover, we can then use the actual return value to indicate an error with the inputs (if any). Redesign your functions from the previous lab as follows. For the gray scale functionality. implement a single function with the following signature: int toGrayscale(int "r, int "g, int "b, Mode m) The function takes three integer values by reference and will use the value stored in them to compute a gray scale RGB value. It will then store the result back into the variables. To specify which of the three modes is to be used, we have defined an enumerated type in the colorUtils.h header file: typedet enum 1 AVERAGE, LIGHTZESS, LUMINOSITY I Node; Finally, identify any and all error conditions and use the return value to indicate an error code ( 0 for no error, non-zero value(s) for error conditions). You should define another enumerated type to represent error codes. For the sepia filter, implement a single function with the following signature: Int tosepia(int "r, int g, int +b); The function should use the values stored in the variables passed by reference and then store the results in them. Again, error codes should be returned for invalid input values and you should use the enumerated type you defined for error codes. Finally, add proper documentation to your functions' prototypes. Color Formulas To convert an RGB value to gray-scale you can use one of several different techniques. Each technique "removes" the color value by setting all three RGB values to the same value but each technique does so in a slightly different way. The first technique is to simply take the average of all three values: 3r+g+b The second technique, known as the "lightness" technique averages the most prominent and least prominent colors: 2max{r,g,b}+min{r,g,b} The luminosity technique uses a weighted average to account for a human perceptual preference toward green, setting all three values to: 0.21r+0.72g+0.07b In all three cases, the integer values should be rounded rather than truncated. A sepia fiter sets different values to each of the three RGB components using the following formulas. Given a current (r,g,b) value, the sepia tone RGB value, (r,g,b) would be: r=0.393r+0.769g+0.189bg=0.349r+0.686g+0.168bb=0.272r+0.534g+0.131b As with the gray-scale techniques, values should be rounded. If any of the resulting RGB values exceeds 255 , they should be reset to the maximum, 255

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

Statistical And Scientific Database Management International Working Conference Ssdbm Rome Italy June 21 23 1988 Proceedings Lncs 339

Authors: Maurizio Rafanelli ,John C. Klensin ,Per Svensson

1st Edition

354050575X, 978-3540505754

More Books

Students also viewed these Databases questions