TEST_F(ColorTest, Spin) { l.push_back(Token("spin", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); hsl("10", "90%", "50%"); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("30", Token::NUMBER, 0, 0, "-")); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); ASSERT_EQ((uint)1, l.size()); EXPECT_EQ("#f2a60d", l.toString()); l.clear(); l.push_back(Token("spin", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); hsl("10", "90%", "50%"); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("-30", Token::NUMBER, 0, 0, "-")); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); ASSERT_EQ((uint)1, l.size()); EXPECT_EQ("#f20d59", l.toString()); }
void DrawAni::applyHSL(NDPicture* picture, const AniModify* mod_lev2) { if (!picture || !mod_lev2) return; // apply HSL (only lev2) const HSL_Modify& mod = mod_lev2->m_KHSLModify; if (mod.isValid()) { if (mod.isModeSet()) { COLOR_RGB rgb; COLOR_HSL hsl(mod.h, mod.s, mod.l); HSLtoRGB(hsl, rgb); picture->SetMaskColor(ccc4(rgb.red, rgb.green, rgb.blue, 255)); } else if (mod.isModeAdd()) { ccColor4B cr = picture->getMaskColor(); COLOR_RGB rgb(cr.r, cr.g, cr.b); COLOR_HSL hsl; RGBtoHSL(rgb, hsl); COLOR_HSL ofs(mod.h, mod.s, mod.l); hsl.add(ofs); HSLtoRGB(hsl, rgb); picture->SetMaskColor(ccc4(rgb.red, rgb.green, rgb.blue, 255)); } } }
TEST_F(ColorTest, HSL) { hsl("90", "100%", "50%"); vp.processValue(l, c); ASSERT_EQ((uint)1, l.size()); EXPECT_EQ("#80ff00", l.toString()); }
TEST_F(ColorTest, Greyscale) { l.push_back(Token("greyscale", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); hsl("90", "90%", "50%"); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); ASSERT_EQ((uint)1, l.size()); EXPECT_EQ("#808080", l.toString()); }
TEST_F(ColorTest, Lightness) { l.push_back(Token("lightness", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); hsl("90", "100%", "50%"); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); ASSERT_EQ((uint)1, l.size()); EXPECT_EQ("50%", l.toString()); }
TEST_F(ColorTest, Fade) { l.push_back(Token("fade", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); hsl("90", "90%", "50%"); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("10%", Token::PERCENTAGE, 0, 0, "-")); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); ASSERT_EQ((uint)13, l.size()); EXPECT_EQ("rgba(128, 242, 13, 0.1)", l.toString()); }
TEST_F(ColorTest, Darken) { l.push_back(Token("darken", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); hsl("90", "80%", "50%"); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("20%", Token::PERCENTAGE, 0, 0, "-")); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); ASSERT_EQ((uint)1, l.size()); EXPECT_EQ("#4d8a0f", l.toString()); }
bool compare(std::string a, std::string b) { int r_a, g_a, b_a; int r_b, g_b, b_b; sscanf(a.c_str(), "rgb: %d %d %d", &r_a, &g_a, &b_a); sscanf(b.c_str(), "rgb: %d %d %d", &r_b, &g_b, &b_b); float h_a, s_a, l_a; float h_b, s_b, l_b; hsl(r_a, g_a, b_a, h_a, s_a, l_a); hsl(r_b, g_b, b_b, h_b, s_b, l_b); if (fabs(h_a-h_b) > 0.01f) { return h_a < h_b; } if (fabs(s_a-s_b) > 0.01f) { return s_a < s_b; } return l_a < l_b; }
int main() { double a,b,c,d; char s[99]; for(; ~(scanf("%s",s));) { if(*s=='(') { sscanf(s,"(%lf,%lf,%lf,%lf)",&a,&b,&c,&d); cmyk(a,b,c,d); } else if(s[2]=='L') { sscanf(s,"HSL(%lf,%lf,%lf)",&a,&b,&c); hsl(a,b/100,c/100); } else if(s[2]=='V') { sscanf(s,"HSV(%lf,%lf,%lf)",&a,&b,&c); hsv(a,b/100,c/100); } else { hex(s); } } return 0; }
t_rgb getcolor(t_cplx z) { double d; double in; double sat; int k; const double in0 = 0.6, sat0 = 0.3; d = dot(z, z); if (d >= 1) d = log(d); d = 4 * (d - (int)d); k = (int)d; d = d - k; if (!k) { in = 0.99; sat = 0.99 - (0.99 - sat0) * d; } if (k == 1) { in = 0.99 - (0.99 - in0) * d; sat = sat0; } if (k == 2) { in = in0; sat = 0.99 - (0.99 - sat0) * (1 - d); } if (k == 3) { in = 0.99 - (0.99 - in0) * (1 - d); sat = 0.99; } return (hsltorgb(hsl(in, phase(z.r, z.i), sat))); }
TEST_F(ColorTest, Contrast) { l.push_back(Token("contrast", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); l.push_back(Token("#bbbbbb", Token::HASH,0, 0, "-")); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); ASSERT_EQ((uint)1, l.size()); EXPECT_EQ("#000", l.toString()); l.clear(); l.push_back(Token("contrast", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); l.push_back(Token("#222222", Token::HASH,0, 0, "-")); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("#101010", Token::HASH,0, 0, "-")); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); EXPECT_EQ((uint)1, l.size()); EXPECT_EQ("#fff", l.toString()); l.clear(); l.push_back(Token("contrast", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); l.push_back(Token("#222222", Token::HASH,0, 0, "-")); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("#101010", Token::HASH,0, 0, "-")); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("#dddddd", Token::HASH,0, 0, "-")); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); EXPECT_EQ((uint)1, l.size()); EXPECT_EQ("#dddddd", l.toString()); l.clear(); l.push_back(Token("contrast", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); hsl("90", "100%", "50%"); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("#000000", Token::HASH,0, 0, "-")); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("#ffffff", Token::HASH,0, 0, "-")); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("30%", Token::PERCENTAGE, 0, 0, "-")); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); EXPECT_EQ((uint)1, l.size()); EXPECT_EQ("#000000", l.toString()); l.clear(); l.push_back(Token("contrast", Token::IDENTIFIER,0, 0, "-")); l.push_back(Token("(", Token::PAREN_OPEN,0, 0, "-")); hsl("90", "100%", "50%"); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("#000000", Token::HASH,0, 0, "-")); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("#ffffff", Token::HASH,0, 0, "-")); l.push_back(Token(",", Token::DELIMITER,0, 0, "-")); l.push_back(Token("80%", Token::PERCENTAGE, 0, 0, "-")); l.push_back(Token(")", Token::PAREN_CLOSED,0, 0, "-")); vp.processValue(l, c); EXPECT_EQ((uint)1, l.size()); EXPECT_EQ("#ffffff", l.toString()); }
//! called if an event happened. bool CGUIColorSelectDialog::OnEvent(const SEvent& event) { if (isEnabled()) { switch(event.EventType) { case EET_GUI_EVENT: switch(event.GUIEvent.EventType) { case EGET_SPINBOX_CHANGED: { for ( u32 i = 0; i!= Battery.size (); ++i ) { if ( event.GUIEvent.Caller == Battery[i] ) { if (i<4) { video::SColor rgb((u32)Battery[0]->getValue(), (u32)Battery[1]->getValue(), (u32)Battery[2]->getValue(), (u32)Battery[3]->getValue()); video::SColorHSL hsl; video::SColorf rgb2(rgb); hsl.fromRGB(rgb2); Battery[4]->setValue(hsl.Hue); Battery[5]->setValue(hsl.Saturation); Battery[6]->setValue(hsl.Luminance); } else { video::SColorHSL hsl(Battery[4]->getValue(), Battery[5]->getValue(), Battery[6]->getValue()); video::SColorf rgb2; hsl.toRGB(rgb2); video::SColor rgb = rgb2.toSColor(); Battery[1]->setValue((f32)rgb.getRed()); Battery[2]->setValue((f32)rgb.getGreen()); Battery[3]->setValue((f32)rgb.getBlue()); } } } return true; } case EGET_ELEMENT_FOCUS_LOST: Dragging = false; break; case EGET_BUTTON_CLICKED: if (event.GUIEvent.Caller == CloseButton || event.GUIEvent.Caller == CancelButton) { sendCancelEvent(); remove(); return true; } else if (event.GUIEvent.Caller == OKButton) { sendSelectedEvent(); remove(); return true; } break; case EGET_LISTBOX_CHANGED: case EGET_LISTBOX_SELECTED_AGAIN: default: break; } break; case EET_MOUSE_INPUT_EVENT: switch(event.MouseInput.Event) { case EMIE_LMOUSE_PRESSED_DOWN: DragStart.X = event.MouseInput.X; DragStart.Y = event.MouseInput.Y; Dragging = true; Environment->setFocus(this); return true; case EMIE_LMOUSE_LEFT_UP: Dragging = false; Environment->removeFocus(this); return true; case EMIE_MOUSE_MOVED: if (Dragging) { // gui window should not be dragged outside its parent if (Parent) if (event.MouseInput.X < Parent->getAbsolutePosition().UpperLeftCorner.X +1 || event.MouseInput.Y < Parent->getAbsolutePosition().UpperLeftCorner.Y +1 || event.MouseInput.X > Parent->getAbsolutePosition().LowerRightCorner.X -1 || event.MouseInput.Y > Parent->getAbsolutePosition().LowerRightCorner.Y -1) return true; move(core::position2d<s32>(event.MouseInput.X - DragStart.X, event.MouseInput.Y - DragStart.Y)); DragStart.X = event.MouseInput.X; DragStart.Y = event.MouseInput.Y; return true; } default: break; } default: break; } } return IGUIElement::OnEvent(event); }
void TestApp::test_hsl() { Console::write_line(" Header: color_hsl.h"); Console::write_line(" Class: ColorHSLi"); Console::write_line(" Function: ColorHSLi()"); { ColorHSLi hsl; if (hsl.h !=0) fail(); if (hsl.s !=0) fail(); if (hsl.l !=0) fail(); if (hsl.a !=0) fail(); } Console::write_line(" Function: ColorHSLi(int h, int s, int l, int a)"); { ColorHSLi hsl(1,2,3,4); if (hsl.h != 1) fail(); if (hsl.s != 2) fail(); if (hsl.l != 3) fail(); if (hsl.a != 4) fail(); } Console::write_line(" Function: ColorHSLi(const ColorHSLi ©)"); { ColorHSLi hsl(1,2,3,4); ColorHSLi hsl_copy(hsl); if (hsl_copy.h != 1) fail(); if (hsl_copy.s != 2) fail(); if (hsl_copy.l != 3) fail(); if (hsl_copy.a != 4) fail(); } Console::write_line(" Function: ColorHSLi(const Color &color)"); { Color color(255, 0, 0, 64); ColorHSLi hsl(color); if (hsl.h != 0) fail(); if (hsl.s != 255) fail(); if (hsl.l != 128) fail(); if (hsl.a != 64) fail(); } { Color color(128, 255, 128, 64); ColorHSLi hsl(color); if (hsl.h != 120) fail(); if (hsl.s != 255) fail(); if (hsl.l < 191) fail(); if (hsl.l > 192) fail(); if (hsl.a != 64) fail(); } { Colorf colorf(0.5f, 1.0f, 0.5f, 1.0f); ColorHSLi hsl(colorf); if (hsl.h != 120) fail(); if (hsl.s != 255) fail(); if (hsl.l != 191) fail(); if (hsl.a != 255) fail(); } { Color color(0, 0, 128, 64); ColorHSLi hsl(color); if (hsl.h != 240) fail(); if (hsl.s != 255) fail(); if (hsl.l != 64) fail(); if (hsl.a != 64) fail(); } { Color color(64, 90, 136, 90); ColorHSLi hsl(color); if (hsl.h != 218) fail(); if (hsl.s != 92) fail(); if (hsl.l != 100) fail(); if (hsl.a != 90) fail(); } { Color color(128, 128, 128, 90); ColorHSLi hsl(color); if (hsl.h != 0) fail(); if (hsl.s != 0) fail(); if (hsl.l != 128) fail(); if (hsl.a != 90) fail(); } { Color color(64, 90, 136, 90); ColorHSLi hsl(color); Color color2(hsl); int red = color2.get_red(); int green = color2.get_green(); int blue = color2.get_blue(); int alpha = color2.get_alpha(); if (red < 63) fail(); if (red > 65) fail(); if (green != 90) fail(); if (blue != 136) fail(); if (alpha != 90) fail(); } Console::write_line(" Class: ColorHSLf"); Console::write_line(" Function: ColorHSLf()"); { ColorHSLf hsl; if (hsl.h !=0.0f) fail(); if (hsl.s !=0.0f) fail(); if (hsl.l !=0.0f) fail(); if (hsl.a !=0.0f) fail(); } Console::write_line(" Function: ColorHSLf(float h, float s, float l, float a)"); { ColorHSLf hsl(0.1f, 0.2f, 0.3f, 0.4f); if (hsl.h != 0.1f) fail(); if (hsl.s != 0.2f) fail(); if (hsl.l != 0.3f) fail(); if (hsl.a != 0.4f) fail(); } Console::write_line(" Function: ColorHSLf(const ColorHSLf ©)"); { ColorHSLf hsl(0.1f, 0.2f, 0.3f, 0.4f); ColorHSLf hsl_copy(hsl); if (hsl_copy.h != 0.1f) fail(); if (hsl_copy.s != 0.2f) fail(); if (hsl_copy.l != 0.3f) fail(); if (hsl_copy.a != 0.4f) fail(); } Console::write_line(" Function: ColorHSLf(const Colorf &color)"); { Colorf color(1.0f, 0.0f, 0.0f, 0.2f); ColorHSLf hsl(color); if (hsl.h != 0.0f) fail(); if (hsl.s != 1.0f) fail(); if (hsl.l != 0.5f) fail(); if (hsl.a != 0.2f) fail(); } { Colorf color(0.5f, 1.0f, 0.5f, 0.2f); ColorHSLf hsl(color); if (hsl.h != 120.0f) fail(); if (hsl.s != 1.0f) fail(); if (hsl.l != 0.75f) fail(); if (hsl.a != 0.2f) fail(); } { Color color(127, 255, 127, 255); ColorHSLf hsl(color); if (hsl.h != 120.0f) fail(); if (hsl.s != 1.0f) fail(); if (hsl.l < 0.74f) fail(); if (hsl.l > 0.76f) fail(); if (hsl.a != 1.0f) fail(); } { Colorf color(0.0f, 0.0f, 0.5, 0.3f); ColorHSLf hsl(color); if (hsl.h != 240.0f) fail(); if (hsl.s != 1.0f) fail(); if (hsl.l < 0.24f) fail(); if (hsl.l > 0.26f) fail(); if (hsl.a != 0.3f) fail(); } { Colorf color(0.2f, 0.4f, 0.7f, 0.3f); ColorHSLf hsl(color); Colorf color2(hsl); if (color.r < 0.1999f) fail(); if (color.r > 0.2001f) fail(); if (color.g < 0.3999f) fail(); if (color.g > 0.4001f) fail(); if (color.b < 0.6999f) fail(); if (color.b > 0.7001f) fail(); if (color.a < 0.2999f) fail(); if (color.a > 0.3001f) fail(); } }