/src/libjpeg-turbo.main/cmyk.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * cmyk.h |
3 | | * |
4 | | * Copyright (C) 2017-2018, 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 | | |
21 | | |
22 | | /* Fully reversible */ |
23 | | |
24 | | INLINE |
25 | | LOCAL(void) |
26 | | rgb_to_cmyk(JSAMPLE r, JSAMPLE g, JSAMPLE b, JSAMPLE *c, JSAMPLE *m, |
27 | | JSAMPLE *y, JSAMPLE *k) |
28 | 0 | { |
29 | 0 | double ctmp = 1.0 - ((double)r / 255.0); |
30 | 0 | double mtmp = 1.0 - ((double)g / 255.0); |
31 | 0 | double ytmp = 1.0 - ((double)b / 255.0); |
32 | 0 | double ktmp = MIN(MIN(ctmp, mtmp), ytmp); |
33 | |
|
34 | 0 | if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0; |
35 | 0 | else { |
36 | 0 | ctmp = (ctmp - ktmp) / (1.0 - ktmp); |
37 | 0 | mtmp = (mtmp - ktmp) / (1.0 - ktmp); |
38 | 0 | ytmp = (ytmp - ktmp) / (1.0 - ktmp); |
39 | 0 | } |
40 | 0 | *c = (JSAMPLE)(255.0 - ctmp * 255.0 + 0.5); |
41 | 0 | *m = (JSAMPLE)(255.0 - mtmp * 255.0 + 0.5); |
42 | 0 | *y = (JSAMPLE)(255.0 - ytmp * 255.0 + 0.5); |
43 | 0 | *k = (JSAMPLE)(255.0 - ktmp * 255.0 + 0.5); |
44 | 0 | } Unexecuted instantiation: rdbmp.c:rgb_to_cmyk Unexecuted instantiation: rdppm.c:rgb_to_cmyk Unexecuted instantiation: wrbmp.c:rgb_to_cmyk Unexecuted instantiation: wrppm.c:rgb_to_cmyk |
45 | | |
46 | | |
47 | | /* Fully reversible only for C/M/Y/K values generated with rgb_to_cmyk() */ |
48 | | |
49 | | INLINE |
50 | | LOCAL(void) |
51 | | cmyk_to_rgb(JSAMPLE c, JSAMPLE m, JSAMPLE y, JSAMPLE k, JSAMPLE *r, JSAMPLE *g, |
52 | | JSAMPLE *b) |
53 | 0 | { |
54 | 0 | *r = (JSAMPLE)((double)c * (double)k / 255.0 + 0.5); |
55 | 0 | *g = (JSAMPLE)((double)m * (double)k / 255.0 + 0.5); |
56 | 0 | *b = (JSAMPLE)((double)y * (double)k / 255.0 + 0.5); |
57 | 0 | } Unexecuted instantiation: rdbmp.c:cmyk_to_rgb Unexecuted instantiation: rdppm.c:cmyk_to_rgb Unexecuted instantiation: wrbmp.c:cmyk_to_rgb Unexecuted instantiation: wrppm.c:cmyk_to_rgb |
58 | | |
59 | | |
60 | | #endif /* CMYK_H */ |