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}
, mDimming {1.0f}
, mThemeOpacity {1.0f}
, mThemeSaturation {1.0f}
, mRotation {0.0f}
, mScale {1.0f}
, mDefaultZIndex {0.0f}
@ -376,6 +377,9 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
else
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"))
mThemeGameSelector = elem->get<std::string>("gameselector");
}

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -165,10 +165,10 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans)
for (int i = 0; i < 4; ++i)
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->saturation = mSaturation;
vertices->saturation = mSaturation * mThemeSaturation;
vertices->dimming = mDimming;
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_DYNAMIC_DRAW));
mScanlinelShader->setOpacity(vertices->opacity);
mScanlinelShader->setSaturation(vertices->saturation);
mScanlinelShader->setTextureSize({shaderWidth, shaderHeight});
GL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices));
mLastShader = mScanlinelShader;

View file

@ -54,6 +54,7 @@ precision mediump float;
uniform vec2 textureSize;
uniform float opacity;
uniform float saturation;
uniform sampler2D textureSampler;
in vec2 texCoord;
in vec2 onex;
@ -100,6 +101,13 @@ void main()
float h_weight_00 = dx / SPOT_WIDTH;
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);
// Get closest horizontal neighbour to blend.
@ -114,6 +122,13 @@ void main()
}
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;
WEIGHT(h_weight_01);
@ -137,6 +152,13 @@ void main()
}
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;
WEIGHT(v_weight_10);