diff --git a/scwx-qt/scwx-qt.cmake b/scwx-qt/scwx-qt.cmake index 1c654b0e..54703605 100644 --- a/scwx-qt/scwx-qt.cmake +++ b/scwx-qt/scwx-qt.cmake @@ -357,6 +357,7 @@ set(HDR_UTIL source/scwx/qt/util/color.hpp source/scwx/qt/util/network.hpp source/scwx/qt/util/streams.hpp source/scwx/qt/util/texture_atlas.hpp + source/scwx/qt/util/q_color_modulate.hpp source/scwx/qt/util/q_file_buffer.hpp source/scwx/qt/util/q_file_input_stream.hpp source/scwx/qt/util/time.hpp @@ -369,6 +370,7 @@ set(SRC_UTIL source/scwx/qt/util/color.cpp source/scwx/qt/util/maplibre.cpp source/scwx/qt/util/network.cpp source/scwx/qt/util/texture_atlas.cpp + source/scwx/qt/util/q_color_modulate.cpp source/scwx/qt/util/q_file_buffer.cpp source/scwx/qt/util/q_file_input_stream.cpp source/scwx/qt/util/time.cpp diff --git a/scwx-qt/source/scwx/qt/util/q_color_modulate.cpp b/scwx-qt/source/scwx/qt/util/q_color_modulate.cpp new file mode 100644 index 00000000..567fc62d --- /dev/null +++ b/scwx-qt/source/scwx/qt/util/q_color_modulate.cpp @@ -0,0 +1,56 @@ +#include + +#include +#include +#include +#include +#include + +namespace scwx +{ +namespace qt +{ +namespace util +{ + +void modulateColors_(QImage& image, const QColor& color) +{ + for (int y = 0; y < image.height(); ++y) + { + QRgb* line = reinterpret_cast(image.scanLine(y)); + for (int x = 0; x < image.width(); ++x) + { + QRgb& rgb = line[x]; + int red = qRed(rgb) * color.redF(); + int green = qGreen(rgb) * color.greenF(); + int blue = qBlue(rgb) * color.blueF(); + int alpha = qAlpha(rgb) * color.alphaF(); + + rgb = qRgba(red, green, blue, alpha); + } + } +} + +QImage modulateColors(const QImage& image, const QColor& color) +{ + QImage copy = image.copy(); + modulateColors_(copy, color); + return copy; +} + +QPixmap modulateColors(const QPixmap& pixmap, const QColor& color) +{ + QImage image = pixmap.toImage(); + modulateColors_(image, color); + return QPixmap::fromImage(image); +} + +QIcon modulateColors(const QIcon& icon, const QSize& size, const QColor& color) +{ + QPixmap pixmap = modulateColors(icon.pixmap(size), color); + return QIcon(pixmap); +} + +} // namespace util +} // namespace qt +} // namespace scwx diff --git a/scwx-qt/source/scwx/qt/util/q_color_modulate.hpp b/scwx-qt/source/scwx/qt/util/q_color_modulate.hpp new file mode 100644 index 00000000..c54b852f --- /dev/null +++ b/scwx-qt/source/scwx/qt/util/q_color_modulate.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include +#include +#include +#include +#include + +namespace scwx +{ +namespace qt +{ +namespace util +{ + +QImage modulateColors(const QImage& image, const QColor& color); +QPixmap modulateColors(const QPixmap& pixmap, const QColor& color); +QIcon modulateColors(const QIcon& icon, const QSize& size, const QColor& color); + +} // namespace util +} // namespace qt +} // namespace scwx