2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 % CCCC LLLLL IIIII P %
13 % Write Clip Mask To MIFF File. %
20 % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
21 % dedicated to making software imaging solutions freely available. %
23 % You may not use this file except in compliance with the License. You may %
24 % obtain a copy of the License at %
26 % http://www.imagemagick.org/script/license.php %
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. %
34 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
42 #include "MagickCore/studio.h"
43 #include "MagickCore/attribute.h"
44 #include "MagickCore/blob.h"
45 #include "MagickCore/blob-private.h"
46 #include "MagickCore/constitute.h"
47 #include "MagickCore/exception.h"
48 #include "MagickCore/exception-private.h"
49 #include "MagickCore/list.h"
50 #include "MagickCore/magick.h"
51 #include "MagickCore/memory_.h"
52 #include "MagickCore/monitor.h"
53 #include "MagickCore/monitor-private.h"
54 #include "MagickCore/quantum-private.h"
55 #include "MagickCore/static.h"
56 #include "MagickCore/string_.h"
57 #include "MagickCore/module.h"
62 static MagickBooleanType
63 WriteCLIPImage(const ImageInfo *,Image *,ExceptionInfo *);
66 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
70 % R e a d C L I P I m a g e %
74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
76 % ReadCLIPImage returns the rendered clip path associated with the image.
78 % The format of the ReadCLIPImage method is:
80 % Image *ReadCLIPImage(const ImageInfo *image_info,
81 % ExceptionInfo *exception)
83 % A description of each parameter follows:
85 % o image_info: the image info.
87 % o exception: return any errors or warnings in this structure.
90 static Image *ReadCLIPImage(const ImageInfo *image_info,
91 ExceptionInfo *exception)
100 Initialize Image structure.
102 assert(image_info != (const ImageInfo *) NULL);
103 assert(image_info->signature == MagickSignature);
104 if (image_info->debug != MagickFalse)
105 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
106 image_info->filename);
107 assert(exception != (ExceptionInfo *) NULL);
108 assert(exception->signature == MagickSignature);
109 read_info=CloneImageInfo(image_info);
110 SetImageInfoBlob(read_info,(void *) NULL,0);
111 (void) CopyMagickString(read_info->magick,"MIFF",MagickPathExtent);
112 image=ReadImage(read_info,exception);
113 read_info=DestroyImageInfo(read_info);
114 if (image != (Image *) NULL)
119 (void) ClipImage(image,exception);
120 clip_image=GetImageMask(image,exception);
121 if (clip_image == (Image *) NULL)
122 ThrowReaderException(CoderError,"ImageDoesNotHaveAClipMask");
123 image=DestroyImage(image);
126 return(GetFirstImageInList(image));
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
134 % R e g i s t e r C L I P I m a g e %
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
140 % RegisterCLIPImage() adds attributes for the CLIP image format to
141 % the list of supported formats. The attributes include the image format
142 % tag, a method to read and/or write the format, whether the format
143 % supports the saving of more than one frame to the same file or blob,
144 % whether the format supports native in-memory I/O, and a brief
145 % description of the format.
147 % The format of the RegisterCLIPImage method is:
149 % size_t RegisterCLIPImage(void)
152 ModuleExport size_t RegisterCLIPImage(void)
157 entry=AcquireMagickInfo("CLIP","CLIP","Image Clip Mask");
158 entry->decoder=(DecodeImageHandler *) ReadCLIPImage;
159 entry->encoder=(EncodeImageHandler *) WriteCLIPImage;
160 (void) RegisterMagickInfo(entry);
161 return(MagickImageCoderSignature);
165 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
169 % U n r e g i s t e r C L I P I m a g e %
173 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
175 % UnregisterCLIPImage() removes format registrations made by the
176 % CLIP module from the list of supported formats.
178 % The format of the UnregisterCLIPImage method is:
180 % UnregisterCLIPImage(void)
183 ModuleExport void UnregisterCLIPImage(void)
185 (void) UnregisterMagickInfo("CLIP");
189 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
193 % W r i t e C L I P I m a g e %
197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
199 % WriteCLIPImage() writes an image of clip bytes to a file. It consists of
200 % data from the clip mask of the image.
202 % The format of the WriteCLIPImage method is:
204 % MagickBooleanType WriteCLIPImage(const ImageInfo *image_info,
205 % Image *image,ExceptionInfo *exception)
207 % A description of each parameter follows.
209 % o image_info: the image info.
211 % o image: The image.
213 % o exception: return any errors or warnings in this structure.
216 static MagickBooleanType WriteCLIPImage(const ImageInfo *image_info,
217 Image *image,ExceptionInfo *exception)
228 if (image->read_mask == MagickFalse)
229 (void) ClipImage(image,exception);
230 if (image->read_mask == MagickFalse)
231 ThrowWriterException(CoderError,"ImageDoesNotHaveAClipMask");
232 clip_image=GetImageMask(image,exception);
233 if (clip_image == (Image *) NULL)
235 (void) CopyMagickString(clip_image->filename,image->filename,MagickPathExtent);
236 write_info=CloneImageInfo(image_info);
237 (void) SetImageInfo(write_info,1,exception);
238 if (LocaleCompare(write_info->magick,"CLIP") == 0)
239 (void) FormatLocaleString(clip_image->filename,MagickPathExtent,"miff:%s",
240 write_info->filename);
241 status=WriteImage(write_info,clip_image,exception);
242 clip_image=DestroyImage(clip_image);
243 write_info=DestroyImageInfo(write_info);