mirror of
https://github.com/Llewellynvdm/conky.git
synced 2024-12-25 12:10:03 +00:00
use shift for masks; fix tests for 16-bit color depth
This commit is contained in:
parent
ca56109dc9
commit
48b7271c0d
@ -49,8 +49,8 @@ gradient_factory::gradient_factory(int width, unsigned long first_colour,
|
||||
|
||||
if (!is_set) {
|
||||
setup_colour_depth();
|
||||
setup_masks();
|
||||
setup_shifts();
|
||||
setup_masks();
|
||||
is_set = true;
|
||||
}
|
||||
}
|
||||
@ -70,17 +70,18 @@ void gradient_factory::setup_masks() {
|
||||
mask[2] |= 1 << i;
|
||||
}
|
||||
|
||||
if (colour_depth % 3 == 1) { mask[1] |= 1 << (colour_depth / 3); }
|
||||
if (colour_depth % 3 == 1) {
|
||||
mask[1] |= 1 << (colour_depth / 3);
|
||||
}
|
||||
|
||||
mask[0] = mask[0] << (2 * colour_depth / 3 + colour_depth % 3);
|
||||
mask[1] = mask[1] << (colour_depth / 3);
|
||||
for (int i = 0; i < 3; i++) {
|
||||
mask[i] = mask[i] << shift[i];
|
||||
}
|
||||
}
|
||||
|
||||
void gradient_factory::setup_colour_depth() {
|
||||
#ifdef BUILD_X11
|
||||
if (state == nullptr) {
|
||||
colour_depth = 24; // testing purposes
|
||||
} else if (out_to_x.get(*state)) {
|
||||
if (out_to_x.get(*state)) {
|
||||
colour_depth = DisplayPlanes(display, screen);
|
||||
} else
|
||||
#endif /* BUILD_X11 */
|
||||
|
@ -32,9 +32,27 @@
|
||||
#include <gradient.h>
|
||||
|
||||
const int width = 4;
|
||||
#ifdef BUILD_GUI // 24-bit color depth
|
||||
const long colour = 0x996633; // brown
|
||||
const long colour_hue = 30;
|
||||
const long colour_value = 0x99;
|
||||
const long expected_hue = 256;
|
||||
const long expected_value = 0x99; // max(0x99, 0x66, 0x33)
|
||||
const long expected_chroma = 0x66; // (0x99 - 0x33)
|
||||
const long expected_luma = 20712665L;
|
||||
const long expected_saturation = 122880L;
|
||||
const long expected_red = 0x99;
|
||||
const long expected_green = 0x66;
|
||||
const long expected_blue = 0x33;
|
||||
#else // 16-bit color depth
|
||||
const long colour = 0x99A6; // brown
|
||||
const long expected_hue = 275;
|
||||
const long expected_value = 0x13; // max(0x13, 0x0d, 0x06)
|
||||
const long expected_chroma = 0x0d; // (0x1a - 0x06)
|
||||
const long expected_luma = 2610173L;
|
||||
const long expected_saturation = 126113L;
|
||||
const long expected_red = 0x13;
|
||||
const long expected_green = 0x0d;
|
||||
const long expected_blue = 0x06;
|
||||
#endif
|
||||
|
||||
const long full_scale = conky::gradient_factory::SCALE360;
|
||||
|
||||
@ -47,13 +65,13 @@ TEST_CASE("gradient_factory::convert_from_rgb returns correct value") {
|
||||
factory->convert_from_rgb(colour, result);
|
||||
|
||||
SECTION("red") {
|
||||
REQUIRE(result[0] == 0x99 * full_scale);
|
||||
REQUIRE(result[0] == expected_red * full_scale);
|
||||
}
|
||||
SECTION("green") {
|
||||
REQUIRE(result[1] == 0x66 * full_scale);
|
||||
REQUIRE(result[1] == expected_green * full_scale);
|
||||
}
|
||||
SECTION("blue") {
|
||||
REQUIRE(result[2] == 0x33 * full_scale);
|
||||
REQUIRE(result[2] == expected_blue * full_scale);
|
||||
}
|
||||
|
||||
delete factory;
|
||||
@ -66,13 +84,13 @@ TEST_CASE("gradient_factory::convert_from_rgb returns correct value") {
|
||||
factory->convert_from_rgb(colour, result);
|
||||
|
||||
SECTION("hue") {
|
||||
REQUIRE(result[0] == colour_hue * conky::gradient_factory::SCALE);
|
||||
REQUIRE(result[0] == expected_hue * 60);
|
||||
}
|
||||
SECTION("saturation") {
|
||||
REQUIRE(result[1] == conky::gradient_factory::SCALE * 240L);
|
||||
REQUIRE(result[1] == expected_saturation);
|
||||
}
|
||||
SECTION("value") {
|
||||
REQUIRE(result[2] == colour_value * full_scale);
|
||||
REQUIRE(result[2] == expected_value * full_scale);
|
||||
}
|
||||
|
||||
delete factory;
|
||||
@ -85,13 +103,13 @@ TEST_CASE("gradient_factory::convert_from_rgb returns correct value") {
|
||||
factory->convert_from_rgb(colour, result);
|
||||
|
||||
SECTION("hue") {
|
||||
REQUIRE(result[0] == colour_hue * conky::gradient_factory::SCALE);
|
||||
REQUIRE(result[0] == expected_hue * 60);
|
||||
}
|
||||
SECTION("chroma") {
|
||||
REQUIRE(result[1] == 0x66 * full_scale);
|
||||
REQUIRE(result[1] == expected_chroma * full_scale);
|
||||
}
|
||||
SECTION("luma") {
|
||||
REQUIRE(result[2] == 20712665L);
|
||||
REQUIRE(result[2] == expected_luma);
|
||||
}
|
||||
|
||||
delete factory;
|
||||
@ -113,6 +131,11 @@ TEST_CASE(
|
||||
delete factory;
|
||||
}
|
||||
|
||||
/*
|
||||
* Due to lack of precision, the HSV and HCL functions are not reversible
|
||||
* if color depth is less than 24-bit
|
||||
*/
|
||||
#ifdef BUILD_GUI
|
||||
SECTION("hsv_gradient_factory") {
|
||||
long tmp[3];
|
||||
auto factory = new conky::hsv_gradient_factory(width, colour, colour);
|
||||
@ -134,4 +157,5 @@ TEST_CASE(
|
||||
|
||||
delete factory;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user