Coverage Report

Created: 2026-12-01 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvips/libvips/create/zone.c
Line
Count
Source
1
/* square zone plate of size
2
 *
3
 * N. Dessipris 01/02/1991
4
 *
5
 * 22/7/93 JC
6
 *  - externs removed
7
 *  - im_outcheck() added
8
 * 30/8/95 JC
9
 *  - modernized
10
 *  - memory leaks fixed
11
 *  - split into im_zone() and im_fzone()
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 VipsPoint VipsZone;
65
typedef VipsPointClass VipsZoneClass;
66
67
2
G_DEFINE_TYPE(VipsZone, vips_zone, VIPS_TYPE_POINT);
68
2
69
2
static float
70
2
vips_zone_point(VipsPoint *point, int x, int y)
71
2
{
72
0
  VipsZone *zone = (VipsZone *) point;
73
74
0
  int hwidth = point->width / 2;
75
0
  int hheight = point->height / 2;
76
0
  int h2 = (x - hwidth) * (x - hwidth);
77
0
  int v2 = (y - hheight) * (y - hheight);
78
0
  float c = VIPS_PI / zone->width;
79
80
0
  return cosf(c * (v2 + h2));
81
0
}
82
83
static void
84
vips_zone_class_init(VipsZoneClass *class)
85
1
{
86
1
  VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS(class);
87
1
  VipsPointClass *point_class = VIPS_POINT_CLASS(class);
88
89
1
  vobject_class->nickname = "zone";
90
1
  vobject_class->description = _("make a zone plate");
91
92
1
  point_class->point = vips_zone_point;
93
1
}
94
95
static void
96
vips_zone_init(VipsZone *zone)
97
0
{
98
0
}
99
100
/**
101
 * vips_zone:
102
 * @out: (out): output image
103
 * @width: image size
104
 * @height: image size
105
 * @...: `NULL`-terminated list of optional named arguments
106
 *
107
 * Create a one-band image of a zone plate.
108
 *
109
 * Pixels are normally in [-1, +1], set @uchar to output [0, 255].
110
 *
111
 * ::: tip "Optional arguments"
112
 *     * @uchar: `gboolean`, output a uchar image
113
 *
114
 * ::: seealso
115
 *     [ctor@Image.eye], [ctor@Image.xyz].
116
 *
117
 * Returns: 0 on success, -1 on error
118
 */
119
int
120
vips_zone(VipsImage **out, int width, int height, ...)
121
0
{
122
0
  va_list ap;
123
0
  int result;
124
125
0
  va_start(ap, height);
126
0
  result = vips_call_split("zone", ap, out, width, height);
127
0
  va_end(ap);
128
129
0
  return result;
130
0
}