Use a C++ implementation of hsluv

This commit is contained in:
miruka
2019-12-27 08:19:56 -04:00
parent 77f851c319
commit e7caa0b8ef
8 changed files with 22 additions and 16 deletions

View File

@@ -7,7 +7,6 @@ import traceback
from pathlib import Path
from typing import Any, DefaultDict, Dict, List, Optional, Tuple
import hsluv
from appdirs import AppDirs
import nio
@@ -245,13 +244,6 @@ class Backend:
# General functions
@staticmethod
def hsluv(hue: int, saturation: int, lightness: int) -> List[float]:
"""Convert HSLuv (0-360, 0-100, 0-100) to RGB (0-1, 0-1, 0-1) color."""
return hsluv.hsluv_to_rgb([hue, saturation, lightness])
async def load_settings(self) -> tuple:
"""Return parsed user config files."""

View File

@@ -91,9 +91,7 @@ QtObject {
function hsluv(hue, saturation, lightness, alpha=1.0) {
hue = numberWrapAt(hue, 360)
let rgb = py.callSync("hsluv", [hue, saturation, lightness])
return Qt.rgba(rgb[0], rgb[1], rgb[2], alpha)
return CppUtils.hsluv(hue, saturation, lightness, alpha)
}

View File

@@ -2,10 +2,12 @@
// Function implementations of the Utils class, see the utils.h file.
#include <QColor>
#include <QLocale>
#include <QUuid>
#include "utils.h"
#include "../submodules/hsluv-c/src/hsluv.h"
Utils::Utils() {
@@ -23,3 +25,10 @@ QString Utils::formattedBytes(qint64 bytes, int precision) {
QString Utils::uuid() {
return QUuid::createUuid().toString(QUuid::WithoutBraces);
}
QColor Utils::hsluv(qreal hue, qreal saturation, qreal luv, qreal alpha) {
double red, green, blue;
hsluv2rgb(hue, saturation, luv, &red, &green, &blue);
return QColor::fromRgbF(red, green, blue, alpha);
}

View File

@@ -1,13 +1,14 @@
// SPDX-License-Identifier: LGPL-3.0-or-later
// The Utils class exposes various useful functions for QML that aren't
// normally provided by Qt.
// provided by the `Qt` object.
#ifndef UTILS_H
#define UTILS_H
#include <QObject>
#include <QColor>
#include <QLocale>
#include <QObject>
class Utils : public QObject {
@@ -20,6 +21,7 @@ public:
public slots:
QString formattedBytes(qint64 bytes, int precision = 2);
QString uuid();
QColor hsluv(qreal hue, qreal saturation, qreal luv, qreal alpha = 1.0);
private:
QLocale m_locale;