Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added yuv function to Color module #502

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions include/faker-cxx/Color.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,15 @@ class Color
* @endcode
*/
static std::string hsv();

/**
* @brief Return a YUV color
*
* @returns YUV color formatted with yuv(X,X,X)
* @code
* Color::yuv() // "yuv(42, 234, 109)"
* @endcode
*/
static std::string yuv();
};
}
9 changes: 9 additions & 0 deletions src/modules/color/Color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,13 @@ std::string Color::hsv()
return FormatHelper::format("hsv({}, {}, {})", hue, saturation, value);
}

std::string Color::yuv()
{
const std::integral auto luminance = Number::integer(255);
const std::integral auto chrominanceBlueColor = Number::integer(255);
const std::integral auto chrominanceRedColor = Number::integer(255);

return FormatHelper::format("yuv({}, {}, {})", luminance, chrominanceBlueColor, chrominanceRedColor);
}

}
18 changes: 18 additions & 0 deletions src/modules/color/ColorTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,4 +246,22 @@ TEST_F(ColorTest, shouldGenerateHsv)
ASSERT_TRUE(hue >= 0 && hue <= 360);
ASSERT_TRUE(staturation >= 0 && staturation <= 100);
ASSERT_TRUE(brightness >= 0 && brightness <= 100);
}

TEST_F(ColorTest, shouldGenerateYuv)
{
const auto generatedYuvColor = faker::Color::yuv();
const auto yuvValues = faker::StringHelper::split(generatedYuvColor.substr(4, generatedYuvColor.size() - 1), " ");

int luminance, chrominanceBlueColor, chrominanceRedColor;

std::from_chars(yuvValues[0].data(), yuvValues[0].data() + yuvValues[0].size(), luminance);
std::from_chars(yuvValues[1].data(), yuvValues[1].data() + yuvValues[1].size(), chrominanceBlueColor);
std::from_chars(yuvValues[2].data(), yuvValues[2].data() + yuvValues[2].size(), chrominanceRedColor);

ASSERT_TRUE(generatedYuvColor.starts_with("yuv("));
ASSERT_TRUE(generatedYuvColor.ends_with(")"));
ASSERT_TRUE(luminance >= 0 && luminance <= 255);
ASSERT_TRUE(chrominanceBlueColor >= 0 && chrominanceBlueColor <= 255);
ASSERT_TRUE(chrominanceRedColor >= 0 && chrominanceRedColor <= 255);
}
Loading