Coverage Report

Created: 2025-06-22 07:12

/src/libvips/libvips/colour/XYZ2Yxy.c
Line
Count
Source (jump to first uncovered line)
1
/* Turn XYZ to Yxy colourspace.
2
 *
3
 * Modified:
4
 * 29/5/02 JC
5
 *  - from lab2xyz
6
 * 2/11/09
7
 *  - gtkdoc
8
 *  - cleanups
9
 * 20/9/12
10
 *  redo as a class
11
 */
12
13
/*
14
15
  This file is part of VIPS.
16
17
  VIPS is free software; you can redistribute it and/or modify
18
  it under the terms of the GNU Lesser General Public License as published by
19
  the Free Software Foundation; either version 2 of the License, or
20
  (at your option) any later version.
21
22
  This program is distributed in the hope that it will be useful,
23
  but WITHOUT ANY WARRANTY; without even the implied warranty of
24
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25
  GNU Lesser General Public License for more details.
26
27
  You should have received a copy of the GNU Lesser General Public License
28
  along with this program; if not, write to the Free Software
29
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30
  02110-1301  USA
31
32
 */
33
34
/*
35
36
  These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
37
38
 */
39
40
#ifdef HAVE_CONFIG_H
41
#include <config.h>
42
#endif /*HAVE_CONFIG_H*/
43
#include <glib/gi18n-lib.h>
44
45
#include <stdio.h>
46
#include <math.h>
47
48
#include <vips/vips.h>
49
50
#include "pcolour.h"
51
52
typedef VipsColourTransform VipsXYZ2Yxy;
53
typedef VipsColourTransformClass VipsXYZ2YxyClass;
54
55
G_DEFINE_TYPE(VipsXYZ2Yxy, vips_XYZ2Yxy, VIPS_TYPE_COLOUR_TRANSFORM);
56
57
static void
58
vips_XYZ2Yxy_line(VipsColour *colour, VipsPel *out, VipsPel **in, int width)
59
0
{
60
0
  float *restrict p = (float *) in[0];
61
0
  float *restrict q = (float *) out;
62
63
0
  int i;
64
65
0
  for (i = 0; i < width; i++) {
66
0
    float X = p[0];
67
0
    float Y = p[1];
68
0
    float Z = p[2];
69
0
    double total = X + Y + Z;
70
71
0
    float x, y;
72
73
0
    p += 3;
74
75
0
    if (total == 0.0) {
76
0
      x = 0;
77
0
      y = 0;
78
0
    }
79
0
    else {
80
0
      x = X / total;
81
0
      y = Y / total;
82
0
    }
83
84
0
    q[0] = Y;
85
0
    q[1] = x;
86
0
    q[2] = y;
87
0
    q += 3;
88
0
  }
89
0
}
90
91
static void
92
vips_XYZ2Yxy_class_init(VipsXYZ2YxyClass *class)
93
17
{
94
17
  VipsObjectClass *object_class = (VipsObjectClass *) class;
95
17
  VipsColourClass *colour_class = VIPS_COLOUR_CLASS(class);
96
97
17
  object_class->nickname = "XYZ2Yxy";
98
17
  object_class->description = _("transform XYZ to Yxy");
99
100
17
  colour_class->process_line = vips_XYZ2Yxy_line;
101
17
}
102
103
static void
104
vips_XYZ2Yxy_init(VipsXYZ2Yxy *XYZ2Yxy)
105
0
{
106
0
  VipsColour *colour = VIPS_COLOUR(XYZ2Yxy);
107
108
0
  colour->interpretation = VIPS_INTERPRETATION_YXY;
109
0
}
110
111
/**
112
 * vips_XYZ2Yxy: (method)
113
 * @in: input image
114
 * @out: (out): output image
115
 * @...: `NULL`-terminated list of optional named arguments
116
 *
117
 * Turn XYZ to Yxy.
118
 *
119
 * Returns: 0 on success, -1 on error
120
 */
121
int
122
vips_XYZ2Yxy(VipsImage *in, VipsImage **out, ...)
123
0
{
124
0
  va_list ap;
125
0
  int result;
126
127
0
  va_start(ap, out);
128
0
  result = vips_call_split("XYZ2Yxy", ap, in, out);
129
0
  va_end(ap);
130
131
0
  return result;
132
0
}