D29637: Introduce ImageColors
This revision was automatically updated to reflect the committed changes. Closed by commit R169:3986ad9d0955: Introduce ImageColors (authored by mart). CHANGED PRIOR TO COMMIT https://phabricator.kde.org/D29637?vs=82645=82820#toc REPOSITORY R169 Kirigami CHANGES SINCE LAST UPDATE https://phabricator.kde.org/D29637?vs=82645=82820 REVISION DETAIL https://phabricator.kde.org/D29637 AFFECTED FILES examples/imagecolorstest.qml src/CMakeLists.txt src/colorutils.cpp src/colorutils.h src/imagecolors.cpp src/imagecolors.h src/kirigamiplugin.cpp To: mart, #kirigami, cblack Cc: cblack, plasma-devel, fbampaloukas, GB_2, domson, dkardarakos, ngraham, apol, ahiemstra, davidedmundson, mart
D29637: Introduce ImageColors
mart updated this revision to Diff 82645. mart marked 12 inline comments as done. mart added a comment. - adress feedbacks REPOSITORY R169 Kirigami CHANGES SINCE LAST UPDATE https://phabricator.kde.org/D29637?vs=82537=82645 BRANCH mart/imageColors REVISION DETAIL https://phabricator.kde.org/D29637 AFFECTED FILES examples/imagecolorstest.qml src/CMakeLists.txt src/colorutils.cpp src/colorutils.h src/imagecolors.cpp src/imagecolors.h src/kirigamiplugin.cpp To: mart, #kirigami Cc: cblack, plasma-devel, fbampaloukas, GB_2, domson, dkardarakos, ngraham, apol, ahiemstra, davidedmundson, mart
D29637: Introduce ImageColors
cblack added inline comments. INLINE COMMENTS > colorutils.h:182 > +/** > + * Returns the Cielab "Chroma" of the color which is a slightly better > quantificator for how much a color appears > https://en.wikipedia.org/wiki/Colorfulness > + * This is how much a color looks diffenent from a gray of the same Returns the CIELAB chroma of the given color. CIELAB chroma may give a better quantification of how vibrant a color is compared to HSV saturation. \sa https://en.wikipedia.org/wiki/Colorfulness \sa https://en.wikipedia.org/wiki/CIELAB_color_space > imagecolors.h:64-70 > + * The source which colors should be analyzed, it can be: > + * * Any Item: it will be rendered to an image and the static grab > + * analyzed. It won't be updated if the item changes, but manual > + * calls to update() are needed. > + * * A QImage (for example coming from a QAbstractItemModel data role) > + * * A QIcon (for example coming from a QAbstractItemModel data role) > + * * An icon name: an icon name present in the theme. The source from which colors should be extracted from. `source` can be one of the following: * Item * QImage * QIcon * Icon name Note that an Item's color palette will only be extracted once unless you call `update()`, regardless of how the item hanges. > imagecolors.h:75-82 > + * A list of the color palette extracted from the image. > + * It uses K-means-clustering tecnique, by averaging groups of > + * "similar" colors https://en.wikipedia.org/wiki/K-means_clustering > + * it's a list of maps containing the following keys: > + * * "color": the color of the cluster > + * * "ratio": the ratio from 0 to 1 of diffusion of the cluster in the > image > + * * "contrastingColor": another color from the clusters (if possible) > that is the nearest to its negative A list of colors and related information about then. Each list item has the following properties: * `color`: The color of the list item. * `ratio`: How dominant the color is in the source image. * `contrastingColor`: The color from the source image that's closest to the inverse of `color`. The list is sorted by `ratio`; the first element is the most dominant color in the source image and the last element is the least dominant color of the image. \note K-means clustering is used to extract these colors; see https://en.wikipedia.org/wiki/K-means_clustering. > imagecolors.h:86-89 > +/** > + * If true, it should be considered a "Dark" color palette (this if the > dominant color is darker than a 50% gray > + */ > +Q_PROPERTY(bool isDarkPalette READ isDarkPalette NOTIFY paletteChanged) I think it would be better to have this return a `ColorUtils::Brightness` enum. > imagecolors.h:92 > +/** > + * The average color of the whole image. > + */ The average color of the source image. > imagecolors.h:97 > +/** > + * The dominant color of the image. This is the color of the cluster > which covers the bigger area of the image > + */ The dominant color of the source image. The dominant color of the image is the color of the largest cluster in the image. \sa https://en.wikipedia.org/wiki/K-means_clustering > imagecolors.h:102 > +/** > + * Suggested "contrasting" color to the dominant one. It's the color in > the palette nearest to the negative of the dominant > + */ The color closest to the inverse of the dominant color found in the source image. > imagecolors.h:107-109 > + * An "accent" color extracted from the image, heuristically found most > "vibrant" color from the cluster with highest CIELab Chroma > + * https://en.wikipedia.org/wiki/Colorfulness#Chroma > + * which is a better indication than saturation as doesn't decrease with > lightness An accent color extracted from the source image. The accent color is the color cluster with the highest CIELAB chroma in the source image. \sa https://en.wikipedia.org/wiki/Colorfulness#Chroma > imagecolors.h:114-116 > + * A color suggested for foreground items over the image > + * * on dark palettes will be closestToWhite if light enough, or a very > light gray otherwise > + * * on light palettes will be closestToBlack if dark enough or a very > dark gray A color suitable for rendering text and other foreground over the source image. On dark items, this will be the color closest to white in the image if it's light enough, or a bright gray otherwise. On light items, this will be the color closest to black in the image if it's dark enough, or a dark gray otherwise. > imagecolors.h:120-124 > +/** > + * A color suggested for background items over the image, like a dialog > frame > + * * on light palettes will be closestToWhite if light enough, or a very > light gray otherwise > + * * on dark palettes will be closestToBlack if dark enough or a very > dark gray > +
D29637: Introduce ImageColors
cblack added inline comments. INLINE COMMENTS > imagecolorstest.qml:1 > + > +import QtQuick 2.12 There's no test cases here, this should probably go in examples. REPOSITORY R169 Kirigami REVISION DETAIL https://phabricator.kde.org/D29637 To: mart, #kirigami Cc: cblack, plasma-devel, fbampaloukas, GB_2, domson, dkardarakos, ngraham, apol, ahiemstra, davidedmundson, mart
D29637: Introduce ImageColors
mart created this revision. mart added a reviewer: Kirigami. Herald added a project: Kirigami. Herald added a subscriber: plasma-devel. mart requested review of this revision. REVISION SUMMARY ImageColors is a class to extract color statistics out of an image. it supports as source : - Grabbing a static frame out of any Item - A QImage or a QIcon (for instance coming from a QAbstractItemModel - An icon name from the theme By a pixel-by pixel analisys it uses a K-means clustering algorythm https://en.wikipedia.org/wiki/K-means_clustering that groups averages of colors group that have a computed "distance" less than an arbitrary value and so extracts a palette of the "dominant" colors of the image, having also other imformations such as the % occurrence of each cluster, a complementary color for each cluster, the global average color, the most "vibrant" color of the image, usable as an accent, and good colors for text and background, based on the extracted palette REPOSITORY R169 Kirigami BRANCH mart/imageColors REVISION DETAIL https://phabricator.kde.org/D29637 AFFECTED FILES src/CMakeLists.txt src/colorutils.cpp src/colorutils.h src/imagecolors.cpp src/imagecolors.h src/kirigamiplugin.cpp tests/imagecolorstest.qml To: mart, #kirigami Cc: plasma-devel, fbampaloukas, GB_2, domson, dkardarakos, ngraham, apol, ahiemstra, davidedmundson, mart