Added theme support for defining color saturation for the image, video and animation components.

This commit is contained in:
Leon Styhre 2022-03-17 19:33:09 +01:00
parent b6e38dcf67
commit 5de2855d60
11 changed files with 43 additions and 10 deletions

View file

@ -33,6 +33,7 @@ GuiComponent::GuiComponent()
, mSaturation {1.0f} , mSaturation {1.0f}
, mDimming {1.0f} , mDimming {1.0f}
, mThemeOpacity {1.0f} , mThemeOpacity {1.0f}
, mThemeSaturation {1.0f}
, mRotation {0.0f} , mRotation {0.0f}
, mScale {1.0f} , mScale {1.0f}
, mDefaultZIndex {0.0f} , mDefaultZIndex {0.0f}
@ -376,6 +377,9 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
else else
setVisible(true); setVisible(true);
if (properties & ThemeFlags::SATURATION && elem->has("saturation"))
mThemeSaturation = glm::clamp(elem->get<float>("saturation"), 0.0f, 1.0f);
if (properties && elem->has("gameselector")) if (properties && elem->has("gameselector"))
mThemeGameSelector = elem->get<std::string>("gameselector"); mThemeGameSelector = elem->get<std::string>("gameselector");
} }

View file

@ -113,10 +113,10 @@ public:
void setVisible(bool visible) { mVisible = visible; } void setVisible(bool visible) { mVisible = visible; }
// clang-format off // clang-format off
enum ComponentThemeFlags : unsigned int { enum ComponentThemeFlags : unsigned int {
SCROLL_HIDE = 0x00000001, SCROLL_HIDE = 0x00000001,
SCROLL_FADE_IN = 0x00000002 SCROLL_FADE_IN = 0x00000002
}; };
// clang-format on // clang-format on
const bool getScrollHide() { return mComponentThemeFlags & ComponentThemeFlags::SCROLL_HIDE; } const bool getScrollHide() { return mComponentThemeFlags & ComponentThemeFlags::SCROLL_HIDE; }
@ -303,6 +303,7 @@ protected:
float mSaturation; float mSaturation;
float mDimming; float mDimming;
float mThemeOpacity; float mThemeOpacity;
float mThemeSaturation;
float mRotation; float mRotation;
float mScale; float mScale;
float mDefaultZIndex; float mDefaultZIndex;

View file

@ -96,6 +96,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"gradientType", STRING}, {"gradientType", STRING},
{"scrollFadeIn", BOOLEAN}, {"scrollFadeIn", BOOLEAN},
{"opacity", FLOAT}, {"opacity", FLOAT},
{"saturation", FLOAT},
{"visible", BOOLEAN}, {"visible", BOOLEAN},
{"zIndex", FLOAT}}}, {"zIndex", FLOAT}}},
{"video", {"video",
@ -116,6 +117,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"fadeInTime", FLOAT}, {"fadeInTime", FLOAT},
{"scrollFadeIn", BOOLEAN}, {"scrollFadeIn", BOOLEAN},
{"opacity", FLOAT}, {"opacity", FLOAT},
{"saturation", FLOAT},
{"visible", BOOLEAN}, {"visible", BOOLEAN},
{"zIndex", FLOAT}, {"zIndex", FLOAT},
{"showSnapshotNoVideo", BOOLEAN}, // For backward compatibility with legacy themes. {"showSnapshotNoVideo", BOOLEAN}, // For backward compatibility with legacy themes.
@ -132,6 +134,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"keepAspectRatio", BOOLEAN}, {"keepAspectRatio", BOOLEAN},
{"interpolation", STRING}, {"interpolation", STRING},
{"opacity", FLOAT}, {"opacity", FLOAT},
{"saturation", FLOAT},
{"visible", BOOLEAN}, {"visible", BOOLEAN},
{"zIndex", FLOAT}}}, {"zIndex", FLOAT}}},
{"badges", {"badges",

View file

@ -62,7 +62,8 @@ namespace ThemeFlags
Z_INDEX = 0x00004000, Z_INDEX = 0x00004000,
ROTATION = 0x00008000, ROTATION = 0x00008000,
OPACITY = 0x00010000, OPACITY = 0x00010000,
VISIBLE = 0x00020000, SATURATION = 0x00020000,
VISIBLE = 0x00040000,
ALL = 0xFFFFFFFF ALL = 0xFFFFFFFF
}; };
// clang-format on // clang-format on

View file

@ -488,7 +488,7 @@ void GIFAnimComponent::render(const glm::mat4& parentTrans)
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
vertices[i].position = glm::round(vertices[i].position); vertices[i].position = glm::round(vertices[i].position);
vertices->saturation = mSaturation; vertices->saturation = mSaturation * mThemeSaturation;
vertices->opacity = mOpacity * mThemeOpacity; vertices->opacity = mOpacity * mThemeOpacity;
vertices->dimming = mDimming; vertices->dimming = mDimming;
vertices->shaderFlags = Renderer::ShaderFlags::BGRA_TO_RGBA; vertices->shaderFlags = Renderer::ShaderFlags::BGRA_TO_RGBA;

View file

@ -419,7 +419,7 @@ void ImageComponent::render(const glm::mat4& parentTrans)
else else
fadeIn(mTexture->bind()); fadeIn(mTexture->bind());
mVertices->saturation = mSaturation; mVertices->saturation = mSaturation * mThemeSaturation;
mVertices->opacity = mThemeOpacity; mVertices->opacity = mThemeOpacity;
mVertices->dimming = mDimming; mVertices->dimming = mDimming;

View file

@ -477,7 +477,7 @@ void LottieAnimComponent::render(const glm::mat4& parentTrans)
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
vertices[i].position = glm::round(vertices[i].position); vertices[i].position = glm::round(vertices[i].position);
vertices->saturation = mSaturation; vertices->saturation = mSaturation * mThemeSaturation;
vertices->opacity = mOpacity * mThemeOpacity; vertices->opacity = mOpacity * mThemeOpacity;
vertices->dimming = mDimming; vertices->dimming = mDimming;
vertices->shaderFlags = Renderer::ShaderFlags::BGRA_TO_RGBA; vertices->shaderFlags = Renderer::ShaderFlags::BGRA_TO_RGBA;

View file

@ -277,6 +277,7 @@ void VideoComponent::renderSnapshot(const glm::mat4& parentTrans)
if (mStaticImagePath != "") { if (mStaticImagePath != "") {
mStaticImage.setOpacity(mOpacity * mThemeOpacity); mStaticImage.setOpacity(mOpacity * mThemeOpacity);
mStaticImage.setSaturation(mSaturation * mThemeSaturation);
mStaticImage.setDimming(mDimming); mStaticImage.setDimming(mDimming);
mStaticImage.render(parentTrans); mStaticImage.render(parentTrans);
} }

View file

@ -165,10 +165,10 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans)
for (int i = 0; i < 4; ++i) for (int i = 0; i < 4; ++i)
vertices[i].position = glm::round(vertices[i].position); vertices[i].position = glm::round(vertices[i].position);
if (mDecodedFrame && (mFadeIn < 1.0f || mThemeOpacity < 1.0f)) if (mFadeIn < 1.0f || mThemeOpacity < 1.0f)
vertices->opacity = mFadeIn * mThemeOpacity; vertices->opacity = mFadeIn * mThemeOpacity;
vertices->saturation = mSaturation; vertices->saturation = mSaturation * mThemeSaturation;
vertices->dimming = mDimming; vertices->dimming = mDimming;
std::unique_lock<std::mutex> pictureLock(mPictureMutex); std::unique_lock<std::mutex> pictureLock(mPictureMutex);

View file

@ -446,6 +446,7 @@ void RendererOpenGL::drawTriangleStrips(const Vertex* vertices,
GL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * numVertices, vertices, GL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * numVertices, vertices,
GL_DYNAMIC_DRAW)); GL_DYNAMIC_DRAW));
mScanlinelShader->setOpacity(vertices->opacity); mScanlinelShader->setOpacity(vertices->opacity);
mScanlinelShader->setSaturation(vertices->saturation);
mScanlinelShader->setTextureSize({shaderWidth, shaderHeight}); mScanlinelShader->setTextureSize({shaderWidth, shaderHeight});
GL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices)); GL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices));
mLastShader = mScanlinelShader; mLastShader = mScanlinelShader;

View file

@ -54,6 +54,7 @@ precision mediump float;
uniform vec2 textureSize; uniform vec2 textureSize;
uniform float opacity; uniform float opacity;
uniform float saturation;
uniform sampler2D textureSampler; uniform sampler2D textureSampler;
in vec2 texCoord; in vec2 texCoord;
in vec2 onex; in vec2 onex;
@ -100,6 +101,13 @@ void main()
float h_weight_00 = dx / SPOT_WIDTH; float h_weight_00 = dx / SPOT_WIDTH;
WEIGHT(h_weight_00); WEIGHT(h_weight_00);
// Saturation.
if (saturation != 1.0) {
vec3 grayscale = vec3(dot(color.rgb, vec3(0.34, 0.55, 0.11)));
vec3 blendedColor = mix(grayscale, color.rgb, saturation);
color = vec4(blendedColor, color.a);
}
color *= vec4(h_weight_00, h_weight_00, h_weight_00, h_weight_00); color *= vec4(h_weight_00, h_weight_00, h_weight_00, h_weight_00);
// Get closest horizontal neighbour to blend. // Get closest horizontal neighbour to blend.
@ -114,6 +122,13 @@ void main()
} }
vec4 colorNB = TEX2D(texture_coords + coords01); vec4 colorNB = TEX2D(texture_coords + coords01);
// Saturation.
if (saturation != 1.0) {
vec3 grayscale = vec3(dot(colorNB.rgb, vec3(0.34, 0.55, 0.11)));
vec3 blendedColor = mix(grayscale, colorNB.rgb, saturation);
colorNB = vec4(blendedColor, colorNB.a);
}
float h_weight_01 = dx / SPOT_WIDTH; float h_weight_01 = dx / SPOT_WIDTH;
WEIGHT(h_weight_01); WEIGHT(h_weight_01);
@ -137,6 +152,13 @@ void main()
} }
colorNB = TEX2D(texture_coords + coords10); colorNB = TEX2D(texture_coords + coords10);
// Saturation.
if (saturation != 1.0) {
vec3 grayscale = vec3(dot(colorNB.rgb, vec3(0.34, 0.55, 0.11)));
vec3 blendedColor = mix(grayscale, colorNB.rgb, saturation);
colorNB = vec4(blendedColor, colorNB.a);
}
float v_weight_10 = dy / SPOT_HEIGHT; float v_weight_10 = dy / SPOT_HEIGHT;
WEIGHT(v_weight_10); WEIGHT(v_weight_10);