File indexing completed on 2024-05-12 15:59:32
0001 /* 0002 * SPDX-FileCopyrightText: 2005 Boudewijn Rempt <boud@valdyas.org> 0003 * 0004 * SPDX-License-Identifier: LGPL-2.1-or-later 0005 */ 0006 0007 #ifndef _KO_COLORCONVERSIONS_H_ 0008 #define _KO_COLORCONVERSIONS_H_ 0009 0010 #include <QtGlobal> 0011 #include "kritapigment_export.h" 0012 0013 /** 0014 * A number of often-used conversions between color models 0015 */ 0016 0017 // 8-bit integer versions. RGBSL are 0-255, H is 0-360. 0018 KRITAPIGMENT_EXPORT void rgb_to_hsv(int R, int G, int B, int *H, int *S, int *V); 0019 KRITAPIGMENT_EXPORT void hsv_to_rgb(int H, int S, int V, int *R, int *G, int *B); 0020 0021 // Floating point versions. RGBSL are 0-1, H is 0-360. 0022 KRITAPIGMENT_EXPORT void RGBToHSV(float r, float g, float b, float *h, float *s, float *v); 0023 KRITAPIGMENT_EXPORT void HSVToRGB(float h, float s, float v, float *r, float *g, float *b); 0024 0025 KRITAPIGMENT_EXPORT void RGBToHSL(float r, float g, float b, float *h, float *s, float *l); 0026 KRITAPIGMENT_EXPORT void HSLToRGB(float h, float sl, float l, float *r, float *g, float *b); 0027 0028 KRITAPIGMENT_EXPORT void rgb_to_hls(quint8 r, quint8 g, quint8 b, float * h, float * l, float * s); 0029 0030 KRITAPIGMENT_EXPORT float hue_value(float n1, float n2, float hue); 0031 0032 KRITAPIGMENT_EXPORT void hls_to_rgb(float h, float l, float s, quint8 * r, quint8 * g, quint8 * b); 0033 0034 KRITAPIGMENT_EXPORT void rgb_to_hls(quint8 r, quint8 g, quint8 b, int * h, int * l, int * s); 0035 KRITAPIGMENT_EXPORT void hls_to_rgb(int h, int l, int s, quint8 * r, quint8 * g, quint8 * b); 0036 0037 //HSI and HSY' functions. 0038 //These are modified to calculate a cylinder, this is good for color selectors sliders. 0039 //All eight expect 0.0-1.0 for all parameters. 0040 //HSI measures the Tone, Intensity, by adding the r, g and b components and then normalising that. 0041 KRITAPIGMENT_EXPORT void HSIToRGB(const qreal h, const qreal s, const qreal i, qreal *red, qreal *green, qreal *blue); 0042 KRITAPIGMENT_EXPORT void RGBToHSI(qreal r, qreal g, qreal b, qreal *h, qreal *s, qreal *i); 0043 0044 //HSY' measures the tone, Luma, by weighting the r, g, and b components before adding them up. 0045 //The R, G, B refers to the weights, and defaults to the 601 rec for luma. 0046 KRITAPIGMENT_EXPORT void RGBToHSY( qreal r, qreal g, qreal b, qreal *h, qreal *s, qreal *y, qreal R=0.299, qreal G=0.587, qreal B=0.114); 0047 KRITAPIGMENT_EXPORT void HSYToRGB(const qreal h, const qreal s, const qreal y, qreal *red, qreal *green, qreal *blue, qreal R=0.299, qreal G=0.587, qreal B=0.114); 0048 0049 0050 //HCI and HCY' functions. 0051 //These are the original conversion functions, producing cones. Put in for completion. 0052 //There's HCI to RGB is based on the HCY to RGB one for now, it may not be correct. 0053 KRITAPIGMENT_EXPORT void HCIToRGB(const qreal h, const qreal s, const qreal i, qreal *red, qreal *green, qreal *blue); 0054 KRITAPIGMENT_EXPORT void RGBToHCI(const qreal r, const qreal g, const qreal b, qreal *h, qreal *c, qreal *i); 0055 0056 KRITAPIGMENT_EXPORT void HCYToRGB(const qreal h, const qreal s, const qreal y, qreal *red, qreal *green, qreal *blue, qreal R=0.299, qreal G=0.587, qreal B=0.114); 0057 KRITAPIGMENT_EXPORT void RGBToHCY(const qreal r, const qreal g, const qreal b, qreal *h, qreal *c, qreal *y, qreal R=0.299, qreal G=0.587, qreal B=0.114); 0058 0059 KRITAPIGMENT_EXPORT void RGBToYUV( qreal r, qreal g, qreal b, qreal *y, qreal *cb, qreal *cr, qreal R=0.299, qreal G=0.587, qreal B=0.114); 0060 KRITAPIGMENT_EXPORT void YUVToRGB(const qreal y, const qreal cb, const qreal cr, qreal *r, qreal *g, qreal *b, qreal R=0.299, qreal G=0.587, qreal B=0.114); 0061 0062 KRITAPIGMENT_EXPORT void LabToLCH(const qreal l, const qreal a, const qreal b, qreal *L, qreal *C, qreal *H); 0063 KRITAPIGMENT_EXPORT void LCHToLab(const qreal L, const qreal C, const qreal H, qreal *l, qreal *a, qreal *b); 0064 0065 KRITAPIGMENT_EXPORT void XYZToxyY(const qreal X, const qreal Y, const qreal Z, qreal *x, qreal *y, qreal *yY); 0066 KRITAPIGMENT_EXPORT void xyYToXYZ(const qreal x, const qreal y, const qreal yY, qreal *X, qreal *Y, qreal *Z); 0067 0068 KRITAPIGMENT_EXPORT void CMYToCMYK(qreal *c, qreal *m, qreal *y, qreal *k); 0069 KRITAPIGMENT_EXPORT void CMYKToCMY(qreal *c, qreal *m, qreal *y, qreal *k); 0070 0071 #endif // _KO_COLORCONVERSIONS_H_ 0072