Coverage Report

Created: 2026-06-16 07:20

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/graphicsmagick/coders/xc.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
%                               X   X   CCCC                                  %
15
%                                X X   C                                      %
16
%                                 X    C                                      %
17
%                                X X   C                                      %
18
%                               X   X   CCCC                                  %
19
%                                                                             %
20
%                                                                             %
21
%                        Read Constant Color Image.                           %
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/composite.h"
44
#include "magick/magick.h"
45
#include "magick/pixel_cache.h"
46
#include "magick/utility.h"
47
#include "magick/static.h"
48

49
/*
50
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
51
%                                                                             %
52
%                                                                             %
53
%                                                                             %
54
%   R e a d X C I m a g e                                                     %
55
%                                                                             %
56
%                                                                             %
57
%                                                                             %
58
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
59
%
60
%  Method ReadXCImage creates a constant image and initializes it to the
61
%  X server color as specified by the filename.  It allocates the memory
62
%  necessary for the new Image structure and returns a pointer to the new
63
%  image.
64
%
65
%  The format of the ReadXCImage method is:
66
%
67
%      Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
68
%
69
%  A description of each parameter follows:
70
%
71
%    o image:  Method ReadXCImage returns a pointer to the image after
72
%      creating it. A null image is returned if there is a memory shortage
73
%      or if the image cannot be read.
74
%
75
%    o image_info: Specifies a pointer to a ImageInfo structure.
76
%
77
%    o exception: return any errors or warnings in this structure.
78
%
79
%
80
*/
81
static Image *ReadXCImage(const ImageInfo *image_info,ExceptionInfo *exception)
82
0
{
83
0
  Image
84
0
    *image;
85
86
0
  MagickPassFail
87
0
    status;
88
89
  /*
90
    Initialize Image structure.
91
  */
92
0
  assert(image_info != (const ImageInfo *) NULL);
93
0
  assert(image_info->signature == MagickSignature);
94
0
  assert(exception != (ExceptionInfo *) NULL);
95
0
  assert(exception->signature == MagickSignature);
96
0
  image=AllocateImage(image_info);
97
0
  if (image->columns == 0)
98
0
    image->columns=1;
99
0
  if (image->rows == 0)
100
0
    image->rows=1;
101
0
  if (CheckImagePixelLimits(image, exception) != MagickPass)
102
0
    ThrowReaderException(ResourceLimitError,ImagePixelLimitExceeded,image);
103
0
  (void) strlcpy(image->filename,image_info->filename,MaxTextExtent);
104
0
  status=QueryColorDatabase((char *) image_info->filename,
105
0
    &image->background_color,exception);
106
0
  if (status == MagickFail)
107
0
    {
108
      /* Promote warning to error */
109
0
      exception->severity = OptionError;
110
0
      DestroyImage(image);
111
0
      return ((Image *) NULL);
112
0
    }
113
  /*
114
    Create a colormap if image is not DirectClass type.
115
  */
116
0
  if ((TrueColorType != image_info->type) &&
117
0
      (TrueColorMatteType != image_info->type))
118
0
    {
119
0
      if (!AllocateImageColormap(image,1))
120
0
        ThrowReaderException(ResourceLimitError,MemoryAllocationFailed,image);
121
0
      image->colormap[0]=image->background_color;
122
0
    }
123
  /*
124
    Initialize image pixels to the value of image->background_color
125
  */
126
0
  status=SetImageEx(image,image->background_color.opacity,exception);
127
0
  if (status == MagickFail)
128
0
    {
129
0
      DestroyImage(image);
130
0
      image=(Image *) NULL;
131
0
    }
132
0
  else
133
0
    {
134
0
      StopTimer(&image->timer);
135
0
    }
136
137
0
  return image;
138
0
}
139

140
/*
141
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142
%                                                                             %
143
%                                                                             %
144
%                                                                             %
145
%   R e g i s t e r X C I m a g e                                             %
146
%                                                                             %
147
%                                                                             %
148
%                                                                             %
149
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
150
%
151
%  Method RegisterXCImage adds attributes for the XC image format to
152
%  the list of supported formats.  The attributes include the image format
153
%  tag, a method to read and/or write the format, whether the format
154
%  supports the saving of more than one frame to the same file or blob,
155
%  whether the format supports native in-memory I/O, and a brief
156
%  description of the format.
157
%
158
%  The format of the RegisterXCImage method is:
159
%
160
%      RegisterXCImage(void)
161
%
162
*/
163
ModuleExport void RegisterXCImage(void)
164
0
{
165
0
  MagickInfo
166
0
    *entry;
167
168
0
  entry=SetMagickInfo("XC");
169
0
  entry->decoder=(DecoderHandler) ReadXCImage;
170
0
  entry->adjoin=False;
171
0
  entry->raw=True;
172
0
  entry->description="Constant image uniform color";
173
0
  entry->module="XC";
174
0
  entry->coder_class=PrimaryCoderClass;
175
0
  entry->extension_treatment=IgnoreExtensionTreatment;
176
0
  (void) RegisterMagickInfo(entry);
177
0
}
178

179
/*
180
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
181
%                                                                             %
182
%                                                                             %
183
%                                                                             %
184
%   U n r e g i s t e r X C I m a g e                                         %
185
%                                                                             %
186
%                                                                             %
187
%                                                                             %
188
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
189
%
190
%  Method UnregisterXCImage removes format registrations made by the
191
%  XC module from the list of supported formats.
192
%
193
%  The format of the UnregisterXCImage method is:
194
%
195
%      UnregisterXCImage(void)
196
%
197
*/
198
ModuleExport void UnregisterXCImage(void)
199
0
{
200
0
  (void) UnregisterMagickInfo("XC");
201
0
}