mpr.c revision 3ed852eea50f9d4cd633efb8c2b054b8e33c253
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%                                John Cristy                                  %
17%                                 July 1992                                   %
18%                                                                             %
19%                                                                             %
20%  Copyright 1999-2009 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%    http://www.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 "magick/studio.h"
43#include "magick/blob.h"
44#include "magick/blob-private.h"
45#include "magick/exception.h"
46#include "magick/exception-private.h"
47#include "magick/magick.h"
48#include "magick/memory_.h"
49#include "magick/registry.h"
50#include "magick/quantum-private.h"
51#include "magick/static.h"
52#include "magick/string_.h"
53#include "magick/module.h"
54
55/*
56  Forward declarations.
57*/
58static MagickBooleanType
59  WriteMPRImage(const ImageInfo *,Image *);
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*/
88static Image *ReadMPRImage(const ImageInfo *image_info,ExceptionInfo *exception)
89{
90  Image
91    *image;
92
93  assert(image_info != (const ImageInfo *) NULL);
94  assert(image_info->signature == MagickSignature);
95  if (image_info->debug != MagickFalse)
96    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
97      image_info->filename);
98  assert(exception != (ExceptionInfo *) NULL);
99  assert(exception->signature == MagickSignature);
100  image=(Image *) GetImageRegistry(ImageRegistryType,image_info->filename,
101    exception);
102  return(image);
103}
104
105/*
106%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
107%                                                                             %
108%                                                                             %
109%                                                                             %
110%   R e g i s t e r M P R I m a g e                                           %
111%                                                                             %
112%                                                                             %
113%                                                                             %
114%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115%
116%  RegisterMPRImage() adds attributes for the MPR image format to
117%  the list of supported formats.  The attributes include the image format
118%  tag, a method to read and/or write the format, whether the format
119%  supports the saving of more than one frame to the same file or blob,
120%  whether the format supports native in-memory I/O, and a brief
121%  description of the format.
122%
123%  The format of the RegisterMPRImage method is:
124%
125%      unsigned long RegisterMPRImage(void)
126%
127*/
128ModuleExport unsigned long RegisterMPRImage(void)
129{
130  MagickInfo
131    *entry;
132
133  entry=SetMagickInfo("MPR");
134  entry->decoder=(DecodeImageHandler *) ReadMPRImage;
135  entry->encoder=(EncodeImageHandler *) WriteMPRImage;
136  entry->adjoin=MagickFalse;
137  entry->stealth=MagickTrue;
138  entry->description=ConstantString("Magick Persistent Registry");
139  entry->module=ConstantString("MPR");
140  (void) RegisterMagickInfo(entry);
141  entry=SetMagickInfo("MPRI");
142  entry->decoder=(DecodeImageHandler *) ReadMPRImage;
143  entry->encoder=(EncodeImageHandler *) WriteMPRImage;
144  entry->stealth=MagickTrue;
145  entry->adjoin=MagickFalse;
146  entry->stealth=MagickTrue;
147  entry->description=ConstantString("Magick Persistent Registry");
148  entry->module=ConstantString("MPRI");
149  (void) RegisterMagickInfo(entry);
150  return(MagickImageCoderSignature);
151}
152
153/*
154%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
155%                                                                             %
156%                                                                             %
157%                                                                             %
158%   U n r e g i s t e r M P R I m a g e                                       %
159%                                                                             %
160%                                                                             %
161%                                                                             %
162%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
163%
164%  UnregisterMPRImage() removes format registrations made by the
165%  MPR module from the list of supported formats.
166%
167%  The format of the UnregisterMPRImage method is:
168%
169%      UnregisterMPRImage(void)
170%
171*/
172ModuleExport void UnregisterMPRImage(void)
173{
174  (void) UnregisterMagickInfo("MPRI");
175  (void) UnregisterMagickInfo("MPR");
176}
177
178/*
179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
180%                                                                             %
181%                                                                             %
182%                                                                             %
183%   W r i t e M P R I m a g e                                                 %
184%                                                                             %
185%                                                                             %
186%                                                                             %
187%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
188%
189%  WriteMPRImage() writes an image into the Magick Persistent Registry
190%  image as a blob from memory.  It allocates the memory necessary for the
191%  new Image structure and returns a pointer to the new image.
192%
193%  The format of the WriteMPRImage method is:
194%
195%      MagickBooleanType WriteMPRImage(const ImageInfo *image_info,Image *image)
196%
197%  A description of each parameter follows.
198%
199%    o image_info: the image info.
200%
201%    o image:  The image.
202%
203*/
204static MagickBooleanType WriteMPRImage(const ImageInfo *image_info,Image *image)
205{
206  MagickBooleanType
207    status;
208
209  assert(image_info != (const ImageInfo *) NULL);
210  assert(image_info->signature == MagickSignature);
211  assert(image != (Image *) NULL);
212  assert(image->signature == MagickSignature);
213  if (image->debug != MagickFalse)
214    (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
215  status=SetImageRegistry(ImageRegistryType,image->filename,image,
216    &image->exception);
217  return(status);
218}
219