Coverage Report

Created: 2025-07-01 06:27

/src/libjpeg-turbo.3.0.x/cmyk.h
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * cmyk.h
3
 *
4
 * Copyright (C) 2017-2018, 2022, 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(_JSAMPLE r, _JSAMPLE g, _JSAMPLE b,
28
            _JSAMPLE *c, _JSAMPLE *m, _JSAMPLE *y, _JSAMPLE *k)
29
88.4M
{
30
88.4M
  double ctmp = 1.0 - ((double)r / (double)_MAXJSAMPLE);
31
88.4M
  double mtmp = 1.0 - ((double)g / (double)_MAXJSAMPLE);
32
88.4M
  double ytmp = 1.0 - ((double)b / (double)_MAXJSAMPLE);
33
88.4M
  double ktmp = MIN(MIN(ctmp, mtmp), ytmp);
34
35
88.4M
  if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0;
36
42.2M
  else {
37
42.2M
    ctmp = (ctmp - ktmp) / (1.0 - ktmp);
38
42.2M
    mtmp = (mtmp - ktmp) / (1.0 - ktmp);
39
42.2M
    ytmp = (ytmp - ktmp) / (1.0 - ktmp);
40
42.2M
  }
41
88.4M
  *c = (_JSAMPLE)((double)_MAXJSAMPLE - ctmp * (double)_MAXJSAMPLE + 0.5);
42
88.4M
  *m = (_JSAMPLE)((double)_MAXJSAMPLE - mtmp * (double)_MAXJSAMPLE + 0.5);
43
88.4M
  *y = (_JSAMPLE)((double)_MAXJSAMPLE - ytmp * (double)_MAXJSAMPLE + 0.5);
44
88.4M
  *k = (_JSAMPLE)((double)_MAXJSAMPLE - ktmp * (double)_MAXJSAMPLE + 0.5);
45
88.4M
}
rdbmp.c:rgb_to_cmyk
Line
Count
Source
29
23.0M
{
30
23.0M
  double ctmp = 1.0 - ((double)r / (double)_MAXJSAMPLE);
31
23.0M
  double mtmp = 1.0 - ((double)g / (double)_MAXJSAMPLE);
32
23.0M
  double ytmp = 1.0 - ((double)b / (double)_MAXJSAMPLE);
33
23.0M
  double ktmp = MIN(MIN(ctmp, mtmp), ytmp);
34
35
23.0M
  if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0;
36
15.2M
  else {
37
15.2M
    ctmp = (ctmp - ktmp) / (1.0 - ktmp);
38
15.2M
    mtmp = (mtmp - ktmp) / (1.0 - ktmp);
39
15.2M
    ytmp = (ytmp - ktmp) / (1.0 - ktmp);
40
15.2M
  }
41
23.0M
  *c = (_JSAMPLE)((double)_MAXJSAMPLE - ctmp * (double)_MAXJSAMPLE + 0.5);
42
23.0M
  *m = (_JSAMPLE)((double)_MAXJSAMPLE - mtmp * (double)_MAXJSAMPLE + 0.5);
43
23.0M
  *y = (_JSAMPLE)((double)_MAXJSAMPLE - ytmp * (double)_MAXJSAMPLE + 0.5);
44
23.0M
  *k = (_JSAMPLE)((double)_MAXJSAMPLE - ktmp * (double)_MAXJSAMPLE + 0.5);
45
23.0M
}
rdppm.c:rgb_to_cmyk
Line
Count
Source
29
65.3M
{
30
65.3M
  double ctmp = 1.0 - ((double)r / (double)_MAXJSAMPLE);
31
65.3M
  double mtmp = 1.0 - ((double)g / (double)_MAXJSAMPLE);
32
65.3M
  double ytmp = 1.0 - ((double)b / (double)_MAXJSAMPLE);
33
65.3M
  double ktmp = MIN(MIN(ctmp, mtmp), ytmp);
34
35
65.3M
  if (ktmp == 1.0) ctmp = mtmp = ytmp = 0.0;
36
27.0M
  else {
37
27.0M
    ctmp = (ctmp - ktmp) / (1.0 - ktmp);
38
27.0M
    mtmp = (mtmp - ktmp) / (1.0 - ktmp);
39
27.0M
    ytmp = (ytmp - ktmp) / (1.0 - ktmp);
40
27.0M
  }
41
65.3M
  *c = (_JSAMPLE)((double)_MAXJSAMPLE - ctmp * (double)_MAXJSAMPLE + 0.5);
42
65.3M
  *m = (_JSAMPLE)((double)_MAXJSAMPLE - mtmp * (double)_MAXJSAMPLE + 0.5);
43
65.3M
  *y = (_JSAMPLE)((double)_MAXJSAMPLE - ytmp * (double)_MAXJSAMPLE + 0.5);
44
65.3M
  *k = (_JSAMPLE)((double)_MAXJSAMPLE - ktmp * (double)_MAXJSAMPLE + 0.5);
45
65.3M
}
Unexecuted instantiation: wrbmp.c:rgb_to_cmyk
Unexecuted instantiation: wrppm.c:rgb_to_cmyk
Unexecuted instantiation: rdbmp.c:rgb_to_cmyk
Unexecuted instantiation: rdppm.c:rgb_to_cmyk
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(_JSAMPLE c, _JSAMPLE m, _JSAMPLE y, _JSAMPLE k,
53
            _JSAMPLE *r, _JSAMPLE *g, _JSAMPLE *b)
54
0
{
55
0
  *r = (_JSAMPLE)((double)c * (double)k / (double)_MAXJSAMPLE + 0.5);
56
0
  *g = (_JSAMPLE)((double)m * (double)k / (double)_MAXJSAMPLE + 0.5);
57
0
  *b = (_JSAMPLE)((double)y * (double)k / (double)_MAXJSAMPLE + 0.5);
58
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
59
60
61
#endif /* CMYK_H */