-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.h
More file actions
60 lines (48 loc) · 1.88 KB
/
common.h
File metadata and controls
60 lines (48 loc) · 1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// common.h
#pragma once
#ifndef COMMON_H
#define COMMON_H
#include <string.h> // For strlen, strcpy_s
#include <stdio.h> // Required for sprintf
#include <objbase.h> // For malloc
//#define TRUE 1
//#define FALSE 0
//#define BOOL int
static const double COLORS_PI_F = 3.14159265358979323846f; // float
static const double COLORS_PI = 3.14159265358979323846; // double
static const double COLORS_PI_L = 3.14159265358979323846264338327950288L; // long double
static const double COLORS_LCH_CHROMA_EPS = 0.003; // 1e-6 - A small epsilon value to treat very low chroma as zero in LCH conversions.
// Perceptual stability: treat near-neutral colors as neutral.
// 0.003 clamps your observed D65Full gray drift (C=0.002).
static inline char* createBuffer(const char* str) {
if (!str) return NULL;
size_t len = strlen(str) + 1;
char* buffer = (char*)malloc(len);
if (buffer) {
memcpy(buffer, str, len);
}
return buffer;
}
static inline unsigned char clampUChr(unsigned char v, unsigned char min, unsigned char max) { return v < min ? min : (v > max ? max : v); }
static inline int clampInt(int v, int min, int max) { return v < min ? min : (v > max ? max : v); }
static inline double clampDbl(double v, double min, double max) { return v < min ? min : (v > max ? max : v); }
static inline double normalize01_to_0max(double v, double max) { return (v > 0.0 && v < 1.0) ? (v * max) : v; }
static inline unsigned char clampIntToUChr(int v)
{
v = clampInt(v, 0, 255);
return (unsigned char)v;
}
static inline double makeWholeClamp(double v, double min, double max)
{
if (v > 0.0 && v < 1.0)
v *= max;
return clampDbl(v, min, max);
}
static inline double chkDbleClamp(double v, double min, double max, double div)
{
v = makeWholeClamp(v, min, max);
if (div != 0.0)
v /= div;
return clampDbl(v, min, max);
}
#endif