Coverage Report

Created: 2026-04-01 07:49

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/graphicsmagick/coders/null.c
Line
Count
Source
1
/*
2
% Copyright (C) 2003-2025 GraphicsMagick Group
3
% Copyright (C) 2002 ImageMagick Studio
4
% Copyright 1991-1999 E. I. du Pont de Nemours and Company
5
%
6
% This program is covered by multiple licenses, which are described in
7
% Copyright.txt. You should have received a copy of Copyright.txt with this
8
% package; otherwise see http://www.graphicsmagick.org/www/Copyright.html.
9
%
10
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11
%                                                                             %
12
%                                                                             %
13
%                                                                             %
14
%                        N   N  U   U  L      L                               %
15
%                        NN  N  U   U  L      L                               %
16
%                        N N N  U   U  L      L                               %
17
%                        N  NN  U   U  L      L                               %
18
%                        N   N   UUU   LLLLL  LLLLL                           %
19
%                                                                             %
20
%                                                                             %
21
%                   Read/Write Image Of Uniform Color                         %
22
%                                                                             %
23
%                                                                             %
24
%                              Software Design                                %
25
%                                John Cristy                                  %
26
%                                 July 1992                                   %
27
%                                                                             %
28
%                                                                             %
29
%                                                                             %
30
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
31
%
32
%
33
*/
34

35
/*
36
  Include declarations.
37
*/
38
#include "magick/studio.h"
39
#include "magick/blob.h"
40
#include "magick/color.h"
41
#include "magick/color_lookup.h"
42
#include "magick/colormap.h"
43
#include "magick/magick.h"
44
#include "magick/pixel_cache.h"
45
#include "magick/utility.h"
46
#include "magick/static.h"
47

48
/*
49
  Forward declarations.
50
*/
51
static unsigned int
52
  WriteNULLImage(const ImageInfo *,Image *) MAGICK_FUNC_PURE;
53

54
/*
55
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
56
%                                                                             %
57
%                                                                             %
58
%                                                                             %
59
%   R e a d N U L L I m a g e                                                 %
60
%                                                                             %
61
%                                                                             %
62
%                                                                             %
63
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
64
%
65
%  Method ReadNULLImage creates a constant image and initializes it to the
66
%  X server color as specified by the filename.  It allocates the memory
67
%  necessary for the new Image structure and returns a pointer to the new
68
%  image.
69
%
70
%  The format of the ReadNULLImage method is:
71
%
72
%      Image *ReadNULLImage(const ImageInfo *image_info,
73
%        ExceptionInfo *exception)
74
%
75
%  A description of each parameter follows:
76
%
77
%    o image:  Method ReadNULLImage returns a pointer to the image after
78
%      creating it. A null image is returned if there is a memory shortage
79
%      or if the image cannot be read.
80
%
81
%    o image_info: Specifies a pointer to a ImageInfo structure.
82
%
83
%    o exception: return any errors or warnings in this structure.
84
%
85
%
86
*/
87
static Image *ReadNULLImage(const ImageInfo *image_info,
88
  ExceptionInfo *exception)
89
0
{
90
0
  Image
91
0
    *image;
92
93
0
  unsigned int
94
0
    status;
95
96
  /*
97
    Initialize Image structure.
98
  */
99
0
  assert(image_info != (const ImageInfo *) NULL);
100
0
  assert(image_info->signature == MagickSignature);
101
0
  assert(exception != (ExceptionInfo *) NULL);
102
0
  assert(exception->signature == MagickSignature);
103
0
  image=AllocateImage(image_info);
104
0
  if (image->columns == 0)
105
0
    image->columns=1;
106
0
  if (image->rows == 0)
107
0
    image->rows=1;
108
109
0
  if (CheckImagePixelLimits(image, exception) != MagickPass)
110
0
    ThrowReaderException(ResourceLimitError,ImagePixelLimitExceeded,image);
111
112
0
  (void) strlcpy(image->filename,image_info->filename,MaxTextExtent);
113
0
  status=QueryColorDatabase((char *) image_info->filename,
114
0
    &image->background_color,exception);
115
0
  if (status == MagickFail)
116
0
    {
117
      /* Promote warning to error */
118
0
      exception->severity = OptionError;
119
0
      DestroyImage(image);
120
0
      return((Image *) NULL);
121
0
    }
122
0
  if (!AllocateImageColormap(image,1))
123
0
    ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
124
0
  image->colormap[0]=image->background_color;
125
0
  status=SetImageEx(image,OpaqueOpacity,exception);
126
0
  StopTimer(&image->timer);
127
0
  if (status == MagickFail)
128
0
    {
129
0
      DestroyImage(image);
130
0
      image=(Image *) NULL;
131
0
    }
132
133
0
  return(image);
134
0
}
135

136
/*
137
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
138
%                                                                             %
139
%                                                                             %
140
%                                                                             %
141
%   R e g i s t e r N U L L I m a g e                                         %
142
%                                                                             %
143
%                                                                             %
144
%                                                                             %
145
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
146
%
147
%  Method RegisterNULLImage adds attributes for the NULL image format to
148
%  the list of supported formats.  The attributes include the image format
149
%  tag, a method to read and/or write the format, whether the format
150
%  supports the saving of more than one frame to the same file or blob,
151
%  whether the format supports native in-memory I/O, and a brief
152
%  description of the format.
153
%
154
%  The format of the RegisterNULLImage method is:
155
%
156
%      RegisterNULLImage(void)
157
%
158
*/
159
ModuleExport void RegisterNULLImage(void)
160
0
{
161
0
  MagickInfo
162
0
    *entry;
163
164
0
  entry=SetMagickInfo("NULL");
165
0
  entry->decoder=(DecoderHandler) ReadNULLImage;
166
0
  entry->encoder=(EncoderHandler) WriteNULLImage;
167
0
  entry->adjoin=False;
168
0
  entry->description="Constant image of uniform color";
169
0
  entry->module="NULL";
170
0
  entry->coder_class=PrimaryCoderClass;
171
0
  entry->extension_treatment=IgnoreExtensionTreatment;
172
0
  (void) RegisterMagickInfo(entry);
173
0
}
174

175
/*
176
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
177
%                                                                             %
178
%                                                                             %
179
%                                                                             %
180
%   U n r e g i s t e r N U L L I m a g e                                     %
181
%                                                                             %
182
%                                                                             %
183
%                                                                             %
184
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
185
%
186
%  Method UnregisterNULLImage removes format registrations made by the
187
%  NULL module from the list of supported formats.
188
%
189
%  The format of the UnregisterNULLImage method is:
190
%
191
%      UnregisterNULLImage(void)
192
%
193
*/
194
ModuleExport void UnregisterNULLImage(void)
195
0
{
196
0
  (void) UnregisterMagickInfo("NULL");
197
0
}
198

199
/*
200
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
201
%                                                                             %
202
%                                                                             %
203
%                                                                             %
204
%   W r i t e N U L L I m a g e                                               %
205
%                                                                             %
206
%                                                                             %
207
%                                                                             %
208
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209
%
210
%  Method WriteNULLImage writes no output at all. It is useful when specified
211
%  as an output format when profiling.
212
%
213
%  The format of the WriteNULLImage method is:
214
%
215
%      unsigned int WriteNULLImage(const ImageInfo *image_info,Image *image)
216
%
217
%  A description of each parameter follows.
218
%
219
%    o status: Always returns True.
220
%
221
%    o image_info: Specifies a pointer to a ImageInfo structure.
222
%
223
%    o image:  A pointer to an Image structure.
224
%
225
%
226
*/
227
static unsigned int WriteNULLImage(const ImageInfo *image_info,Image *image)
228
0
{
229
0
  assert(image_info != (const ImageInfo *) NULL);
230
0
  assert(image_info->signature == MagickSignature);
231
0
  assert(image != (Image *) NULL);
232
0
  assert(image->signature == MagickSignature);
233
0
  return(True);
234
0
}