Coverage Report

Created: 2026-02-09 06:54

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libvips/libvips/create/black.c
Line
Count
Source
1
/* black.c
2
 *
3
 * Copyright: 1990, J. Cupitt
4
 *
5
 * Author: J. Cupitt
6
 * Written on: 02/08/1990
7
 * Modified on : 16/04/1991 by N. Dessipris to work on a line by line basis
8
 * 15/8/94 JC
9
 *  - adapted for partials
10
 *  - ANSIfied
11
 *  - memory leaks fixed!
12
 * 2/3/98 JC
13
 *  - IM_ANY added
14
 * 18/1/09
15
 *  - gtkdoc
16
 * 31/10/11
17
 *  - redo as a class
18
 * 3/4/18
19
 *  - always write MULTIBAND, otherwise when we join up these things it'll
20
 *    look like we have an alpha
21
 */
22
23
/*
24
25
  This file is part of VIPS.
26
27
  VIPS is free software; you can redistribute it and/or modify
28
  it under the terms of the GNU Lesser General Public License as published by
29
  the Free Software Foundation; either version 2 of the License, or
30
  (at your option) any later version.
31
32
  This program is distributed in the hope that it will be useful,
33
  but WITHOUT ANY WARRANTY; without even the implied warranty of
34
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
35
  GNU Lesser General Public License for more details.
36
37
  You should have received a copy of the GNU Lesser General Public License
38
  along with this program; if not, write to the Free Software
39
  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
40
  02110-1301  USA
41
42
 */
43
44
/*
45
46
  These files are distributed with VIPS - http://www.vips.ecs.soton.ac.uk
47
48
 */
49
50
/*
51
#define VIPS_DEBUG
52
 */
53
54
#ifdef HAVE_CONFIG_H
55
#include <config.h>
56
#endif /*HAVE_CONFIG_H*/
57
#include <glib/gi18n-lib.h>
58
59
#include <stdio.h>
60
#include <string.h>
61
#include <stdlib.h>
62
63
#include <vips/vips.h>
64
#include <vips/internal.h>
65
#include <vips/debug.h>
66
67
#include "pcreate.h"
68
69
typedef struct _VipsBlack {
70
  VipsCreate parent_instance;
71
72
  int width;
73
  int height;
74
  int bands;
75
76
} VipsBlack;
77
78
typedef VipsCreateClass VipsBlackClass;
79
80
72
G_DEFINE_TYPE(VipsBlack, vips_black, VIPS_TYPE_CREATE);
81
72
82
72
static int
83
72
vips_black_gen(VipsRegion *out_region,
84
72
  void *seq, void *a, void *b, gboolean *stop)
85
37.9k
{
86
  /*
87
  VipsRect *r = &out_region->valid;
88
89
  printf("vips_black_gen: "
90
       "left = %d, top = %d, width = %d, height = %d\n",
91
    r->left, r->top, r->width, r->height);
92
   */
93
94
37.9k
  vips_region_black(out_region);
95
96
37.9k
  return 0;
97
37.9k
}
98
99
static int
100
vips_black_build(VipsObject *object)
101
4.51k
{
102
4.51k
  VipsCreate *create = VIPS_CREATE(object);
103
4.51k
  VipsBlack *black = (VipsBlack *) object;
104
105
4.51k
  if (VIPS_OBJECT_CLASS(vips_black_parent_class)->build(object))
106
0
    return -1;
107
108
4.51k
  vips_image_init_fields(create->out,
109
4.51k
    black->width, black->height, black->bands,
110
4.51k
    VIPS_FORMAT_UCHAR, VIPS_CODING_NONE,
111
4.51k
    VIPS_INTERPRETATION_MULTIBAND,
112
4.51k
    1.0, 1.0);
113
4.51k
  if (vips_image_pipelinev(create->out,
114
4.51k
      VIPS_DEMAND_STYLE_ANY, NULL))
115
0
    return -1;
116
117
4.51k
  if (vips_image_generate(create->out,
118
4.51k
      NULL, vips_black_gen, NULL, NULL, NULL))
119
0
    return -1;
120
121
4.51k
  return 0;
122
4.51k
}
123
124
static void
125
vips_black_class_init(VipsBlackClass *class)
126
18
{
127
18
  GObjectClass *gobject_class = G_OBJECT_CLASS(class);
128
18
  VipsObjectClass *vobject_class = VIPS_OBJECT_CLASS(class);
129
130
18
  VIPS_DEBUG_MSG("vips_black_class_init\n");
131
132
18
  gobject_class->set_property = vips_object_set_property;
133
18
  gobject_class->get_property = vips_object_get_property;
134
135
18
  vobject_class->nickname = "black";
136
18
  vobject_class->description = _("make a black image");
137
18
  vobject_class->build = vips_black_build;
138
139
18
  VIPS_ARG_INT(class, "width", 4,
140
18
    _("Width"),
141
18
    _("Image width in pixels"),
142
18
    VIPS_ARGUMENT_REQUIRED_INPUT,
143
18
    G_STRUCT_OFFSET(VipsBlack, width),
144
18
    1, VIPS_MAX_COORD, 1);
145
146
18
  VIPS_ARG_INT(class, "height", 5,
147
18
    _("Height"),
148
18
    _("Image height in pixels"),
149
18
    VIPS_ARGUMENT_REQUIRED_INPUT,
150
18
    G_STRUCT_OFFSET(VipsBlack, height),
151
18
    1, VIPS_MAX_COORD, 1);
152
153
18
  VIPS_ARG_INT(class, "bands", 6,
154
18
    _("Bands"),
155
18
    _("Number of bands in image"),
156
18
    VIPS_ARGUMENT_OPTIONAL_INPUT,
157
18
    G_STRUCT_OFFSET(VipsBlack, bands),
158
18
    1, VIPS_MAX_COORD, 1);
159
18
}
160
161
static void
162
vips_black_init(VipsBlack *black)
163
44.2k
{
164
44.2k
  black->bands = 1;
165
44.2k
}
166
167
/**
168
 * vips_black:
169
 * @out: (out): output image
170
 * @width: output width
171
 * @height: output height
172
 * @...: `NULL`-terminated list of optional named arguments
173
 *
174
 * Make a black unsigned char image of a specified size.
175
 *
176
 * ::: tip "Optional arguments"
177
 *     * @bands: `gint`, output bands
178
 *
179
 * ::: seealso
180
 *     [ctor@Image.xyz], [ctor@Image.text], [ctor@Image.gaussnoise].
181
 *
182
 * Returns: 0 on success, -1 on error
183
 */
184
int
185
vips_black(VipsImage **out, int width, int height, ...)
186
44.2k
{
187
44.2k
  va_list ap;
188
44.2k
  int result;
189
190
44.2k
  va_start(ap, height);
191
44.2k
  result = vips_call_split("black", ap, out, width, height);
192
44.2k
  va_end(ap);
193
194
44.2k
  return result;
195
44.2k
}