Coverage Report

Created: 2025-08-12 07:37

/src/imagemagick/coders/mpr.c
Line
Count
Source (jump to first uncovered line)
1
/*
2
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3
%                                                                             %
4
%                                                                             %
5
%                                                                             %
6
%                            M   M  PPPP   RRRR                               %
7
%                            MM MM  P   P  R   R                              %
8
%                            M M M  PPPP   RRRR                               %
9
%                            M   M  P      R R                                %
10
%                            M   M  P      R  R                               %
11
%                                                                             %
12
%                                                                             %
13
%                  Read/Write the Magick Persistent Registry.                 %
14
%                                                                             %
15
%                              Software Design                                %
16
%                                   Cristy                                    %
17
%                                 July 1992                                   %
18
%                                                                             %
19
%                                                                             %
20
%  Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization         %
21
%  dedicated to making software imaging solutions freely available.           %
22
%                                                                             %
23
%  You may not use this file except in compliance with the License.  You may  %
24
%  obtain a copy of the License at                                            %
25
%                                                                             %
26
%    https://imagemagick.org/script/license.php                               %
27
%                                                                             %
28
%  Unless required by applicable law or agreed to in writing, software        %
29
%  distributed under the License is distributed on an "AS IS" BASIS,          %
30
%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
31
%  See the License for the specific language governing permissions and        %
32
%  limitations under the License.                                             %
33
%                                                                             %
34
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35
%
36
%
37
*/
38

39
/*
40
  Include declarations.
41
*/
42
#include "MagickCore/studio.h"
43
#include "MagickCore/blob.h"
44
#include "MagickCore/blob-private.h"
45
#include "MagickCore/exception.h"
46
#include "MagickCore/exception-private.h"
47
#include "MagickCore/magick.h"
48
#include "MagickCore/memory_.h"
49
#include "MagickCore/registry.h"
50
#include "MagickCore/quantum-private.h"
51
#include "MagickCore/static.h"
52
#include "MagickCore/string_.h"
53
#include "MagickCore/module.h"
54

55
/*
56
  Forward declarations.
57
*/
58
static MagickBooleanType
59
  WriteMPRImage(const ImageInfo *,Image *,ExceptionInfo *);
60

61
/*
62
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
63
%                                                                             %
64
%                                                                             %
65
%                                                                             %
66
%   R e a d M P R I m a g e                                                   %
67
%                                                                             %
68
%                                                                             %
69
%                                                                             %
70
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
71
%
72
%  ReadMPRImage() reads a Magick Persistent Registry image as a blob from
73
%  memory.  It allocates the memory necessary for the new Image structure and
74
%  returns a pointer to the new image.
75
%
76
%  The format of the ReadMPRImage method is:
77
%
78
%      Image *ReadMPRImage(const ImageInfo *image_info,
79
%        ExceptionInfo *exception)
80
%
81
%  A description of each parameter follows:
82
%
83
%    o image_info: the image info.
84
%
85
%    o exception: return any errors or warnings in this structure.
86
%
87
*/
88
static Image *ReadMPRImage(const ImageInfo *image_info,ExceptionInfo *exception)
89
0
{
90
0
  Image
91
0
    *image;
92
93
0
  assert(image_info != (const ImageInfo *) NULL);
94
0
  assert(image_info->signature == MagickCoreSignature);
95
0
  assert(exception != (ExceptionInfo *) NULL);
96
0
  assert(exception->signature == MagickCoreSignature);
97
0
  if (IsEventLogging() != MagickFalse)
98
0
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
99
0
      image_info->filename);
100
0
  image=(Image *) GetImageRegistry(ImageRegistryType,image_info->filename,
101
0
    exception);
102
0
  if (image == (Image *) NULL)
103
0
    {
104
0
      (void) ThrowMagickException(exception,GetMagickModule(),FileOpenError,
105
0
        "UnableToOpenFile","`%s'",image_info->filename);
106
0
      return(image);
107
0
    }
108
0
  (void) SyncImageSettings(image_info,image,exception);
109
0
  return(image);
110
0
}
111

112
/*
113
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
114
%                                                                             %
115
%                                                                             %
116
%                                                                             %
117
%   R e g i s t e r M P R I m a g e                                           %
118
%                                                                             %
119
%                                                                             %
120
%                                                                             %
121
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
122
%
123
%  RegisterMPRImage() adds attributes for the MPR image format to
124
%  the list of supported formats.  The attributes include the image format
125
%  tag, a method to read and/or write the format, whether the format
126
%  supports the saving of more than one frame to the same file or blob,
127
%  whether the format supports native in-memory I/O, and a brief
128
%  description of the format.
129
%
130
%  The format of the RegisterMPRImage method is:
131
%
132
%      size_t RegisterMPRImage(void)
133
%
134
*/
135
ModuleExport size_t RegisterMPRImage(void)
136
7
{
137
7
  MagickInfo
138
7
    *entry;
139
140
7
  entry=AcquireMagickInfo("MPR","MPR","Magick Persistent Registry");
141
7
  entry->decoder=(DecodeImageHandler *) ReadMPRImage;
142
7
  entry->encoder=(EncodeImageHandler *) WriteMPRImage;
143
7
  entry->flags^=CoderAdjoinFlag;
144
7
  entry->format_type=ImplicitFormatType;
145
7
  entry->flags|=CoderStealthFlag;
146
7
  (void) RegisterMagickInfo(entry);
147
7
  entry=AcquireMagickInfo("MPR","MPRI","Magick Persistent Registry");
148
7
  entry->decoder=(DecodeImageHandler *) ReadMPRImage;
149
7
  entry->encoder=(EncodeImageHandler *) WriteMPRImage;
150
7
  entry->flags^=CoderAdjoinFlag;
151
7
  entry->format_type=ImplicitFormatType;
152
7
  entry->flags|=CoderStealthFlag;
153
7
  (void) RegisterMagickInfo(entry);
154
7
  return(MagickImageCoderSignature);
155
7
}
156

157
/*
158
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
159
%                                                                             %
160
%                                                                             %
161
%                                                                             %
162
%   U n r e g i s t e r M P R I m a g e                                       %
163
%                                                                             %
164
%                                                                             %
165
%                                                                             %
166
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
167
%
168
%  UnregisterMPRImage() removes format registrations made by the
169
%  MPR module from the list of supported formats.
170
%
171
%  The format of the UnregisterMPRImage method is:
172
%
173
%      UnregisterMPRImage(void)
174
%
175
*/
176
ModuleExport void UnregisterMPRImage(void)
177
0
{
178
0
  (void) UnregisterMagickInfo("MPRI");
179
0
  (void) UnregisterMagickInfo("MPR");
180
0
}
181

182
/*
183
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
184
%                                                                             %
185
%                                                                             %
186
%                                                                             %
187
%   W r i t e M P R I m a g e                                                 %
188
%                                                                             %
189
%                                                                             %
190
%                                                                             %
191
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
192
%
193
%  WriteMPRImage() writes an image into the Magick Persistent Registry
194
%  image as a blob from memory.  It allocates the memory necessary for the
195
%  new Image structure and returns a pointer to the new image.
196
%
197
%  The format of the WriteMPRImage method is:
198
%
199
%      MagickBooleanType WriteMPRImage(const ImageInfo *image_info,
200
%        Image *image,ExceptionInfo *exception)
201
%
202
%  A description of each parameter follows.
203
%
204
%    o image_info: the image info.
205
%
206
%    o image:  The image.
207
%
208
%    o exception: return any errors or warnings in this structure.
209
%
210
*/
211
static MagickBooleanType WriteMPRImage(const ImageInfo *image_info,Image *image,
212
  ExceptionInfo *exception)
213
0
{
214
0
  MagickBooleanType
215
0
    status;
216
217
0
  assert(image_info != (const ImageInfo *) NULL);
218
0
  assert(image_info->signature == MagickCoreSignature);
219
0
  assert(image != (Image *) NULL);
220
0
  assert(image->signature == MagickCoreSignature);
221
0
  if (IsEventLogging() != MagickFalse)
222
0
    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
223
0
  magick_unreferenced(image_info);
224
0
  status=SetImageRegistry(ImageRegistryType,image->filename,image,exception);
225
0
  return(status);
226
0
}