Added theme support for defining relative brightness for images, videos and animations.

This commit is contained in:
Leon Styhre 2022-12-14 20:17:41 +01:00
parent cfdfe3e6e0
commit f4d4abb33b
17 changed files with 82 additions and 6 deletions

View file

@ -29,6 +29,7 @@ GuiComponent::GuiComponent()
, mOrigin {0.0f, 0.0f}
, mRotationOrigin {0.5f, 0.5f}
, mSize {0.0f, 0.0f}
, mBrightness {0.0f}
, mOpacity {1.0f}
, mSaturation {1.0f}
, mDimming {1.0f}
@ -183,6 +184,16 @@ const int GuiComponent::getChildIndex() const
return -1;
}
void GuiComponent::setBrightness(float brightness)
{
if (mBrightness == brightness)
return;
mBrightness = brightness;
for (auto it = mChildren.cbegin(); it != mChildren.cend(); ++it)
(*it)->setBrightness(brightness);
}
void GuiComponent::setOpacity(float opacity)
{
if (mOpacity == opacity)
@ -371,6 +382,9 @@ void GuiComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
else
setZIndex(getDefaultZIndex());
if (properties & ThemeFlags::BRIGHTNESS && elem->has("brightness"))
mBrightness = glm::clamp(elem->get<float>("brightness"), -2.0f, 2.0f);
if (properties & ThemeFlags::OPACITY && elem->has("opacity"))
mThemeOpacity = glm::clamp(elem->get<float>("opacity"), 0.0f, 1.0f);

View file

@ -222,8 +222,10 @@ public:
virtual void stopGamelistFadeAnimations() {}
virtual bool isListScrolling() { return false; }
virtual void stopListScrolling() {}
virtual const float getBrightness() const { return mBrightness; }
virtual const float getOpacity() const { return mOpacity; }
virtual const float getColorOpacity() const { return 1.0f; }
virtual void setBrightness(float brightness);
virtual void setOpacity(float opacity);
virtual float getSaturation() const { return static_cast<float>(mColor); }
virtual void setSaturation(float saturation) { mSaturation = saturation; }
@ -336,6 +338,7 @@ protected:
glm::vec2 mRotationOrigin;
glm::vec2 mSize;
float mBrightness;
float mOpacity;
float mSaturation;
float mDimming;

View file

@ -133,6 +133,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"imageColor", COLOR},
{"imageColorEnd", COLOR},
{"imageGradientType", STRING},
{"imageBrightness", FLOAT},
{"imageSaturation", FLOAT},
{"itemTransitions", STRING},
{"itemHorizontalAlignment", STRING},
@ -185,6 +186,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"imageColor", COLOR},
{"imageColorEnd", COLOR},
{"imageGradientType", STRING},
{"imageBrightness", FLOAT},
{"imageSaturation", FLOAT},
{"backgroundImage", PATH},
{"backgroundRelativeScale", FLOAT},
@ -260,6 +262,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"colorEnd", COLOR},
{"gradientType", STRING},
{"scrollFadeIn", BOOLEAN},
{"brightness", FLOAT},
{"opacity", FLOAT},
{"saturation", FLOAT},
{"visible", BOOLEAN},
@ -286,6 +289,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"delay", FLOAT},
{"fadeInTime", FLOAT},
{"scrollFadeIn", BOOLEAN},
{"brightness", FLOAT},
{"opacity", FLOAT},
{"saturation", FLOAT},
{"visible", BOOLEAN},
@ -304,6 +308,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"direction", STRING},
{"keepAspectRatio", BOOLEAN},
{"interpolation", STRING},
{"brightness", FLOAT},
{"opacity", FLOAT},
{"saturation", FLOAT},
{"visible", BOOLEAN},

View file

@ -57,9 +57,10 @@ namespace ThemeFlags
DELAY = 0x00002000,
Z_INDEX = 0x00004000,
ROTATION = 0x00008000,
OPACITY = 0x00010000,
SATURATION = 0x00020000,
VISIBLE = 0x00040000,
BRIGHTNESS = 0x00010000,
OPACITY = 0x00020000,
SATURATION = 0x00040000,
VISIBLE = 0x00080000,
ALL = 0xFFFFFFFF
};
// clang-format on

View file

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

View file

@ -394,8 +394,9 @@ void ImageComponent::render(const glm::mat4& parentTrans)
else
fadeIn(mTexture->bind());
mVertices->saturation = mSaturation * mThemeSaturation;
mVertices->brightness = mBrightness;
mVertices->opacity = mThemeOpacity;
mVertices->saturation = mSaturation * mThemeSaturation;
mVertices->dimming = mDimming;
mVertices->reflectionsFalloff = mReflectionsFalloff;

View file

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

View file

@ -381,6 +381,8 @@ void VideoComponent::renderSnapshot(const glm::mat4& parentTrans)
if (mStaticImagePath != "") {
mStaticImage.setOpacity(mOpacity * mThemeOpacity);
mStaticImage.setSaturation(mSaturation * mThemeSaturation);
if (mBrightness != 0.0f)
mStaticImage.setBrightness(mBrightness);
if (mColorShift != 0xFFFFFFFF)
mStaticImage.setColorShift(mColorShift);
if (mColorShift != mColorShiftEnd)

View file

@ -176,6 +176,7 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans)
if (mFadeIn < 1.0f || mThemeOpacity < 1.0f)
vertices->opacity = mFadeIn * mThemeOpacity;
vertices->brightness = mBrightness;
vertices->saturation = mSaturation * mThemeSaturation;
vertices->dimming = mDimming;

View file

@ -147,6 +147,7 @@ private:
unsigned int mImageColorShift;
unsigned int mImageColorShiftEnd;
bool mImageColorGradientHorizontal;
float mImageBrightness;
float mImageSaturation;
bool mInstantItemTransitions;
Alignment mItemHorizontalAlignment;
@ -200,6 +201,7 @@ CarouselComponent<T>::CarouselComponent()
, mImageColorShift {0xFFFFFFFF}
, mImageColorShiftEnd {0xFFFFFFFF}
, mImageColorGradientHorizontal {true}
, mImageBrightness {0.0f}
, mImageSaturation {1.0f}
, mInstantItemTransitions {false}
, mItemHorizontalAlignment {ALIGN_CENTER}
@ -265,6 +267,8 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
item->setImage(entry.data.imagePath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageBrightness != 0.0)
item->setBrightness(mImageBrightness);
if (mImageSaturation != 1.0)
item->setSaturation(mImageSaturation);
if (mImageColorShift != 0xFFFFFFFF)
@ -285,6 +289,8 @@ void CarouselComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeDat
glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
defaultImage->setImage(entry.data.defaultImagePath);
defaultImage->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageBrightness != 0.0)
defaultImage->setBrightness(mImageBrightness);
if (mImageSaturation != 1.0)
defaultImage->setSaturation(mImageSaturation);
if (mImageColorShift != 0xFFFFFFFF)
@ -354,6 +360,8 @@ void CarouselComponent<T>::updateEntry(Entry& entry, const std::shared_ptr<Theme
item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f)));
item->setImage(entry.data.imagePath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageBrightness != 0.0)
item->setBrightness(mImageBrightness);
if (mImageSaturation != 1.0)
item->setSaturation(mImageSaturation);
if (mImageColorShift != 0xFFFFFFFF)
@ -1124,6 +1132,9 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
if (elem->has("imageBrightness"))
mImageBrightness = glm::clamp(elem->get<float>("imageBrightness"), -2.0f, 2.0f);
if (elem->has("imageSaturation"))
mImageSaturation = glm::clamp(elem->get<float>("imageSaturation"), 0.0f, 1.0f);

View file

@ -148,6 +148,7 @@ private:
unsigned int mImageColor;
unsigned int mImageColorEnd;
bool mImageColorGradientHorizontal;
float mImageBrightness;
float mImageSaturation;
std::unique_ptr<ImageComponent> mBackgroundImage;
std::string mBackgroundImagePath;
@ -205,6 +206,7 @@ GridComponent<T>::GridComponent()
, mImageColor {0xFFFFFFFF}
, mImageColorEnd {0xFFFFFFFF}
, mImageColorGradientHorizontal {true}
, mImageBrightness {0.0f}
, mImageSaturation {1.0f}
, mBackgroundRelativeScale {1.0f}
, mBackgroundColor {0xFFFFFFFF}
@ -258,6 +260,8 @@ void GridComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeData>&
item->setCroppedSize(mItemSize * mImageRelativeScale);
item->setImage(entry.data.imagePath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageBrightness != 0.0)
item->setBrightness(mImageBrightness);
if (mImageSaturation != 1.0)
item->setSaturation(mImageSaturation);
if (mImageColor != 0xFFFFFFFF)
@ -284,6 +288,8 @@ void GridComponent<T>::addEntry(Entry& entry, const std::shared_ptr<ThemeData>&
defaultImage->setCroppedSize(mItemSize * mImageRelativeScale);
defaultImage->setImage(entry.data.defaultImagePath);
defaultImage->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageBrightness != 0.0)
defaultImage->setBrightness(mImageBrightness);
if (mImageSaturation != 1.0)
defaultImage->setSaturation(mImageSaturation);
if (mImageColor != 0xFFFFFFFF)
@ -335,6 +341,8 @@ void GridComponent<T>::updateEntry(Entry& entry, const std::shared_ptr<ThemeData
item->setCroppedSize(mItemSize * mImageRelativeScale);
item->setImage(entry.data.imagePath);
item->applyTheme(theme, "system", "", ThemeFlags::ALL);
if (mImageBrightness != 0.0)
item->setBrightness(mImageBrightness);
if (mImageSaturation != 1.0)
item->setSaturation(mImageSaturation);
if (mImageColor != 0xFFFFFFFF)
@ -1027,6 +1035,9 @@ void GridComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
}
}
if (elem->has("imageBrightness"))
mImageBrightness = glm::clamp(elem->get<float>("imageBrightness"), -2.0f, 2.0f);
if (elem->has("imageSaturation"))
mImageSaturation = glm::clamp(elem->get<float>("imageSaturation"), 0.0f, 1.0f);

View file

@ -61,6 +61,7 @@ public:
glm::vec2 texcoord;
unsigned int color;
glm::vec4 clipregion;
float brightness;
float opacity;
float saturation;
float dimming;
@ -69,7 +70,8 @@ public:
unsigned int shaderFlags;
Vertex()
: opacity {1.0f}
: brightness {0.0f}
, opacity {1.0f}
, saturation {1.0f}
, dimming {1.0f}
, reflectionsFalloff {0.0f}
@ -86,6 +88,7 @@ public:
, texcoord(textureCoord)
, color(color)
, clipregion(clipRegion)
, brightness {0.0f}
, opacity {1.0f}
, saturation {1.0f}
, dimming {1.0f}

View file

@ -443,6 +443,7 @@ void RendererOpenGL::drawTriangleStrips(const Vertex* vertices,
GL_CHECK_ERROR(glBufferData(GL_ARRAY_BUFFER, sizeof(Vertex) * numVertices, vertices,
GL_DYNAMIC_DRAW));
mCoreShader->setClipRegion(vertices->clipregion);
mCoreShader->setBrightness(vertices->brightness);
mCoreShader->setOpacity(vertices->opacity);
mCoreShader->setSaturation(vertices->saturation);
mCoreShader->setDimming(vertices->dimming);
@ -517,6 +518,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->setBrightness(vertices->brightness);
mScanlinelShader->setSaturation(vertices->saturation);
mScanlinelShader->setTextureSize({shaderWidth, shaderHeight});
GL_CHECK_ERROR(glDrawArrays(GL_TRIANGLE_STRIP, 0, numVertices));

View file

@ -19,6 +19,7 @@ ShaderOpenGL::ShaderOpenGL()
, mShaderTextureCoord {0}
, mShaderColor {0}
, mShaderTextureSize {0}
, mShaderBrightness {0}
, mShaderOpacity {0}
, mShaderSaturation {0}
, mShaderDimming {0}
@ -122,6 +123,7 @@ void ShaderOpenGL::getVariableLocations(GLuint programID)
mShaderColor = glGetAttribLocation(mProgramID, "colorVertex");
mShaderTextureSize = glGetUniformLocation(mProgramID, "textureSize");
mShaderClipRegion = glGetUniformLocation(mProgramID, "clipRegion");
mShaderBrightness = glGetUniformLocation(mProgramID, "brightness");
mShaderOpacity = glGetUniformLocation(mProgramID, "opacity");
mShaderSaturation = glGetUniformLocation(mProgramID, "saturation");
mShaderDimming = glGetUniformLocation(mProgramID, "dimming");
@ -166,6 +168,12 @@ void ShaderOpenGL::setClipRegion(glm::vec4 clipRegion)
clipRegion[3]));
}
void ShaderOpenGL::setBrightness(GLfloat brightness)
{
if (mShaderBrightness != -1)
GL_CHECK_ERROR(glUniform1f(mShaderBrightness, brightness));
}
void ShaderOpenGL::setOpacity(GLfloat opacity)
{
if (mShaderOpacity != -1)

View file

@ -69,6 +69,7 @@ public:
void setAttribPointers();
void setTextureSize(std::array<GLfloat, 2> shaderVec2);
void setClipRegion(glm::vec4 clipRegion);
void setBrightness(GLfloat brightness);
void setOpacity(GLfloat opacity);
void setSaturation(GLfloat saturation);
void setDimming(GLfloat dimming);
@ -95,6 +96,7 @@ private:
GLint mShaderColor;
GLint mShaderClipRegion;
GLint mShaderTextureSize;
GLint mShaderBrightness;
GLint mShaderOpacity;
GLint mShaderSaturation;
GLint mShaderDimming;

View file

@ -4,7 +4,7 @@
// core.glsl
//
// Core shader functionality:
// Clipping, saturation, opacity, dimming and reflections falloff.
// Clipping, brightness, saturation, opacity, dimming and reflections falloff.
//
// Vertex section of code:
@ -39,6 +39,7 @@ in vec2 texCoord;
in vec4 color;
uniform vec4 clipRegion;
uniform float brightness;
uniform float saturation;
uniform float opacity;
uniform float dimming;
@ -70,6 +71,10 @@ void main()
vec4 sampledColor = texture(textureSampler, texCoord);
// Brightness.
if (brightness != 0.0)
sampledColor.rgb = sampledColor.rgb * pow(2.0, brightness);
// Saturation.
if (saturation != 1.0) {
vec3 grayscale;

View file

@ -58,6 +58,7 @@ precision mediump float;
uniform vec2 textureSize;
uniform float opacity;
uniform float brightness;
uniform float saturation;
uniform sampler2D textureSampler;
in vec2 texCoord;
@ -155,6 +156,10 @@ void main()
vec4 colorTemp = clamp(GAMMA_OUT(color), 0.0, 1.0);
// Brightness.
if (brightness != 0.0)
colorTemp.rgb = colorTemp.rgb * pow(2.0, brightness);
// Saturation.
if (saturation != 1.0) {
vec3 grayscale;