Coverage Report

Created: 2025-12-03 07:28

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-2020 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

47
/*
48
  Forward declarations.
49
*/
50
static unsigned int
51
  WriteNULLImage(const ImageInfo *,Image *) MAGICK_FUNC_PURE;
52

53
/*
54
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
55
%                                                                             %
56
%                                                                             %
57
%                                                                             %
58
%   R e a d N U L L I m a g e                                                 %
59
%                                                                             %
60
%                                                                             %
61
%                                                                             %
62
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
%
64
%  Method ReadNULLImage creates a constant image and initializes it to the
65
%  X server color as specified by the filename.  It allocates the memory
66
%  necessary for the new Image structure and returns a pointer to the new
67
%  image.
68
%
69
%  The format of the ReadNULLImage method is:
70
%
71
%      Image *ReadNULLImage(const ImageInfo *image_info,
72
%        ExceptionInfo *exception)
73
%
74
%  A description of each parameter follows:
75
%
76
%    o image:  Method ReadNULLImage returns a pointer to the image after
77
%      creating it. A null image is returned if there is a memory shortage
78
%      or if the image cannot be read.
79
%
80
%    o image_info: Specifies a pointer to a ImageInfo structure.
81
%
82
%    o exception: return any errors or warnings in this structure.
83
%
84
%
85
*/
86
static Image *ReadNULLImage(const ImageInfo *image_info,
87
  ExceptionInfo *exception)
88
0
{
89
0
  Image
90
0
    *image;
91
92
0
  unsigned int
93
0
    status;
94
95
  /*
96
    Initialize Image structure.
97
  */
98
0
  assert(image_info != (const ImageInfo *) NULL);
99
0
  assert(image_info->signature == MagickSignature);
100
0
  assert(exception != (ExceptionInfo *) NULL);
101
0
  assert(exception->signature == MagickSignature);
102
0
  image=AllocateImage(image_info);
103
0
  if (image->columns == 0)
104
0
    image->columns=1;
105
0
  if (image->rows == 0)
106
0
    image->rows=1;
107
108
0
  if (CheckImagePixelLimits(image, exception) != MagickPass)
109
0
    ThrowReaderException(ResourceLimitError,ImagePixelLimitExceeded,image);
110
111
0
  (void) strlcpy(image->filename,image_info->filename,MaxTextExtent);
112
0
  status=QueryColorDatabase((char *) image_info->filename,
113
0
    &image->background_color,exception);
114
0
  if (status == MagickFail)
115
0
    {
116
      /* Promote warning to error */
117
0
      exception->severity = OptionError;
118
0
      DestroyImage(image);
119
0
      return((Image *) NULL);
120
0
    }
121
0
  if (!AllocateImageColormap(image,1))
122
0
    ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
123
0
  image->colormap[0]=image->background_color;
124
0
  status=SetImageEx(image,OpaqueOpacity,exception);
125
0
  StopTimer(&image->timer);
126
0
  if (status == MagickFail)
127
0
    {
128
0
      DestroyImage(image);
129
0
      image=(Image *) NULL;
130
0
    }
131
132
0
  return(image);
133
0
}
134

135
/*
136
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
137
%                                                                             %
138
%                                                                             %
139
%                                                                             %
140
%   R e g i s t e r N U L L I m a g e                                         %
141
%                                                                             %
142
%                                                                             %
143
%                                                                             %
144
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
145
%
146
%  Method RegisterNULLImage adds attributes for the NULL image format to
147
%  the list of supported formats.  The attributes include the image format
148
%  tag, a method to read and/or write the format, whether the format
149
%  supports the saving of more than one frame to the same file or blob,
150
%  whether the format supports native in-memory I/O, and a brief
151
%  description of the format.
152
%
153
%  The format of the RegisterNULLImage method is:
154
%
155
%      RegisterNULLImage(void)
156
%
157
*/
158
ModuleExport void RegisterNULLImage(void)
159
0
{
160
0
  MagickInfo
161
0
    *entry;
162
163
0
  entry=SetMagickInfo("NULL");
164
0
  entry->decoder=(DecoderHandler) ReadNULLImage;
165
0
  entry->encoder=(EncoderHandler) WriteNULLImage;
166
0
  entry->adjoin=False;
167
0
  entry->description="Constant image of uniform color";
168
0
  entry->module="NULL";
169
0
  entry->coder_class=PrimaryCoderClass;
170
0
  entry->extension_treatment=IgnoreExtensionTreatment;
171
0
  (void) RegisterMagickInfo(entry);
172
0
}
173

174
/*
175
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
176
%                                                                             %
177
%                                                                             %
178
%                                                                             %
179
%   U n r e g i s t e r N U L L I m a g e                                     %
180
%                                                                             %
181
%                                                                             %
182
%                                                                             %
183
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184
%
185
%  Method UnregisterNULLImage removes format registrations made by the
186
%  NULL module from the list of supported formats.
187
%
188
%  The format of the UnregisterNULLImage method is:
189
%
190
%      UnregisterNULLImage(void)
191
%
192
*/
193
ModuleExport void UnregisterNULLImage(void)
194
0
{
195
0
  (void) UnregisterMagickInfo("NULL");
196
0
}
197

198
/*
199
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
200
%                                                                             %
201
%                                                                             %
202
%                                                                             %
203
%   W r i t e N U L L I m a g e                                               %
204
%                                                                             %
205
%                                                                             %
206
%                                                                             %
207
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
208
%
209
%  Method WriteNULLImage writes no output at all. It is useful when specified
210
%  as an output format when profiling.
211
%
212
%  The format of the WriteNULLImage method is:
213
%
214
%      unsigned int WriteNULLImage(const ImageInfo *image_info,Image *image)
215
%
216
%  A description of each parameter follows.
217
%
218
%    o status: Always returns True.
219
%
220
%    o image_info: Specifies a pointer to a ImageInfo structure.
221
%
222
%    o image:  A pointer to an Image structure.
223
%
224
%
225
*/
226
static unsigned int WriteNULLImage(const ImageInfo *image_info,Image *image)
227
0
{
228
0
  assert(image_info != (const ImageInfo *) NULL);
229
0
  assert(image_info->signature == MagickSignature);
230
0
  assert(image != (Image *) NULL);
231
0
  assert(image->signature == MagickSignature);
232
0
  return(True);
233
0
}