文件
dayu-color/大鱼调色/Plugin/DYHSLPicker.h
T

23 行
1.2 KiB
C++

#pragma once
#include <algorithm>
#include <cmath>
// Display sRGB point -> the existing eight HSL lanes. No grading values change.
// Near-neutrals have no useful hue and keep the current selection (-1).
static inline int DYHSLPickedLane(float r,float g,float b) {
if(!std::isfinite(r)||!std::isfinite(g)||!std::isfinite(b))return -1;
r=std::clamp(r,0.f,1.f);g=std::clamp(g,0.f,1.f);b=std::clamp(b,0.f,1.f);
float high=std::max({r,g,b}),low=std::min({r,g,b}),chroma=high-low;
if(high<.025f||chroma<.015f||chroma/high<.06f)return -1;
float hue=high==r?(g-b)/chroma:high==g?(b-r)/chroma+2:(r-g)/chroma+4;
hue*=60;if(hue<0)hue+=360;
float saturation=chroma/high;
// Warm, less saturated pink/peach/brown points take precedence over red/yellow.
// This is a colour heuristic, not face/person detection; saturated red stays red.
if(hue<=52&&r>g&&g>=b-.025f&&saturation>=.08f&&saturation<=.72f)return 1;
const float centers[]={0,30,60,120,180,240,270,315};
int best=0;float closest=360;
for(int lane=0;lane<8;lane++){float distance=std::fabs(hue-centers[lane]);distance=std::min(distance,360-distance);if(distance<closest){closest=distance;best=lane;}}
return best;
}