Coverage Report

Created: 2025-01-28 06:33

/src/libvips/libvips/create/eye.c
Line
Count
Source (jump to first uncovered line)
1
/* make a test pattern to show the eye's frequency response
2
 *
3
 * Copyright: 1990, 1991, N.Dessipris.
4
 *
5
 * Author N. Dessipris
6
 * Written on 30/05/1990
7
 * Updated on: 27/01/1991, 07/03/1991,
8
 * 22/7/93 JC
9
 *  - im_outcheck() added
10
 * 30/8/95 JC
11
 *  - modernized
12
 * 1/2/11
13
 *  - gtk-doc
14
 * 13/6/13
15
 *  - redo as a class
16
 */
17
18
/*
19
20
  This file is part of VIPS.
21
22
  VIPS is free software; you can redistribute it and/or modify
23
  it under the terms of the GNU Lesser General Public License as published by
24
  the Free Software Foundation; either version 2 of the License, or
25
  (at your option) any later version.
26
27
  This program is distributed in the hope that it will be useful,
28
  but WITHOUT ANY WARRANTY; without even the implied warranty of
29
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
30
  GNU Lesser General Public License for more details.
31
32
  You should have received a copy of the GNU Lesser General Public License
33
  along with this program; if not, write to the Free Software
34
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
35
  02110-1301  USA
36
37
 */
38
39
/*
40
41
  These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
42
43
 */
44
45
/*
46
#define VIPS_DEBUG
47
 */
48
49
#ifdef HAVE_CONFIG_H
50
#include <config.h>
51
#endif /*HAVE_CONFIG_H*/
52
#include <glib/gi18n-lib.h>
53
54
#include <stdio.h>
55
#include <string.h>
56
#include <stdlib.h>
57
#include <math.h>
58
59
#include <vips/vips.h>
60
61
#include "pcreate.h"
62
#include "point.h"
63
64
typedef struct _VipsEye {
65
  VipsPoint parent_instance;
66
67
  double factor;
68
69
} VipsEye;
70
71
typedef VipsPointClass VipsEyeClass;
72
73
G_DEFINE_TYPE(VipsEye, vips_eye, VIPS_TYPE_POINT);
74
75
static float
76
vips_eye_point(VipsPoint *point, int x, int y)
77
0
{
78
0
  VipsEye *eye = (VipsEye *) point;
79
80
  /* VIPS_MAX to prevent /0.
81
   */
82
0
  int max_x = VIPS_MAX(point->width - 1, 1);
83
0
  int max_y = VIPS_MAX(point->height - 1, 1);
84
85
0
  double c = eye->factor * VIPS_PI / (2 * max_x);
86
0
  double h = max_y * max_y;
87
88
0
  return y * y * cos(c * x * x) / h;
89
0
}
90
91
static void
92
vips_eye_class_init(VipsEyeClass *class)
93
1
{
94
1
  GObjectClass *gobject_class = G_OBJECT_CLASS(class);
95
1
  VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS(class);
96
1
  VipsPointClass *point_class = VIPS_POINT_CLASS(class);
97
98
1
  gobject_class->set_property = vips_object_set_property;
99
1
  gobject_class->get_property = vips_object_get_property;
100
101
1
  vobject_class->nickname = "eye";
102
1
  vobject_class->description =
103
1
    _("make an image showing the eye's spatial response");
104
105
1
  point_class->point = vips_eye_point;
106
107
1
  VIPS_ARG_DOUBLE(class, "factor", 6,
108
1
    _("Factor"),
109
1
    _("Maximum spatial frequency"),
110
1
    VIPS_ARGUMENT_OPTIONAL_INPUT,
111
1
    G_STRUCT_OFFSET(VipsEye, factor),
112
1
    0.0, 1.0, 0.5);
113
1
}
114
115
static void
116
vips_eye_init(VipsEye *eye)
117
0
{
118
0
  eye->factor = 0.5;
119
0
}
120
121
/**
122
 * vips_eye:
123
 * @out: (out): output image
124
 * @width: image size
125
 * @height: image size
126
 * @...: %NULL-terminated list of optional named arguments
127
 *
128
 * Optional arguments:
129
 *
130
 * * @factor: %gdouble, maximum spatial frequency
131
 * * @uchar: %gboolean, output a uchar image
132
 *
133
 * Create a test pattern with increasing spatial frequency in X and
134
 * amplitude in Y. @factor should be between 0 and 1 and determines the
135
 * maximum spatial frequency.
136
 *
137
 * Set @uchar to output a uchar image.
138
 *
139
 * See also: vips_zone().
140
 *
141
 * Returns: 0 on success, -1 on error
142
 */
143
int
144
vips_eye(VipsImage **out, int width, int height, ...)
145
0
{
146
0
  va_list ap;
147
0
  int result;
148
149
0
  va_start(ap, height);
150
0
  result = vips_call_split("eye", ap, out, width, height);
151
0
  va_end(ap);
152
153
0
  return result;
154
0
}