Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
godotengine
GitHub Repository: godotengine/godot
Path: blob/master/thirdparty/libjpeg-turbo/src/cmyk.h
9904 views
1
/*
2
* cmyk.h
3
*
4
* Copyright (C) 2017-2018, 2022, 2024, D. R. Commander.
5
* For conditions of distribution and use, see the accompanying README.ijg
6
* file.
7
*
8
* This file contains convenience functions for performing quick & dirty
9
* CMYK<->RGB conversion. This algorithm is suitable for testing purposes
10
* only. Properly converting between CMYK and RGB requires a color management
11
* system.
12
*/
13
14
#ifndef CMYK_H
15
#define CMYK_H
16
17
#include <jinclude.h>
18
#define JPEG_INTERNALS
19
#include <jpeglib.h>
20
#include "jsamplecomp.h"
21
22
23
/* Fully reversible */
24
25
INLINE
26
LOCAL(void)
27
rgb_to_cmyk(int maxval, _JSAMPLE r, _JSAMPLE g, _JSAMPLE b,
28
_JSAMPLE *c, _JSAMPLE *m, _JSAMPLE *y, _JSAMPLE *k)
29
{
30
double ctmp = 1.0 - ((double)r / (double)maxval);
31
double mtmp = 1.0 - ((double)g / (double)maxval);
32
double ytmp = 1.0 - ((double)b / (double)maxval);
33
double ktmp = MIN(MIN(ctmp, mtmp), ytmp);
34
35
if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0;
36
else {
37
ctmp = (ctmp - ktmp) / (1.0 - ktmp);
38
mtmp = (mtmp - ktmp) / (1.0 - ktmp);
39
ytmp = (ytmp - ktmp) / (1.0 - ktmp);
40
}
41
*c = (_JSAMPLE)((double)maxval - ctmp * (double)maxval + 0.5);
42
*m = (_JSAMPLE)((double)maxval - mtmp * (double)maxval + 0.5);
43
*y = (_JSAMPLE)((double)maxval - ytmp * (double)maxval + 0.5);
44
*k = (_JSAMPLE)((double)maxval - ktmp * (double)maxval + 0.5);
45
}
46
47
48
/* Fully reversible only for C/M/Y/K values generated with rgb_to_cmyk() */
49
50
INLINE
51
LOCAL(void)
52
cmyk_to_rgb(int maxval, _JSAMPLE c, _JSAMPLE m, _JSAMPLE y, _JSAMPLE k,
53
_JSAMPLE *r, _JSAMPLE *g, _JSAMPLE *b)
54
{
55
*r = (_JSAMPLE)((double)c * (double)k / (double)maxval + 0.5);
56
*g = (_JSAMPLE)((double)m * (double)k / (double)maxval + 0.5);
57
*b = (_JSAMPLE)((double)y * (double)k / (double)maxval + 0.5);
58
}
59
60
61
#endif /* CMYK_H */
62
63